Google OR-Tools v9.12
a fast and portable software suite for combinatorial optimization
Loading...
Searching...
No Matches
operations_research::GenericMinCostFlow< Graph, ArcFlowType, ArcScaledCostType > Class Template Reference

Forward declaration. More...

#include <min_cost_flow.h>

Inheritance diagram for operations_research::GenericMinCostFlow< Graph, ArcFlowType, ArcScaledCostType >:
operations_research::MinCostFlowBase

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< ArcIndexArcIndexArray
 
- Public Types inherited from operations_research::MinCostFlowBase
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.
 
GenericMinCostFlowoperator= (const GenericMinCostFlow &)=delete
 
const Graphgraph () 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)
 

Detailed Description

template<typename Graph, typename ArcFlowType = int64_t, typename ArcScaledCostType = int64_t>
class operations_research::GenericMinCostFlow< Graph, ArcFlowType, ArcScaledCostType >

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:

  • For the Graph<> types, i.e. NodeIndexType and ArcIndexType, see graph.h.
  • ArcFlowType is used for the per-arc flow quantity. It must be signed, and large enough to hold the maximum arc capacity and its negation.
  • ArcScaledCostType is used for a per-arc scaled cost. It must be signed and large enough to hold the maximum unit cost of an arc times (num_nodes + 1).
Note
the latter two are different than FlowQuantity and CostValue, which are used for global, aggregated values and may need to be larger.

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.

Member Typedef Documentation

◆ ArcIndex

template<typename Graph, typename ArcFlowType = int64_t, typename ArcScaledCostType = int64_t>
typedef Graph::ArcIndex operations_research::GenericMinCostFlow< Graph, ArcFlowType, ArcScaledCostType >::ArcIndex

Definition at line 408 of file min_cost_flow.h.

◆ ArcIndexArray

template<typename Graph, typename ArcFlowType = int64_t, typename ArcScaledCostType = int64_t>
typedef ZVector<ArcIndex> operations_research::GenericMinCostFlow< Graph, ArcFlowType, ArcScaledCostType >::ArcIndexArray

Definition at line 415 of file min_cost_flow.h.

◆ CostValue

template<typename Graph, typename ArcFlowType = int64_t, typename ArcScaledCostType = int64_t>
typedef int64_t operations_research::GenericMinCostFlow< Graph, ArcFlowType, ArcScaledCostType >::CostValue

Definition at line 409 of file min_cost_flow.h.

◆ FlowQuantity

template<typename Graph, typename ArcFlowType = int64_t, typename ArcScaledCostType = int64_t>
typedef int64_t operations_research::GenericMinCostFlow< Graph, ArcFlowType, ArcScaledCostType >::FlowQuantity

Definition at line 410 of file min_cost_flow.h.

◆ IncomingArcIterator

template<typename Graph, typename ArcFlowType = int64_t, typename ArcScaledCostType = int64_t>
typedef Graph::IncomingArcIterator operations_research::GenericMinCostFlow< Graph, ArcFlowType, ArcScaledCostType >::IncomingArcIterator

Definition at line 411 of file min_cost_flow.h.

◆ NodeIndex

template<typename Graph, typename ArcFlowType = int64_t, typename ArcScaledCostType = int64_t>
typedef Graph::NodeIndex operations_research::GenericMinCostFlow< Graph, ArcFlowType, ArcScaledCostType >::NodeIndex

Definition at line 407 of file min_cost_flow.h.

◆ OutgoingArcIterator

template<typename Graph, typename ArcFlowType = int64_t, typename ArcScaledCostType = int64_t>
typedef Graph::OutgoingArcIterator operations_research::GenericMinCostFlow< Graph, ArcFlowType, ArcScaledCostType >::OutgoingArcIterator

Definition at line 412 of file min_cost_flow.h.

◆ OutgoingOrOppositeIncomingArcIterator

template<typename Graph, typename ArcFlowType = int64_t, typename ArcScaledCostType = int64_t>
typedef Graph::OutgoingOrOppositeIncomingArcIterator operations_research::GenericMinCostFlow< Graph, ArcFlowType, ArcScaledCostType >::OutgoingOrOppositeIncomingArcIterator

