/** * Returns the ordered list of vertices traversed for a path defined by the given start and end vertices. If no path exists, an empty colleciton * is returned. * * @param graph the graph to search * @param start the starting vertex * @param end the ending vertex * @return the ordered collection of vertices or an empty collection if no path exists */ private List<Vertex<T>> getPath(DirectedGraph<T> graph, Vertex<T> start, Vertex<T> end) { List<Vertex<T>> path = traverser.traversePath(graph, start, end); // reverse the order to it goes from source to end destination Collections.reverse(path); return path; }
public List<Vertex<T>> sort(DirectedGraph<T> dag, Vertex<T> start) throws CycleException { // perform the sort over the subgraph graph formed from the given vertex, calculating roots and references // for its children DepthFirstTraverser<T> dfs = new DepthFirstTraverserImpl<T>(); Map<Vertex<T>, AtomicInteger> vertexMap = new HashMap<Vertex<T>, AtomicInteger>(); List<Vertex<T>> vertices = dfs.traverse(dag, start); for (Vertex<T> v : vertices) { List<Vertex<T>> outgoing = dag.getOutgoingAdjacentVertices(v); for (Vertex<T> child : outgoing) { AtomicInteger count = vertexMap.get(child); if (count == null) { count = new AtomicInteger(); vertexMap.put(child, count); } count.incrementAndGet(); } } List<Vertex<T>> roots = new ArrayList<Vertex<T>>(); roots.add(start); // perform the sort return sort(dag, vertexMap, roots); }
public List<Vertex<T>> sort(DirectedGraph<T> dag, Vertex<T> start) throws CycleException { // perform the sort over the subgraph graph formed from the given vertex, calculating roots and references // for its children DepthFirstTraverser<T> dfs = new DepthFirstTraverserImpl<>(); Map<Vertex<T>, AtomicInteger> vertexMap = new HashMap<>(); List<Vertex<T>> vertices = dfs.traverse(dag, start); for (Vertex<T> v : vertices) { List<Vertex<T>> outgoing = dag.getOutgoingAdjacentVertices(v); for (Vertex<T> child : outgoing) { AtomicInteger count = vertexMap.get(child); if (count == null) { count = new AtomicInteger(); vertexMap.put(child, count); } count.incrementAndGet(); } } List<Vertex<T>> roots = new ArrayList<>(); roots.add(start); // perform the sort return sort(dag, vertexMap, roots); }
/** * Returns the ordered list of vertices traversed for a path defined by the given start and end vertices. If no path exists, an empty colleciton * is returned. * * @param graph the graph to search * @param start the starting vertex * @param end the ending vertex * @return the ordered collection of vertices or an empty collection if no path exists */ private List<Vertex<T>> getPath(DirectedGraph<T> graph, Vertex<T> start, Vertex<T> end) { List<Vertex<T>> path = traverser.traversePath(graph, start, end); // reverse the order to it goes from source to end destination Collections.reverse(path); return path; }
public List<Vertex<T>> sort(DirectedGraph<T> dag, Vertex<T> start) throws CycleException { // perform the sort over the subgraph graph formed from the given vertex, calculating roots and references // for its children DepthFirstTraverser<T> dfs = new DepthFirstTraverserImpl<>(); Map<Vertex<T>, AtomicInteger> vertexMap = new HashMap<>(); List<Vertex<T>> vertices = dfs.traverse(dag, start); for (Vertex<T> v : vertices) { List<Vertex<T>> outgoing = dag.getOutgoingAdjacentVertices(v); for (Vertex<T> child : outgoing) { AtomicInteger count = vertexMap.get(child); if (count == null) { count = new AtomicInteger(); vertexMap.put(child, count); } count.incrementAndGet(); } } List<Vertex<T>> roots = new ArrayList<>(); roots.add(start); // perform the sort return sort(dag, vertexMap, roots); }
/** * Returns the ordered list of vertices traversed for a path defined by the given start and end vertices. If no path exists, an empty colleciton * is returned. * * @param graph the graph to search * @param start the starting vertex * @param end the ending vertex * @return the ordered collection of vertices or an empty collection if no path exists */ private List<Vertex<T>> getPath(DirectedGraph<T> graph, Vertex<T> start, Vertex<T> end) { List<Vertex<T>> path = traverser.traversePath(graph, start, end); // reverse the order to it goes from source to end destination Collections.reverse(path); return path; }