Package org.geotools.graph.structure

Examples of org.geotools.graph.structure.GraphVisitor


    Node[] ends = buildNoBifurcations(builder, nnodes-1);
    final Node n = builder.buildNode();
    final ArrayList bif = new ArrayList();
   
    builder.getGraph().visitNodes(
      new GraphVisitor() {
       public int visit(Graphable component) {
          if (component.getID() == bifurcation) {
            bif.add(component);
          }
         
View Full Code Here


   
    m_traversal.init();
   
    //reset edge visited flags
    m_graph.visitNodes(
      new GraphVisitor() {
        public int visit(Graphable component) {
          component.setVisited(false);
          return 0;
        }
      }
    );
   
    //perform the traversal
    m_traversal.traverse();
   
    //if all nodes of degree 2 have been visited, we are finished
    if (m_ndegree2 > 0) {
   
      //if there are still nodes of degree 2 that havent been visited, it means
      // that the graph has a cycle and that the remaining degree 2 nodes are
      // internal to the cycle, so the strategy for the second stage is to
      // find all unvisited nodes of degree 2 that are not visited and start
      // a no bifurcation traversal from them
      Iterator sources = m_graph.queryNodes(
        new GraphVisitor() {
          public int visit(Graphable component) {
            Node node = (Node)component;
            if (!node.isVisited() && node.getDegree() == 2) {
              //check for adjacent node of degree > 2
              for (Iterator itr = node.getRelated(); itr.hasNext(); ) {
                Node rel = (Node)itr.next();
                if (rel.getDegree() > 2) return(Graph.PASS_AND_CONTINUE);
              }
            }
            return(Graph.FAIL_QUERY);
          }
        }
      ).iterator();
     
      //if the query returned no nodes, it means that all the cycle is
      // disconnected from the rest of graph, so just pick any node of degree 2
      if (!sources.hasNext()) {
        sources = m_graph.queryNodes(
          new GraphVisitor() {
            public int visit(Graphable component) {
              if (!component.isVisited()) return(Graph.PASS_AND_STOP);
              return(Graph.FAIL_QUERY);
            }
          }
View Full Code Here

    //ensure correct graph structure
    assertTrue(built.getEdges().size() == n);
    assertTrue(built.getNodes().size() == n+1);
   
    //ensure coordinates
    GraphVisitor visitor = new GraphVisitor() {
      public int visit(Graphable component) {
        Edge e = (Edge)component;
        XYNode a = (XYNode)e.getNodeA();
        XYNode b = (XYNode)e.getNodeB();
       
View Full Code Here

    assertTrue(built.getNodes().size() == n+1);
   
    assertTrue(built.getNodesOfDegree(2).size() == n+1);
   
    //ensure coordinates
    GraphVisitor visitor = new GraphVisitor() {
      public int visit(Graphable component) {
        Edge e = (Edge)component;
        XYNode a = (XYNode)e.getNodeA();
        XYNode b = (XYNode)e.getNodeB();
       
View Full Code Here

    //ensure every node in the original graph is in the new graph
    final Graph g = (Graph)partitions.get(0);
    assertTrue(g.getNodes().size() == builder().getGraph().getNodes().size());
    assertTrue(g.getEdges().size() == builder().getGraph().getEdges().size());
   
    GraphVisitor visitor = new GraphVisitor() {
      public int visit(Graphable component) {
        assertTrue(g.getNodes().contains(component));
        return 0;
      }
    };
View Full Code Here

    assertTrue(left.getNodes().size() == Math.pow(2, k)-1);
    assertTrue(left.getEdges().size() == Math.pow(2, k)-2);
    assertTrue(right.getNodes().size() == Math.pow(2, k)-1);
    assertTrue(right.getEdges().size() == Math.pow(2, k)-2);
   
    GraphVisitor visitor = new GraphVisitor() {
      public int visit(Graphable component) {
        assertTrue(component.getObject().toString().startsWith("0.0"));
        return 0;
      }
    };
    left.visitNodes(visitor);
   
    visitor = new GraphVisitor() {
      public int visit(Graphable component) {
        assertTrue(component.getObject().toString().startsWith("0.1"));
        return 0;
      }
    };
View Full Code Here

      //ensure same number of nodes and edges
      assertTrue(before.getNodes().size() == after.getNodes().size());
      assertTrue(before.getEdges().size() == after.getEdges().size());
     
      //ensure same graph structure
      GraphVisitor visitor = new GraphVisitor() {
        public int visit(Graphable component) {
          Edge e = (Edge)component;
         
          assertTrue(e.getNodeA().getID() == e.getID());
          assertTrue(e.getNodeB().getID() == e.getID()+1);
         
          return(0);
        }
      };
      after.visitEdges(visitor);
     
      visitor = new GraphVisitor() {
        public int visit(Graphable component) {
          Node n = (Node)component;
         
          if (n.getDegree() == 1) {
            assertTrue(n.getID() == 0 || n.getID() == nnodes-1)
View Full Code Here

      //ensure same number of nodes and edges
      assertTrue(before.getNodes().size() == after.getNodes().size());
      assertTrue(before.getEdges().size() == after.getEdges().size());
     
      //ensure same structure
      GraphVisitor visitor = new GraphVisitor() {
        public int visit(Graphable component) {
          Node n = (Node)component;
          String id = (String)n.getObject();
         
          assertTrue(obj2node.get(id) != null);
View Full Code Here

     
      //ensure same number of nodes and edges
      assertTrue(before.getNodes().size() == after.getNodes().size());
      assertTrue(before.getEdges().size() == after.getEdges().size());
     
      GraphVisitor visitor = new GraphVisitor() {
        public int visit(Graphable component) {
          Node n = (Node)component;
          if (n.getID() == 0 || n.getID() == nnodes-1)
            assertTrue(n.getDegree() == 0);
          else if (n.getID() == 1 || n.getID() == nnodes-2)
View Full Code Here

   
    //ensure correct graph structure
    assertTrue(built.getEdges().size() == n);
    assertTrue(built.getNodes().size() == n+1);
   
    GraphVisitor visitor = new GraphVisitor() {
      public int visit(Graphable component) {
        DirectedNode node = (DirectedNode)component;
        Coordinate c = (Coordinate)node.getObject();
       
        if (node.getDegree() == 1) {
          assertTrue(
            (node.getID()==0&&node.getInDegree()==0&&node.getOutDegree()==1)||
            (node.getID()==n&&node.getInDegree()==1&&node.getOutDegree()==0)
          );
        }
        else {
          assertTrue(node.getInDegree() == 1 && node.getOutDegree() == 1);
        }
       
        assertTrue(
          c.x == base.x + node.getID() && c.y == base.y + node.getID()
        );
        return(0);
      }
    };
    built.visitNodes(visitor);
   
    //ensure correct edge direction
    visitor = new GraphVisitor() {
      public int visit(Graphable component) {
        DirectedEdge e = (DirectedEdge)component;
        Coordinate c0 = (Coordinate)e.getInNode().getObject();
        Coordinate c1 = (Coordinate)e.getOutNode().getObject();
        LineSegment ls = (LineSegment)e.getObject();
View Full Code Here

TOP

Related Classes of org.geotools.graph.structure.GraphVisitor

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.