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.
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 |
|
inherited |
| Enumerator | |
|---|---|
| NOT_SOLVED | |
| OPTIMAL | |
| FEASIBLE | |
| INFEASIBLE | |
| UNBALANCED | |
| BAD_RESULT | |
| BAD_COST_RANGE | |
Definition at line 194 of file min_cost_flow.h.
| 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()).
| 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.
| FlowQuantity operations_research::SimpleMinCostFlow::Capacity | ( | ArcIndex | arc | ) | const |
| FlowQuantity operations_research::SimpleMinCostFlow::Flow | ( | ArcIndex | arc | ) | const |
Returns the flow on arc, this only make sense for a successful Solve().
| 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.
| ArcIndex operations_research::SimpleMinCostFlow::NumArcs | ( | ) | const |
| 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()).
| CostValue operations_research::SimpleMinCostFlow::OptimalCost | ( | ) | const |
Returns the cost of the minimum-cost flow found by the algorithm when the returned Status is OPTIMAL.
| 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.
|
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.
|
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.
| FlowQuantity operations_research::SimpleMinCostFlow::Supply | ( | NodeIndex | node | ) | const |