Generated on: Thu Mar 29 07:46:58 PDT 2012 for custom file set
// doxy/ or-tools/ src/ graph/

operations_research::MaxFlow Class Reference

#include <max_flow.h>

List of all members.

Public Types

enum  Status {
  NOT_SOLVED, OPTIMAL, FEASIBLE, INFEASIBLE,
  BAD_INPUT, BAD_RESULT
}
 Different statuses for a given problem. More...

Public Member Functions

 MaxFlow (const StarGraph *graph, NodeIndex source, NodeIndex target)
virtual ~MaxFlow ()
const StarGraphgraph () const
 Returns the graph associated to the current object.
Status status () const
 Returns the status of last call to Solve().
NodeIndex GetSourceNodeIndex () const
 Returns the index of the node corresponding to the source of the network.
NodeIndex GetSinkNodeIndex () const
 Returns the index of the node corresponding to the sink of the network.
void SetArcCapacity (ArcIndex arc, FlowQuantity new_capacity)
 Sets the capacity for arc to new_capacity.
void SetArcFlow (ArcIndex arc, FlowQuantity new_flow)
 Sets the flow for arc.
bool Solve ()
 Returns true if a maximum flow was solved.
FlowQuantity GetOptimalFlow () const
 Returns the total flow found by the algorithm.
FlowQuantity Flow (ArcIndex arc) const
 Returns the flow on arc using the equations given in the comment on residual_arc_capacity_.
FlowQuantity Capacity (ArcIndex arc) const
 Returns the capacity of arc using the equations given in the comment on residual_arc_capacity_.

Protected Member Functions

bool IsAdmissible (ArcIndex arc) const
 Returns true if arc is admissible.
bool IsActive (NodeIndex node) const
 Returns true if node is active, i.e.
ArcIndex GetFirstIncidentArc (NodeIndex node) const
 Returns the first incident arc of node.
void PushFlowUnsafe (ArcIndex arc, FlowQuantity flow)
 Reduces the residual capacity on arc by flow.
void SetCapacityResetFlow (ArcIndex arc, FlowQuantity capacity)
 Sets the capacity of arc to 'capacity' and clears the flow on arc.
void SetCapacitySaturate (ArcIndex arc, FlowQuantity capacity)
 Sets the capacity of arc to 'capacity' and saturates the flow on arc.
bool CheckInputConsistency () const
 Checks the consistency of the input, i.e.
bool CheckResult () const
 Checks whether the result is valid, i.e.
bool CheckRelabelPrecondition (NodeIndex node) const
 Returns true if a precondition for Relabel is met, i.e.
string DebugString (const string &context, ArcIndex arc) const
 Returns context concatenated with information about arc in a human-friendly way.
virtual void InitializeActiveNodeContainer ()
 Initializes the container active_nodes_.
virtual NodeIndex GetAndRemoveFirstActiveNode ()
 Get the first element from the active node container.
virtual void PushActiveNode (const NodeIndex &node)
 Push element to the active node container.
virtual bool IsEmptyActiveNodeContainer ()
 Check the emptiness of the container.
void Refine ()
 Performs optimization step.
virtual void Discharge (NodeIndex node)
 Discharges an active node node by saturating its admissible adjacent arcs, if any, and by relabelling it when it becomes inactive.
void ResetFirstAdmissibleArcs ()
 Resets the first_admissible_arc_ array to the first incident arc of each node.
void InitializePreflow ()
 Initializes the preflow to a state that enables to run Optimize.
void PushFlow (FlowQuantity flow, ArcIndex arc)
 Pushes flow on arc, i.e.
void Relabel (NodeIndex node)
 Relabels a node, i.e. increases its height by the minimum necessary amount.
NodeIndex Head (ArcIndex arc) const
 Handy member functions to make the code more compact.
NodeIndex Tail (ArcIndex arc) const
ArcIndex Opposite (ArcIndex arc) const
bool IsDirect (ArcIndex arc) const
 DISALLOW_COPY_AND_ASSIGN (MaxFlow)

Protected Attributes

const StarGraphgraph_
 A pointer to the graph passed as argument.
QuantityArray node_excess_
 A packed array representing the excess for each node in graph_.
CostArray node_potential_
 A packed array representing the height function for each node in graph_.
QuantityArray residual_arc_capacity_
 A packed array representing the residual_capacity for each arc in graph_.
ArcIndexArray first_admissible_arc_
 A packed array representing the first admissible arc for each node in graph_.
std::stack< NodeIndexactive_nodes_
 A stack used for managing active nodes in the algorithm.
NodeIndex source_
 The index of the source node in graph_.
NodeIndex sink_
 The index of the sink node in graph_.
FlowQuantity total_flow_
 The total flow.
Status status_
 The status of the problem.


Detailed Description

Definition at line 129 of file max_flow.h.


Member Enumeration Documentation

Different statuses for a given problem.

