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>
305 return SolveWithPossibleAdjustment(SupplyAdjustment::DONT_ADJUST);
314 return SolveWithPossibleAdjustment(SupplyAdjustment::ADJUST);
363 typedef ::util::ReverseArcStaticGraph<NodeIndex, ArcIndex>
Graph;
364 enum SupplyAdjustment { ADJUST, DONT_ADJUST };
370 Status SolveWithPossibleAdjustment(SupplyAdjustment adjustment);
373 std::vector<NodeIndex> arc_tail_;
374 std::vector<NodeIndex> arc_head_;
375 std::vector<FlowQuantity> arc_capacity_;
376 std::vector<FlowQuantity> node_supply_;
377 std::vector<CostValue> arc_cost_;
378 std::vector<ArcIndex> arc_permutation_;
379 std::vector<FlowQuantity> arc_flow_;
383 bool scale_prices_ =
true;
403template <
typename Graph,
typename ArcFlowType = int64_t,
404 typename ArcScaledCostType = int64_t>
490 bool CheckFeasibility();
495 bool IsAdmissible(
ArcIndex arc)
const;
510 bool CheckInputConsistency();
516 bool CheckResult()
const;
522 bool CheckRelabelPrecondition(
NodeIndex node)
const;
526 std::string DebugString(absl::string_view context,
ArcIndex arc)
const;
530 void ResetFirstAdmissibleArcs();
544 void SaturateAdmissibleArcs();
554 void InitializeActiveNodeStack();
575 bool NodeHasAdmissibleArc(
NodeIndex node);
587 bool IsArcDirect(
ArcIndex arc)
const;
588 bool IsArcValid(
ArcIndex arc)
const;
595 std::vector<FlowQuantity> node_excess_;
599 std::vector<CostValue> node_potential_;
620 ZVector<ArcFlowType> residual_arc_capacity_;
623 std::vector<ArcIndex> first_admissible_arc_;
628 std::stack<NodeIndex> active_nodes_;
635 const int64_t alpha_;
645 ZVector<ArcScaledCostType> scaled_arc_unit_cost_;
652 std::vector<FlowQuantity> initial_node_excess_;
658 int num_relabels_since_last_price_update_ = 0;
661 bool feasibility_checked_ =
false;
664 bool use_price_update_ =
false;
667 bool check_feasibility_ =
false;
670 bool scale_prices_ =
true;
682 ::util::ReverseArcStaticGraph<uint16_t, int32_t>>;
684 ::util::ReverseArcListGraph<int64_t, int64_t>, int64_t, int64_t>;
686 ::util::ReverseArcStaticGraph<uint16_t, int32_t>,
693 template <
typename =
void>
695 LOG(FATAL) <<
"MinCostFlow is deprecated. Use `SimpleMinCostFlow` or "
696 "`GenericMinCostFlow` with a specific graph type instead.";
FlowQuantity Flow(ArcIndex arc) const
void SetArcUnitCost(ArcIndex arc, ArcScaledCostType unit_cost)
Sets the unit cost for the given arc.
Graph::IncomingArcIterator IncomingArcIterator
Graph::OutgoingOrOppositeIncomingArcIterator OutgoingOrOppositeIncomingArcIterator
GenericMinCostFlow & operator=(const GenericMinCostFlow &)=delete
GenericMinCostFlow(const Graph *graph)
bool Solve()
Solves the problem, returning true if a min-cost flow could be found.
void SetArcCapacity(ArcIndex arc, ArcFlowType new_capacity)
Sets the capacity for the given arc.
Graph::OutgoingArcIterator OutgoingArcIterator
GenericMinCostFlow(const GenericMinCostFlow &)=delete
This type is neither copyable nor movable.
void SetNodeSupply(NodeIndex node, FlowQuantity supply)
void SetUseUpdatePrices(bool value)
Algorithm options.
ZVector< ArcIndex > ArcIndexArray
const Graph * graph() const
Returns the graph associated to the current object.
CostValue UnitCost(ArcIndex arc) const
Returns the unscaled cost for the given arc.
FlowQuantity Supply(NodeIndex node) const
void SetCheckFeasibility(bool value)
void SetPriceScaling(bool value)
Graph::NodeIndex NodeIndex
FlowQuantity Capacity(ArcIndex arc) const
We use the equations given in the comment of residual_arc_capacity_.
CostValue GetOptimalCost()
Status SolveMaxFlowWithMinCost()
NodeIndex Tail(ArcIndex arc) const
CostValue OptimalCost() const
void SetNodeSupply(NodeIndex node, FlowQuantity supply)
void SetArcCapacity(ArcIndex arc, FlowQuantity capacity)
FlowQuantity Flow(ArcIndex arc) const
FlowQuantity Capacity(ArcIndex arc) const
void SetPriceScaling(bool value)
CostValue UnitCost(ArcIndex arc) const
NodeIndex NumNodes() const
ArcIndex AddArcWithCapacityAndUnitCost(NodeIndex tail, NodeIndex head, FlowQuantity capacity, CostValue unit_cost)
SimpleMinCostFlow(const SimpleMinCostFlow &)=delete
This type is neither copyable nor movable.
FlowQuantity MaximumFlow() const
NodeIndex Head(ArcIndex arc) const
SimpleMinCostFlow(NodeIndex reserve_num_nodes=0, ArcIndex reserve_num_arcs=0)
SimpleMinCostFlow & operator=(const SimpleMinCostFlow &)=delete
FlowQuantity Supply(NodeIndex node) const
NodeIndexType Tail(ArcIndexType arc) const
NodeIndexType Head(ArcIndexType arc) const
In SWIG mode, we don't want anything besides these top-level includes.
util::ReverseArcStaticGraph Graph
Type of graph to use.