operations_research::GenericMinCostFlow< Graph, ArcFlowType, ArcScaledCostType > Class Template Reference

Detailed Description

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

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:

  • 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.
Todo:
(user): Avoid using the globally defined type CostValue and FlowQuantity. Also uses the Arc*Type where there is no risk of overflow in more places.

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< ArcIndexArcIndexArray
 
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...
 

Member Typedef Documentation

◆ ArcIndex

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

Definition at line 325 of file min_cost_flow.h.

◆ ArcIndexArray

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

Definition at line 329 of file min_cost_flow.h.

◆ NodeIndex

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

Definition at line 324 of file min_cost_flow.h.

◆ OutgoingArcIterator

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

Definition at line 326 of file min_cost_flow.h.

◆ OutgoingOrOppositeIncomingArcIterator

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

Definition at line 328 of file min_cost_flow.h.

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

◆ GenericMinCostFlow()

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

Member Function Documentation

◆ Capacity()

template<typename Graph, typename ArcFlowType = FlowQuantity, typename ArcScaledCostType = CostValue>
FlowQuantity operations_research::GenericMinCostFlow< Graph, ArcFlowType, ArcScaledCostType >::Capacity ( ArcIndex  arc) const

Returns the capacity of the given arc.

◆ CheckFeasibility()

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

Note
CheckFeasibility is called by Solve() when the flag min_cost_flow_check_feasibility is set to true (which is the default.)

◆ FeasibleSupply()

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

◆ Flow()

template<typename Graph, typename ArcFlowType = FlowQuantity, typename ArcScaledCostType = CostValue>
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_.

◆ GetOptimalCost()

template<typename Graph, typename ArcFlowType = FlowQuantity, typename ArcScaledCostType = CostValue>
CostValue operations_research::GenericMinCostFlow< Graph, ArcFlowType, ArcScaledCostType >::GetOptimalCost ( ) const
inline

Returns the cost of the minimum-cost flow found by the algorithm.

Definition at line 380 of file min_cost_flow.h.

◆ graph()

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

Returns the graph associated to the current object.

Definition at line 337 of file min_cost_flow.h.

◆ InitialSupply()

template<typename Graph, typename ArcFlowType = FlowQuantity, typename ArcScaledCostType = CostValue>
FlowQuantity operations_research::GenericMinCostFlow< Graph, ArcFlowType, ArcScaledCostType >::InitialSupply ( NodeIndex  node) const

Returns the initial supply at a given node.

◆ MakeFeasible()

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

◆ SetArcCapacity()

template<typename Graph, typename ArcFlowType = FlowQuantity, typename ArcScaledCostType = CostValue>
void operations_research::GenericMinCostFlow< Graph, ArcFlowType, ArcScaledCostType >::SetArcCapacity ( ArcIndex  arc,
ArcFlowType  new_capacity 
)

Sets the capacity for the given arc.

◆ SetArcFlow()

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

◆ SetArcUnitCost()

template<typename Graph, typename ArcFlowType = FlowQuantity, typename ArcScaledCostType = CostValue>
void operations_research::GenericMinCostFlow< Graph, ArcFlowType, ArcScaledCostType >::SetArcUnitCost ( ArcIndex  arc,
ArcScaledCostType  unit_cost 
)

Sets the unit cost for the given arc.

◆ SetCheckFeasibility()

template<typename Graph, typename ArcFlowType = FlowQuantity, typename ArcScaledCostType = CostValue>
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 414 of file min_cost_flow.h.

◆ SetNodeSupply()

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

◆ SetUseUpdatePrices()

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

Whether to use the UpdatePrices() heuristic.

Definition at line 406 of file min_cost_flow.h.

◆ Solve()

template<typename Graph, typename ArcFlowType = FlowQuantity, typename ArcScaledCostType = CostValue>
bool operations_research::GenericMinCostFlow< Graph, ArcFlowType, ArcScaledCostType >::Solve ( )

Solves the problem, returning true if a min-cost flow could be found.

◆ status()

template<typename Graph, typename ArcFlowType = FlowQuantity, typename ArcScaledCostType = CostValue>
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 342 of file min_cost_flow.h.

◆ Supply()

template<typename Graph, typename ArcFlowType = FlowQuantity, typename ArcScaledCostType = CostValue>
FlowQuantity operations_research::GenericMinCostFlow< Graph, ArcFlowType, ArcScaledCostType >::Supply ( NodeIndex  node) const

Returns the supply at a given node.

Demands are modelled as negative supplies.

◆ UnitCost()

template<typename Graph, typename ArcFlowType = FlowQuantity, typename ArcScaledCostType = CostValue>
CostValue operations_research::GenericMinCostFlow< Graph, ArcFlowType, ArcScaledCostType >::UnitCost ( ArcIndex  arc) const

Returns the unscaled cost for the given arc.


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