Google OR-Tools: ortools/graph/min_cost_flow.h Source File
168#ifndef ORTOOLS_GRAPH_MIN_COST_FLOW_H_
169#define ORTOOLS_GRAPH_MIN_COST_FLOW_H_
177#include "absl/strings/string_view.h"
185template <typename Graph, typename ArcFlowType, typename ArcScaledCostType>
272 ArcIndex reserve_num_arcs = 0);
363 typedef ::util::ReverseArcStaticGraph<NodeIndex, ArcIndex> Graph;
364 enum SupplyAdjustment { ADJUST, DONT_ADJUST };
370 Status SolveWithPossibleAdjustment(SupplyAdjustment adjustment);
371 void ResizeNodeVectors(NodeIndex node);
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_;
403template <typename Graph, typename ArcFlowType = int64_t,
404 typename ArcScaledCostType = int64_t>
493 bool IsAdmissible(ArcIndex arc) const;
494 bool FastIsAdmissible(ArcIndex arc, CostValue tail_potential) const;
497 bool IsActive(NodeIndex node) const;
504 ArcIndex GetFirstOutgoingOrOppositeIncomingArc(NodeIndex node) const;
508 bool CheckInputConsistency();
520 bool CheckRelabelPrecondition(NodeIndex node) const;
524 std::string DebugString(absl::string_view context, ArcIndex arc) const;
528 void ResetFirstAdmissibleArcs();
542 void SaturateAdmissibleArcs();
552 void InitializeActiveNodeStack();
573 bool NodeHasAdmissibleArc(NodeIndex node);
585 bool IsArcDirect(ArcIndex arc) const;
586 bool IsArcValid(ArcIndex arc) const;
589 const Graph* graph_;
593 std::unique_ptr<FlowQuantity[]> node_excess_;
597 std::unique_ptr<CostValue[]> node_potential_;
618 ZVector<ArcFlowType> residual_arc_capacity_;
621 std::unique_ptr<ArcIndex[]> first_admissible_arc_;
626 std::stack<NodeIndex> active_nodes_;
636 CostValue cost_scaling_factor_ = 1;
643 ZVector<ArcScaledCostType> scaled_arc_unit_cost_;
650 std::unique_ptr<FlowQuantity[]> initial_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;
679 ::util::ReverseArcStaticGraph<uint16_t, int32_t>>;
681 ::util::ReverseArcListGraph<int64_t, int64_t>, int64_t, int64_t>;
683 ::util::ReverseArcStaticGraph<uint16_t, int32_t>,
Definition min_cost_flow.h:405
FlowQuantity Flow(ArcIndex arc) const
void SetArcUnitCost(ArcIndex arc, ArcScaledCostType unit_cost)
Graph::OutgoingOrOppositeIncomingArcIterator OutgoingOrOppositeIncomingArcIterator
Definition min_cost_flow.h:412
int64_t CostValue
Definition min_cost_flow.h:409
GenericMinCostFlow & operator=(const GenericMinCostFlow &)=delete
GenericMinCostFlow(const Graph *graph)
void SetArcCapacity(ArcIndex arc, ArcFlowType new_capacity)
GenericMinCostFlow(const GenericMinCostFlow &)=delete
void SetNodeSupply(NodeIndex node, FlowQuantity supply)
void SetUseUpdatePrices(bool value)
Definition min_cost_flow.h:480
ZVector< ArcIndex > ArcIndexArray
Definition min_cost_flow.h:413
const Graph * graph() const
Definition min_cost_flow.h:427
CostValue UnitCost(ArcIndex arc) const
FlowQuantity Supply(NodeIndex node) const
void SetCheckFeasibility(bool value)
Definition min_cost_flow.h:477
void SetPriceScaling(bool value)
Definition min_cost_flow.h:481
Graph::NodeIndex NodeIndex
Definition min_cost_flow.h:407
int64_t FlowQuantity
Definition min_cost_flow.h:410
Status status() const
Definition min_cost_flow.h:432
Graph::ArcIndex ArcIndex
Definition min_cost_flow.h:408
FlowQuantity Capacity(ArcIndex arc) const
CostValue GetOptimalCost()
Definition min_cost_flow.h:190
Status
Definition min_cost_flow.h:192
@ BAD_RESULT
Definition min_cost_flow.h:198
@ BAD_CAPACITY_RANGE
Definition min_cost_flow.h:246
@ BAD_COST_RANGE
Definition min_cost_flow.h:225
@ NOT_SOLVED
Definition min_cost_flow.h:193
@ OPTIMAL
Definition min_cost_flow.h:194
@ FEASIBLE
Definition min_cost_flow.h:195
@ UNBALANCED
Definition min_cost_flow.h:197
@ INFEASIBLE
Definition min_cost_flow.h:196
int64_t CostValue
Definition min_cost_flow.h:263
int32_t NodeIndex
Definition min_cost_flow.h:260
Status SolveMaxFlowWithMinCost()
Definition min_cost_flow.h:313
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
int32_t ArcIndex
Definition min_cost_flow.h:261
FlowQuantity Capacity(ArcIndex arc) const
void SetPriceScaling(bool value)
Definition min_cost_flow.h:360
CostValue UnitCost(ArcIndex arc) const
NodeIndex NumNodes() const
ArcIndex AddArcWithCapacityAndUnitCost(NodeIndex tail, NodeIndex head, FlowQuantity capacity, CostValue unit_cost)
SimpleMinCostFlow(const SimpleMinCostFlow &)=delete
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
Status Solve()
Definition min_cost_flow.h:304
int64_t FlowQuantity
Definition min_cost_flow.h:262
NodeIndexType Tail(ArcIndexType arc) const
NodeIndexType Head(ArcIndexType arc) const
BlossomGraph::CostValue CostValue
BlossomGraph::NodeIndex NodeIndex
util::ReverseArcStaticGraph Graph
MinCostFlow()
Definition min_cost_flow.h:691