Definition at line 414 of file min_cost_flow.h.

Constructor & Destructor Documentation

◆ GenericMinCostFlow() [1/2]

template<typename Graph, typename ArcFlowType, typename ArcScaledCostType>
operations_research::GenericMinCostFlow< Graph, ArcFlowType, ArcScaledCostType >::GenericMinCostFlow ( const Graph * graph)
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.

◆ GenericMinCostFlow() [2/2]

template<typename Graph, typename ArcFlowType = int64_t, typename ArcScaledCostType = int64_t>
operations_research::GenericMinCostFlow< Graph, ArcFlowType, ArcScaledCostType >::GenericMinCostFlow ( const GenericMinCostFlow< Graph, ArcFlowType, ArcScaledCostType > & )
delete

This type is neither copyable nor movable.

Member Function Documentation

◆ Capacity()

template<typename Graph, typename ArcFlowType, typename ArcScaledCostType>
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.

Warning
If the capacity were close to ArcFlowType::max() we might have adjusted them in order to avoid overflow.

Definition at line 376 of file min_cost_flow.cc.

◆ Flow()

template<typename Graph, typename ArcFlowType, typename ArcScaledCostType>
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.

◆ GetOptimalCost()

template<typename Graph, typename ArcFlowType, typename ArcScaledCostType>
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.

◆ graph()

template<typename Graph, typename ArcFlowType = int64_t, typename ArcScaledCostType = int64_t>
const Graph * operations_research::GenericMinCostFlow< Graph, ArcFlowType, ArcScaledCostType >::graph ( ) const
inline

Returns the graph associated to the current object.

Definition at line 429 of file min_cost_flow.h.

◆ operator=()

template<typename Graph, typename ArcFlowType = int64_t, typename ArcScaledCostType = int64_t>
GenericMinCostFlow & operations_research::GenericMinCostFlow< Graph, ArcFlowType, ArcScaledCostType >::operator= ( const GenericMinCostFlow< Graph, ArcFlowType, ArcScaledCostType > & )
delete

◆ SetArcCapacity()

template<typename Graph, typename ArcFlowType, typename ArcScaledCostType>
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.

◆ SetArcUnitCost()

template<typename Graph, typename ArcFlowType, typename ArcScaledCostType>
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.

◆ SetCheckFeasibility()

template<typename Graph, typename ArcFlowType = int64_t, typename ArcScaledCostType = int64_t>
void operations_research::GenericMinCostFlow< Graph, ArcFlowType, ArcScaledCostType >::SetCheckFeasibility ( bool value)
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.

◆ SetNodeSupply()

template<typename Graph, typename ArcFlowType, typename ArcScaledCostType>
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.

◆ SetPriceScaling()

template<typename Graph, typename ArcFlowType = int64_t, typename ArcScaledCostType = int64_t>
void operations_research::GenericMinCostFlow< Graph, ArcFlowType, ArcScaledCostType >::SetPriceScaling ( bool value)
inline

Definition at line 483 of file min_cost_flow.h.

◆ SetUseUpdatePrices()

template<typename Graph, typename ArcFlowType = int64_t, typename ArcScaledCostType = int64_t>
void operations_research::GenericMinCostFlow< Graph, ArcFlowType, ArcScaledCostType >::SetUseUpdatePrices ( bool value)
inline

Algorithm options.

Definition at line 482 of file min_cost_flow.h.

◆ Solve()

template<typename Graph, typename ArcFlowType, typename ArcScaledCostType>
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.

◆ status()

template<typename Graph, typename ArcFlowType = int64_t, typename ArcScaledCostType = int64_t>
Status operations_research::GenericMinCostFlow< Graph, ArcFlowType, ArcScaledCostType >::status ( ) const
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.

◆ Supply()

template<typename Graph, typename ArcFlowType, typename ArcScaledCostType>
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.

◆ UnitCost()

template<typename Graph, typename ArcFlowType, typename ArcScaledCostType>
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.


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