 |
OR-Tools
8.0
|
Go to the documentation of this file.
123 #ifndef OR_TOOLS_GRAPH_MAX_FLOW_H_
124 #define OR_TOOLS_GRAPH_MAX_FLOW_H_
143 template <
typename Graph>
233 std::vector<NodeIndex> arc_tail_;
234 std::vector<NodeIndex> arc_head_;
235 std::vector<FlowQuantity> arc_capacity_;
236 std::vector<ArcIndex> arc_permutation_;
237 std::vector<FlowQuantity> arc_flow_;
242 typedef ::util::ReverseArcStaticGraph<NodeIndex, ArcIndex> Graph;
243 std::unique_ptr<Graph> underlying_graph_;
244 std::unique_ptr<GenericMaxFlow<Graph> > underlying_max_flow_;
263 template <
typename Element,
typename IntegerPriority>
277 void Push(Element element, IntegerPriority priority);
285 Element PopBack(std::vector<std::pair<Element, IntegerPriority> >* queue);
290 std::vector<std::pair<Element, IntegerPriority> > even_queue_;
291 std::vector<std::pair<Element, IntegerPriority> > odd_queue_;
314 template <
typename Graph>
315 class GenericMaxFlow :
public MaxFlowStatusClass {
320 typedef typename Graph::OutgoingOrOppositeIncomingArcIterator
540 template <
bool reverse>
660 template <
typename Element,
typename IntegerPriority>
663 return even_queue_.empty() && odd_queue_.empty();
666 template <
typename Element,
typename IntegerPriority>
672 template <
typename Element,
typename IntegerPriority>
674 Element element, IntegerPriority priority) {
676 DCHECK(even_queue_.empty() || priority >= even_queue_.back().second - 1);
677 DCHECK(odd_queue_.empty() || priority >= odd_queue_.back().second - 1);
683 DCHECK(odd_queue_.empty() || priority >= odd_queue_.back().second);
684 odd_queue_.push_back(std::make_pair(element, priority));
686 DCHECK(even_queue_.empty() || priority >= even_queue_.back().second);
687 even_queue_.push_back(std::make_pair(element, priority));
691 template <
typename Element,
typename IntegerPriority>
694 if (even_queue_.empty())
return PopBack(&odd_queue_);
695 if (odd_queue_.empty())
return PopBack(&even_queue_);
696 if (odd_queue_.back().second > even_queue_.back().second) {
697 return PopBack(&odd_queue_);
699 return PopBack(&even_queue_);
703 template <
typename Element,
typename IntegerPriority>
705 std::vector<std::pair<Element, IntegerPriority> >* queue) {
706 DCHECK(!queue->empty());
707 Element element = queue->back().first;
713 #endif // OR_TOOLS_GRAPH_MAX_FLOW_H_
std::vector< NodeIndex > bfs_queue_
void SetUseGlobalUpdate(bool value)
FlowQuantity Flow(ArcIndex arc) const
MaxFlow(const StarGraph *graph, NodeIndex source, NodeIndex target)
void Push(Element element, IntegerPriority priority)
FlowModel CreateFlowModelOfLastSolve()
void ProcessNodeByHeight(bool value)
bool IsAdmissible(ArcIndex arc) const
ArcIndex AddArcWithCapacity(NodeIndex tail, NodeIndex head, FlowQuantity capacity)
void ComputeReachableNodes(NodeIndex start, std::vector< NodeIndex > *result)
std::vector< bool > node_in_bfs_queue_
const Graph * graph() const
bool SaturateOutgoingArcsFromSource()
ArcIndex Opposite(ArcIndex arc) const
bool IsArcValid(ArcIndex arc) const
PriorityQueueWithRestrictedPush()
void SetArcFlow(ArcIndex arc, FlowQuantity new_flow)
NodeIndex GetSinkNodeIndex() const
The vehicle routing library lets one model and solve generic vehicle routing problems ranging from th...
Status Solve(NodeIndex source, NodeIndex sink)
PriorityQueueWithRestrictedPush< NodeIndex, NodeHeight > active_node_by_height_
void RefineWithGlobalUpdate()
NodeIndex Head(ArcIndex arc) const
GurobiMPCallbackContext * context
Graph::OutgoingArcIterator OutgoingArcIterator
void Set(int64 index, T value)
FlowQuantity Flow(ArcIndex arc) const
ZVector< ArcIndex > ArcIndexArray
void SetCapacityAndClearFlow(ArcIndex arc, FlowQuantity capacity)
bool IsArcDirect(ArcIndex arc) const
QuantityArray residual_arc_capacity_
void SetCheckResult(bool value)
void GetSourceSideMinCut(std::vector< NodeIndex > *result)
void SetArcCapacity(ArcIndex arc, FlowQuantity capacity)
void Discharge(NodeIndex node)
std::string DebugString(const std::string &context, ArcIndex arc) const
NodeIndex Tail(ArcIndex arc) const
void GetSourceSideMinCut(std::vector< NodeIndex > *result)
void InitializeActiveNodeContainer()
static const FlowQuantity kMaxFlowQuantity
GenericMaxFlow(const Graph *graph, NodeIndex source, NodeIndex sink)
NodeIndex GetAndRemoveFirstActiveNode()
NodeIndex Tail(ArcIndex arc) const
virtual ~GenericMaxFlow()
FlowQuantity OptimalFlow() const
bool IsActive(NodeIndex node) const
NodeIndex NumNodes() const
void PushFlowExcessBackToSource()
void Relabel(NodeIndex node)
bool CheckRelabelPrecondition(NodeIndex node) const
ZVector< NodeHeight > NodeHeightArray
NodeHeightArray node_potential_
Graph::IncomingArcIterator IncomingArcIterator
Graph::OutgoingOrOppositeIncomingArcIterator OutgoingOrOppositeIncomingArcIterator
void PushFlow(FlowQuantity flow, ArcIndex arc)
bool AugmentingPathExists() const
void PushActiveNode(const NodeIndex &node)
void GetSinkSideMinCut(std::vector< NodeIndex > *result)
void SetUseTwoPhaseAlgorithm(bool value)
bool process_node_by_height_
bool use_two_phase_algorithm_
bool CheckInputConsistency() const
FlowQuantity Capacity(ArcIndex arc) const
FlowQuantity GetOptimalFlow() const
QuantityArray node_excess_
FlowModel CreateFlowModel()
std::vector< NodeIndex > active_nodes_
NodeIndex Head(ArcIndex arc) const
ArcIndexArray first_admissible_arc_
FlowQuantity Capacity(ArcIndex arc) const
void SetArcCapacity(ArcIndex arc, FlowQuantity new_capacity)
NodeIndex GetSourceNodeIndex() const
void GetSinkSideMinCut(std::vector< NodeIndex > *result)
Graph::NodeIndex NodeIndex
void SetCheckInput(bool value)
bool IsEmptyActiveNodeContainer()