A simple and efficient max-cost flow interface.
This is as fast as GenericMaxFlow<ReverseArcStaticGraph>, which is the fastest, but uses more memory in order to hide the somewhat involved construction of the static graph.
Definition at line 152 of file max_flow.h.
Public Types | |
| enum | Status { OPTIMAL, POSSIBLE_OVERFLOW, BAD_INPUT, BAD_RESULT } |
| Solves the problem (finds the maximum flow from the given source to the given sink), and returns the problem status. More... | |
Public Member Functions | |
| SimpleMaxFlow () | |
| The constructor takes no size. More... | |
| ArcIndex | AddArcWithCapacity (NodeIndex tail, NodeIndex head, FlowQuantity capacity) |
| Adds a directed arc with the given capacity from tail to head. More... | |
| NodeIndex | NumNodes () const |
| Returns the current number of nodes. More... | |
| ArcIndex | NumArcs () const |
| Returns the current number of arcs in the graph. More... | |
| NodeIndex | Tail (ArcIndex arc) const |
| Returns user-provided data. More... | |
| NodeIndex | Head (ArcIndex arc) const |
| FlowQuantity | Capacity (ArcIndex arc) const |
| Status | Solve (NodeIndex source, NodeIndex sink) |
| FlowQuantity | OptimalFlow () const |
| Returns the maximum flow we can send from the source to the sink in the last OPTIMAL Solve() context. More... | |
| FlowQuantity | Flow (ArcIndex arc) const |
| Returns the flow on the given arc in the last OPTIMAL Solve() context. More... | |
| void | GetSourceSideMinCut (std::vector< NodeIndex > *result) |
| Returns the nodes reachable from the source by non-saturated arcs (.i.e. More... | |
| void | GetSinkSideMinCut (std::vector< NodeIndex > *result) |
| Returns the nodes that can reach the sink by non-saturated arcs, the outgoing arcs of this set form a minimum cut. More... | |
| FlowModel | CreateFlowModelOfLastSolve () |
| Creates the protocol buffer representation of the problem used by the last Solve() call. More... | |
| void | SetArcCapacity (ArcIndex arc, FlowQuantity capacity) |
| Change the capacity of an arc. More... | |
Solves the problem (finds the maximum flow from the given source to the given sink), and returns the problem status.
| Enumerator | |
|---|---|
| OPTIMAL | Solve() was called and found an optimal solution. Note that OptimalFlow() may be 0 which means that the sink is not reachable from the source. |
| POSSIBLE_OVERFLOW | There is a flow > std::numeric_limits<FlowQuantity>::max(). Note that in this case, the class will contain a solution with a flow reaching that bound.
|
| BAD_INPUT | The input is inconsistent (bad tail/head/capacity values). |
| BAD_RESULT | This should not happen. There was an error in our code (i.e. file a bug). |
Definition at line 180 of file max_flow.h.
| operations_research::SimpleMaxFlow::SimpleMaxFlow | ( | ) |
The constructor takes no size.
New node indices will be created lazily by AddArcWithCapacity().
| ArcIndex operations_research::SimpleMaxFlow::AddArcWithCapacity | ( | NodeIndex | tail, |
| NodeIndex | head, | ||
| FlowQuantity | capacity | ||
| ) |
Adds a directed arc with the given capacity from tail to head.
| FlowQuantity operations_research::SimpleMaxFlow::Capacity | ( | ArcIndex | arc | ) | const |
| FlowModel operations_research::SimpleMaxFlow::CreateFlowModelOfLastSolve | ( | ) |
Creates the protocol buffer representation of the problem used by the last Solve() call.
This is mainly useful for debugging.
| FlowQuantity operations_research::SimpleMaxFlow::Flow | ( | ArcIndex | arc | ) | const |
Returns the flow on the given arc in the last OPTIMAL Solve() context.
| void operations_research::SimpleMaxFlow::GetSinkSideMinCut | ( | std::vector< NodeIndex > * | result | ) |
Returns the nodes that can reach the sink by non-saturated arcs, the outgoing arcs of this set form a minimum cut.
Note that if this is the complement set of GetNodeReachableFromSource(), then the min-cut is unique. This works only if Solve() returned OPTIMAL.
| void operations_research::SimpleMaxFlow::GetSourceSideMinCut | ( | std::vector< NodeIndex > * | result | ) |
Returns the nodes reachable from the source by non-saturated arcs (.i.e.
arc with Flow(arc) < Capacity(arc)), the outgoing arcs of this set form a minimum cut. This works only if Solve() returned OPTIMAL.
| ArcIndex operations_research::SimpleMaxFlow::NumArcs | ( | ) | const |
Returns the current number of arcs in the graph.
| NodeIndex operations_research::SimpleMaxFlow::NumNodes | ( | ) | const |
Returns the current number of nodes.
This is one more than the largest node index seen so far in AddArcWithCapacity().
| FlowQuantity operations_research::SimpleMaxFlow::OptimalFlow | ( | ) | const |
Returns the maximum flow we can send from the source to the sink in the last OPTIMAL Solve() context.
| void operations_research::SimpleMaxFlow::SetArcCapacity | ( | ArcIndex | arc, |
| FlowQuantity | capacity | ||
| ) |
Returns user-provided data.
The implementation will crash if "arc" is not in [0, NumArcs()).