public final class Cycles extends Object
v0, v1, v2, ... , vk
(with k > 0 and (vi-1,vi), 0 < i <= k is edge of the given
graph) is called simple if no vertex appears more than once.
v0 = vk
.Example of an acyclic directed graph (edge directions are considered) Example of a graph containing a cycle. Marked edges form a directed cycle.
Modifier and Type | Method and Description |
---|---|
static EdgeList |
findAllCycleEdges(Graph graph,
boolean directed)
Returns an
EdgeList that contains all the edges that are part of at least one directed or undirected simple
cycle. |
static EdgeList |
findCycle(Graph graph,
boolean directed)
Returns an
EdgeList that contains the edges of a cycle found in the given graph. |
static void |
findCycleEdges(Graph graph,
IEdgeMap cycleEdges)
Marks the edges of a given graph whose removal or reversal would make the graph acyclic while trying to minimize the
cost associated with the marked edges.
|
static void |
findCycleEdges(Graph graph,
IEdgeMap cycleEdges,
IDataProvider costDP)
Marks the edges of a given graph whose removal or reversal would make the graph acyclic while trying to minimize the
cost associated with the marked edges.
|
static void |
findCycleEdgesDFS(Graph graph,
IEdgeMap cycleEdges)
Marks the edges of a given graph whose removal or reversal would make the graph acyclic based on a depth first search.
|
public static final EdgeList findAllCycleEdges(Graph graph, boolean directed)
EdgeList
that contains all the edges that are part of at least one directed or undirected simple
cycle.graph
- the input graphdirected
- true
if the graph should be considered directed, false
otherwiseEdgeList
that contains all the edges that are part of at least one directed or undirected simple cyclepublic static final EdgeList findCycle(Graph graph, boolean directed)
EdgeList
that contains the edges of a cycle found in the given graph.
The edges are returned in the order they appear in the detected cycle.
If the returned cycle is empty, no cycle has been found in the given graph.
public static final void findCycleEdges(Graph graph, IEdgeMap cycleEdges)
This minimization is performed heuristically, since it is a well known hard problem to come up with an optimal solution.
The costs are assigned using a IDataProvider
that holds a non-negative double value for each edge.
O(graph.E() + graph.N() * log(graph.E()))
graph
- the given graphcycleEdges
- the IEdgeMap
that will be filled during the execution and returns whether an edge is a detected cycle edgepublic static final void findCycleEdges(Graph graph, IEdgeMap cycleEdges, IDataProvider costDP)
This minimization is performed heuristically, since it is a well known hard problem to come up with an optimal solution.
The costs are assigned using a IDataProvider
that holds a non-negative double value for each edge.
O(graph.E() + graph.N() * log(graph.E()))
graph
- the given graphcycleEdges
- the IEdgeMap
that will be filled during the execution and returns whether an edge is a detected cycle edgecostDP
- the IDataProvider
that holds the non-negative Double
reversal cost for each edgepublic static final void findCycleEdgesDFS(Graph graph, IEdgeMap cycleEdges)
The number of marked cycle edges is expected to be slightly greater than when using
findCycleEdges(Graph, IEdgeMap, IDataProvider)
. The advantage of this method is that the result set is more
stable when edges are added or removed over time.
O(graph.E() + graph.N())
graph
- the given graphcycleEdges
- the IEdgeMap
that will be filled during the execution and returns a boolean value indicating whether or not an
edge is a detected cycle edge