DagShortestPath< _Graph, _LengthMap, _Traits > Class Template Reference


Detailed Description

template<typename _Graph, typename _LengthMap, typename _Traits>
class lemon::DagShortestPath< _Graph, _LengthMap, _Traits >

This class provides an efficient implementation of a Dag sortest path searching algorithm. The edge lengths are passed to the algorithm using a ReadMap, so it is easy to change it to any kind of length.

The complexity of the algorithm is O(n + e).

The type of the length is determined by the Value of the length map.

Parameters:
_Graph The graph type the algorithm runs on. The default value is ListGraph. The value of _Graph is not used directly by DagShortestPath, it is only passed to DagShortestPathDefaultTraits.
_LengthMap This read-only EdgeMap determines the lengths of the edges. The default map type is Graph::EdgeMap<int>. The value of _LengthMap is not used directly by DagShortestPath, it is only passed to DagShortestPathDefaultTraits.
_Traits Traits class to set various data types used by the algorithm. The default traits class is DagShortestPathDefaultTraits<_Graph,_LengthMap>. See DagShortestPathDefaultTraits for the documentation of a DagShortestPath traits class.
Author:
Balazs Attila Mihaly (based on Balazs Dezso's work)
#include <lemon/dag_shortest_path.h>

List of all members.

Query Functions

The result of the DagShortestPath algorithm can be obtained using these functions.
Before the use of these functions, either run() or start() must be called.

typedef PredMapPath< Graph,
PredMap
Path
Path path (Node t)
 Gives back the shortest path.
Value dist (Node v) const
 The distance of a node from the root.
Edge predEdge (Node v) const
 Returns the 'previous edge' of the shortest path tree.
Node predNode (Node v) const
 Returns the 'previous node' of the shortest path tree.
const DistMapdistMap () const
 Returns a reference to the NodeMap of distances.
const PredMappredMap () const
 Returns a reference to the shortest path tree map.
bool reached (Node v)
 Checks if a node is reachable from the root.

Classes

struct  DefDistMap
struct  DefOperationTraits
struct  DefPredMap
 Named parameter for setting PredMap type Named parameter for setting PredMap type More...
class  UninitializedParameter
 Exception for uninitialized parameters. More...

Public Types

typedef _Traits::Graph Graph
 The type of the underlying graph.
typedef _Traits::LengthMap::Value Value
 The type of the length of the edges.
typedef _Traits::LengthMap LengthMap
 The type of the map that stores the edge lengths.
typedef _Traits::PredMap PredMap
 The type of the map that stores the last edges of the shortest paths.
typedef _Traits::DistMap DistMap
 The type of the map that stores the dists of the nodes.
typedef _Traits::OperationTraits OperationTraits
 The operation traits.
typedef Graph::template
NodeMap< Value
WeightMap
 The Node weight map.

Public Member Functions

 DagShortestPath (const Graph &_graph, const LengthMap &_length)
 Constructor.
 DagShortestPath (const Graph &_graph, const WeightMap &_length)
 Constructor with node weight map.
 ~DagShortestPath ()
 Destructor.
DagShortestPathlengthMap (const LengthMap &m)
 Sets the length map.
DagShortestPathpredMap (PredMap &m)
 Sets the map storing the predecessor edges.
DagShortestPathdistMap (DistMap &m)
 Sets the map storing the distances calculated by the algorithm.
Execution control
The simplest way to execute the algorithm is to use one of the member functions called run(...)
If you need more control on the execution, first you must call init(...), then you can add several source nodes with addSource(). Finally start() will perform the actual path computation. Some functions have an alternative form (checkedInit(...), checkedRun(...)) which also verifies if the graph given in the constructor is a dag.

void init (const Value value=OperationTraits::infinity())
void init (const typename Graph::template NodeMap< int > &node_order, const Value value=OperationTraits::infinity())
void init (const std::vector< Node > &node_order, const Value value=OperationTraits::infinity())
bool checkedInit (const Value value=OperationTraits::infinity())
 Initializes the internal data structures. It also checks if the graph is dag.
bool checkedInit (const typename Graph::template NodeMap< int > &node_order, const Value value=OperationTraits::infinity())
 Initializes the internal data structures with a given topological sort (NodeMap). It also checks if the graph is dag.
bool checkedInit (const std::vector< Node > &node_order, const Value value=OperationTraits::infinity())
 Initializes the internal data structures with a given topological sort (std::vector). It also checks if the graph is dag.
void addSource (Node source, Value dst=OperationTraits::zero())
 Adds a new source node.
Node processNextNode ()
 Executes one step from the dag shortest path algorithm.
bool emptyQueue ()
 Returns false if there are nodes to be processed in the queue.
int queueSize ()
 Returns the number of the nodes to be processed.
void start ()
 Executes the algorithm.
void run (Node s)
 Runs DagShortestPath algorithm from node s.
bool checkedRun (Node s)
 Runs DagShortestPath algorithm from node s. It also checks if the graph is a dag.

Private Member Functions

void create_maps ()
 Creates the maps if necessary.

Private Attributes

const Graphgraph
 Pointer to the underlying graph.
const LengthMaplength
 Pointer to the length map.
PredMap_pred
 Pointer to the map of predecessors edges.
bool local_pred
 Indicates if _pred is locally allocated (true) or not.
DistMap_dist
 Pointer to the map of distances.
bool local_dist
 Indicates if _dist is locally allocated (true) or not.
unsigned int _process_step
 Process step counter.


Constructor & Destructor Documentation

DagShortestPath ( const Graph _graph,
const LengthMap _length 
) [inline]

Parameters:
_graph the graph the algorithm will run on.
_length the length map used by the algorithm.

DagShortestPath ( const Graph _graph,
const WeightMap _length 
) [inline]

Parameters:
_graph the graph the algorithm will run on.
_length the length map used by the algorithm. The NodeMap _length will be used as the weight map. Each edge will have the weight of its target node.


Member Function Documentation

DagShortestPath& lengthMap ( const LengthMap m  )  [inline]

Sets the length map.

Returns:
(*this)

DagShortestPath& predMap ( PredMap m  )  [inline]

Sets the map storing the predecessor edges. If you don't use this function before calling run(), it will allocate one. The destuctor deallocates this automatically allocated map, of course.

Returns:
(*this)

DagShortestPath& distMap ( DistMap m  )  [inline]

Sets the map storing the distances calculated by the algorithm. If you don't use this function before calling run(), it will allocate one. The destuctor deallocates this automatically allocated map, of course.

Returns:
(*this)

void init ( const Value  value = OperationTraits::infinity()  )  [inline]

Initializes the internal data structures.

void init ( const typename Graph::template NodeMap< int > &  node_order,
const Value  value = OperationTraits::infinity() 
) [inline]

Initializes the internal data structures with a given topological sort (NodeMap).

void init ( const std::vector< Node > &  node_order,
const Value  value = OperationTraits::infinity() 
) [inline]

Initializes the internal data structures with a given topological sort (std::vector).

bool checkedInit ( const Value  value = OperationTraits::infinity()  )  [inline]

Initializes the internal data structures. It also checks if the graph is dag.

Returns:
true if the graph (given in the constructor) is dag, false otherwise.

bool checkedInit ( const typename Graph::template NodeMap< int > &  node_order,
const Value  value = OperationTraits::infinity() 
) [inline]

Initializes the internal data structures with a given topological sort (NodeMap). It also checks if the graph is dag.

Returns:
true if the graph (given in the constructor) is dag, false otherwise.

bool checkedInit ( const std::vector< Node > &  node_order,
const Value  value = OperationTraits::infinity() 
) [inline]

Initializes the internal data structures with a given topological sort (std::vector). It also checks if the graph is dag.

Returns:
true if the graph (given in the constructor) is dag, false otherwise.

void addSource ( Node  source,
Value  dst = OperationTraits::zero() 
) [inline]

The optional second parameter is the initial distance of the node. It just sets the distance of the node to the given value.

Node processNextNode (  )  [inline]

If the algoritm calculated the distances in the previous step strictly for all at most k length paths then it will calculate the distances strictly for all at most k + 1 length paths. With k iteration this function calculates the at most k length paths.

Precondition:
the queue is not empty
Returns:
the currently processed node

bool emptyQueue (  )  [inline]

Returns false if there are nodes to be processed in the queue

int queueSize (  )  [inline]

Returns the number of the nodes to be processed in the queue.

void start (  )  [inline]

Precondition:
init() must be called and at least one node should be added with addSource() before using this function.
This method runs the DagShortestPath algorithm from the root node(s) in order to compute the shortest path to each node. The algorithm computes
  • The shortest path tree.
  • The distance of each node from the root(s).

void run ( Node  s  )  [inline]

This method runs the DagShortestPath algorithm from a root node s in order to compute the shortest path to each node. The algorithm computes

  • The shortest path tree.
  • The distance of each node from the root.

Note:
d.run(s) is just a shortcut of the following code.
         d.init();
         d.addSource(s);
         d.start();

bool checkedRun ( Node  s  )  [inline]

This method runs the DagShortestPath algorithm from a root node s in order to compute the shortest path to each node. The algorithm computes

  • The shortest path tree.
  • The distance of each node from the root. The algorithm checks if the graph given int the constructor is a dag.

Path path ( Node  t  )  [inline]

Gives back the shortest path.

Precondition:
The t should be reachable from the source.

Value dist ( Node  v  )  const [inline]

Returns the distance of a node from the root.

Precondition:
run() must be called before using this function.
Warning:
If node v in unreachable from the root the return value of this funcion is undefined.

Edge predEdge ( Node  v  )  const [inline]

For a node v it returns the 'previous edge' of the shortest path tree, i.e. it returns the last edge of a shortest path from the root to v. It is INVALID if v is unreachable from the root or if v=s. The shortest path tree used here is equal to the shortest path tree used in predNode().

Precondition:
run() must be called before using this function.

Node predNode ( Node  v  )  const [inline]

For a node v it returns the 'previous node' of the shortest path tree, i.e. it returns the last but one node from a shortest path from the root to /v. It is INVALID if v is unreachable from the root or if v=s. The shortest path tree used here is equal to the shortest path tree used in predEdge().

Precondition:
run() must be called before using this function.

const DistMap& distMap (  )  const [inline]

Returns a reference to the NodeMap of distances.

Precondition:
run() must be called before using this function.

const PredMap& predMap (  )  const [inline]

Returns a reference to the NodeMap of the edges of the shortest path tree.

Precondition:
run() must be called before using this function.

bool reached ( Node  v  )  [inline]

Returns true if v is reachable from the root.

Precondition:
run() must be called before using this function.


Generated on Thu Jun 4 04:03:42 2009 for LEMON by  doxygen 1.5.9