![]() |
Google OR-Tools v9.12
a fast and portable software suite for combinatorial optimization
|
Forward declaration. More...
#include <min_cost_flow.h>
Public Types | |
typedef Graph::NodeIndex | NodeIndex |
typedef Graph::ArcIndex | ArcIndex |
typedef int64_t | CostValue |
typedef int64_t | FlowQuantity |
typedef Graph::IncomingArcIterator | IncomingArcIterator |
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 , BAD_CAPACITY_RANGE } |
Public Member Functions | |
GenericMinCostFlow (const Graph *graph) | |
GenericMinCostFlow (const GenericMinCostFlow &)=delete | |
This type is neither copyable nor movable. | |
GenericMinCostFlow & | operator= (const GenericMinCostFlow &)=delete |
const Graph * | graph () const |
Returns the graph associated to the current object. | |
Status | status () const |
void | SetNodeSupply (NodeIndex node, FlowQuantity supply) |
void | SetArcUnitCost (ArcIndex arc, ArcScaledCostType unit_cost) |
Sets the unit cost for the given arc. | |
void | SetArcCapacity (ArcIndex arc, ArcFlowType new_capacity) |
Sets the capacity for the given arc. | |
bool | Solve () |
Solves the problem, returning true if a min-cost flow could be found. | |
CostValue | GetOptimalCost () |
FlowQuantity | Flow (ArcIndex arc) const |
FlowQuantity | Capacity (ArcIndex arc) const |
We use the equations given in the comment of residual_arc_capacity_. | |
CostValue | UnitCost (ArcIndex arc) const |
Returns the unscaled cost for the given arc. | |
FlowQuantity | Supply (NodeIndex node) const |
void | SetCheckFeasibility (bool value) |
void | SetUseUpdatePrices (bool value) |
Algorithm options. | |
void | SetPriceScaling (bool value) |
Forward declaration.
Generic MinCostFlow that works with 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:
Also uses the Arc*Type where there is no risk of overflow in more places.
Definition at line 405 of file min_cost_flow.h.
typedef Graph::ArcIndex operations_research::GenericMinCostFlow< Graph, ArcFlowType, ArcScaledCostType >::ArcIndex |
Definition at line 408 of file min_cost_flow.h.
typedef ZVector<ArcIndex> operations_research::GenericMinCostFlow< Graph, ArcFlowType, ArcScaledCostType >::ArcIndexArray |
Definition at line 415 of file min_cost_flow.h.
typedef int64_t operations_research::GenericMinCostFlow< Graph, ArcFlowType, ArcScaledCostType >::CostValue |
Definition at line 409 of file min_cost_flow.h.
typedef int64_t operations_research::GenericMinCostFlow< Graph, ArcFlowType, ArcScaledCostType >::FlowQuantity |
Definition at line 410 of file min_cost_flow.h.
typedef Graph::IncomingArcIterator operations_research::GenericMinCostFlow< Graph, ArcFlowType, ArcScaledCostType >::IncomingArcIterator |
Definition at line 411 of file min_cost_flow.h.
typedef Graph::NodeIndex operations_research::GenericMinCostFlow< Graph, ArcFlowType, ArcScaledCostType >::NodeIndex |
Definition at line 407 of file min_cost_flow.h.
typedef Graph::OutgoingArcIterator operations_research::GenericMinCostFlow< Graph, ArcFlowType, ArcScaledCostType >::OutgoingArcIterator |
Definition at line 412 of file min_cost_flow.h.
typedef Graph::OutgoingOrOppositeIncomingArcIterator operations_research::GenericMinCostFlow< Graph, ArcFlowType, ArcScaledCostType >::OutgoingOrOppositeIncomingArcIterator |
Definition at line 414 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.
This class assumes we have negative reverse arcs.
Definition at line 50 of file min_cost_flow.cc.
|
delete |
This type is neither copyable nor movable.
auto operations_research::GenericMinCostFlow< Graph, ArcFlowType, ArcScaledCostType >::Capacity | ( | ArcIndex | arc | ) | const |
We use the equations given in the comment of residual_arc_capacity_.
Returns the capacity of the given arc.
Definition at line 376 of file min_cost_flow.cc.
auto 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_.
Definition at line 365 of file min_cost_flow.cc.
auto operations_research::GenericMinCostFlow< Graph, ArcFlowType, ArcScaledCostType >::GetOptimalCost | ( | ) |
Returns the cost of the minimum-cost flow found by the algorithm. This works in O(num_arcs). This will only work if the last Solve() call was successful and returned true, otherwise it will return 0. Note that the computation might overflow, in which case we will cap the cost at std::numeric_limits<CostValue>::max().
The total cost of the flow. We cap the result if its overflow.
Definition at line 479 of file min_cost_flow.cc.
|
inline |
Returns the graph associated to the current object.
Definition at line 429 of file min_cost_flow.h.
|
delete |
void operations_research::GenericMinCostFlow< Graph, ArcFlowType, ArcScaledCostType >::SetArcCapacity | ( | ArcIndex | arc, |
ArcFlowType | new_capacity ) |
Sets the capacity for the given arc.
The above condition is true when one of two following holds: 1/ (capacity_delta > 0), meaning we are increasing the capacity 2/ (capacity_delta < 0 && free_capacity + capacity_delta >= 0) meaning we are reducing the capacity, but that the capacity reduction is not larger than the free capacity.
We have to reduce the flow on the arc, and update the excesses accordingly.
Definition at line 96 of file min_cost_flow.cc.
void operations_research::GenericMinCostFlow< Graph, ArcFlowType, ArcScaledCostType >::SetArcUnitCost | ( | ArcIndex | arc, |
ArcScaledCostType | unit_cost ) |
Sets the unit cost for the given arc.
Definition at line 86 of file min_cost_flow.cc.
|
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 479 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.
Definition at line 76 of file min_cost_flow.cc.
|
inline |
Definition at line 483 of file min_cost_flow.h.
|
inline |
Algorithm options.
Definition at line 482 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.
Definition at line 449 of file min_cost_flow.cc.
|
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 434 of file min_cost_flow.h.
auto operations_research::GenericMinCostFlow< Graph, ArcFlowType, ArcScaledCostType >::Supply | ( | NodeIndex | node | ) | const |
Returns the supply at a given node. Demands are modelled as negative supplies.
Definition at line 394 of file min_cost_flow.cc.
auto operations_research::GenericMinCostFlow< Graph, ArcFlowType, ArcScaledCostType >::UnitCost | ( | ArcIndex | arc | ) | const |
Returns the unscaled cost for the given arc.
Definition at line 386 of file min_cost_flow.cc.