Package org.geotools.graph.structure

Examples of org.geotools.graph.structure.Graph


        }
        return ret;
    }
   
    private static void showGraph(Collection nodes, Collection edges, int phase){
        Graph g = new BasicGraph(nodes, edges);
        javax.swing.JFrame frame = new javax.swing.JFrame();
        GraphViewer viewer = new GraphViewer();
        viewer.setGraph(g);
        frame.getContentPane().add(viewer);
        frame.setDefaultCloseOperation(javax.swing.JFrame.EXIT_ON_CLOSE);
View Full Code Here


    assertTrue(n1.getDegree() == 2);
  }
   
 
  public void test_getGraph() {
    Graph graph = m_builder.getGraph();
    assertTrue(graph instanceof DirectedGraph);
  }
View Full Code Here

        for (int i = 0; i < nodes.length; i++){
            System.out.println("triangulating node " + i);
            triangleList = insertNode(tempNodes[i], triangleList);
        }

        Graph g = triangleListToGraph(triangleList);
               
        return g; 
    }
View Full Code Here

            if (!(nodesVisited.contains(next))){
                Vector componentNodes = new Vector();
                Vector componentEdges = new Vector();
                expandComponent(next, edges, componentNodes, componentEdges);
                nodesVisited.addAll(componentNodes);
                Graph component = new BasicGraph(componentNodes, componentEdges);
                components.add(component);
            }
        }
       
        return components;
View Full Code Here

          new Coordinate(base.x + i, base.y + i)
        )
      )
    }
    generator().generate();
    Graph built = generator().getGraph();
   
    //ensure correct graph structure
    assertTrue(built.getEdges().size() == n);
    assertTrue(built.getNodes().size() == n+1);
   
    assertTrue(built.getNodesOfDegree(1).size() == 2);
    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();
       
        //coordinats should be a distance of sqrt(2)
        assertTrue(
          Math.abs(a.getCoordinate().x - b.getCoordinate().x) == 1 &&
          Math.abs(a.getCoordinate().y - b.getCoordinate().y) == 1
        );
       
//        assertTrue(
//            Math.abs(a.getX() - b.getX()) == 1
//         && Math.abs(a.getY() - b.getY()) == 1
//        );
        return(0);
      }
    };
    built.visitEdges(visitor);
  }
View Full Code Here

    generator().add(
      new LineSegment(new Coordinate(base.x + n, base.y + n), base)
    );
   
    generator().generate();
    Graph built = generator().getGraph();
   
    assertTrue(built.getEdges().size() == n+1);
    assertTrue(built.getNodes().size() == n+1);
   
    //all nodes should be of degree 2
    assertTrue(
      built.getNodesOfDegree(2).size() == built.getNodes().size()
    );
   
    //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();
       
        if (b.getCoordinate().equals(base)) {
          assertTrue(a.getCoordinate().equals(new Coordinate(n,n)))
        }
        else {
         assertTrue(
            Math.abs(a.getCoordinate().x - b.getCoordinate().x) == 1 &&
            Math.abs(a.getCoordinate().y - b.getCoordinate().y) == 1
          );
        }
   
        return(0);
      }
    };
    built.visitEdges(visitor);
  }
View Full Code Here

        LineString lineString3 = gf.createLineString(new Coordinate[] { c7, c4 });
        gen.add(lineString);
        gen.add(lineString2);
        gen.add(lineString3);

        Graph graph = gen.getGraph();
        Collection graphNodes = graph.getNodes();
        assertEquals(5, graphNodes.size());
        Collection<Coordinate> graphNodeCoordinates = getCoordinates(graphNodes);
        assertTrue(graphNodeCoordinates.contains(c2));
        assertFalse("c6 should be snapped to c2", graphNodeCoordinates.contains(c6));
        assertTrue("c7 should not have been snapped to c2 - distance bigger than tolerance", graphNodeCoordinates.contains(c7)); //
        assertEquals(3, graph.getEdges().size());
    }
