Interface MinimumCostFlow
-
- All Known Implementing Classes:
MinimumCostFlowAbstract
,MinimumCostFlowAbstractBasedSourceSink
,MinimumCostFlowAbstractBasedSupply
,MinimumCostFlowCostScaling
,MinimumCostFlowCycleCanceling
public interface MinimumCostFlow
Compute the minimum-cost (max) flow in a flow network.There are a few variations of the minimum-cost flow problem: (1) given source(s) and sink(s) terminal vertices, and the objecting is to find the flow with the lowest cost out of all maximum flows. (2) given per-vertex finite supply, and the objective is to find a minimum-cost flow satisfying the supply, namely that for each vertex the sum of flow units going out of the vertex minus the sum of flow units going into it is equal to its supply.
In addition to these variants, a lower bound for each edge flow can be specified, similar to the capacities which can be viewed as upper bounds.
Use
newInstance()
to get a default implementation of this interface. A builder obtained viabuilder()
may support different options to obtain different implementations.- Author:
- Barak Ugav
- See Also:
MaximumFlow
,Flow
, Wikipedia
-
-
Nested Class Summary
Nested Classes Modifier and Type Interface Description static interface
MinimumCostFlow.Builder
A builder forMinimumCostFlow
objects.
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Modifier and Type Method Description static MinimumCostFlow.Builder
builder()
Create a new minimum cost flow algorithm builder.<V,E>
Flow<V,E>computeMinCostFlow(Graph<V,E> g, WeightFunction<E> capacity, WeightFunction<E> cost, WeightFunction<E> lowerBound, WeightFunction<V> supply)
Compute the min-cost (not maximum!)<V,E>
Flow<V,E>computeMinCostFlow(Graph<V,E> g, WeightFunction<E> capacity, WeightFunction<E> cost, WeightFunction<V> supply)
Compute the min-cost (not maximum!)<V,E>
Flow<V,E>computeMinCostMaxFlow(Graph<V,E> g, WeightFunction<E> capacity, WeightFunction<E> cost, WeightFunction<E> lowerBound, Collection<V> sources, Collection<V> sinks)
Compute the min-cost max-flow in a network between a set of sources and a set of sinks given a lower bound for the edges flows.<V,E>
Flow<V,E>computeMinCostMaxFlow(Graph<V,E> g, WeightFunction<E> capacity, WeightFunction<E> cost, WeightFunction<E> lowerBound, V source, V sink)
Compute the min-cost max-flow in a network between a source and a sink given a lower bound for the edges flows.<V,E>
Flow<V,E>computeMinCostMaxFlow(Graph<V,E> g, WeightFunction<E> capacity, WeightFunction<E> cost, Collection<V> sources, Collection<V> sinks)
Compute the min-cost max-flow in a network between a set of sources and a set of sinks.<V,E>
Flow<V,E>computeMinCostMaxFlow(Graph<V,E> g, WeightFunction<E> capacity, WeightFunction<E> cost, V source, V sink)
Compute the min-cost max-flow in a network between a source and a sink.static MinimumCostFlow
newInstance()
Create a new min-cost-flow algorithm object.
-
-
-
Method Detail
-
computeMinCostMaxFlow
<V,E> Flow<V,E> computeMinCostMaxFlow(Graph<V,E> g, WeightFunction<E> capacity, WeightFunction<E> cost, V source, V sink)
Compute the min-cost max-flow in a network between a source and a sink.Some algorithm might run faster for integer networks, and
WeightFunctionInt
can be passed as argument ascapacity
andcost
.If
g
is anIntGraph
, its better to pass aIWeightFunction
ascapacity
andcost
to avoid boxing/unboxing. Ifg
is anIntGraph
, the returned object isIFlow
.- Type Parameters:
V
- the vertices typeE
- the edges type- Parameters:
g
- the graphcapacity
- a capacity edge weight functioncost
- an edge weight function representing the cost of each unit of flow along the edgesource
- a source vertexsink
- a sink vertex- Returns:
- the flows computed for each edge
-
computeMinCostMaxFlow
<V,E> Flow<V,E> computeMinCostMaxFlow(Graph<V,E> g, WeightFunction<E> capacity, WeightFunction<E> cost, WeightFunction<E> lowerBound, V source, V sink)
Compute the min-cost max-flow in a network between a source and a sink given a lower bound for the edges flows.If
g
is anIntGraph
, its better to pass aIWeightFunction
ascapacity
,cost
andlowerBound
to avoid boxing/unboxing. Ifg
is anIntGraph
, the returned object isIFlow
.- Type Parameters:
V
- the vertices typeE
- the edges type- Parameters:
g
- the graphcapacity
- a capacity edge weight functioncost
- an edge weight function representing the cost of each unit of flow along the edgelowerBound
- an edge weight function representing a lower bound for the flow along each edgesource
- a source vertexsink
- a sink vertex- Returns:
- the flows computed for each edge
-
computeMinCostMaxFlow
<V,E> Flow<V,E> computeMinCostMaxFlow(Graph<V,E> g, WeightFunction<E> capacity, WeightFunction<E> cost, Collection<V> sources, Collection<V> sinks)
Compute the min-cost max-flow in a network between a set of sources and a set of sinks.Some algorithm might run faster for integer networks, and
WeightFunctionInt
can be passed as argument ascapacity
andcost
.If
g
is anIntGraph
, its better to pass aIWeightFunction
ascapacity
andcost
, andIntCollection
assources
andsinks
to avoid boxing/unboxing. Ifg
is anIntGraph
, the returned object isIFlow
.- Type Parameters:
V
- the vertices typeE
- the edges type- Parameters:
g
- the graphcapacity
- a capacity edge weight functioncost
- an edge weight function representing the cost of each unit of flow along the edgesources
- a set of source verticessinks
- a set of sinks vertices- Returns:
- the flows computed for each edge
-
computeMinCostMaxFlow
<V,E> Flow<V,E> computeMinCostMaxFlow(Graph<V,E> g, WeightFunction<E> capacity, WeightFunction<E> cost, WeightFunction<E> lowerBound, Collection<V> sources, Collection<V> sinks)
Compute the min-cost max-flow in a network between a set of sources and a set of sinks given a lower bound for the edges flows.Some algorithm might run faster for integer networks, and
WeightFunctionInt
can be passed as argument ascapacity
,cost
andlowerBound
.If
g
is anIntGraph
, its better to pass aIWeightFunction
ascapacity
,cost
andlowerBound
, andIntCollection
assources
andsinks
to avoid boxing/unboxing. Ifg
is anIntGraph
, the returned object isIFlow
.- Type Parameters:
V
- the vertices typeE
- the edges type- Parameters:
g
- the graphcapacity
- a capacity edge weight functioncost
- an edge weight function representing the cost of each unit of flow along the edgelowerBound
- an edge weight function representing a lower bound for the flow along each edgesources
- a set of source verticessinks
- a set of sinks vertices- Returns:
- the flows computed for each edge
-
computeMinCostFlow
<V,E> Flow<V,E> computeMinCostFlow(Graph<V,E> g, WeightFunction<E> capacity, WeightFunction<E> cost, WeightFunction<V> supply)
Compute the min-cost (not maximum!) flow in a network given a supply for each vertex.The supply is a scalar for each vertex, and the objective is to find a minimum-cost flow satisfying the supply, namely that for each vertex the sum of flow units going out of the vertex minus the sum of flow units going into it is equal to its supply.
Some algorithm might run faster for integer networks, and
WeightFunctionInt
can be passed as argument ascapacity
,cost
andsupply
.If
g
is anIntGraph
, its better to pass aIWeightFunction
ascapacity
,cost
andsupply
to avoid boxing/unboxing. Ifg
is anIntGraph
, the returned object isIFlow
.- Type Parameters:
V
- the vertices typeE
- the edges type- Parameters:
g
- the graphcapacity
- a capacity edge weight functioncost
- an edge weight function representing the cost of each unit of flow along the edgesupply
- a vertex weight function representing the supply for each vertex- Returns:
- the flows computed for each edge
-
computeMinCostFlow
<V,E> Flow<V,E> computeMinCostFlow(Graph<V,E> g, WeightFunction<E> capacity, WeightFunction<E> cost, WeightFunction<E> lowerBound, WeightFunction<V> supply)
Compute the min-cost (not maximum!) flow in a network given a supply for each vertex and a lower bound for the edges flows.The supply is a scalar for each vertex, and the objective is to find a minimum-cost flow satisfying the supply, namely that for each vertex the sum of flow units going out of the vertex minus the sum of flow units going into it is equal to its supply.
Some algorithm might run faster for integer networks, and
WeightFunctionInt
can be passed as argument ascapacity
,cost
,lowerBound
andsupply
.If
g
is anIntGraph
, its better to pass aIWeightFunction
ascapacity
,cost
,lowerBound
andsupply
to avoid boxing/unboxing. Ifg
is anIntGraph
, the returned object isIFlow
.- Type Parameters:
V
- the vertices typeE
- the edges type- Parameters:
g
- the graphcapacity
- a capacity edge weight functioncost
- an edge weight function representing the cost of each unit of flow along the edgelowerBound
- an edge weight function representing a lower bound for the flow along each edgesupply
- a vertex weight function representing the supply for each vertex- Returns:
- the flows computed for each edge
-
newInstance
static MinimumCostFlow newInstance()
Create a new min-cost-flow algorithm object.This is the recommended way to instantiate a new
MinimumCostFlow
object. TheMinimumCostFlow.Builder
might support different options to obtain different implementations.- Returns:
- a default implementation of
MinimumCostFlow
-
builder
static MinimumCostFlow.Builder builder()
Create a new minimum cost flow algorithm builder.Use
newInstance()
for a default implementation.- Returns:
- a new builder that can build
MinimumCostFlow
objects
-
-