/** * Returns true if a path exists between two vertices. * * @param graph the graph to search * @param start the starting vertex * @param end the ending vertex * @return true if a path exists between two vertices */ private boolean isPath(DirectedGraph<T> graph, Vertex<T> start, Vertex<T> end) { return !getPath(graph, start, end).isEmpty(); }
public boolean hasCycles(DirectedGraph<T> graph) { for (Vertex<T> vertex : graph.getVertices()) { if (isCycle(graph, vertex)) { return true; } } return false; }
public List<Cycle<T>> findCycles(DirectedGraph<T> graph) { List<Cycle<T>> cycles = new ArrayList<>(); for (Edge<T> edge : graph.getEdges()) { List<Vertex<T>> path = getPath(graph, edge.getSink(), edge.getSource()); if (!path.isEmpty()) { Cycle<T> cycle = searchCycle(cycles, edge); if (cycle == null) { cycle = new Cycle<>(); cycle.setOriginPath(path); cycles.add(cycle); } else { cycle.setBackPath(path); } } } return cycles; }
private boolean isCycle(DirectedGraph<T> graph, Vertex<T> from) { Set<Edge<T>> edges = graph.getOutgoingEdges(from); for (Edge<T> edge : edges) { Vertex<T> opposite = edge.getOppositeVertex(from); if (isPath(graph, opposite, from)) { // cycle found return true; } } return false; }
public List<Cycle<T>> findCycles(DirectedGraph<T> graph) { List<Cycle<T>> cycles = new ArrayList<>(); for (Edge<T> edge : graph.getEdges()) { List<Vertex<T>> path = getPath(graph, edge.getSink(), edge.getSource()); if (!path.isEmpty()) { Cycle<T> cycle = searchCycle(cycles, edge); if (cycle == null) { cycle = new Cycle<>(); cycle.setOriginPath(path); cycles.add(cycle); } else { cycle.setBackPath(path); } } } return cycles; }
private boolean isCycle(DirectedGraph<T> graph, Vertex<T> from) { Set<Edge<T>> edges = graph.getOutgoingEdges(from); for (Edge<T> edge : edges) { Vertex<T> opposite = edge.getOppositeVertex(from); if (isPath(graph, opposite, from)) { // cycle found return true; } } return false; }
public List<Cycle<T>> findCycles(DirectedGraph<T> graph) { List<Cycle<T>> cycles = new ArrayList<Cycle<T>>(); for (Edge<T> edge : graph.getEdges()) { List<Vertex<T>> path = getPath(graph, edge.getSink(), edge.getSource()); if (!path.isEmpty()) { Cycle<T> cycle = searchCycle(cycles, edge); if (cycle == null) { cycle = new Cycle<T>(); cycle.setOriginPath(path); cycles.add(cycle); } else { cycle.setBackPath(path); } } } return cycles; }
private boolean isCycle(DirectedGraph<T> graph, Vertex<T> from) { Set<Edge<T>> edges = graph.getOutgoingEdges(from); for (Edge<T> edge : edges) { Vertex<T> opposite = edge.getOppositeVertex(from); if (isPath(graph, opposite, from)) { // cycle found return true; } } return false; }
public boolean hasCycles(DirectedGraph<T> graph) { for (Vertex<T> vertex : graph.getVertices()) { if (isCycle(graph, vertex)) { return true; } } return false; }
/** * Returns true if a path exists between two vertices. * * @param graph the graph to search * @param start the starting vertex * @param end the ending vertex * @return true if a path exists between two vertices */ private boolean isPath(DirectedGraph<T> graph, Vertex<T> start, Vertex<T> end) { return !getPath(graph, start, end).isEmpty(); }
public DirectedGraph<T> findCycleSubgraph(DirectedGraph<T> graph) { DirectedGraph<T> subGraph = new DirectedGraphImpl<>(); for (Edge<T> edge : graph.getEdges()) { if (isPath(graph, edge.getSink(), edge.getSource())) { subGraph.add(edge); } } return subGraph; }
public boolean hasCycles(DirectedGraph<T> graph) { for (Vertex<T> vertex : graph.getVertices()) { if (isCycle(graph, vertex)) { return true; } } return false; }
/** * Returns true if a path exists between two vertices. * * @param graph the graph to search * @param start the starting vertex * @param end the ending vertex * @return true if a path exists between two vertices */ private boolean isPath(DirectedGraph<T> graph, Vertex<T> start, Vertex<T> end) { return !getPath(graph, start, end).isEmpty(); }
public DirectedGraph<T> findCycleSubgraph(DirectedGraph<T> graph) { DirectedGraph<T> subGraph = new DirectedGraphImpl<>(); for (Edge<T> edge : graph.getEdges()) { if (isPath(graph, edge.getSink(), edge.getSource())) { subGraph.add(edge); } } return subGraph; }
public DirectedGraph<T> findCycleSubgraph(DirectedGraph<T> graph) { DirectedGraph<T> subGraph = new DirectedGraphImpl<T>(); for (Edge<T> edge : graph.getEdges()) { if (isPath(graph, edge.getSink(), edge.getSource())) { subGraph.add(edge); } } return subGraph; }