Processes the unordered set of squares and creates a graph out of them using prior knowledge and geometric
constraints.
@param squares Set of squares
@return List of graphs.  All data structures are recycled on the next call to process().
438309
public List<List<SquareNode>> process(List<DetectPolygonFromContour.Info> squares ) {
		recycleData();

		// set up nodes
		computeNodeInfo(squares);

		// Connect nodes to each other
		connectNodes();

		// Find all valid graphs
		findClusters();
		return clusters.toList();
	}
1122939
private void advance() {
        // If we don't have any simple graphs to return, and there are still
        // more subgraphs, then pick off the next subgraph and decompose it
        if (next.isEmpty() && subgraphIterator.hasNext()) {
            Multigraph<T,E> g = subgraphIterator.next();

            // Find all pairs of edges, checking whether the graph is a simple
            // graph already
            boolean isSimpleAlready = true;
            List<IntPair> connected = new ArrayList<IntPair>();
            for (int i : g.vertices()) {
                for (int j : g.vertices()) {
                    if (i == j)
                        break;
                    Set<E> edges = null;
                    try {
                        edges = g.getEdges(i, j);
                    } catch (NullPointerException npe) {
                        System.out.println("Bad graph? : " + g);
                        throw npe;
                    }
                    int size = edges.size();
                    if (size > 0)
                        connected.add(new IntPair(i, j));
                    if (size > 1)
                        isSimpleAlready = false;
                }
            }
            // If the subgraph was already a simple graph, then just append it
            // to the list
            if (isSimpleAlready) {
                // System.out.println("next graph was already simple: " + g);
                next.add(g);
            }
            // Otherwise, generate a recursive call to enumerate all the
            // simple graphs from this graph
            else {
                // Create an empty graph which will be populated with a new edge
                // and then copied 
                Multigraph<T,E> m = g.copy(Collections.<Integer>emptySet()); //Graphs.asMultigraph(new GenericGraph<E>());
                next.addAll(enumerateSimpleGraphs(g, connected, 0, m));
            }
        }
    }
798219
static int[] rank(final int[][] g) {
        final int ord = g.length;

        final int[] count = new int[ord + 1];
        final int[] rank = new int[ord];

        // frequency of each degree
        for (int v = 0; v < ord; v++)
            count[g[v].length + 1]++;
        // cumulated counts
        for (int i = 0; count[i] < ord; i++)
            count[i + 1] += count[i];
        // store sorted position of each vertex
        for (int v = 0; v < ord; v++)
            rank[v] = count[g[v].length]++;

        return rank;
    }
394074
public static List<String> getProblems(Graph g) {
        List<String> problems = new ArrayList<>();
        int nodes = g.getNodes();
        int nodeIndex = 0;
        NodeAccess na = g.getNodeAccess();
        try {
            EdgeExplorer explorer = g.createEdgeExplorer();
            for (; nodeIndex < nodes; nodeIndex++) {
                double lat = na.getLatitude(nodeIndex);
                if (lat > 90 || lat < -90)
                    problems.add("latitude is not within its bounds " + lat);

                double lon = na.getLongitude(nodeIndex);
                if (lon > 180 || lon < -180)
                    problems.add("longitude is not within its bounds " + lon);

                EdgeIterator iter = explorer.setBaseNode(nodeIndex);
                while (iter.next()) {
                    if (iter.getAdjNode() >= nodes) {
                        problems.add("edge of " + nodeIndex + " has a node " + iter.getAdjNode() + " greater or equal to getNodes");
                    }
                    if (iter.getAdjNode() < 0) {
                        problems.add("edge of " + nodeIndex + " has a negative node " + iter.getAdjNode());
                    }
                }
            }
        } catch (Exception ex) {
            throw new RuntimeException("problem with node " + nodeIndex, ex);
        }

//        for (int i = 0; i < nodes; i++) {
//            new BreadthFirstSearch().start(g, i);
//        }
        return problems;
    }
203938
public List<String> nextParagraphs() {
        return nextParagraphs(Math.min(Math.max(4 + (int) (random.nextGaussian() * 3d), 1), 8));
    }
