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) {
707 Element element = queue->back().first;
713 #endif // OR_TOOLS_GRAPH_MAX_FLOW_H_
void GetSourceSideMinCut(std::vector< NodeIndex > *result)
NodeIndex Head(ArcIndex arc) const
NodeIndex Tail(ArcIndex arc) const
bool CheckRelabelPrecondition(NodeIndex node) const
FlowQuantity Flow(ArcIndex arc) const
MaxFlow(const StarGraph *graph, NodeIndex source, NodeIndex target)
FlowQuantity OptimalFlow() const
void InitializeActiveNodeContainer()
bool process_node_by_height_
void Set(int64_t index, T value)
PriorityQueueWithRestrictedPush< NodeIndex, NodeHeight > active_node_by_height_
NodeIndex GetSourceNodeIndex() const
FlowQuantity Capacity(ArcIndex arc) const
void SetArcFlow(ArcIndex arc, FlowQuantity new_flow)
Graph::IncomingArcIterator IncomingArcIterator
void PushActiveNode(const NodeIndex &node)
QuantityArray node_excess_
void Push(Element element, IntegerPriority priority)
FlowModel CreateFlowModelOfLastSolve()
NodeIndex GetAndRemoveFirstActiveNode()
PriorityQueueWithRestrictedPush()
Status Solve(NodeIndex source, NodeIndex sink)
bool AugmentingPathExists() const
std::vector< NodeIndex > bfs_queue_
bool use_two_phase_algorithm_
void SetCheckInput(bool value)
virtual ~GenericMaxFlow()
void PushFlowExcessBackToSource()
ArcIndex AddArcWithCapacity(NodeIndex tail, NodeIndex head, FlowQuantity capacity)
void ComputeReachableNodes(NodeIndex start, std::vector< NodeIndex > *result)
std::vector< NodeIndex > active_nodes_
bool IsArcValid(ArcIndex arc) const
FlowModel CreateFlowModel()
bool IsActive(NodeIndex node) const
void GetSinkSideMinCut(std::vector< NodeIndex > *result)
void SetArcCapacity(ArcIndex arc, FlowQuantity new_capacity)
GenericMaxFlow(const Graph *graph, NodeIndex source, NodeIndex sink)
void ProcessNodeByHeight(bool value)
void SetCheckResult(bool value)
ArcIndexArray first_admissible_arc_
NodeIndex Tail(ArcIndex arc) const
QuantityArray residual_arc_capacity_
bool IsAdmissible(ArcIndex arc) const
FlowQuantity Flow(ArcIndex arc) const
void PushFlow(FlowQuantity flow, ArcIndex arc)
static const FlowQuantity kMaxFlowQuantity
ZVector< ArcIndex > ArcIndexArray
void SetArcCapacity(ArcIndex arc, FlowQuantity capacity)
bool IsEmptyActiveNodeContainer()
bool SaturateOutgoingArcsFromSource()
#define DCHECK(condition)
void GetSinkSideMinCut(std::vector< NodeIndex > *result)
void RefineWithGlobalUpdate()
const Graph * graph() const
Graph::OutgoingOrOppositeIncomingArcIterator OutgoingOrOppositeIncomingArcIterator
bool CheckInputConsistency() const
Graph::NodeIndex NodeIndex
Collection of objects used to extend the Constraint Solver library.
bool IsArcDirect(ArcIndex arc) const
NodeIndex Head(ArcIndex arc) const
void SetUseGlobalUpdate(bool value)
void Relabel(NodeIndex node)
ZVector< NodeHeight > NodeHeightArray
NodeHeightArray node_potential_
std::vector< bool > node_in_bfs_queue_
void GetSourceSideMinCut(std::vector< NodeIndex > *result)
void SetCapacityAndClearFlow(ArcIndex arc, FlowQuantity capacity)
void Discharge(NodeIndex node)
GurobiMPCallbackContext * context
NodeIndex GetSinkNodeIndex() const
std::string DebugString(const std::string &context, ArcIndex arc) const
NodeIndex NumNodes() const
FlowQuantity GetOptimalFlow() const
void SetUseTwoPhaseAlgorithm(bool value)
FlowQuantity Capacity(ArcIndex arc) const
Graph::OutgoingArcIterator OutgoingArcIterator
ArcIndex Opposite(ArcIndex arc) const