Package org.geotools.graph.structure.basic

Examples of org.geotools.graph.structure.basic.BasicGraph


            allShortEdges.addAll(shortEdges);
            allOtherEdges.addAll(otherEdges);
        }
       
        //for the poster
        Graph gp = new BasicGraph(nodes, edges);
        javax.swing.JFrame frame = new javax.swing.JFrame();
        GraphViewer viewer = new GraphViewer();
        viewer.setLongEdges(allLongEdges);
        viewer.setShortEdges(allShortEdges);
        viewer.setOtherEdges(allOtherEdges);
        viewer.setColorEdges(true);
        viewer.setGraph(gp);
        frame.getContentPane().add(viewer);
        frame.setDefaultCloseOperation(javax.swing.JFrame.EXIT_ON_CLOSE);
        frame.setSize(new java.awt.Dimension(800, 800));
        frame.setTitle("Assigned edge categories");
        frame.setVisible(true);
       
        //Phase I
        Iterator nodeIt3 = nodes.iterator();
        while (nodeIt3.hasNext()){
            DelaunayNode next = (DelaunayNode) nodeIt3.next();
            AutoClustData acd = (AutoClustData) map.get(next);
            List shortEdges = acd.getShortEdges();
            List longEdges = acd.getLongEdges();
            edges.removeAll(shortEdges);
            LOGGER.finer("removed " + shortEdges);
            edges.removeAll(longEdges);
            LOGGER.finer("removed " + longEdges);
        }
       
        LOGGER.fine("End of phase one and ");
        LOGGER.fine("Nodes are " + nodes);
        LOGGER.fine("Edges are " + edges);               
        showGraph(nodes, edges, 1);       
        Vector connectedComponents = AutoClustUtils.findConnectedComponents(nodes, edges);
       
        //Phase II
        Iterator nodeIt4 = nodes.iterator();
        while (nodeIt4.hasNext()){
            DelaunayNode next = (DelaunayNode) nodeIt4.next();
            AutoClustData acd = (AutoClustData) map.get(next);
            List shortEdges = acd.getShortEdges();
            if (!(shortEdges.isEmpty())){
                Vector shortlyConnectedComponents = new Vector();
                Iterator shortIt = shortEdges.iterator();
                while (shortIt.hasNext()){
                    Edge nextEdge = (Edge) shortIt.next();
                    Node other = nextEdge.getOtherNode(next);
                    Graph g = getMyComponent(other, connectedComponents);
                    if (!(shortlyConnectedComponents.contains(g))){
                        shortlyConnectedComponents.add(g);
                    }
                }
                Graph cv = null;
                if (shortlyConnectedComponents.size() > 1){
                    Iterator sccIt = shortlyConnectedComponents.iterator();
                    int maxSize = 0;
                    while (sccIt.hasNext()){
                        Graph nextGraph = (Graph) sccIt.next();
                        int size = nextGraph.getNodes().size();
                        if (size > maxSize){
                            maxSize = size;
                            cv = nextGraph;
                        }
                    }
                } else {
                    cv = (Graph) shortlyConnectedComponents.get(0);
                }
                Iterator shortIt2 = shortEdges.iterator();
                while (shortIt2.hasNext()){
                    Edge nextEdge = (Edge) shortIt2.next();
                    Node other = nextEdge.getOtherNode(next);
                    if (cv.equals(getMyComponent(other, shortlyConnectedComponents))){
                        edges.add(nextEdge);
                    }
                }
            } //end if shortEdges isn't empty
            Graph gr = getMyComponent(next, connectedComponents);
            if (gr.getNodes().size() == 1){
                Vector shortlyConnectedComponents = new Vector();
                Iterator shortIt = shortEdges.iterator();
                while (shortIt.hasNext()){
                    Edge nextEdge = (Edge) shortIt.next();
                    Node other = nextEdge.getOtherNode(next);
                    Graph g = getMyComponent(other, connectedComponents);
                    if (!(shortlyConnectedComponents.contains(g))){
                        shortlyConnectedComponents.add(g);
                    }
                }
                if (shortlyConnectedComponents.size() == 1){
                    edges.addAll(shortEdges);
                }
            }
        } //end nodeIt4 while loop.
       
        LOGGER.fine("End of phase two and ");
        LOGGER.fine("Nodes are " + nodes);
        LOGGER.fine("Edges are " + edges);  
        showGraph(nodes, edges, 2);
        connectedComponents = AutoClustUtils.findConnectedComponents(nodes, edges);
       
        //Phase III
        Iterator nodeIt5 = nodes.iterator();
        while (nodeIt5.hasNext()){
            DelaunayNode next = (DelaunayNode) nodeIt5.next();
            Vector edgesWithinTwo = new Vector();
            List adjacentEdges = AutoClustUtils.findAdjacentEdges(next, edges); //yes, next.getEdges() could work, but there's no guarantee that next's edge list is current anymore
            edgesWithinTwo.addAll(adjacentEdges);
            Iterator adjacentIt = adjacentEdges.iterator();
            while (adjacentIt.hasNext()){
                Edge nextEdge = (Edge) adjacentIt.next();
                Node other = nextEdge.getOtherNode(next);
                List adjacentToOther = AutoClustUtils.findAdjacentEdges(other, edges)//yes, other.getEdges() could work, but there's no guarantee that other's edge list is current anymore
                Iterator atoIt = adjacentToOther.iterator();
                while (atoIt.hasNext()){
                    Edge nextEdge2 = (Edge) atoIt.next();
                    if (!(edgesWithinTwo.contains(nextEdge2))){
                        edgesWithinTwo.add(nextEdge2);
                    }
                }
            }
            double totalLength = 0;
            Iterator ewtIt = edgesWithinTwo.iterator();
            while (ewtIt.hasNext()){
                totalLength = totalLength + ((DelaunayEdge) ewtIt.next()).getEuclideanDistance();
            }
            double local2Mean = totalLength/edgesWithinTwo.size();
           
            Iterator ewtIt2 = edgesWithinTwo.iterator();
            while (ewtIt2.hasNext()){
                DelaunayEdge dEdge = (DelaunayEdge) ewtIt2.next();
                if (dEdge.getEuclideanDistance() > (local2Mean + meanStDev)){
                    edges.remove(dEdge);
                }
            }                       
        } //end nodeIt5 loop
       
        LOGGER.fine("End of phase three and ");
        LOGGER.fine("Nodes are " + nodes);
        LOGGER.fine("Edges are " + edges);   
        showGraph(nodes, edges, 3);
        connectedComponents = AutoClustUtils.findConnectedComponents(nodes, edges);
       
        return new BasicGraph(nodes, edges);
    }
View Full Code Here


        }
        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

                clusterNodes.addAll(newNodes);
                clusterEdges.addAll(newEdges);
            }           
        }  //end while (nodeIt.hasNext())
       
        return new BasicGraph(clusterNodes, clusterEdges);
       
    }
View Full Code Here

                    }
                }
            }
        }
       
        return new BasicGraph(nodeList, edgeList);       
    }
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

   * Creates the underlying graph object.
   *
   * @return A Graph object.
   */
  protected Graph buildGraph() {
    return(new BasicGraph(m_nodes, m_edges));
  }
View Full Code Here

          Node node = (Node)nitr.next();
          nodes.add(node);
          edges.addAll(node.getEdges());
        }
       
        graphs.add(new BasicGraph(nodes, edges));
      }
     
      m_partitions = graphs;
     
      return(true);
View Full Code Here

TOP

Related Classes of org.geotools.graph.structure.basic.BasicGraph

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.