Enumerator:
NOT_SOLVED  The problem was not solved, or its data were edited.
OPTIMAL  Solve() was called and found an optimal solution.
FEASIBLE  There is a feasible flow.
INFEASIBLE  There is no feasible flow.
BAD_INPUT  The input is inconsistent.
BAD_RESULT  There was an error.

Definition at line 132 of file max_flow.h.


Constructor & Destructor Documentation

operations_research::MaxFlow::MaxFlow ( const StarGraph graph,
NodeIndex  source,
NodeIndex  target 
)

Definition at line 28 of file max_flow.cc.

virtual operations_research::MaxFlow::~MaxFlow (  )  [inline, virtual]

Definition at line 143 of file max_flow.h.


Member Function Documentation

const StarGraph* operations_research::MaxFlow::graph (  )  const [inline]

Returns the graph associated to the current object.

Definition at line 146 of file max_flow.h.

Status operations_research::MaxFlow::status (  )  const [inline]

Returns the status of last call to Solve().

NOT_SOLVED is returned Solve() has never been called or if the problem has been modified in such a way that the previous solution becomes invalid.

Definition at line 151 of file max_flow.h.

NodeIndex operations_research::MaxFlow::GetSourceNodeIndex (  )  const [inline]

Returns the index of the node corresponding to the source of the network.

Definition at line 154 of file max_flow.h.

NodeIndex operations_research::MaxFlow::GetSinkNodeIndex (  )  const [inline]

Returns the index of the node corresponding to the sink of the network.

Definition at line 157 of file max_flow.h.

void operations_research::MaxFlow::SetArcCapacity ( ArcIndex  arc,
FlowQuantity  new_capacity 
)

Sets the capacity for arc to new_capacity.

Definition at line 68 of file max_flow.cc.

void operations_research::MaxFlow::SetArcFlow ( ArcIndex  arc,
FlowQuantity  new_flow 
) [inline]

Sets the flow for arc.

Definition at line 163 of file max_flow.h.

bool operations_research::MaxFlow::Solve (  ) 

Returns true if a maximum flow was solved.

Definition at line 169 of file max_flow.cc.

FlowQuantity operations_research::MaxFlow::GetOptimalFlow (  )  const [inline]

Returns the total flow found by the algorithm.

Definition at line 176 of file max_flow.h.

FlowQuantity operations_research::MaxFlow::Flow ( ArcIndex  arc  )  const [inline]

Returns the flow on arc using the equations given in the comment on residual_arc_capacity_.

Definition at line 180 of file max_flow.h.

FlowQuantity operations_research::MaxFlow::Capacity ( ArcIndex  arc  )  const [inline]

Returns the capacity of arc using the equations given in the comment on residual_arc_capacity_.

Definition at line 191 of file max_flow.h.

bool operations_research::MaxFlow::IsAdmissible ( ArcIndex  arc  )  const [inline, protected]

Returns true if arc is admissible.

Definition at line 203 of file max_flow.h.

bool operations_research::MaxFlow::IsActive ( NodeIndex  node  )  const [inline, protected]

Returns true if node is active, i.e.

if its supply is positive and it is neither the source or the target of the graph.

Definition at line 210 of file max_flow.h.

ArcIndex operations_research::MaxFlow::GetFirstIncidentArc ( NodeIndex  node  )  const [inline, protected]

Returns the first incident arc of node.

Definition at line 215 of file max_flow.h.

void operations_research::MaxFlow::PushFlowUnsafe ( ArcIndex  arc,
FlowQuantity  flow 
) [inline, protected]

Reduces the residual capacity on arc by flow.

Increase the residual capacity on opposite arc by flow. Does not update the excesses at the tail and head of arc. No check is performed either.

Definition at line 224 of file max_flow.h.

void operations_research::MaxFlow::SetCapacityResetFlow ( ArcIndex  arc,
FlowQuantity  capacity 
) [inline, protected]

Sets the capacity of arc to 'capacity' and clears the flow on arc.

Definition at line 232 of file max_flow.h.

void operations_research::MaxFlow::SetCapacitySaturate ( ArcIndex  arc,
FlowQuantity  capacity 
) [inline, protected]

Sets the capacity of arc to 'capacity' and saturates the flow on arc.

Definition at line 238 of file max_flow.h.

bool operations_research::MaxFlow::CheckInputConsistency (  )  const [protected]

Checks the consistency of the input, i.e.

that capacities on the arcs are non-negative (>=0.)

Definition at line 57 of file max_flow.cc.

bool operations_research::MaxFlow::CheckResult (  )  const [protected]

Checks whether the result is valid, i.e.

that node excesses are all equal to zero (we have a flow) and that residual capacities are all non-negative (>=0.)

Definition at line 107 of file max_flow.cc.

bool operations_research::MaxFlow::CheckRelabelPrecondition ( NodeIndex  node  )  const [protected]

Returns true if a precondition for Relabel is met, i.e.

the outgoing arcs of node are all either saturated or the heights of their heads are greater or equal to the height of node.

Definition at line 144 of file max_flow.cc.

