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