View Full Code Here

     
      serializer().setProperty(SerializedReaderWriter.FILENAME, victim.getAbsolutePath());
     
      serializer().write(builder().getGraph());
     
      Graph before = builder().getGraph();
      Graph after = serializer().read();
     
      //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) {
          DirectedEdge e = (DirectedEdge)component;
         
          assertTrue(e.getInNode().getID() == e.getID());
          assertTrue(e.getOutNode().getID() == e.getID()+1);
         
          return(0);
        }
      };
      after.visitEdges(visitor);
     
      visitor = new GraphVisitor() {
        public int visit(Graphable component) {
          DirectedNode n = (DirectedNode)component;
         
          if (n.getDegree() == 1) {
            assertTrue(n.getID() == 0 || n.getID() == nnodes-1)
          }
          else {
            assertTrue(n.getDegree() == 2);
           
            Edge in = (Edge)n.getInEdges().get(0);
            Edge out = (Edge)n.getOutEdges().get(0);
           
            assertTrue(
              (in.getID() == n.getID()-1 && out.getID() == n.getID())
            );
           
          }
         
          return(0);
        }
      };
      after.visitNodes(visitor);
     
    }
    catch(Exception e) {
      e.printStackTrace();
      assertTrue(false)
View Full Code Here

      serializer().setProperty(SerializedReaderWriter.FILENAME, victim.getAbsolutePath());
     
      serializer().write(builder().getGraph());
     
      Graph before = builder().getGraph();
      Graph after = serializer().read();
     
      //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) {
          DirectedNode n = (DirectedNode)component;
          String id = (String)n.getObject();
         
          assertTrue(obj2node.get(id) != null);
         
          StringTokenizer st = new StringTokenizer(id, ".");
         
          if (st.countTokens() == 1) {
            //root
            assertTrue(n.getDegree() == 2);
           
            Node n0 = ((Edge)n.getEdges().get(0)).getOtherNode(n);
            Node n1 = ((Edge)n.getEdges().get(1)).getOtherNode(n);
           
            assertTrue(
              n0.getObject().equals("0.0") && n1.getObject().equals("0.1")
           || n0.getObject().equals("0.1") && n1.getObject().equals("0.0")
            );
          }
          else if (st.countTokens() == k+1) {
            //leaf
            assertTrue(n.getDegree() == 1);
           
            Node parent = ((DirectedEdge)n.getInEdges().get(0)).getInNode();
            String parentid = (String)parent.getObject();
           
            assertTrue(parentid.equals(id.substring(0, id.length()-2)));  
          }
          else {
            //internal
            assertTrue(n.getDegree() == 3);
           
            String parent = ((DirectedEdge)n.getInEdges().get(0)).getInNode()
                              .getObject().toString();
            String c0 = ((DirectedEdge)n.getOutEdges().get(0)).getOutNode()
                              .getObject().toString();                     
            String c1 = ((DirectedEdge)n.getOutEdges().get(1)).getOutNode()
                              .getObject().toString();                     
                                             
            String parentid = id.substring(0, id.length()-2);
           
            assertTrue(
             parent.equals(parentid) && c0.equals(id+".0") && c1.equals(id+".1")
          || parent.equals(parentid) && c1.equals(id+".0") && c0.equals(id+".1")
            );
         
         
          return(0);
        }
      };
      after.visitNodes(visitor);
     
    }
    catch(Exception e) {
      e.printStackTrace();
      assertTrue(false)
View Full Code Here

     
      serializer().setProperty(SerializedReaderWriter.FILENAME, victim.getAbsolutePath());
     
      serializer().write(builder().getGraph());
     
      Graph before = builder().getGraph();
      Graph after = serializer().read();
     
      //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)
            assertTrue(n.getDegree() == 1);
          else assertTrue(n.getDegree() == 2);
          
          return(0);
        }
      };
      after.visitNodes(visitor);
    }
    catch(Exception e) {
      e.printStackTrace();
      assertTrue(false);
    }
View Full Code Here

TOP

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

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.