554043
public List<Polygon> polygons() {
    List<List<List<Point>>> coordinates = coordinates();
    List<Polygon> polygons = new ArrayList<>(coordinates.size());
    for (List<List<Point>> points : coordinates) {
      polygons.add(Polygon.fromLngLats(points));
    }
    return polygons;
  }
804495
@Override
    public Iterable<Vertex> vertices() {
        GraphCentricQuery query = constructQuery(ElementCategory.VERTEX);
        return Iterables.filter(new QueryProcessor<>(query, tx.elementProcessor), Vertex.class);
    }
794759
private List<Coordinate> getCoordinates(List<Geometry> geometries) {
		List<Coordinate> coordinates = new ArrayList<Coordinate>();
		for (Geometry geometry : geometries) {
			Coordinate[] geometryCoordinates = geometry.getCoordinates();
			for (int i = 0; i < geometryCoordinates.length; i++) {
				coordinates.add(geometryCoordinates[i]);
			}
		}
		return coordinates;
	}
852981
public Graph<K, VV, EV> removeVertices(List<Vertex<K, VV>> verticesToBeRemoved) {
		return removeVertices(this.context.fromCollection(verticesToBeRemoved));
	}
664257
void saveResults( List<List<NodeInfo>> graph ) {
		Grid g = foundGrids.grow();
		g.reset();

		g.columns = graph.get(0).size() + graph.get(1).size();
		g.rows = graph.size();

		for (int row = 0; row < g.rows; row++) {
			List<NodeInfo> list = graph.get(row);
			for (int i = 0; i < g.columns; i++) {
				if( (i%2) == (row%2))
					g.ellipses.add(list.get(i/2).ellipse );
				else
					g.ellipses.add(null);
			}
		}
	}
658879
public Graph<K, VV, EV> reverse() throws UnsupportedOperationException {
		DataSet<Edge<K, EV>> reversedEdges = edges.map(new ReverseEdgesMap<>()).name("Reverse edges");
		return new Graph<>(vertices, reversedEdges, this.context);
	}
26414
public List<VertexT> topologicalSort() {
    Preconditions.checkState(!wasSorted);
    wasSorted = true;

    Queue<VertexT> queue = new ArrayDeque<>();

    for (Map.Entry<VertexT, Integer> entry : vertices.entrySet()) {
      if (entry.getValue() == 0) {
        queue.add(entry.getKey());
      }
    }

    List<VertexT> result = Lists.newArrayList();
    while (!queue.isEmpty()) {
      VertexT vertex = queue.remove();
      result.add(vertex);
      for (VertexT successor : adjacencyList.get(vertex)) {
        if (decrementAndGetCount(successor) == 0) {
          queue.add(successor);
        }
      }
    }

    if (result.size() != vertices.size()) {
      throw new IllegalArgumentException("failed to perform topological sort, graph has a cycle");
    }

    return result;
  }
1131363
public static <K, VV, EV> Graph<K, VV, EV> fromCollection(Collection<Vertex<K, VV>> vertices,
			Collection<Edge<K, EV>> edges, ExecutionEnvironment context) {

		return fromDataSet(context.fromCollection(vertices),
				context.fromCollection(edges), context);
	}
1300523
public static STRtree geometriesToSRTree( List<Geometry> geometries ) {
        STRtree tree = new STRtree();
        for( Geometry geometry : geometries ) {
            tree.insert(geometry.getEnvelopeInternal(), geometry);
        }
        return tree;
    }
541102
def edges
	    points = self.vertices
	    points.each_cons(2).map {|p1,p2| Edge.new(p1,p2) } + [Edge.new(points.last, points.first)]
	end
781053
List<Coordinate> allMatches() {
        List<Coordinate> pairs = new ArrayList<>();
        int rows = rowList().size();
        int cols = columnList().size();
        for (int i = 0; i < rows; i++) {
            for (int j = 0; j < cols; j++) {
                VariantGraph.Vertex vertex = vertexAt(i, j);
                if (vertex != null) pairs.add(new Coordinate(i, j, new Match(vertex, null)));
            }
        }
        return pairs;
    }
48414
public int[] getVertexPointIndices() {
        int[] indices = new int[numVertices];
        for (int i = 0; i < numVertices; i++) {
            indices[i] = vertexPointIndices[i];
        }
        return indices;
    }