src/lemon/dijkstra.h
author deba
Mon, 07 Feb 2005 11:29:25 +0000
changeset 1137 83a48cfd8553
parent 1130 47ef467ccf70
child 1151 b217fc69f913
permissions -rw-r--r--
IO moved to lemon.
alpar@906
     1
/* -*- C++ -*-
alpar@921
     2
 * src/lemon/dijkstra.h - Part of LEMON, a generic C++ optimization library
alpar@906
     3
 *
alpar@906
     4
 * Copyright (C) 2004 Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
alpar@906
     5
 * (Egervary Combinatorial Optimization Research Group, EGRES).
alpar@906
     6
 *
alpar@906
     7
 * Permission to use, modify and distribute this software is granted
alpar@906
     8
 * provided that this copyright notice appears in all copies. For
alpar@906
     9
 * precise terms see the accompanying LICENSE file.
alpar@906
    10
 *
alpar@906
    11
 * This software is provided "AS IS" with no warranty of any kind,
alpar@906
    12
 * express or implied, and with no claim as to its suitability for any
alpar@906
    13
 * purpose.
alpar@906
    14
 *
alpar@906
    15
 */
alpar@906
    16
alpar@921
    17
#ifndef LEMON_DIJKSTRA_H
alpar@921
    18
#define LEMON_DIJKSTRA_H
alpar@255
    19
alpar@758
    20
///\ingroup flowalgs
alpar@255
    21
///\file
alpar@255
    22
///\brief Dijkstra algorithm.
alpar@255
    23
alpar@953
    24
#include <lemon/list_graph.h>
alpar@921
    25
#include <lemon/bin_heap.h>
alpar@921
    26
#include <lemon/invalid.h>
alpar@1119
    27
#include <lemon/error.h>
alpar@1119
    28
#include <lemon/maps.h>
alpar@255
    29
alpar@921
    30
