168#ifndef OR_TOOLS_GRAPH_MIN_COST_FLOW_H_
169#define OR_TOOLS_GRAPH_MIN_COST_FLOW_H_
176#include "absl/strings/string_view.h"
185template <
typename Graph,
typename ArcFlowType,
typename ArcScaledCostType>
186class GenericMinCostFlow;
277 return SolveWithPossibleAdjustment(SupplyAdjustment::DONT_ADJUST);
286 return SolveWithPossibleAdjustment(SupplyAdjustment::ADJUST);
335 typedef ::util::ReverseArcStaticGraph<NodeIndex, ArcIndex>
Graph;
336 enum SupplyAdjustment { ADJUST, DONT_ADJUST };
342 Status SolveWithPossibleAdjustment(SupplyAdjustment adjustment);
345 std::vector<NodeIndex> arc_tail_;
346 std::vector<NodeIndex> arc_head_;
347 std::vector<FlowQuantity> arc_capacity_;
348 std::vector<FlowQuantity> node_supply_;
349 std::vector<CostValue> arc_cost_;
350 std::vector<ArcIndex> arc_permutation_;
351 std::vector<FlowQuantity> arc_flow_;
355 bool scale_prices_ =
true;
432 std::vector<NodeIndex>* infeasible_demand_node);
502 bool CheckInputConsistency();
508 bool CheckResult()
const;
514 bool CheckRelabelPrecondition(
NodeIndex node)
const;
522 void ResetFirstAdmissibleArcs();
536 void SaturateAdmissibleArcs();
546 void InitializeActiveNodeStack();
567 bool NodeHasAdmissibleArc(
NodeIndex node);
587 std::vector<FlowQuantity> node_excess_;
591 std::vector<CostValue> node_potential_;
612 ZVector<ArcFlowType> residual_arc_capacity_;
615 std::vector<ArcIndex> first_admissible_arc_;
620 std::stack<NodeIndex> active_nodes_;
627 const int64_t alpha_;
637 ZVector<ArcScaledCostType> scaled_arc_unit_cost_;
644 std::vector<FlowQuantity> initial_node_excess_;
650 std::vector<FlowQuantity> feasible_node_excess_;
656 int num_relabels_since_last_price_update_ = 0;
659 bool feasibility_checked_ =
false;
662 bool use_price_update_ =
false;
665 bool check_feasibility_ =
false;
668 bool scale_prices_ =
true;
676extern template class GenericMinCostFlow<StarGraph>;
677extern template class GenericMinCostFlow<::util::ReverseArcListGraph<>>;
678extern template class GenericMinCostFlow<::util::ReverseArcStaticGraph<>>;
679extern template class GenericMinCostFlow<::util::ReverseArcMixedGraph<>>;
680extern template class GenericMinCostFlow<
682extern template class GenericMinCostFlow<
684extern template class GenericMinCostFlow<
void SetArcUnitCost(ArcIndex arc, ArcScaledCostType unit_cost)
Sets the unit cost for the given arc.
Graph::OutgoingOrOppositeIncomingArcIterator OutgoingOrOppositeIncomingArcIterator
CostValue GetOptimalCost()
GenericMinCostFlow & operator=(const GenericMinCostFlow &)=delete
FlowQuantity InitialSupply(NodeIndex node) const
Returns the initial supply at a given node.
GenericMinCostFlow(const Graph *graph)
bool Solve()
Solves the problem, returning true if a min-cost flow could be found.
Graph::OutgoingArcIterator OutgoingArcIterator
bool CheckFeasibility(std::vector< NodeIndex > *infeasible_supply_node, std::vector< NodeIndex > *infeasible_demand_node)
void SetArcCapacity(ArcIndex arc, ArcFlowType new_capacity)
Sets the capacity for the given arc.
FlowQuantity Capacity(ArcIndex arc) const
Returns the capacity of the given arc.
GenericMinCostFlow(const GenericMinCostFlow &)=delete
This type is neither copyable nor movable.
void SetArcFlow(ArcIndex arc, ArcFlowType new_flow)
FlowQuantity Supply(NodeIndex node) const
ZVector< ArcIndex > ArcIndexArray
void SetNodeSupply(NodeIndex node, FlowQuantity supply)
void SetUseUpdatePrices(bool value)
Algorithm options.
const Graph * graph() const
Returns the graph associated to the current object.
void SetCheckFeasibility(bool value)
void SetPriceScaling(bool value)
FlowQuantity Flow(ArcIndex arc) const
Graph::NodeIndex NodeIndex
CostValue UnitCost(ArcIndex arc) const
Returns the unscaled cost for the given arc.
FlowQuantity FeasibleSupply(NodeIndex node) const
MinCostFlow(const StarGraph *graph)
FlowQuantity Supply(NodeIndex node) const
Status SolveMaxFlowWithMinCost()
FlowQuantity MaximumFlow() const
ArcIndex AddArcWithCapacityAndUnitCost(NodeIndex tail, NodeIndex head, FlowQuantity capacity, CostValue unit_cost)
FlowQuantity Capacity(ArcIndex arc) const
void SetNodeSupply(NodeIndex node, FlowQuantity supply)
void SetPriceScaling(bool value)
CostValue UnitCost(ArcIndex arc) const
CostValue OptimalCost() const
NodeIndex Tail(ArcIndex arc) const
FlowQuantity Flow(ArcIndex arc) const
NodeIndex NumNodes() const
SimpleMinCostFlow(const SimpleMinCostFlow &)=delete
This type is neither copyable nor movable.
SimpleMinCostFlow(NodeIndex reserve_num_nodes=0, ArcIndex reserve_num_arcs=0)
SimpleMinCostFlow & operator=(const SimpleMinCostFlow &)=delete
NodeIndex Head(ArcIndex arc) const
NodeIndexType Tail(ArcIndexType arc) const
NodeIndexType Head(ArcIndexType arc) const
GurobiMPCallbackContext * context
In SWIG mode, we don't want anything besides these top-level includes.
util::ReverseArcStaticGraph Graph
Type of graph to use.