string operations_research::MaxFlow::DebugString ( const string &  context,
ArcIndex  arc 
) const [protected]

Returns context concatenated with information about arc in a human-friendly way.

Definition at line 155 of file max_flow.cc.

void operations_research::MaxFlow::InitializeActiveNodeContainer (  )  [protected, virtual]

Initializes the container active_nodes_.

Definition at line 241 of file max_flow.cc.

virtual NodeIndex operations_research::MaxFlow::GetAndRemoveFirstActiveNode (  )  [inline, protected, virtual]

Get the first element from the active node container.

Definition at line 265 of file max_flow.h.

virtual void operations_research::MaxFlow::PushActiveNode ( const NodeIndex node  )  [inline, protected, virtual]

Push element to the active node container.

Definition at line 272 of file max_flow.h.

virtual bool operations_research::MaxFlow::IsEmptyActiveNodeContainer (  )  [inline, protected, virtual]

Check the emptiness of the container.

Definition at line 277 of file max_flow.h.

void operations_research::MaxFlow::Refine (  )  [protected]

Performs optimization step.

Definition at line 252 of file max_flow.cc.

void operations_research::MaxFlow::Discharge ( NodeIndex  node  )  [protected, virtual]

Discharges an active node node by saturating its admissible adjacent arcs, if any, and by relabelling it when it becomes inactive.

Definition at line 263 of file max_flow.cc.

void operations_research::MaxFlow::ResetFirstAdmissibleArcs (  )  [protected]

Resets the first_admissible_arc_ array to the first incident arc of each node.

Definition at line 193 of file max_flow.cc.

void operations_research::MaxFlow::InitializePreflow (  )  [protected]

Initializes the preflow to a state that enables to run Optimize.

Definition at line 200 of file max_flow.cc.

void operations_research::MaxFlow::PushFlow ( FlowQuantity  flow,
ArcIndex  arc 
) [protected]

Pushes flow on arc, i.e.

consumes flow on residual_arc_capacity_[arc], and consumes -flow on residual_arc_capacity_[Opposite(arc)]. Updates node_excess_ at the tail and head of arc accordingly.

Definition at line 227 of file max_flow.cc.

void operations_research::MaxFlow::Relabel ( NodeIndex  node  )  [protected]

Relabels a node, i.e. increases its height by the minimum necessary amount.

Definition at line 295 of file max_flow.cc.

NodeIndex operations_research::MaxFlow::Head ( ArcIndex  arc  )  const [inline, protected]

Handy member functions to make the code more compact.

Definition at line 304 of file max_flow.h.

NodeIndex operations_research::MaxFlow::Tail ( ArcIndex  arc  )  const [inline, protected]

Definition at line 306 of file max_flow.h.

ArcIndex operations_research::MaxFlow::Opposite ( ArcIndex  arc  )  const [inline, protected]

Definition at line 308 of file max_flow.h.

bool operations_research::MaxFlow::IsDirect ( ArcIndex  arc  )  const [inline, protected]

Definition at line 310 of file max_flow.h.

operations_research::MaxFlow::DISALLOW_COPY_AND_ASSIGN ( MaxFlow   )  [protected]


Member Data Documentation

A pointer to the graph passed as argument.

Definition at line 313 of file max_flow.h.

A packed array representing the excess for each node in graph_.

Definition at line 316 of file max_flow.h.

A packed array representing the height function for each node in graph_.

Definition at line 319 of file max_flow.h.

A packed array representing the residual_capacity for each arc in graph_.

Residual capacities enable one to represent the capacity and flow for all arcs in the graph in the following manner. For all arc, residual_arc_capacity_[arc] = capacity[arc] - flow[arc] Moreover, for reverse arcs, capacity[arc] = 0 by definition, Also flow[Opposite(arc)] = -flow[arc] by definition. Therefore:

  • for a direct arc: flow[arc] = 0 - flow[Opposite(arc)] = capacity[Opposite(arc)] - flow[Opposite(arc)] = residual_arc_capacity_[Opposite(arc)]
  • for a reverse arc: flow[arc] = -residual_arc_capacity_[arc] Using these facts enables one to only maintain residual_arc_capacity_, instead of both capacity and flow, for each direct and indirect arc. This reduces the amount of memory for this information by a factor 2.s reduces the amount of memory for this information by a factor 2.

Definition at line 338 of file max_flow.h.

A packed array representing the first admissible arc for each node in graph_.

Definition at line 342 of file max_flow.h.

A stack used for managing active nodes in the algorithm.

Note that the papers cited above recommend the use of a queue, but benchmarking so far has not proved it is better.

Definition at line 347 of file max_flow.h.

The index of the source node in graph_.

Definition at line 350 of file max_flow.h.

The index of the sink node in graph_.

Definition at line 353 of file max_flow.h.

The total flow.

Definition at line 356 of file max_flow.h.

The status of the problem.

Definition at line 359 of file max_flow.h.


The documentation for this class was generated from the following files: