operations_research::SimpleMinCostFlow Class Reference

Detailed Description

A simple and efficient min-cost flow interface.

This is as fast as GenericMinCostFlow<ReverseArcStaticGraph>, which is the fastest, but is uses more memory in order to hide the somewhat involved construction of the static graph.

Todo:
(user): If the need arises, extend this interface to support warm start and incrementality between solves. Note that this is already supported by the GenericMinCostFlow<> interface.

Definition at line 213 of file min_cost_flow.h.

Public Types

enum  Status {
  NOT_SOLVED, OPTIMAL, FEASIBLE, INFEASIBLE,
  UNBALANCED, BAD_RESULT, BAD_COST_RANGE
}
 

Public Member Functions

 SimpleMinCostFlow ()
 The constructor takes no size. More...
 
ArcIndex AddArcWithCapacityAndUnitCost (NodeIndex tail, NodeIndex head, FlowQuantity capacity, CostValue unit_cost)
 Adds a directed arc from tail to head to the underlying graph with a given capacity and cost per unit of flow. More...
 
void SetNodeSupply (NodeIndex node, FlowQuantity supply)
 Sets the supply of the given node. More...
 
Status Solve ()
 Solves the problem, and returns the problem status. More...
 
Status SolveMaxFlowWithMinCost ()
 Same as Solve(), but does not have the restriction that the supply must match the demand or that the graph has enough capacity to serve all the demand or use all the supply. More...
 
CostValue OptimalCost () const
 Returns the cost of the minimum-cost flow found by the algorithm when the returned Status is OPTIMAL. More...
 
FlowQuantity MaximumFlow () const
 Returns the total flow of the minimum-cost flow found by the algorithm when the returned Status is OPTIMAL. More...
 
FlowQuantity Flow (ArcIndex arc) const
 Returns the flow on arc, this only make sense for a successful Solve(). More...
 
NodeIndex NumNodes () const
 Accessors for the user given data. More...
 
ArcIndex NumArcs () const
 
NodeIndex Tail (ArcIndex arc) const
 
NodeIndex Head (ArcIndex arc) const
 
FlowQuantity Capacity (ArcIndex arc) const
 
FlowQuantity Supply (NodeIndex node) const
 
CostValue UnitCost (ArcIndex arc) const
 

Member Enumeration Documentation

◆ Status

Enumerator
NOT_SOLVED 
OPTIMAL 
FEASIBLE 
INFEASIBLE 
UNBALANCED 
BAD_RESULT 
BAD_COST_RANGE 

Definition at line 194 of file min_cost_flow.h.

Constructor & Destructor Documentation

◆ SimpleMinCostFlow()

operations_research::SimpleMinCostFlow::SimpleMinCostFlow ( )

The constructor takes no size.

New node indices will be created lazily by AddArcWithCapacityAndUnitCost() or SetNodeSupply() such that the set of valid nodes will always be [0, NumNodes()).

Member Function Documentation

◆ AddArcWithCapacityAndUnitCost()

ArcIndex operations_research::SimpleMinCostFlow::AddArcWithCapacityAndUnitCost ( NodeIndex  tail,
NodeIndex  head,
FlowQuantity  capacity,
CostValue  unit_cost 
)

Adds a directed arc from tail to head to the underlying graph with a given capacity and cost per unit of flow.

  • Node indices and the capacity must be non-negative (>= 0).
  • The unit cost can take any integer value (even negative).
  • Self-looping and duplicate arcs are supported.
  • After the method finishes, NumArcs() == the returned ArcIndex + 1.

◆ Capacity()

FlowQuantity operations_research::SimpleMinCostFlow::Capacity ( ArcIndex  arc) const

◆ Flow()

FlowQuantity operations_research::SimpleMinCostFlow::Flow ( ArcIndex  arc) const

Returns the flow on arc, this only make sense for a successful Solve().

Note
It is possible that there is more than one optimal solution. The algorithm is deterministic so it will always return the same solution for a given problem. However, there is no guarantee of this from one code version to the next (but the code does not change often).

◆ Head()

NodeIndex operations_research::SimpleMinCostFlow::Head ( ArcIndex  arc) const

◆ MaximumFlow()

FlowQuantity operations_research::SimpleMinCostFlow::MaximumFlow ( ) const

Returns the total flow of the minimum-cost flow found by the algorithm when the returned Status is OPTIMAL.

◆ NumArcs()

ArcIndex operations_research::SimpleMinCostFlow::NumArcs ( ) const

◆ NumNodes()

NodeIndex operations_research::SimpleMinCostFlow::NumNodes ( ) const

Accessors for the user given data.

The implementation will crash if "arc" is not in [0, NumArcs()) or "node" is not in [0, NumNodes()).

◆ OptimalCost()

CostValue operations_research::SimpleMinCostFlow::OptimalCost ( ) const

Returns the cost of the minimum-cost flow found by the algorithm when the returned Status is OPTIMAL.

◆ SetNodeSupply()

void operations_research::SimpleMinCostFlow::SetNodeSupply ( NodeIndex  node,
FlowQuantity  supply 
)

Sets the supply of the given node.

The node index must be non-negative (>= 0). Nodes implicitly created will have a default supply set to 0. A demand is modeled as a negative supply.

◆ Solve()

Status operations_research::SimpleMinCostFlow::Solve ( )
inline

Solves the problem, and returns the problem status.

This function requires that the sum of all node supply minus node demand is zero and that the graph has enough capacity to send all supplies and serve all demands. Otherwise, it will return INFEASIBLE.

Definition at line 239 of file min_cost_flow.h.

◆ SolveMaxFlowWithMinCost()

Status operations_research::SimpleMinCostFlow::SolveMaxFlowWithMinCost ( )
inline

Same as Solve(), but does not have the restriction that the supply must match the demand or that the graph has enough capacity to serve all the demand or use all the supply.

This will compute a maximum-flow with minimum cost. The value of the maximum-flow will be given by MaximumFlow().

Definition at line 248 of file min_cost_flow.h.

◆ Supply()

FlowQuantity operations_research::SimpleMinCostFlow::Supply ( NodeIndex  node) const

◆ Tail()

NodeIndex operations_research::SimpleMinCostFlow::Tail ( ArcIndex  arc) const

◆ UnitCost()

CostValue operations_research::SimpleMinCostFlow::UnitCost ( ArcIndex  arc) const

The documentation for this class was generated from the following file: