java.lang.Object
org.jgrapht.alg.flow.MaximumFlowAlgorithmBase<V,E>
- Type Parameters:
V- the graph vertex typeE- the graph edge type
- All Implemented Interfaces:
FlowAlgorithm<V,,E> MaximumFlowAlgorithm<V,,E> MinimumSTCutAlgorithm<V,E>
- Direct Known Subclasses:
BoykovKolmogorovMFImpl,DinicMFImpl,EdmondsKarpMFImpl,PushRelabelMFImpl
public abstract class MaximumFlowAlgorithmBase<V,E>
extends Object
implements MaximumFlowAlgorithm<V,E>, MinimumSTCutAlgorithm<V,E>
Base class backing algorithms allowing to derive
maximum-flow from the supplied
flow network
- Author:
- Alexey Kudinkin, Joris Kinable
-
Nested Class Summary
Nested classes/interfaces inherited from interface org.jgrapht.alg.interfaces.FlowAlgorithm
FlowAlgorithm.Flow<E>, FlowAlgorithm.FlowImpl<E>Nested classes/interfaces inherited from interface org.jgrapht.alg.interfaces.MaximumFlowAlgorithm
MaximumFlowAlgorithm.MaximumFlow<E>, MaximumFlowAlgorithm.MaximumFlowImpl<E> -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected Comparator<Double>static final doubleDefault tolerance.protected final booleanprotected ExtensionManager<E,? extends MaximumFlowAlgorithmBase<V, E>.org.jgrapht.alg.flow.MaximumFlowAlgorithmBase.AnnotatedFlowEdge> protected doubleprotected Vprotected Vprotected ExtensionManager<V,? extends MaximumFlowAlgorithmBase<V, E>.org.jgrapht.alg.flow.MaximumFlowAlgorithmBase.VertexExtensionBase> -
Constructor Summary
ConstructorsConstructorDescriptionMaximumFlowAlgorithmBase(Graph<V, E> network, double epsilon) Construct a new maximum flow -
Method Summary
Modifier and TypeMethodDescriptiondoublecalculateMinCut(V source, V sink) Computes a minimum capacity $s-t$ cut.protected voidCalculate the set of reachable vertices from $s$ in the residual graph.Create a map which specifies for each edge in the input map the amount of flow that flows through itReturns current sink vertex, ornullif there was nocalculateMaximumFlowcalls.Returns current source vertex, ornullif there was nocalculateMaximumFlowcalls.doubleReturns the capacity of the cut obtained after the last invocation ofMinimumSTCutAlgorithm.calculateMinCut(Object, Object)Returns the set of edges which run from $S$ to $T$, in the $s-t$ cut obtained after the last invocation ofMinimumSTCutAlgorithm.calculateMinCut(Object, Object)In case of a directed graph, only the edges with their tail in $S$ and their head in $T$ are returned.Returns the direction of the flow on an edge $(u,v)$.Returns maximum flow, that was calculated during lastcalculateMaximumFlowcall, ornull, if there was nocalculateMaximumFlowcalls.doubleReturns maximum flow value, that was calculated during lastcalculateMaximumFlowcall.Returns the sink partition $T$, $t \in T$, of the cut obtained after the last invocation ofMinimumSTCutAlgorithm.calculateMinCut(Object, Object)Returns the source partition $S$, $s \in S$, of the cut obtained after the last invocation ofMinimumSTCutAlgorithm.calculateMinCut(Object, Object)protected <VE extends MaximumFlowAlgorithmBase<V,E>.org.jgrapht.alg.flow.MaximumFlowAlgorithmBase.VertexExtensionBase>
voidinit(V source, V sink, ExtensionFactory<VE> vertexExtensionFactory, ExtensionFactory<MaximumFlowAlgorithmBase<V, E>.org.jgrapht.alg.flow.MaximumFlowAlgorithmBase.AnnotatedFlowEdge> edgeExtensionFactory) Prepares all data structures to start a new invocation of the Maximum Flow or Minimum Cut algorithmsprotected voidpushFlowThrough(MaximumFlowAlgorithmBase<V, E>.org.jgrapht.alg.flow.MaximumFlowAlgorithmBase.AnnotatedFlowEdge edge, double flow) Increase flow in the direction denoted by edge $(u,v)$.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.jgrapht.alg.interfaces.FlowAlgorithm
getFlowMethods inherited from interface org.jgrapht.alg.interfaces.MaximumFlowAlgorithm
getMaximumFlow, getMaximumFlowValue
-
Field Details
-
DEFAULT_EPSILON
public static final double DEFAULT_EPSILONDefault tolerance.- See Also:
-
network
-
directedGraph
protected final boolean directedGraph -
comparator
-
vertexExtensionManager
protected ExtensionManager<V,? extends MaximumFlowAlgorithmBase<V, vertexExtensionManagerE>.org.jgrapht.alg.flow.MaximumFlowAlgorithmBase.VertexExtensionBase> -
edgeExtensionManager
protected ExtensionManager<E,? extends MaximumFlowAlgorithmBase<V, edgeExtensionManagerE>.org.jgrapht.alg.flow.MaximumFlowAlgorithmBase.AnnotatedFlowEdge> -
source
-
sink
-
maxFlowValue
protected double maxFlowValue -
maxFlow
-
sourcePartition
-
sinkPartition
-
cutEdges
-
-
Constructor Details
-
MaximumFlowAlgorithmBase
Construct a new maximum flow- Parameters:
network- the networkepsilon- the tolerance for the comparison of floating point values
-
-
Method Details
-
init
protected <VE extends MaximumFlowAlgorithmBase<V,E>.org.jgrapht.alg.flow.MaximumFlowAlgorithmBase.VertexExtensionBase> void init(V source, V sink, ExtensionFactory<VE> vertexExtensionFactory, ExtensionFactory<MaximumFlowAlgorithmBase<V, E>.org.jgrapht.alg.flow.MaximumFlowAlgorithmBase.AnnotatedFlowEdge> edgeExtensionFactory) Prepares all data structures to start a new invocation of the Maximum Flow or Minimum Cut algorithms- Type Parameters:
VE- vertex extension type- Parameters:
source- sourcesink- sinkvertexExtensionFactory- vertex extension factoryedgeExtensionFactory- edge extension factory
-
pushFlowThrough
protected void pushFlowThrough(MaximumFlowAlgorithmBase<V, E>.org.jgrapht.alg.flow.MaximumFlowAlgorithmBase.AnnotatedFlowEdge edge, double flow) Increase flow in the direction denoted by edge $(u,v)$. Any existing flow in the reverse direction $(v,u)$ gets reduced first. More precisely, let $f_2$ be the existing flow in the direction $(v,u)$, and $f_1$ be the desired increase of flow in direction $(u,v)$. If $f_1 \geq f_2$, then the flow on $(v,u)$ becomes $0$, and the flow on $(u,v)$ becomes $f_1-f_2$. Else, if $f_1 \textlptr f_2$, the flow in the direction $(v, u)$ is reduced, i.e. the flow on $(v, u)$ becomes $f_2 - f_1$, whereas the flow on $(u,v)$ remains zero.- Parameters:
edge- desired direction in which the flow is increasedflow- increase of flow in the the direction indicated by the forwardEdge
-
composeFlow
Create a map which specifies for each edge in the input map the amount of flow that flows through it- Returns:
- a map which specifies for each edge in the input map the amount of flow that flows through it
-
getCurrentSource
Returns current source vertex, ornullif there was nocalculateMaximumFlowcalls.- Returns:
- current source
-
getCurrentSink
Returns current sink vertex, ornullif there was nocalculateMaximumFlowcalls.- Returns:
- current sink
-
getMaximumFlowValue
public double getMaximumFlowValue()Returns maximum flow value, that was calculated during lastcalculateMaximumFlowcall.- Returns:
- maximum flow value
-
getFlowMap
Returns maximum flow, that was calculated during lastcalculateMaximumFlowcall, ornull, if there was nocalculateMaximumFlowcalls.- Specified by:
getFlowMapin interfaceFlowAlgorithm<V,E> - Returns:
- read-only mapping from edges to doubles - flow values
-
getFlowDirection
Returns the direction of the flow on an edge $(u,v)$. In case $(u,v)$ is a directed edge (arc), this function will always return the edge target $v$. However, if $(u,v)$ is an edge in an undirected graph, flow may go through the edge in either side. If the flow goes from $u$ to $v$, we return $v$, otherwise $u$. If the flow on an edge equals $0$, the returned value has no meaning.- Specified by:
getFlowDirectionin interfaceFlowAlgorithm<V,E> - Parameters:
e- edge- Returns:
- the vertex where the flow leaves the edge
-
calculateMinCut
Description copied from interface:MinimumSTCutAlgorithmComputes a minimum capacity $s-t$ cut.- Specified by:
calculateMinCutin interfaceMinimumSTCutAlgorithm<V,E> - Parameters:
source- ssink- t- Returns:
- capacity of the cut
-
getCutCapacity
public double getCutCapacity()Description copied from interface:MinimumSTCutAlgorithmReturns the capacity of the cut obtained after the last invocation ofMinimumSTCutAlgorithm.calculateMinCut(Object, Object)- Specified by:
getCutCapacityin interfaceMinimumSTCutAlgorithm<V,E> - Returns:
- capacity of the cut
-
getSourcePartition
Description copied from interface:MinimumSTCutAlgorithmReturns the source partition $S$, $s \in S$, of the cut obtained after the last invocation ofMinimumSTCutAlgorithm.calculateMinCut(Object, Object)- Specified by:
getSourcePartitionin interfaceMinimumSTCutAlgorithm<V,E> - Returns:
- source partition S
-
getSinkPartition
Description copied from interface:MinimumSTCutAlgorithmReturns the sink partition $T$, $t \in T$, of the cut obtained after the last invocation ofMinimumSTCutAlgorithm.calculateMinCut(Object, Object)- Specified by:
getSinkPartitionin interfaceMinimumSTCutAlgorithm<V,E> - Returns:
- source partition T
-
getCutEdges
Description copied from interface:MinimumSTCutAlgorithmReturns the set of edges which run from $S$ to $T$, in the $s-t$ cut obtained after the last invocation ofMinimumSTCutAlgorithm.calculateMinCut(Object, Object)In case of a directed graph, only the edges with their tail in $S$ and their head in $T$ are returned. In cased of a undirected graph, all edges with one endpoint in $S$ and one endpoint in $T$ are returned.- Specified by:
getCutEdgesin interfaceMinimumSTCutAlgorithm<V,E> - Returns:
- set of edges which run from $S$ to $T$
-
calculateSourcePartition
protected void calculateSourcePartition()Calculate the set of reachable vertices from $s$ in the residual graph.
-