namespace lemon {
jacint@385
    31
alpar@1119
    32
alpar@758
    33
/// \addtogroup flowalgs
alpar@430
    34
/// @{
alpar@430
    35
alpar@954
    36
  ///Default traits class of Dijkstra class.
alpar@954
    37
alpar@954
    38
  ///Default traits class of Dijkstra class.
alpar@954
    39
  ///\param GR Graph type.
alpar@954
    40
  ///\param LM Type of length map.
alpar@953
    41
  template<class GR, class LM>
alpar@953
    42
  struct DijkstraDefaultTraits
alpar@953
    43
  {
alpar@954
    44
    ///The graph type the algorithm runs on. 
alpar@953
    45
    typedef GR Graph;
alpar@953
    46
    ///The type of the map that stores the edge lengths.
alpar@953
    47
hegyi@1124
    48
    ///The type of the map that stores the edge lengths.
alpar@967
    49
    ///It must meet the \ref concept::ReadMap "ReadMap" concept.
alpar@953
    50
    typedef LM LengthMap;
alpar@954
    51
    //The type of the length of the edges.
alpar@987
    52
    typedef typename LM::Value Value;
alpar@954
    53
    ///The heap type used by Dijkstra algorithm.
alpar@967
    54
alpar@967
    55
    ///The heap type used by Dijkstra algorithm.
alpar@967
    56
    ///
alpar@967
    57
    ///\sa BinHeap
alpar@967
    58
    ///\sa Dijkstra
alpar@953
    59
    typedef BinHeap<typename Graph::Node,
alpar@987
    60
		    typename LM::Value,
alpar@953
    61
		    typename GR::template NodeMap<int>,
alpar@987
    62
		    std::less<Value> > Heap;
alpar@953
    63
alpar@953
    64
    ///\brief The type of the map that stores the last
alpar@953
    65
    ///edges of the shortest paths.
alpar@953
    66
    /// 
hegyi@1124
    67
    ///The type of the map that stores the last
hegyi@1124
    68
    ///edges of the shortest paths.
alpar@967
    69
    ///It must meet the \ref concept::WriteMap "WriteMap" concept.
alpar@953
    70
    ///
alpar@954
    71
    typedef typename Graph::template NodeMap<typename GR::Edge> PredMap;
alpar@954
    72
    ///Instantiates a PredMap.
alpar@953
    73
 
hegyi@1123
    74
    ///This function instantiates a \ref PredMap. 
hegyi@1123
    75
    ///\param G is the graph, to which we would like to define the PredMap.
alpar@1119
    76
    ///\todo The graph alone may be insufficient for the initialization
alpar@954
    77
    static PredMap *createPredMap(const GR &G) 
alpar@953
    78
    {
alpar@953
    79
      return new PredMap(G);
alpar@953
    80
    }
alpar@953
    81
    ///\brief The type of the map that stores the last but one
alpar@953
    82
    ///nodes of the shortest paths.
alpar@953
    83
    ///
hegyi@1124
    84
    ///The type of the map that stores the last but one
hegyi@1124
    85
    ///nodes of the shortest paths.
alpar@967
    86
    ///It must meet the \ref concept::WriteMap "WriteMap" concept.
alpar@953
    87
    ///
alpar@1130
    88
    typedef NullMap<typename Graph::Node,typename Graph::Node> PredNodeMap;
alpar@954
    89
    ///Instantiates a PredNodeMap.
alpar@1125
    90
    
hegyi@1123
    91
    ///This function instantiates a \ref PredNodeMap. 
hegyi@1123
    92
    ///\param G is the graph, to which we would like to define the \ref PredNodeMap
alpar@954
    93
    static PredNodeMap *createPredNodeMap(const GR &G)
alpar@953
    94
    {
alpar@1130
    95
      return new PredNodeMap();
alpar@953
    96
    }
alpar@1119
    97
alpar@1119
    98
    ///The type of the map that stores whether a nodes is reached.
alpar@1119
    99
 
hegyi@1124
   100
    ///The type of the map that stores whether a nodes is reached.
alpar@1119
   101
    ///It must meet the \ref concept::WriteMap "WriteMap" concept.
alpar@1119
   102
    ///By default it is a NullMap.
alpar@1119
   103
    ///\todo If it is set to a real map, Dijkstra::reached() should read this.
alpar@1119
   104
    ///\todo named parameter to set this type, function to read and write.
alpar@1119
   105
    typedef NullMap<typename Graph::Node,bool> ReachedMap;
alpar@1119
   106
    ///Instantiates a ReachedMap.
alpar@1119
   107
 
hegyi@1123
   108
    ///This function instantiates a \ref ReachedMap. 
hegyi@1123
   109
    ///\param G is the graph, to which we would like to define the \ref ReachedMap
alpar@1119
   110
    static ReachedMap *createReachedMap(const GR &G)
alpar@1119
   111
    {
alpar@1119
   112
      return new ReachedMap();
alpar@1119
   113
    }
alpar@953
   114
    ///The type of the map that stores the dists of the nodes.
alpar@953
   115
 
hegyi@1124
   116
    ///The type of the map that stores the dists of the nodes.
alpar@967
   117
    ///It must meet the \ref concept::WriteMap "WriteMap" concept.
alpar@953
   118
    ///
alpar@987
   119
    typedef typename Graph::template NodeMap<typename LM::Value> DistMap;
alpar@954
   120
    ///Instantiates a DistMap.
alpar@953
   121
 
hegyi@1123
   122
    ///This function instantiates a \ref DistMap. 
hegyi@1123
   123
    ///\param G is the graph, to which we would like to define the \ref DistMap
alpar@954
   124
    static DistMap *createDistMap(const GR &G)
alpar@953
   125
    {
alpar@953
   126
      return new DistMap(G);
alpar@953
   127
    }
alpar@953
   128
  };
alpar@953
   129
  
alpar@255
   130
  ///%Dijkstra algorithm class.
alpar@1125
   131
  
alpar@255
   132
  ///This class provides an efficient implementation of %Dijkstra algorithm.
alpar@255
   133
  ///The edge lengths are passed to the algorithm using a
klao@959
   134
  ///\ref concept::ReadMap "ReadMap",
alpar@255
   135
  ///so it is easy to change it to any kind of length.
alpar@255
   136
  ///
alpar@880
   137
  ///The type of the length is determined by the
alpar@987
   138
  ///\ref concept::ReadMap::Value "Value" of the length map.
alpar@255
   139
  ///
alpar@255
   140
  ///It is also possible to change the underlying priority heap.
alpar@255
   141
  ///
alpar@953
   142
  ///\param GR The graph type the algorithm runs on. The default value is
alpar@955
   143
  ///\ref ListGraph. The value of GR is not used directly by Dijkstra, it
alpar@954
   144
  ///is only passed to \ref DijkstraDefaultTraits.
alpar@584
   145
  ///\param LM This read-only
jacint@385
   146
  ///EdgeMap
jacint@385
   147
  ///determines the
jacint@385
   148
  ///lengths of the edges. It is read once for each edge, so the map
jacint@385
   149
  ///may involve in relatively time consuming process to compute the edge
jacint@385
   150
  ///length if it is necessary. The default map type is
klao@959
   151
  ///\ref concept::StaticGraph::EdgeMap "Graph::EdgeMap<int>".
alpar@955
   152
  ///The value of LM is not used directly by Dijkstra, it
alpar@954
   153
  ///is only passed to \ref DijkstraDefaultTraits.
alpar@954
   154
  ///\param TR Traits class to set various data types used by the algorithm.
alpar@954
   155
  ///The default traits class is
alpar@955
   156
  ///\ref DijkstraDefaultTraits "DijkstraDefaultTraits<GR,LM>".
alpar@954
   157
  ///See \ref DijkstraDefaultTraits for the documentation of
alpar@954
   158
  ///a Dijkstra traits class.
alpar@456
   159
  ///
alpar@689
   160
  ///\author Jacint Szabo and Alpar Juttner
alpar@1128
   161
  ///\todo A compare object would be nice.
alpar@584
   162
alpar@255
   163
#ifdef DOXYGEN
alpar@584
   164
  template <typename GR,
alpar@584
   165
	    typename LM,
alpar@953
   166
	    typename TR>
alpar@255
   167
#else
alpar@953
   168
  template <typename GR=ListGraph,
alpar@584
   169
	    typename LM=typename GR::template EdgeMap<int>,
alpar@953
   170
	    typename TR=DijkstraDefaultTraits<GR,LM> >
alpar@255
   171
#endif
alpar@1116
   172
  class Dijkstra {
alpar@255
   173
  public:
alpar@1125
   174
    /**
alpar@1125
   175
     * \brief \ref Exception for uninitialized parameters.
alpar@1125
   176
     *
alpar@1125
   177
     * This error represents problems in the initialization
alpar@1125
   178
     * of the parameters of the algorithms.
alpar@1125
   179
     */
alpar@1125
   180
    class UninitializedParameter : public lemon::UninitializedParameter {
alpar@1125
   181
    public:
alpar@1125
   182
      virtual const char* exceptionName() const {
alpar@1125
   183
	return "lemon::Dijsktra::UninitializedParameter";
alpar@1125
   184
      }
alpar@1125
   185
    };
alpar@1119
   186
alpar@953
   187
    typedef TR Traits;
alpar@584
   188
    ///The type of the underlying graph.
alpar@954
   189
    typedef typename TR::Graph Graph;
alpar@911
   190
    ///\e
alpar@255
   191
    typedef typename Graph::Node Node;
alpar@911
   192
    ///\e
alpar@255
   193
    typedef typename Graph::NodeIt NodeIt;
alpar@911
   194
    ///\e
alpar@255
   195
    typedef typename Graph::Edge Edge;
alpar@911
   196
    ///\e
alpar@255
   197
    typedef typename Graph::OutEdgeIt OutEdgeIt;
alpar@255
   198
    
alpar@584
   199
    ///The type of the length of the edges.
alpar@987
   200
    typedef typename TR::LengthMap::Value Value;
alpar@693
   201
    ///The type of the map that stores the edge lengths.
alpar@954
   202
    typedef typename TR::LengthMap LengthMap;
alpar@693
   203
    ///\brief The type of the map that stores the last
alpar@584
   204
    ///edges of the shortest paths.
alpar@953
   205
    typedef typename TR::PredMap PredMap;
alpar@693
   206
    ///\brief The type of the map that stores the last but one
alpar@584
   207
    ///nodes of the shortest paths.
alpar@953
   208
    typedef typename TR::PredNodeMap PredNodeMap;
alpar@1119
   209
    ///The type of the map indicating if a node is reached.
alpar@1119
   210
    typedef typename TR::ReachedMap ReachedMap;
alpar@693
   211
    ///The type of the map that stores the dists of the nodes.
alpar@953
   212
    typedef typename TR::DistMap DistMap;
alpar@953
   213
    ///The heap type used by the dijkstra algorithm.
alpar@953
   214
    typedef typename TR::Heap Heap;
alpar@255
   215
  private:
alpar@802
   216
    /// Pointer to the underlying graph.
alpar@688
   217
    const Graph *G;
alpar@802
   218
    /// Pointer to the length map
alpar@954
   219
    const LengthMap *length;
alpar@802
   220
    ///Pointer to the map of predecessors edges.
alpar@1119
   221
    PredMap *_pred;
alpar@1119
   222
    ///Indicates if \ref _pred is locally allocated (\c true) or not.
alpar@1119
   223
    bool local_pred;
alpar@802
   224
    ///Pointer to the map of predecessors nodes.
alpar@1130
   225
    PredNodeMap *_predNode;
alpar@1130
   226
    ///Indicates if \ref _predNode is locally allocated (\c true) or not.
alpar@1130
   227
    bool local_predNode;
alpar@802
   228
    ///Pointer to the map of distances.
alpar@1130
   229
    DistMap *_dist;
alpar@1130
   230
    ///Indicates if \ref _dist is locally allocated (\c true) or not.
alpar@1130
   231
    bool local_dist;
alpar@1119
   232
    ///Pointer to the map of reached status of the nodes.
alpar@1119
   233
    ReachedMap *_reached;
alpar@1119
   234
    ///Indicates if \ref _reached is locally allocated (\c true) or not.
alpar@1119
   235
    bool local_reached;
alpar@688
   236
alpar@802
   237
    ///The source node of the last execution.
alpar@774
   238
    Node source;
alpar@774
   239
alpar@1128
   240
    ///Creates the maps if necessary.
alpar@688
   241
    
alpar@694
   242
    ///\todo Error if \c G or are \c NULL. What about \c length?
alpar@688
   243
    ///\todo Better memory allocation (instead of new).
alpar@1128
   244
    void create_maps() 
alpar@688
   245
    {
alpar@1119
   246
      if(!_pred) {
alpar@1119
   247
	local_pred = true;
alpar@1119
   248
	_pred = Traits::createPredMap(*G);
alpar@688
   249
      }
alpar@1130
   250
      if(!_predNode) {
alpar@1130
   251
	local_predNode = true;
alpar@1130
   252
	_predNode = Traits::createPredNodeMap(*G);
alpar@688
   253
      }
alpar@1130
   254
      if(!_dist) {
alpar@1130
   255
	local_dist = true;
alpar@1130
   256
	_dist = Traits::createDistMap(*G);
alpar@688
   257
      }
alpar@1119
   258
      if(!_reached) {
alpar@1119
   259
	local_reached = true;
alpar@1119
   260
	_reached = Traits::createReachedMap(*G);
alpar@1119
   261
      }
alpar@688
   262
    }
alpar@255
   263
    
alpar@255
   264
  public :
alpar@1116
   265
 
alpar@1128
   266
    ///\name Named template parameters
alpar@1128
   267
alpar@1128
   268
    ///@{
alpar@1128
   269
alpar@953
   270
    template <class T>
alpar@1116
   271
    struct DefPredMapTraits : public Traits {
alpar@953
   272
      typedef T PredMap;
alpar@953
   273
      static PredMap *createPredMap(const Graph &G) 
alpar@953
   274
      {
alpar@1126
   275
	throw UninitializedParameter();
alpar@953
   276
      }
alpar@953
   277
    };
alpar@954
   278
    ///\ref named-templ-param "Named parameter" for setting PredMap type
alpar@954
   279
alpar@954
   280
    ///\ref named-templ-param "Named parameter" for setting PredMap type
alpar@1043
   281
    ///
alpar@953
   282
    template <class T>
alpar@1116
   283
    class DefPredMap : public Dijkstra< Graph,
alpar@953
   284
					LengthMap,
alpar@1116
   285
					DefPredMapTraits<T> > { };
alpar@953
   286
    
alpar@953
   287
    template <class T>
alpar@1116
   288
    struct DefPredNodeMapTraits : public Traits {
alpar@953
   289
      typedef T PredNodeMap;
alpar@953
   290
      static PredNodeMap *createPredNodeMap(const Graph &G) 
alpar@953
   291
      {
alpar@1126
   292
	throw UninitializedParameter();
alpar@953
   293
      }
alpar@953
   294
    };
alpar@954
   295
    ///\ref named-templ-param "Named parameter" for setting PredNodeMap type
alpar@954
   296
alpar@954
   297
    ///\ref named-templ-param "Named parameter" for setting PredNodeMap type
alpar@1043
   298
    ///
alpar@953
   299
    template <class T>
alpar@1116
   300
    class DefPredNodeMap : public Dijkstra< Graph,
alpar@953
   301
					    LengthMap,
alpar@1116
   302
					    DefPredNodeMapTraits<T> > { };
alpar@953
   303
    
alpar@953
   304
    template <class T>
alpar@1116
   305
    struct DefDistMapTraits : public Traits {
alpar@953
   306
      typedef T DistMap;
alpar@953
   307
      static DistMap *createDistMap(const Graph &G) 
alpar@953
   308
      {
alpar@1126
   309
	throw UninitializedParameter();
alpar@953
   310
      }
alpar@953
   311
    };
alpar@954
   312
    ///\ref named-templ-param "Named parameter" for setting DistMap type
alpar@954
   313
alpar@954
   314
    ///\ref named-templ-param "Named parameter" for setting DistMap type
alpar@1043
   315
    ///
alpar@953
   316
    template <class T>
alpar@1116
   317
    class DefDistMap : public Dijkstra< Graph,
alpar@953
   318
					LengthMap,
alpar@1116
   319
					DefDistMapTraits<T> > { };
alpar@953
   320
    
alpar@1128
   321
    template <class T>
alpar@1128
   322
    struct DefReachedMapTraits : public Traits {
alpar@1128
   323
      typedef T ReachedMap;
alpar@1128
   324
      static ReachedMap *createReachedMap(const Graph &G) 
alpar@1128
   325
      {
alpar@1128
   326
	throw UninitializedParameter();
alpar@1128
   327
      }
alpar@1128
   328
    };
alpar@1128
   329
    ///\ref named-templ-param "Named parameter" for setting ReachedMap type
alpar@1128
   330
alpar@1128
   331
    ///\ref named-templ-param "Named parameter" for setting ReachedMap type
alpar@1128
   332
    ///
alpar@1128
   333
    template <class T>
alpar@1128
   334
    class DefReachedMap : public Dijkstra< Graph,
alpar@1128
   335
					LengthMap,
alpar@1128
   336
					DefReachedMapTraits<T> > { };
alpar@1128
   337
    
alpar@1128
   338
    struct DefGraphReachedMapTraits : public Traits {
alpar@1128
   339
      typedef typename Graph::NodeMap<bool> ReachedMap;
alpar@1128
   340
      static ReachedMap *createReachedMap(const Graph &G) 
alpar@1128
   341
      {
alpar@1128
   342
	return new ReachedMap(G);
alpar@1128
   343
      }
alpar@1128
   344
    };
alpar@1128
   345
    ///\brief \ref named-templ-param "Named parameter"
alpar@1128
   346
    ///for setting the ReachedMap type to be Graph::NodeMap<bool>.
alpar@1128
   347
    ///
alpar@1128
   348
    ///\ref named-templ-param "Named parameter"
alpar@1128
   349
    ///for setting the ReachedMap type to be Graph::NodeMap<bool>.
alpar@1128
   350
    ///If you don't set it explicitely, it will be automatically allocated.
alpar@1128
   351
    template <class T>
alpar@1128
   352
    class DefReachedMapToBeDefaultMap :
alpar@1128
   353
      public Dijkstra< Graph,
alpar@1128
   354
		       LengthMap,
alpar@1128
   355
		       DefGraphReachedMapTraits> { };
alpar@1128
   356
    
alpar@1128
   357
    ///@}
alpar@1128
   358
alpar@1128
   359
alpar@1128
   360
  private:
alpar@1128
   361
    typename Graph::template NodeMap<int> _heap_map;
alpar@1128
   362
    Heap _heap;
alpar@1128
   363
  public:      
alpar@1128
   364
    
alpar@802
   365
    ///Constructor.
alpar@255
   366
    
alpar@802
   367
    ///\param _G the graph the algorithm will run on.
alpar@802
   368
    ///\param _length the length map used by the algorithm.
alpar@954
   369
    Dijkstra(const Graph& _G, const LengthMap& _length) :
alpar@688
   370
      G(&_G), length(&_length),
alpar@1119
   371
      _pred(NULL), local_pred(false),
alpar@1130
   372
      _predNode(NULL), local_predNode(false),
alpar@1130
   373
      _dist(NULL), local_dist(false),
alpar@1128
   374
      _reached(NULL), local_reached(false),
alpar@1128
   375
      _heap_map(*G,-1),_heap(_heap_map)
alpar@688
   376
    { }
alpar@688
   377
    
alpar@802
   378
    ///Destructor.
alpar@688
   379
    ~Dijkstra() 
alpar@688
   380
    {
alpar@1119
   381
      if(local_pred) delete _pred;
alpar@1130
   382
      if(local_predNode) delete _predNode;
alpar@1130
   383
      if(local_dist) delete _dist;
alpar@1119
   384
      if(local_reached) delete _reached;
alpar@688
   385
    }
alpar@688
   386
alpar@688
   387
    ///Sets the length map.
alpar@688
   388
alpar@688
   389
    ///Sets the length map.
alpar@688
   390
    ///\return <tt> (*this) </tt>
alpar@1116
   391
    Dijkstra &lengthMap(const LengthMap &m) 
alpar@688
   392
    {
alpar@688
   393
      length = &m;
alpar@688
   394
      return *this;
alpar@688
   395
    }
alpar@688
   396
alpar@688
   397
    ///Sets the map storing the predecessor edges.
alpar@688
   398
alpar@688
   399
    ///Sets the map storing the predecessor edges.
alpar@688
   400
    ///If you don't use this function before calling \ref run(),
alpar@688
   401
    ///it will allocate one. The destuctor deallocates this
alpar@688
   402
    ///automatically allocated map, of course.
alpar@688
   403
    ///\return <tt> (*this) </tt>
alpar@1116
   404
    Dijkstra &predMap(PredMap &m) 
alpar@688
   405
    {
alpar@1119
   406
      if(local_pred) {
alpar@1119
   407
	delete _pred;
alpar@1119
   408
	local_pred=false;
alpar@688
   409
      }
alpar@1119
   410
      _pred = &m;
alpar@688
   411
      return *this;
alpar@688
   412
    }
alpar@688
   413
alpar@688
   414
    ///Sets the map storing the predecessor nodes.
alpar@688
   415
alpar@688
   416
    ///Sets the map storing the predecessor nodes.
alpar@688
   417
    ///If you don't use this function before calling \ref run(),
alpar@688
   418
    ///it will allocate one. The destuctor deallocates this
alpar@688
   419
    ///automatically allocated map, of course.
alpar@688
   420
    ///\return <tt> (*this) </tt>
alpar@1116
   421
    Dijkstra &predNodeMap(PredNodeMap &m) 
alpar@688
   422
    {
alpar@1130
   423
      if(local_predNode) {
alpar@1130
   424
	delete _predNode;
alpar@1130
   425
	local_predNode=false;
alpar@688
   426
      }
alpar@1130
   427
      _predNode = &m;
alpar@688
   428
      return *this;
alpar@688
   429
    }
alpar@688
   430
alpar@688
   431
    ///Sets the map storing the distances calculated by the algorithm.
alpar@688
   432
alpar@688
   433
    ///Sets the map storing the distances calculated by the algorithm.
alpar@688
   434
    ///If you don't use this function before calling \ref run(),
alpar@688
   435
    ///it will allocate one. The destuctor deallocates this
alpar@688
   436
    ///automatically allocated map, of course.
alpar@688
   437
    ///\return <tt> (*this) </tt>
alpar@1116
   438
    Dijkstra &distMap(DistMap &m) 
alpar@688
   439
    {
alpar@1130
   440
      if(local_dist) {
alpar@1130
   441
	delete _dist;
alpar@1130
   442
	local_dist=false;
alpar@688
   443
      }
alpar@1130
   444
      _dist = &m;
alpar@688
   445
      return *this;
alpar@688
   446
    }
alpar@694
   447
alpar@1130
   448
  private:
alpar@1130
   449
    void finalizeNodeData(Node v,Value dst)
alpar@1130
   450
    {
alpar@1130
   451
      _reached->set(v,true);
alpar@1130
   452
      _dist->set(v, dst);
alpar@1130
   453
      _predNode->set(v,G->source((*_pred)[v]));
alpar@1130
   454
    }
alpar@1130
   455
alpar@1130
   456
  public:
alpar@1128
   457
    ///\name Excetution control
alpar@1128
   458
    ///The simplest way to execute the algorithm is to use
alpar@1128
   459
    ///\ref run().
alpar@1128
   460
    ///\n
alpar@1128
   461
    ///It you need more control on the execution,
alpar@1128
   462
    ///first you must call \ref init(), then you can add several source nodes
alpar@1128
   463
    ///with \ref addSource(). Finally \ref start() will perform the actual path
alpar@1128
   464
    ///computation.
alpar@1128
   465
alpar@1128
   466
    ///@{
alpar@1128
   467
alpar@1128
   468
    ///Initializes the internal data structures.
alpar@1128
   469
alpar@1128
   470
    ///Initializes the internal data structures.
alpar@1128
   471
    ///
alpar@1128
   472
    ///\todo _heap_map's type could also be in the traits class.
alpar@1128
   473
    void init()
alpar@1128
   474
    {
alpar@1128
   475
      create_maps();
alpar@774
   476
      
alpar@774
   477
      for ( NodeIt u(*G) ; u!=INVALID ; ++u ) {
alpar@1119
   478
	_pred->set(u,INVALID);
alpar@1130
   479
	_predNode->set(u,INVALID);
alpar@1119
   480
	///\todo *_reached is not set to false.
alpar@1128
   481
	_heap_map.set(u,Heap::PRE_HEAP);
alpar@694
   482
      }
alpar@1128
   483
    }
alpar@1128
   484
    
alpar@1128
   485
    ///Adds a new source node.
alpar@1128
   486
alpar@1128
   487
    ///Adds a new source node the the priority heap.
alpar@1128
   488
    ///It checks if the node has already been added to the heap.
alpar@1128
   489
    ///
alpar@1128
   490
    ///The optional second parameter is the initial distance of the node.
alpar@1128
   491
    ///
alpar@1128
   492
    ///\todo Do we really want to check it?
alpar@1128
   493
    void addSource(Node s,Value dst=0)
alpar@1128
   494
    {
alpar@1128
   495
      source = s;
alpar@1128
   496
      if(_heap.state(s) != Heap::IN_HEAP) _heap.push(s,dst);
alpar@1128
   497
    }
alpar@1128
   498
    
alpar@1128
   499
    void processNode()
alpar@1128
   500
    {
alpar@1128
   501
      Node v=_heap.top(); 
alpar@1128
   502
      Value oldvalue=_heap[v];
alpar@1128
   503
      _heap.pop();
alpar@1130
   504
      finalizeNodeData(v,oldvalue);
alpar@694
   505
      
alpar@1128
   506
      for(OutEdgeIt e(*G,v); e!=INVALID; ++e) {
alpar@1128
   507
	Node w=G->target(e); 
alpar@1128
   508
	switch(_heap.state(w)) {
alpar@1128
   509
	case Heap::PRE_HEAP:
alpar@1128
   510
	  _heap.push(w,oldvalue+(*length)[e]); 
alpar@1128
   511
	  _pred->set(w,e);
alpar@1130
   512
//  	  _predNode->set(w,v);
alpar@1128
   513
	  break;
alpar@1128
   514
	case Heap::IN_HEAP:
alpar@1128
   515
	  if ( oldvalue+(*length)[e] < _heap[w] ) {
alpar@1128
   516
	    _heap.decrease(w, oldvalue+(*length)[e]); 
alpar@1119
   517
	    _pred->set(w,e);
alpar@1130
   518
// 	    _predNode->set(w,v);
alpar@694
   519
	  }
alpar@1128
   520
	  break;
alpar@1128
   521
	case Heap::POST_HEAP:
alpar@1128
   522
	  break;
alpar@694
   523
	}
alpar@694
   524
      }
alpar@694
   525
    }
alpar@1128
   526
alpar@1130
   527
    ///Executes the algorithm.
alpar@1128
   528
alpar@1130
   529
    ///Executes the algorithm.
alpar@1128
   530
    ///
alpar@1130
   531
    ///\pre init() must be called and at least one node should be added
alpar@1130
   532
    ///with addSource() before using this function.
alpar@1128
   533
    ///
alpar@1128
   534
    ///This method runs the %Dijkstra algorithm from the root node(s)
alpar@1128
   535
    ///in order to
alpar@1128
   536
    ///compute the
alpar@1128
   537
    ///shortest path to each node. The algorithm computes
alpar@1128
   538
    ///- The shortest path tree.
alpar@1128
   539
    ///- The distance of each node from the root(s).
alpar@1128
   540
    ///
alpar@1128
   541
    void start()
alpar@1128
   542
    {
alpar@1128
   543
      while ( !_heap.empty() ) processNode();
alpar@1128
   544
    }
alpar@255
   545
    
alpar@1130
   546
    ///Executes the algorithm until \c dest is reached.
alpar@1128
   547
alpar@1130
   548
    ///Executes the algorithm until \c dest is reached.
alpar@1128
   549
    ///
alpar@1130
   550
    ///\pre init() must be called and at least one node should be added
alpar@1130
   551
    ///with addSource() before using this function.
alpar@1128
   552
    ///
alpar@1128
   553
    ///This method runs the %Dijkstra algorithm from the root node(s)
alpar@1128
   554
    ///in order to
alpar@1128
   555
    ///compute the
alpar@1128
   556
    ///shortest path to \c dest. The algorithm computes
alpar@1128
   557
    ///- The shortest path to \c  dest.
alpar@1128
   558
    ///- The distance of \c dest from the root(s).
alpar@1128
   559
    ///
alpar@1128
   560
    void start(Node dest)
alpar@1128
   561
    {
alpar@1130
   562
      while ( !_heap.empty() && _heap.top()!=dest ) processNode();
alpar@1130
   563
      if ( _heap.top()==dest ) finalizeNodeData(_heap.top());
alpar@1130
   564
    }
alpar@1130
   565
    
alpar@1130
   566
    ///Executes the algorithm until a condition is met.
alpar@1130
   567
alpar@1130
   568
    ///Executes the algorithm until a condition is met.
alpar@1130
   569
    ///
alpar@1130
   570
    ///\pre init() must be called and at least one node should be added
alpar@1130
   571
    ///with addSource() before using this function.
alpar@1130
   572
    ///
alpar@1130
   573
    ///\param nm must be a bool (or convertible) node map. The algorithm
alpar@1130
   574
    ///will stop when it reaches a node \c v with <tt>nm[v]==true</tt>.
alpar@1130
   575
    template<class NM>
alpar@1130
   576
    void start(const NM &nm)
alpar@1130
   577
    {
alpar@1130
   578
      while ( !_heap.empty() && !mn[_heap.top()] ) processNode();
alpar@1130
   579
      if ( !_heap.empty() ) finalizeNodeData(_heap.top());
alpar@1128
   580
    }
alpar@1128
   581
    
alpar@1128
   582
    ///Runs %Dijkstra algorithm from node \c s.
alpar@1128
   583
    
alpar@1128
   584
    ///This method runs the %Dijkstra algorithm from a root node \c s
alpar@1128
   585
    ///in order to
alpar@1128
   586
    ///compute the
alpar@1128
   587
    ///shortest path to each node. The algorithm computes
alpar@1128
   588
    ///- The shortest path tree.
alpar@1128
   589
    ///- The distance of each node from the root.
alpar@1128
   590
    ///
alpar@1128
   591
    ///\note d.run(s) is just a shortcut of the following code.
alpar@1128
   592
    ///\code
alpar@1128
   593
    ///  d.init();
alpar@1128
   594
    ///  d.addSource(s);
alpar@1128
   595
    ///  d.start();
alpar@1128
   596
    ///\endcode
alpar@1128
   597
    void run(Node s) {
alpar@1128
   598
      init();
alpar@1128
   599
      addSource(s);
alpar@1128
   600
      start();
alpar@1128
   601
    }
alpar@1128
   602
    
alpar@1130
   603
    ///Finds the shortest path between \c s and \c t.
alpar@1130
   604
    
alpar@1130
   605
    ///Finds the shortest path between \c s and \c t.
alpar@1130
   606
    ///
alpar@1130
   607
    ///\return The length of the shortest s---t path if there exists one,
alpar@1130
   608
    ///0 otherwise.
alpar@1130
   609
    ///\note Apart from the return value, d.run(s) is
alpar@1130
   610
    ///just a shortcut of the following code.
alpar@1130
   611
    ///\code
alpar@1130
   612
    ///  d.init();
alpar@1130
   613
    ///  d.addSource(s);
alpar@1130
   614
    ///  d.start(t);
alpar@1130
   615
    ///\endcode
alpar@1130
   616
    Value run(Node s,Node t) {
alpar@1130
   617
      init();
alpar@1130
   618
      addSource(s);
alpar@1130
   619
      start(t);
alpar@1130
   620
      return (*_pred)[t]==INVALID?0:(*_dist)[t];
alpar@1130
   621
    }
alpar@1130
   622
    
alpar@1128
   623
    ///@}
alpar@1128
   624
alpar@1128
   625
    ///\name Query Functions
alpar@1128
   626
    ///The result of the %Dijkstra algorithm can be obtained using these
alpar@1128
   627
    ///functions.\n
alpar@1128
   628
    ///Before the use of these functions,
alpar@1128
   629
    ///either run() or start() must be called.
alpar@1128
   630
    
alpar@1128
   631
    ///@{
alpar@1128
   632
jacint@385
   633
    ///The distance of a node from the root.
alpar@255
   634
jacint@385
   635
    ///Returns the distance of a node from the root.
alpar@255
   636
    ///\pre \ref run() must be called before using this function.
jacint@385
   637
    ///\warning If node \c v in unreachable from the root the return value
alpar@255
   638
    ///of this funcion is undefined.
alpar@1130
   639
    Value dist(Node v) const { return (*_dist)[v]; }
jacint@373
   640
alpar@584
   641
    ///Returns the 'previous edge' of the shortest path tree.
alpar@255
   642
alpar@584
   643
    ///For a node \c v it returns the 'previous edge' of the shortest path tree,
alpar@785
   644
    ///i.e. it returns the last edge of a shortest path from the root to \c
alpar@688
   645
    ///v. It is \ref INVALID
alpar@688
   646
    ///if \c v is unreachable from the root or if \c v=s. The
jacint@385
   647
    ///shortest path tree used here is equal to the shortest path tree used in
jacint@385
   648
    ///\ref predNode(Node v).  \pre \ref run() must be called before using
jacint@385
   649
    ///this function.
alpar@780
   650
    ///\todo predEdge could be a better name.
alpar@1119
   651
    Edge pred(Node v) const { return (*_pred)[v]; }
jacint@373
   652
alpar@584
   653
    ///Returns the 'previous node' of the shortest path tree.
alpar@255
   654
alpar@584
   655
    ///For a node \c v it returns the 'previous node' of the shortest path tree,
jacint@385
   656
    ///i.e. it returns the last but one node from a shortest path from the
jacint@385
   657
    ///root to \c /v. It is INVALID if \c v is unreachable from the root or if
jacint@385
   658
    ///\c v=s. The shortest path tree used here is equal to the shortest path
jacint@385
   659
    ///tree used in \ref pred(Node v).  \pre \ref run() must be called before
jacint@385
   660
    ///using this function.
alpar@1130
   661
    Node predNode(Node v) const { return (*_pred)[v]==INVALID ? INVALID:
alpar@1130
   662
				  G->source((*_pred)[v]); }
alpar@255
   663
    
alpar@255
   664
    ///Returns a reference to the NodeMap of distances.
alpar@255
   665
jacint@385
   666
    ///Returns a reference to the NodeMap of distances. \pre \ref run() must
jacint@385
   667
    ///be called before using this function.
alpar@1130
   668
    const DistMap &distMap() const { return *_dist;}
jacint@385
   669
 
alpar@255
   670
    ///Returns a reference to the shortest path tree map.
alpar@255
   671
alpar@255
   672
    ///Returns a reference to the NodeMap of the edges of the
alpar@255
   673
    ///shortest path tree.
alpar@255
   674
    ///\pre \ref run() must be called before using this function.
alpar@1119
   675
    const PredMap &predMap() const { return *_pred;}
jacint@385
   676
 
jacint@385
   677
    ///Returns a reference to the map of nodes of shortest paths.
alpar@255
   678
alpar@255
   679
    ///Returns a reference to the NodeMap of the last but one nodes of the
jacint@385
   680
    ///shortest path tree.
alpar@255
   681
    ///\pre \ref run() must be called before using this function.
alpar@1130
   682
    const PredNodeMap &predNodeMap() const { return *_predNode;}
alpar@255
   683
jacint@385
   684
    ///Checks if a node is reachable from the root.
alpar@255
   685
jacint@385
   686
    ///Returns \c true if \c v is reachable from the root.
alpar@1128
   687
    ///\warning If the algorithm is started from multiple nodes,
alpar@1128
   688
    ///this function may give false result for the source nodes.
alpar@255
   689
    ///\pre \ref run() must be called before using this function.
jacint@385
   690
    ///
alpar@1119
   691
    bool reached(Node v) { return v==source || (*_pred)[v]!=INVALID; }
alpar@255
   692
    
alpar@1128
   693
    ///@}
alpar@255
   694
  };
alpar@953
   695
hegyi@1123
   696
  /// Default traits used by \ref DijkstraWizard
hegyi@1123
   697
hegyi@1124
   698
  /// To make it easier to use Dijkstra algorithm we have created a wizard class.
hegyi@1124
   699
  /// This \ref DijkstraWizard class needs default traits, as well as the \ref Dijkstra class.
hegyi@1123
   700
  /// The \ref DijkstraWizardBase is a class to be the default traits of the
hegyi@1123
   701
  /// \ref DijkstraWizard class.
alpar@1116
   702
  template<class GR,class LM>
alpar@1116
   703
  class DijkstraWizardBase : public DijkstraDefaultTraits<GR,LM>
alpar@1116
   704
  {
alpar@1116
   705
alpar@1116
   706
    typedef DijkstraDefaultTraits<GR,LM> Base;
alpar@1116
   707
  protected:
alpar@1116
   708
    /// Pointer to the underlying graph.
alpar@1116
   709
    void *_g;
alpar@1116
   710
    /// Pointer to the length map
alpar@1116
   711
    void *_length;
alpar@1116
   712
    ///Pointer to the map of predecessors edges.
alpar@1116
   713
    void *_pred;
alpar@1116
   714
    ///Pointer to the map of predecessors nodes.
alpar@1116
   715
    void *_predNode;
alpar@1116
   716
    ///Pointer to the map of distances.
alpar@1116
   717
    void *_dist;
alpar@1116
   718
    ///Pointer to the source node.
alpar@1116
   719
    void *_source;
alpar@1116
   720
hegyi@1123
   721
    /// Type of the nodes in the graph.
alpar@1116
   722
    typedef typename Base::Graph::Node Node;
alpar@1116
   723
alpar@1116
   724
    public:
hegyi@1123
   725
    /// Constructor.
hegyi@1123
   726
    
hegyi@1123
   727
    /// This constructor does not require parameters, therefore it initiates
hegyi@1123
   728
    /// all of the attributes to default values (0, INVALID).
alpar@1116
   729
    DijkstraWizardBase() : _g(0), _length(0), _pred(0), _predNode(0),
alpar@1116
   730
		       _dist(0), _source(INVALID) {}
alpar@1116
   731
hegyi@1123
   732
    /// Constructor.
hegyi@1123
   733
    
hegyi@1123
   734
    /// This constructor requires some parameters, listed in the parameters list.
hegyi@1123
   735
    /// Others are initiated to 0.
hegyi@1123
   736
    /// \param g is the initial value of  \ref _g
hegyi@1123
   737
    /// \param l is the initial value of  \ref _length
hegyi@1123
   738
    /// \param s is the initial value of  \ref _source
alpar@1116
   739
    DijkstraWizardBase(const GR &g,const LM &l, Node s=INVALID) :
alpar@1116
   740
      _g((void *)&g), _length((void *)&l), _pred(0), _predNode(0),
alpar@1116
   741
		  _dist(0), _source((void *)&s) {}
alpar@1116
   742
alpar@1116
   743
  };
alpar@1116
   744
  
hegyi@1123
   745
  /// A class to make easier the usage of Dijkstra algorithm
alpar@953
   746
hegyi@1123
   747
  /// This class is created to make it easier to use Dijkstra algorithm.
hegyi@1123
   748
  /// It uses the functions and features of the plain \ref Dijkstra,
hegyi@1123
   749
  /// but it is much more simple to use it.
alpar@953
   750
  ///
hegyi@1123
   751
  /// Simplicity means that the way to change the types defined
hegyi@1123
   752
  /// in the traits class is based on functions that returns the new class
hegyi@1124
   753
  /// and not on templatable built-in classes. When using the plain \ref Dijkstra
hegyi@1124
   754
  /// the new class with the modified type comes from the original class by using the ::
hegyi@1124
   755
  /// operator. In the case of \ref DijkstraWizard only a function have to be called and it will
hegyi@1123
   756
  /// return the needed class.
hegyi@1123
   757
  ///
hegyi@1123
   758
  /// It does not have own \ref run method. When its \ref run method is called
hegyi@1123
   759
  /// it initiates a plain \ref Dijkstra class, and calls the \ref Dijkstra::run
hegyi@1123
   760
  /// method of it.
alpar@953
   761
  template<class TR>
alpar@1116
   762
  class DijkstraWizard : public TR
alpar@953
   763
  {
alpar@1116
   764
    typedef TR Base;
alpar@953
   765
hegyi@1123
   766
    ///The type of the underlying graph.
alpar@953
   767
    typedef typename TR::Graph Graph;
alpar@1119
   768
    //\e
alpar@953
   769
    typedef typename Graph::Node Node;
alpar@1119
   770
    //\e
alpar@953
   771
    typedef typename Graph::NodeIt NodeIt;
alpar@1119
   772
    //\e
alpar@953
   773
    typedef typename Graph::Edge Edge;
alpar@1119
   774
    //\e
alpar@953
   775
    typedef typename Graph::OutEdgeIt OutEdgeIt;
alpar@953
   776
    
hegyi@1123
   777
    ///The type of the map that stores the edge lengths.
alpar@953
   778
    typedef typename TR::LengthMap LengthMap;
hegyi@1123
   779
    ///The type of the length of the edges.
alpar@987
   780
    typedef typename LengthMap::Value Value;
hegyi@1123
   781
    ///\brief The type of the map that stores the last
hegyi@1123
   782
    ///edges of the shortest paths.
alpar@953
   783
    typedef typename TR::PredMap PredMap;
hegyi@1123
   784
    ///\brief The type of the map that stores the last but one
hegyi@1123
   785
    ///nodes of the shortest paths.
alpar@953
   786
    typedef typename TR::PredNodeMap PredNodeMap;
hegyi@1123
   787
    ///The type of the map that stores the dists of the nodes.
alpar@953
   788
    typedef typename TR::DistMap DistMap;
alpar@953
   789
hegyi@1123
   790
    ///The heap type used by the dijkstra algorithm.
alpar@953
   791
    typedef typename TR::Heap Heap;
alpar@1116
   792
public:
hegyi@1123
   793
    /// Constructor.
alpar@1116
   794
    DijkstraWizard() : TR() {}
alpar@953
   795
hegyi@1123
   796
    /// Constructor that requires parameters.
hegyi@1124
   797
hegyi@1124
   798
    /// Constructor that requires parameters.
hegyi@1123
   799
    /// These parameters will be the default values for the traits class.
alpar@1116
   800
    DijkstraWizard(const Graph &g,const LengthMap &l, Node s=INVALID) :
alpar@1116
   801
      TR(g,l,s) {}
alpar@953
   802
hegyi@1123
   803
    ///Copy constructor
alpar@1116
   804
    DijkstraWizard(const TR &b) : TR(b) {}
alpar@953
   805
alpar@1116
   806
    ~DijkstraWizard() {}
alpar@1116
   807
hegyi@1123
   808
    ///Runs Dijkstra algorithm from a given node.
hegyi@1123
   809
    
hegyi@1123
   810
    ///Runs Dijkstra algorithm from a given node.
hegyi@1123
   811
    ///The node can be given by the \ref source function.
alpar@1116
   812
    void run()
alpar@953
   813
    {
alpar@1126
   814
      if(_source==0) throw UninitializedParameter();
alpar@1116
   815
      Dijkstra<Graph,LengthMap,TR> Dij(*(Graph*)_g,*(LengthMap*)_length);
alpar@1116
   816
      if(_pred) Dij.predMap(*(PredMap*)_pred);
alpar@1116
   817
      if(_predNode) Dij.predNodeMap(*(PredNodeMap*)_predNode);
alpar@1116
   818
      if(_dist) Dij.distMap(*(DistMap*)_dist);
alpar@1116
   819
      Dij.run(*(Node*)_source);
alpar@1116
   820
    }
alpar@1116
   821
hegyi@1124
   822
    ///Runs Dijkstra algorithm from the given node.
hegyi@1123
   823
hegyi@1124
   824
    ///Runs Dijkstra algorithm from the given node.
hegyi@1123
   825
    ///\param s is the given source.
alpar@1116
   826
    void run(Node s)
alpar@1116
   827
    {
alpar@1116
   828
      _source=(void *)&s;
alpar@1116
   829
      run();
alpar@953
   830
    }
alpar@953
   831
alpar@953
   832
    template<class T>
alpar@1116
   833
    struct DefPredMapBase : public Base {
alpar@1116
   834
      typedef T PredMap;
alpar@1117
   835
      static PredMap *createPredMap(const Graph &G) { return 0; };
alpar@1117
   836
      DefPredMapBase(const Base &b) : Base(b) {}
alpar@1116
   837
    };
alpar@953
   838
    
hegyi@1123
   839
    /// \ref named-templ-param "Named parameter" function for setting PredMap type
hegyi@1123
   840
hegyi@1123
   841
    /// \ref named-templ-param "Named parameter" function for setting PredMap type
hegyi@1124
   842
    ///
alpar@953
   843
    template<class T>
alpar@1116
   844
    DijkstraWizard<DefPredMapBase<T> > predMap(const T &t) 
alpar@953
   845
    {
alpar@1116
   846
      _pred=(void *)&t;
alpar@1116
   847
      return DijkstraWizard<DefPredMapBase<T> >(*this);
alpar@953
   848
    }
alpar@953
   849
    
alpar@1116
   850
alpar@953
   851
    template<class T>
alpar@1116
   852
    struct DefPredNodeMapBase : public Base {
alpar@1116
   853
      typedef T PredNodeMap;
alpar@1117
   854
      static PredNodeMap *createPredNodeMap(const Graph &G) { return 0; };
alpar@1117
   855
      DefPredNodeMapBase(const Base &b) : Base(b) {}
alpar@1116
   856
    };
alpar@1116
   857
    
hegyi@1123
   858
    /// \ref named-templ-param "Named parameter" function for setting PredNodeMap type
hegyi@1123
   859
hegyi@1123
   860
    /// \ref named-templ-param "Named parameter" function for setting PredNodeMap type
hegyi@1124
   861
    ///
alpar@953
   862
    template<class T>
alpar@1116
   863
    DijkstraWizard<DefPredNodeMapBase<T> > predNodeMap(const T &t) 
alpar@953
   864
    {
alpar@1116
   865
      _predNode=(void *)&t;
alpar@1116
   866
      return DijkstraWizard<DefPredNodeMapBase<T> >(*this);
alpar@953
   867
    }
alpar@1116
   868
   
alpar@1116
   869
    template<class T>
alpar@1116
   870
    struct DefDistMapBase : public Base {
alpar@1116
   871
      typedef T DistMap;
alpar@1117
   872
      static DistMap *createDistMap(const Graph &G) { return 0; };
alpar@1117
   873
      DefDistMapBase(const Base &b) : Base(b) {}
alpar@1116
   874
    };
alpar@953
   875
    
hegyi@1123
   876
    /// \ref named-templ-param "Named parameter" function for setting DistMap type
hegyi@1123
   877
hegyi@1123
   878
    /// \ref named-templ-param "Named parameter" function for setting DistMap type
hegyi@1124
   879
    ///
alpar@953
   880
    template<class T>
alpar@1116
   881
    DijkstraWizard<DefDistMapBase<T> > distMap(const T &t) 
alpar@953
   882
    {
alpar@1116
   883
      _dist=(void *)&t;
alpar@1116
   884
      return DijkstraWizard<DefDistMapBase<T> >(*this);
alpar@953
   885
    }
alpar@1117
   886
    
hegyi@1123
   887
    /// Sets the source node, from which the Dijkstra algorithm runs.
hegyi@1123
   888
hegyi@1123
   889
    /// Sets the source node, from which the Dijkstra algorithm runs.
hegyi@1123
   890
    /// \param s is the source node.
alpar@1117
   891
    DijkstraWizard<TR> &source(Node s) 
alpar@953
   892
    {
alpar@1116
   893
      source=(void *)&s;
alpar@953
   894
      return *this;
alpar@953
   895
    }
alpar@953
   896
    
alpar@953
   897
  };
alpar@255
   898
  
alpar@953
   899
  ///\e
alpar@953
   900
alpar@954
   901
  ///\todo Please document...
alpar@953
   902
  ///
alpar@953
   903
  template<class GR, class LM>
alpar@1116
   904
  DijkstraWizard<DijkstraWizardBase<GR,LM> >
alpar@1116
   905
  dijkstra(const GR &g,const LM &l,typename GR::Node s=INVALID)
alpar@953
   906
  {
alpar@1116
   907
    return DijkstraWizard<DijkstraWizardBase<GR,LM> >(g,l,s);
alpar@953
   908
  }
alpar@953
   909
alpar@430
   910
/// @}
alpar@255
   911
  
alpar@921
   912
} //END OF NAMESPACE LEMON
alpar@255
   913
alpar@255
   914
#endif
alpar@255
   915