Forward declaration.
Generic MinCostFlow that works with StarGraph and all the graphs handling reverse arcs from graph.h, see the end of min_cost_flow.cc for the exact types this class is compiled for.
One can greatly decrease memory usage by using appropriately small integer types:
Definition at line 188 of file min_cost_flow.h.
Public Types | |
| typedef Graph::NodeIndex | NodeIndex |
| typedef Graph::ArcIndex | ArcIndex |
| typedef Graph::OutgoingArcIterator | OutgoingArcIterator |
| typedef Graph::OutgoingOrOppositeIncomingArcIterator | OutgoingOrOppositeIncomingArcIterator |
| typedef ZVector< ArcIndex > | ArcIndexArray |
| enum | Status { NOT_SOLVED, OPTIMAL, FEASIBLE, INFEASIBLE, UNBALANCED, BAD_RESULT, BAD_COST_RANGE } |
Public Member Functions | |
| GenericMinCostFlow (const Graph *graph) | |
| Initialize a MinCostFlow instance on the given graph. More... | |
| const Graph * | graph () const |
| Returns the graph associated to the current object. More... | |
| Status | status () const |
| Returns the status of last call to Solve(). More... | |
| void | SetNodeSupply (NodeIndex node, FlowQuantity supply) |
| Sets the supply corresponding to node. More... | |
| void | SetArcUnitCost (ArcIndex arc, ArcScaledCostType unit_cost) |
| Sets the unit cost for the given arc. More... | |
| void | SetArcCapacity (ArcIndex arc, ArcFlowType new_capacity) |
| Sets the capacity for the given arc. More... | |
| void | SetArcFlow (ArcIndex arc, ArcFlowType new_flow) |
| Sets the flow for the given arc. More... | |
| bool | Solve () |
| Solves the problem, returning true if a min-cost flow could be found. More... | |
| bool | CheckFeasibility (std::vector< NodeIndex > *const infeasible_supply_node, std::vector< NodeIndex > *const infeasible_demand_node) |
| Checks for feasibility, i.e., that all the supplies and demands can be matched without exceeding bottlenecks in the network. More... | |
| bool | MakeFeasible () |
| Makes the min-cost flow problem solvable by truncating supplies and demands to a level acceptable by the network. More... | |
| CostValue | GetOptimalCost () const |
| Returns the cost of the minimum-cost flow found by the algorithm. More... | |
| FlowQuantity | Flow (ArcIndex arc) const |
| Returns the flow on the given arc using the equations given in the comment on residual_arc_capacity_. More... | |
| FlowQuantity | Capacity (ArcIndex arc) const |
| Returns the capacity of the given arc. More... | |
| CostValue | UnitCost (ArcIndex arc) const |
| Returns the unscaled cost for the given arc. More... | |
| FlowQuantity | Supply (NodeIndex node) const |
| Returns the supply at a given node. More... | |
| FlowQuantity | InitialSupply (NodeIndex node) const |
| Returns the initial supply at a given node. More... | |
| FlowQuantity | FeasibleSupply (NodeIndex node) const |
| Returns the largest supply (if > 0) or largest demand in absolute value (if < 0) admissible at node. More... | |
| void | SetUseUpdatePrices (bool value) |
| Whether to use the UpdatePrices() heuristic. More... | |
| void | SetCheckFeasibility (bool value) |
| Whether to check the feasibility of the problem with a max-flow, prior to solving it. More... | |
| typedef Graph::ArcIndex operations_research::GenericMinCostFlow< Graph, ArcFlowType, ArcScaledCostType >::ArcIndex |
Definition at line 325 of file min_cost_flow.h.
| typedef ZVector<ArcIndex> operations_research::GenericMinCostFlow< Graph, ArcFlowType, ArcScaledCostType >::ArcIndexArray |
Definition at line 329 of file min_cost_flow.h.
| typedef Graph::NodeIndex operations_research::GenericMinCostFlow< Graph, ArcFlowType, ArcScaledCostType >::NodeIndex |
Definition at line 324 of file min_cost_flow.h.
| typedef Graph::OutgoingArcIterator operations_research::GenericMinCostFlow< Graph, ArcFlowType, ArcScaledCostType >::OutgoingArcIterator |
Definition at line 326 of file min_cost_flow.h.
| typedef Graph::OutgoingOrOppositeIncomingArcIterator operations_research::GenericMinCostFlow< Graph, ArcFlowType, ArcScaledCostType >::OutgoingOrOppositeIncomingArcIterator |
Definition at line 328 of file min_cost_flow.h.
|
inherited |
| Enumerator | |
|---|---|
| NOT_SOLVED | |
| OPTIMAL | |
| FEASIBLE | |
| INFEASIBLE | |
| UNBALANCED | |
| BAD_RESULT | |
| BAD_COST_RANGE | |
Definition at line 194 of file min_cost_flow.h.
|
explicit |
Initialize a MinCostFlow instance on the given graph.
The graph does not need to be fully built yet, but its capacity reservation is used to initialize the memory of this class.
| FlowQuantity operations_research::GenericMinCostFlow< Graph, ArcFlowType, ArcScaledCostType >::Capacity | ( | ArcIndex | arc | ) | const |
Returns the capacity of the given arc.
| bool operations_research::GenericMinCostFlow< Graph, ArcFlowType, ArcScaledCostType >::CheckFeasibility | ( | std::vector< NodeIndex > *const | infeasible_supply_node, |
| std::vector< NodeIndex > *const | infeasible_demand_node | ||
| ) |
Checks for feasibility, i.e., that all the supplies and demands can be matched without exceeding bottlenecks in the network.
If infeasible_supply_node (resp. infeasible_demand_node) are not NULL, they are populated with the indices of the nodes where the initial supplies (resp. demands) are too large. Feasible values for the supplies and demands are accessible through FeasibleSupply.
| FlowQuantity operations_research::GenericMinCostFlow< Graph, ArcFlowType, ArcScaledCostType >::FeasibleSupply | ( | NodeIndex | node | ) | const |
Returns the largest supply (if > 0) or largest demand in absolute value (if < 0) admissible at node.
If the problem is not feasible, some of these values will be smaller (in absolute value) than the initial supplies and demand given as input.
| FlowQuantity operations_research::GenericMinCostFlow< Graph, ArcFlowType, ArcScaledCostType >::Flow | ( | ArcIndex | arc | ) | const |
Returns the flow on the given arc using the equations given in the comment on residual_arc_capacity_.
|
inline |
Returns the cost of the minimum-cost flow found by the algorithm.
Definition at line 380 of file min_cost_flow.h.
|
inline |
Returns the graph associated to the current object.
Definition at line 337 of file min_cost_flow.h.
| FlowQuantity operations_research::GenericMinCostFlow< Graph, ArcFlowType, ArcScaledCostType >::InitialSupply | ( | NodeIndex | node | ) | const |
Returns the initial supply at a given node.
| bool operations_research::GenericMinCostFlow< Graph, ArcFlowType, ArcScaledCostType >::MakeFeasible | ( | ) |
Makes the min-cost flow problem solvable by truncating supplies and demands to a level acceptable by the network.
There may be several ways to do it. In our case, the levels are computed from the result of the max-flow algorithm run in CheckFeasibility(). MakeFeasible returns false if CheckFeasibility() was not called before.
| void operations_research::GenericMinCostFlow< Graph, ArcFlowType, ArcScaledCostType >::SetArcCapacity | ( | ArcIndex | arc, |
| ArcFlowType | new_capacity | ||
| ) |
Sets the capacity for the given arc.
| void operations_research::GenericMinCostFlow< Graph, ArcFlowType, ArcScaledCostType >::SetArcFlow | ( | ArcIndex | arc, |
| ArcFlowType | new_flow | ||
| ) |
Sets the flow for the given arc.
Note that new_flow must be smaller than the capacity of the arc.
| void operations_research::GenericMinCostFlow< Graph, ArcFlowType, ArcScaledCostType >::SetArcUnitCost | ( | ArcIndex | arc, |
| ArcScaledCostType | unit_cost | ||
| ) |
Sets the unit cost for the given arc.
|
inline |
Whether to check the feasibility of the problem with a max-flow, prior to solving it.
This uses about twice as much memory, but detects infeasible problems (where the flow can't be satisfied) and makes Solve() return INFEASIBLE. If you disable this check, you will spare memory but you must make sure that your problem is feasible, otherwise the code can loop forever.
Definition at line 414 of file min_cost_flow.h.
| void operations_research::GenericMinCostFlow< Graph, ArcFlowType, ArcScaledCostType >::SetNodeSupply | ( | NodeIndex | node, |
| FlowQuantity | supply | ||
| ) |
Sets the supply corresponding to node.
A demand is modeled as a negative supply.
|
inline |
Whether to use the UpdatePrices() heuristic.
Definition at line 406 of file min_cost_flow.h.
| bool operations_research::GenericMinCostFlow< Graph, ArcFlowType, ArcScaledCostType >::Solve | ( | ) |
Solves the problem, returning true if a min-cost flow could be found.
|
inline |
Returns the status of last call to Solve().
NOT_SOLVED is returned if Solve() has never been called or if the problem has been modified in such a way that the previous solution becomes invalid.
Definition at line 342 of file min_cost_flow.h.
| FlowQuantity operations_research::GenericMinCostFlow< Graph, ArcFlowType, ArcScaledCostType >::Supply | ( | NodeIndex | node | ) | const |
Returns the supply at a given node.
Demands are modelled as negative supplies.
| CostValue operations_research::GenericMinCostFlow< Graph, ArcFlowType, ArcScaledCostType >::UnitCost | ( | ArcIndex | arc | ) | const |
Returns the unscaled cost for the given arc.