lemon/dijkstra.h
author Peter Kovacs <kpeter@inf.elte.hu>
Sun, 30 Nov 2008 19:17:51 +0100
changeset 421 6b9057cdcd8b
parent 313 64f8f7cc6168
child 424 69f33ef03334
permissions -rw-r--r--
Doc improvements for Bfs, Dfs, Dijkstra (#185)

- More precise references to overloaded member functions.
- Hide the doc of the traits class parameters.
- Better doc for named groups.
- More precise doc for the case of multiple sources in Dfs.
alpar@209
     1
/* -*- mode: C++; indent-tabs-mode: nil; -*-
alpar@100
     2
 *
alpar@209
     3
 * This file is a part of LEMON, a generic C++ optimization library.
alpar@100
     4
 *
alpar@100
     5
 * Copyright (C) 2003-2008
alpar@100
     6
 * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
alpar@100
     7
 * (Egervary Research Group on Combinatorial Optimization, EGRES).
alpar@100
     8
 *
alpar@100
     9
 * Permission to use, modify and distribute this software is granted
alpar@100
    10
 * provided that this copyright notice appears in all copies. For
alpar@100
    11
 * precise terms see the accompanying LICENSE file.
alpar@100
    12
 *
alpar@100
    13
 * This software is provided "AS IS" with no warranty of any kind,
alpar@100
    14
 * express or implied, and with no claim as to its suitability for any
alpar@100
    15
 * purpose.
alpar@100
    16
 *
alpar@100
    17
 */
alpar@100
    18
alpar@100
    19
#ifndef LEMON_DIJKSTRA_H
alpar@100
    20
#define LEMON_DIJKSTRA_H
alpar@100
    21
alpar@100
    22
///\ingroup shortest_path
alpar@100
    23
///\file
alpar@100
    24
///\brief Dijkstra algorithm.
alpar@100
    25
alpar@184
    26
#include <limits>
kpeter@169
    27
#include <lemon/list_graph.h>
alpar@100
    28
#include <lemon/bin_heap.h>
alpar@100
    29
#include <lemon/bits/path_dump.h>
deba@220
    30
#include <lemon/core.h>
alpar@100
    31
#include <lemon/error.h>
alpar@100
    32
#include <lemon/maps.h>
kpeter@278
    33
#include <lemon/path.h>
alpar@100
    34
alpar@100
    35
namespace lemon {
alpar@100
    36
kpeter@244
    37
  /// \brief Default operation traits for the Dijkstra algorithm class.
alpar@209
    38
  ///
kpeter@244
    39
  /// This operation traits class defines all computational operations and
kpeter@244
    40
  /// constants which are used in the Dijkstra algorithm.
alpar@100
    41
  template <typename Value>
alpar@100
    42
  struct DijkstraDefaultOperationTraits {
alpar@100
    43
    /// \brief Gives back the zero value of the type.
alpar@100
    44
    static Value zero() {
alpar@100
    45
      return static_cast<Value>(0);
alpar@100
    46
    }
alpar@100
    47
    /// \brief Gives back the sum of the given two elements.
alpar@100
    48
    static Value plus(const Value& left, const Value& right) {
alpar@100
    49
      return left + right;
alpar@100
    50
    }
kpeter@244
    51
    /// \brief Gives back true only if the first value is less than the second.
alpar@100
    52
    static bool less(const Value& left, const Value& right) {
alpar@100
    53
      return left < right;
alpar@100
    54
    }
alpar@100
    55
  };
alpar@100
    56
kpeter@244
    57
  /// \brief Widest path operation traits for the Dijkstra algorithm class.
alpar@209
    58
  ///
kpeter@244
    59
  /// This operation traits class defines all computational operations and
kpeter@244
    60
  /// constants which are used in the Dijkstra algorithm for widest path
kpeter@244
    61
  /// computation.
kpeter@244
    62
  ///
kpeter@244
    63
  /// \see DijkstraDefaultOperationTraits
alpar@100
    64
  template <typename Value>
alpar@100
    65
  struct DijkstraWidestPathOperationTraits {
alpar@100
    66
    /// \brief Gives back the maximum value of the type.
alpar@100
    67
    static Value zero() {
alpar@100
    68
      return std::numeric_limits<Value>::max();
alpar@100
    69
    }
alpar@100
    70
    /// \brief Gives back the minimum of the given two elements.
alpar@100
    71
    static Value plus(const Value& left, const Value& right) {
alpar@100
    72
      return std::min(left, right);
alpar@100
    73
    }
kpeter@244
    74
    /// \brief Gives back true only if the first value is less than the second.
alpar@100
    75
    static bool less(const Value& left, const Value& right) {
alpar@100
    76
      return left < right;
alpar@100
    77
    }
alpar@100
    78
  };
alpar@209
    79
alpar@100
    80
  ///Default traits class of Dijkstra class.
alpar@100
    81
alpar@100
    82
  ///Default traits class of Dijkstra class.
kpeter@244
    83
  ///\tparam GR The type of the digraph.
kpeter@244
    84
  ///\tparam LM The type of the length map.
alpar@100
    85
  template<class GR, class LM>
alpar@100
    86
  struct DijkstraDefaultTraits
alpar@100
    87
  {
kpeter@244
    88
    ///The type of the digraph the algorithm runs on.
alpar@100
    89
    typedef GR Digraph;
kpeter@244
    90
alpar@100
    91
    ///The type of the map that stores the arc lengths.
alpar@100
    92
alpar@100
    93
    ///The type of the map that stores the arc lengths.
alpar@100
    94
    ///It must meet the \ref concepts::ReadMap "ReadMap" concept.
alpar@100
    95
    typedef LM LengthMap;
kpeter@244
    96
    ///The type of the length of the arcs.
alpar@100
    97
    typedef typename LM::Value Value;
kpeter@244
    98
alpar@100
    99
    /// Operation traits for Dijkstra algorithm.
alpar@100
   100
kpeter@244
   101
    /// This class defines the operations that are used in the algorithm.
alpar@100
   102
    /// \see DijkstraDefaultOperationTraits
alpar@100
   103
    typedef DijkstraDefaultOperationTraits<Value> OperationTraits;
alpar@100
   104
kpeter@244
   105
    /// The cross reference type used by the heap.
alpar@100
   106
kpeter@244
   107
    /// The cross reference type used by the heap.
alpar@100
   108
    /// Usually it is \c Digraph::NodeMap<int>.
alpar@100
   109
    typedef typename Digraph::template NodeMap<int> HeapCrossRef;
kpeter@244
   110
    ///Instantiates a \ref HeapCrossRef.
alpar@100
   111
kpeter@244
   112
    ///This function instantiates a \ref HeapCrossRef.
kpeter@244
   113
    /// \param g is the digraph, to which we would like to define the
kpeter@244
   114
    /// \ref HeapCrossRef.
kpeter@244
   115
    static HeapCrossRef *createHeapCrossRef(const Digraph &g)
alpar@100
   116
    {
kpeter@244
   117
      return new HeapCrossRef(g);
alpar@100
   118
    }
alpar@209
   119
kpeter@244
   120
    ///The heap type used by the Dijkstra algorithm.
alpar@100
   121
kpeter@244
   122
    ///The heap type used by the Dijkstra algorithm.
alpar@100
   123
    ///
alpar@100
   124
    ///\sa BinHeap
alpar@100
   125
    ///\sa Dijkstra
alpar@100
   126
    typedef BinHeap<typename LM::Value, HeapCrossRef, std::less<Value> > Heap;
kpeter@244
   127
    ///Instantiates a \ref Heap.
alpar@100
   128
kpeter@244
   129
    ///This function instantiates a \ref Heap.
kpeter@244
   130
    static Heap *createHeap(HeapCrossRef& r)
alpar@100
   131
    {
kpeter@244
   132
      return new Heap(r);
alpar@100
   133
    }
alpar@100
   134
kpeter@244
   135
    ///\brief The type of the map that stores the predecessor
alpar@100
   136
    ///arcs of the shortest paths.
alpar@209
   137
    ///
kpeter@244
   138
    ///The type of the map that stores the predecessor
alpar@100
   139
    ///arcs of the shortest paths.
alpar@100
   140
    ///It must meet the \ref concepts::WriteMap "WriteMap" concept.
kpeter@244
   141
    typedef typename Digraph::template NodeMap<typename Digraph::Arc> PredMap;
kpeter@301
   142
    ///Instantiates a PredMap.
alpar@209
   143
kpeter@301
   144
    ///This function instantiates a PredMap.
kpeter@244
   145
    ///\param g is the digraph, to which we would like to define the
kpeter@301
   146
    ///PredMap.
kpeter@244
   147
    static PredMap *createPredMap(const Digraph &g)
alpar@100
   148
    {
kpeter@244
   149
      return new PredMap(g);
alpar@100
   150
    }
alpar@100
   151
kpeter@244
   152
    ///The type of the map that indicates which nodes are processed.
alpar@209
   153
kpeter@244
   154
    ///The type of the map that indicates which nodes are processed.
alpar@100
   155
    ///It must meet the \ref concepts::WriteMap "WriteMap" concept.
alpar@100
   156
    ///By default it is a NullMap.
alpar@100
   157
    typedef NullMap<typename Digraph::Node,bool> ProcessedMap;
kpeter@301
   158
    ///Instantiates a ProcessedMap.
alpar@209
   159
kpeter@301
   160
    ///This function instantiates a ProcessedMap.
alpar@100
   161
    ///\param g is the digraph, to which
kpeter@301
   162
    ///we would like to define the ProcessedMap
alpar@100
   163
#ifdef DOXYGEN
kpeter@244
   164
    static ProcessedMap *createProcessedMap(const Digraph &g)
alpar@100
   165
#else
kpeter@244
   166
    static ProcessedMap *createProcessedMap(const Digraph &)
alpar@100
   167
#endif
alpar@100
   168
    {
alpar@100
   169
      return new ProcessedMap();
alpar@100
   170
    }
alpar@209
   171
kpeter@244
   172
    ///The type of the map that stores the distances of the nodes.
kpeter@244
   173
kpeter@244
   174
    ///The type of the map that stores the distances of the nodes.
alpar@100
   175
    ///It must meet the \ref concepts::WriteMap "WriteMap" concept.
alpar@100
   176
    typedef typename Digraph::template NodeMap<typename LM::Value> DistMap;
kpeter@301
   177
    ///Instantiates a DistMap.
alpar@209
   178
kpeter@301
   179
    ///This function instantiates a DistMap.
kpeter@244
   180
    ///\param g is the digraph, to which we would like to define
kpeter@301
   181
    ///the DistMap
kpeter@244
   182
    static DistMap *createDistMap(const Digraph &g)
alpar@100
   183
    {
kpeter@244
   184
      return new DistMap(g);
alpar@100
   185
    }
alpar@100
   186
  };
alpar@209
   187
alpar@100
   188
  ///%Dijkstra algorithm class.
alpar@209
   189
alpar@100
   190
  /// \ingroup shortest_path
kpeter@244
   191
  ///This class provides an efficient implementation of the %Dijkstra algorithm.
kpeter@244
   192
  ///
alpar@100
   193
  ///The arc lengths are passed to the algorithm using a
alpar@100
   194
  ///\ref concepts::ReadMap "ReadMap",
alpar@100
   195
  ///so it is easy to change it to any kind of length.
alpar@100
   196
  ///The type of the length is determined by the
alpar@100
   197
  ///\ref concepts::ReadMap::Value "Value" of the length map.
alpar@100
   198
  ///It is also possible to change the underlying priority heap.
alpar@100
   199
  ///
kpeter@278
   200
  ///There is also a \ref dijkstra() "function-type interface" for the
kpeter@244
   201
  ///%Dijkstra algorithm, which is convenient in the simplier cases and
kpeter@244
   202
  ///it can be used easier.
kpeter@244
   203
  ///
kpeter@244
   204
  ///\tparam GR The type of the digraph the algorithm runs on.
kpeter@421
   205
  ///The default type is \ref ListDigraph.
kpeter@421
   206
  ///\tparam LM A \ref concepts::ReadMap "readable" arc map that specifies
kpeter@421
   207
  ///the lengths of the arcs.
kpeter@421
   208
  ///It is read once for each arc, so the map may involve in
kpeter@244
   209
  ///relatively time consuming process to compute the arc lengths if
alpar@100
   210
  ///it is necessary. The default map type is \ref
kpeter@421
   211
  ///concepts::Digraph::ArcMap "GR::ArcMap<int>".
alpar@100
   212
#ifdef DOXYGEN
alpar@100
   213
  template <typename GR, typename LM, typename TR>
alpar@100
   214
#else
alpar@100
   215
  template <typename GR=ListDigraph,
alpar@209
   216
            typename LM=typename GR::template ArcMap<int>,
alpar@209
   217
            typename TR=DijkstraDefaultTraits<GR,LM> >
alpar@100
   218
#endif
alpar@100
   219
  class Dijkstra {
alpar@100
   220
  public:
alpar@100
   221
kpeter@244
   222
    ///The type of the digraph the algorithm runs on.
alpar@100
   223
    typedef typename TR::Digraph Digraph;
alpar@209
   224
alpar@100
   225
    ///The type of the length of the arcs.
alpar@100
   226
    typedef typename TR::LengthMap::Value Value;
alpar@100
   227
    ///The type of the map that stores the arc lengths.
alpar@100
   228
    typedef typename TR::LengthMap LengthMap;
kpeter@244
   229
    ///\brief The type of the map that stores the predecessor arcs of the
kpeter@244
   230
    ///shortest paths.
alpar@100
   231
    typedef typename TR::PredMap PredMap;
kpeter@244
   232
    ///The type of the map that stores the distances of the nodes.
kpeter@244
   233
    typedef typename TR::DistMap DistMap;
kpeter@244
   234
    ///The type of the map that indicates which nodes are processed.
alpar@100
   235
    typedef typename TR::ProcessedMap ProcessedMap;
kpeter@244
   236
    ///The type of the paths.
kpeter@244
   237
    typedef PredMapPath<Digraph, PredMap> Path;
alpar@100
   238
    ///The cross reference type used for the current heap.
alpar@100
   239
    typedef typename TR::HeapCrossRef HeapCrossRef;
kpeter@244
   240
    ///The heap type used by the algorithm.
alpar@100
   241
    typedef typename TR::Heap Heap;
kpeter@244
   242
    ///The operation traits class.
alpar@100
   243
    typedef typename TR::OperationTraits OperationTraits;
kpeter@244
   244
kpeter@421
   245
    ///The \ref DijkstraDefaultTraits "traits class" of the algorithm.
kpeter@244
   246
    typedef TR Traits;
kpeter@244
   247
alpar@100
   248
  private:
kpeter@244
   249
kpeter@244
   250
    typedef typename Digraph::Node Node;
kpeter@244
   251
    typedef typename Digraph::NodeIt NodeIt;
kpeter@244
   252
    typedef typename Digraph::Arc Arc;
kpeter@244
   253
    typedef typename Digraph::OutArcIt OutArcIt;
kpeter@244
   254
kpeter@244
   255
    //Pointer to the underlying digraph.
alpar@100
   256
    const Digraph *G;
kpeter@244
   257
    //Pointer to the length map.
alpar@100
   258
    const LengthMap *length;
kpeter@244
   259
    //Pointer to the map of predecessors arcs.
alpar@100
   260
    PredMap *_pred;
kpeter@244
   261
    //Indicates if _pred is locally allocated (true) or not.
alpar@100
   262
    bool local_pred;
kpeter@244
   263
    //Pointer to the map of distances.
alpar@100
   264
    DistMap *_dist;
kpeter@244
   265
    //Indicates if _dist is locally allocated (true) or not.
alpar@100
   266
    bool local_dist;
kpeter@244
   267
    //Pointer to the map of processed status of the nodes.
alpar@100
   268
    ProcessedMap *_processed;
kpeter@244
   269
    //Indicates if _processed is locally allocated (true) or not.
alpar@100
   270
    bool local_processed;
kpeter@244
   271
    //Pointer to the heap cross references.
alpar@100
   272
    HeapCrossRef *_heap_cross_ref;
kpeter@244
   273
    //Indicates if _heap_cross_ref is locally allocated (true) or not.
alpar@100
   274
    bool local_heap_cross_ref;
kpeter@244
   275
    //Pointer to the heap.
alpar@100
   276
    Heap *_heap;
kpeter@244
   277
    //Indicates if _heap is locally allocated (true) or not.
alpar@100
   278
    bool local_heap;
alpar@100
   279
alpar@280
   280
    //Creates the maps if necessary.
alpar@209
   281
    void create_maps()
alpar@100
   282
    {
alpar@100
   283
      if(!_pred) {
alpar@209
   284
        local_pred = true;
alpar@209
   285
        _pred = Traits::createPredMap(*G);
alpar@100
   286
      }
alpar@100
   287
      if(!_dist) {
alpar@209
   288
        local_dist = true;
alpar@209
   289
        _dist = Traits::createDistMap(*G);
alpar@100
   290
      }
alpar@100
   291
      if(!_processed) {
alpar@209
   292
        local_processed = true;
alpar@209
   293
        _processed = Traits::createProcessedMap(*G);
alpar@100
   294
      }
alpar@100
   295
      if (!_heap_cross_ref) {
alpar@209
   296
        local_heap_cross_ref = true;
alpar@209
   297
        _heap_cross_ref = Traits::createHeapCrossRef(*G);
alpar@100
   298
      }
alpar@100
   299
      if (!_heap) {
alpar@209
   300
        local_heap = true;
alpar@209
   301
        _heap = Traits::createHeap(*_heap_cross_ref);
alpar@100
   302
      }
alpar@100
   303
    }
alpar@209
   304
kpeter@244
   305
  public:
alpar@100
   306
alpar@100
   307
    typedef Dijkstra Create;
alpar@209
   308
alpar@100
   309
    ///\name Named template parameters
alpar@100
   310
alpar@100
   311
    ///@{
alpar@100
   312
alpar@100
   313
    template <class T>
kpeter@257
   314
    struct SetPredMapTraits : public Traits {
alpar@100
   315
      typedef T PredMap;
alpar@100
   316
      static PredMap *createPredMap(const Digraph &)
alpar@100
   317
      {
deba@290
   318
        LEMON_ASSERT(false, "PredMap is not initialized");
deba@290
   319
        return 0; // ignore warnings
alpar@100
   320
      }
alpar@100
   321
    };
kpeter@244
   322
    ///\brief \ref named-templ-param "Named parameter" for setting
kpeter@301
   323
    ///PredMap type.
alpar@100
   324
    ///
kpeter@244
   325
    ///\ref named-templ-param "Named parameter" for setting
kpeter@301
   326
    ///PredMap type.
kpeter@421
   327
    ///It must meet the \ref concepts::WriteMap "WriteMap" concept.
alpar@100
   328
    template <class T>
kpeter@257
   329
    struct SetPredMap
kpeter@257
   330
      : public Dijkstra< Digraph, LengthMap, SetPredMapTraits<T> > {
kpeter@257
   331
      typedef Dijkstra< Digraph, LengthMap, SetPredMapTraits<T> > Create;
alpar@100
   332
    };
alpar@209
   333
alpar@100
   334
    template <class T>
kpeter@257
   335
    struct SetDistMapTraits : public Traits {
alpar@100
   336
      typedef T DistMap;
alpar@100
   337
      static DistMap *createDistMap(const Digraph &)
alpar@100
   338
      {
deba@290
   339
        LEMON_ASSERT(false, "DistMap is not initialized");
deba@290
   340
        return 0; // ignore warnings
alpar@100
   341
      }
alpar@100
   342
    };
kpeter@244
   343
    ///\brief \ref named-templ-param "Named parameter" for setting
kpeter@301
   344
    ///DistMap type.
alpar@100
   345
    ///
kpeter@244
   346
    ///\ref named-templ-param "Named parameter" for setting
kpeter@301
   347
    ///DistMap type.
kpeter@421
   348
    ///It must meet the \ref concepts::WriteMap "WriteMap" concept.
alpar@100
   349
    template <class T>
kpeter@257
   350
    struct SetDistMap
kpeter@257
   351
      : public Dijkstra< Digraph, LengthMap, SetDistMapTraits<T> > {
kpeter@257
   352
      typedef Dijkstra< Digraph, LengthMap, SetDistMapTraits<T> > Create;
alpar@100
   353
    };
alpar@209
   354
alpar@100
   355
    template <class T>
kpeter@257
   356
    struct SetProcessedMapTraits : public Traits {
alpar@100
   357
      typedef T ProcessedMap;
kpeter@244
   358
      static ProcessedMap *createProcessedMap(const Digraph &)
alpar@100
   359
      {
deba@290
   360
        LEMON_ASSERT(false, "ProcessedMap is not initialized");
deba@290
   361
        return 0; // ignore warnings
alpar@100
   362
      }
alpar@100
   363
    };
kpeter@244
   364
    ///\brief \ref named-templ-param "Named parameter" for setting
kpeter@301
   365
    ///ProcessedMap type.
alpar@100
   366
    ///
kpeter@244
   367
    ///\ref named-templ-param "Named parameter" for setting
kpeter@301
   368
    ///ProcessedMap type.
kpeter@421
   369
    ///It must meet the \ref concepts::WriteMap "WriteMap" concept.
alpar@100
   370
    template <class T>
kpeter@257
   371
    struct SetProcessedMap
kpeter@257
   372
      : public Dijkstra< Digraph, LengthMap, SetProcessedMapTraits<T> > {
kpeter@257
   373
      typedef Dijkstra< Digraph, LengthMap, SetProcessedMapTraits<T> > Create;
alpar@100
   374
    };
alpar@209
   375
kpeter@257
   376
    struct SetStandardProcessedMapTraits : public Traits {
alpar@100
   377
      typedef typename Digraph::template NodeMap<bool> ProcessedMap;
kpeter@244
   378
      static ProcessedMap *createProcessedMap(const Digraph &g)
alpar@100
   379
      {
kpeter@244
   380
        return new ProcessedMap(g);
alpar@100
   381
      }
alpar@100
   382
    };
kpeter@244
   383
    ///\brief \ref named-templ-param "Named parameter" for setting
kpeter@301
   384
    ///ProcessedMap type to be <tt>Digraph::NodeMap<bool></tt>.
alpar@100
   385
    ///
kpeter@244
   386
    ///\ref named-templ-param "Named parameter" for setting
kpeter@301
   387
    ///ProcessedMap type to be <tt>Digraph::NodeMap<bool></tt>.
kpeter@244
   388
    ///If you don't set it explicitly, it will be automatically allocated.
kpeter@257
   389
    struct SetStandardProcessedMap
kpeter@257
   390
      : public Dijkstra< Digraph, LengthMap, SetStandardProcessedMapTraits > {
kpeter@257
   391
      typedef Dijkstra< Digraph, LengthMap, SetStandardProcessedMapTraits >
alpar@210
   392
      Create;
alpar@100
   393
    };
alpar@100
   394
alpar@100
   395
    template <class H, class CR>
kpeter@257
   396
    struct SetHeapTraits : public Traits {
alpar@100
   397
      typedef CR HeapCrossRef;
alpar@100
   398
      typedef H Heap;
alpar@100
   399
      static HeapCrossRef *createHeapCrossRef(const Digraph &) {
deba@290
   400
        LEMON_ASSERT(false, "HeapCrossRef is not initialized");
deba@290
   401
        return 0; // ignore warnings
alpar@100
   402
      }
alpar@209
   403
      static Heap *createHeap(HeapCrossRef &)
alpar@100
   404
      {
deba@290
   405
        LEMON_ASSERT(false, "Heap is not initialized");
deba@290
   406
        return 0; // ignore warnings
alpar@100
   407
      }
alpar@100
   408
    };
alpar@100
   409
    ///\brief \ref named-templ-param "Named parameter" for setting
kpeter@421
   410
    ///heap and cross reference types
alpar@100
   411
    ///
alpar@209
   412
    ///\ref named-templ-param "Named parameter" for setting heap and cross
kpeter@421
   413
    ///reference types. If this named parameter is used, then external
kpeter@421
   414
    ///heap and cross reference objects must be passed to the algorithm
kpeter@421
   415
    ///using the \ref heap() function before calling \ref run(Node) "run()"
kpeter@421
   416
    ///or \ref init().
kpeter@421
   417
    ///\sa SetStandardHeap
alpar@100
   418
    template <class H, class CR = typename Digraph::template NodeMap<int> >
kpeter@257
   419
    struct SetHeap
kpeter@257
   420
      : public Dijkstra< Digraph, LengthMap, SetHeapTraits<H, CR> > {
kpeter@257
   421
      typedef Dijkstra< Digraph, LengthMap, SetHeapTraits<H, CR> > Create;
alpar@100
   422
    };
alpar@100
   423
alpar@100
   424
    template <class H, class CR>
kpeter@257
   425
    struct SetStandardHeapTraits : public Traits {
alpar@100
   426
      typedef CR HeapCrossRef;
alpar@100
   427
      typedef H Heap;
alpar@100
   428
      static HeapCrossRef *createHeapCrossRef(const Digraph &G) {
alpar@209
   429
        return new HeapCrossRef(G);
alpar@100
   430
      }
alpar@209
   431
      static Heap *createHeap(HeapCrossRef &R)
alpar@100
   432
      {
alpar@209
   433
        return new Heap(R);
alpar@100
   434
      }
alpar@100
   435
    };
alpar@100
   436
    ///\brief \ref named-templ-param "Named parameter" for setting
kpeter@421
   437
    ///heap and cross reference types with automatic allocation
alpar@100
   438
    ///
alpar@209
   439
    ///\ref named-templ-param "Named parameter" for setting heap and cross
kpeter@421
   440
    ///reference types with automatic allocation.
kpeter@421
   441
    ///They should have standard constructor interfaces to be able to
kpeter@421
   442
    ///automatically created by the algorithm (i.e. the digraph should be
kpeter@421
   443
    ///passed to the constructor of the cross reference and the cross
kpeter@421
   444
    ///reference should be passed to the constructor of the heap).
kpeter@421
   445
    ///However external heap and cross reference objects could also be
kpeter@421
   446
    ///passed to the algorithm using the \ref heap() function before
kpeter@421
   447
    ///calling \ref run(Node) "run()" or \ref init().
kpeter@421
   448
    ///\sa SetHeap
alpar@100
   449
    template <class H, class CR = typename Digraph::template NodeMap<int> >
kpeter@257
   450
    struct SetStandardHeap
kpeter@257
   451
      : public Dijkstra< Digraph, LengthMap, SetStandardHeapTraits<H, CR> > {
kpeter@257
   452
      typedef Dijkstra< Digraph, LengthMap, SetStandardHeapTraits<H, CR> >
alpar@100
   453
      Create;
alpar@100
   454
    };
alpar@100
   455
alpar@100
   456
    template <class T>
kpeter@257
   457
    struct SetOperationTraitsTraits : public Traits {
alpar@100
   458
      typedef T OperationTraits;
alpar@100
   459
    };
alpar@209
   460
alpar@209
   461
    /// \brief \ref named-templ-param "Named parameter" for setting
kpeter@313
   462
    ///\c OperationTraits type
alpar@100
   463
    ///
kpeter@244
   464
    ///\ref named-templ-param "Named parameter" for setting
kpeter@244
   465
    ///\ref OperationTraits type.
alpar@100
   466
    template <class T>
kpeter@257
   467
    struct SetOperationTraits
kpeter@257
   468
      : public Dijkstra<Digraph, LengthMap, SetOperationTraitsTraits<T> > {
kpeter@257
   469
      typedef Dijkstra<Digraph, LengthMap, SetOperationTraitsTraits<T> >
alpar@100
   470
      Create;
alpar@100
   471
    };
alpar@209
   472
alpar@100
   473
    ///@}
alpar@100
   474
alpar@100
   475
  protected:
alpar@100
   476
alpar@100
   477
    Dijkstra() {}
alpar@100
   478
alpar@209
   479
  public:
alpar@209
   480
alpar@100
   481
    ///Constructor.
alpar@209
   482
kpeter@244
   483
    ///Constructor.
kpeter@244
   484
    ///\param _g The digraph the algorithm runs on.
kpeter@244
   485
    ///\param _length The length map used by the algorithm.
kpeter@244
   486
    Dijkstra(const Digraph& _g, const LengthMap& _length) :
kpeter@244
   487
      G(&_g), length(&_length),
alpar@100
   488
      _pred(NULL), local_pred(false),
alpar@100
   489
      _dist(NULL), local_dist(false),
alpar@100
   490
      _processed(NULL), local_processed(false),
alpar@100
   491
      _heap_cross_ref(NULL), local_heap_cross_ref(false),
alpar@100
   492
      _heap(NULL), local_heap(false)
alpar@100
   493
    { }
alpar@209
   494
alpar@100
   495
    ///Destructor.
alpar@209
   496
    ~Dijkstra()
alpar@100
   497
    {
alpar@100
   498
      if(local_pred) delete _pred;
alpar@100
   499
      if(local_dist) delete _dist;
alpar@100
   500
      if(local_processed) delete _processed;
alpar@100
   501
      if(local_heap_cross_ref) delete _heap_cross_ref;
alpar@100
   502
      if(local_heap) delete _heap;
alpar@100
   503
    }
alpar@100
   504
alpar@100
   505
    ///Sets the length map.
alpar@100
   506
alpar@100
   507
    ///Sets the length map.
alpar@100
   508
    ///\return <tt> (*this) </tt>
alpar@209
   509
    Dijkstra &lengthMap(const LengthMap &m)
alpar@100
   510
    {
alpar@100
   511
      length = &m;
alpar@100
   512
      return *this;
alpar@100
   513
    }
alpar@100
   514
kpeter@244
   515
    ///Sets the map that stores the predecessor arcs.
alpar@100
   516
kpeter@244
   517
    ///Sets the map that stores the predecessor arcs.
kpeter@421
   518
    ///If you don't use this function before calling \ref run(Node) "run()"
kpeter@421
   519
    ///or \ref init(), an instance will be allocated automatically.
kpeter@421
   520
    ///The destructor deallocates this automatically allocated map,
kpeter@421
   521
    ///of course.
alpar@100
   522
    ///\return <tt> (*this) </tt>
alpar@209
   523
    Dijkstra &predMap(PredMap &m)
alpar@100
   524
    {
alpar@100
   525
      if(local_pred) {
alpar@209
   526
        delete _pred;
alpar@209
   527
        local_pred=false;
alpar@100
   528
      }
alpar@100
   529
      _pred = &m;
alpar@100
   530
      return *this;
alpar@100
   531
    }
alpar@100
   532
kpeter@244
   533
    ///Sets the map that indicates which nodes are processed.
alpar@100
   534
kpeter@244
   535
    ///Sets the map that indicates which nodes are processed.
kpeter@421
   536
    ///If you don't use this function before calling \ref run(Node) "run()"
kpeter@421
   537
    ///or \ref init(), an instance will be allocated automatically.
kpeter@421
   538
    ///The destructor deallocates this automatically allocated map,
kpeter@421
   539
    ///of course.
kpeter@244
   540
    ///\return <tt> (*this) </tt>
kpeter@244
   541
    Dijkstra &processedMap(ProcessedMap &m)
kpeter@244
   542
    {
kpeter@244
   543
      if(local_processed) {
kpeter@244
   544
        delete _processed;
kpeter@244
   545
        local_processed=false;
kpeter@244
   546
      }
kpeter@244
   547
      _processed = &m;
kpeter@244
   548
      return *this;
kpeter@244
   549
    }
kpeter@244
   550
kpeter@244
   551
    ///Sets the map that stores the distances of the nodes.
kpeter@244
   552
kpeter@244
   553
    ///Sets the map that stores the distances of the nodes calculated by the
kpeter@244
   554
    ///algorithm.
kpeter@421
   555
    ///If you don't use this function before calling \ref run(Node) "run()"
kpeter@421
   556
    ///or \ref init(), an instance will be allocated automatically.
kpeter@421
   557
    ///The destructor deallocates this automatically allocated map,
kpeter@421
   558
    ///of course.
alpar@100
   559
    ///\return <tt> (*this) </tt>
alpar@209
   560
    Dijkstra &distMap(DistMap &m)
alpar@100
   561
    {
alpar@100
   562
      if(local_dist) {
alpar@209
   563
        delete _dist;
alpar@209
   564
        local_dist=false;
alpar@100
   565
      }
alpar@100
   566
      _dist = &m;
alpar@100
   567
      return *this;
alpar@100
   568
    }
alpar@100
   569
alpar@100
   570
    ///Sets the heap and the cross reference used by algorithm.
alpar@100
   571
alpar@100
   572
    ///Sets the heap and the cross reference used by algorithm.
kpeter@421
   573
    ///If you don't use this function before calling \ref run(Node) "run()"
kpeter@421
   574
    ///or \ref init(), heap and cross reference instances will be
kpeter@421
   575
    ///allocated automatically.
kpeter@421
   576
    ///The destructor deallocates these automatically allocated objects,
kpeter@421
   577
    ///of course.
alpar@100
   578
    ///\return <tt> (*this) </tt>
alpar@100
   579
    Dijkstra &heap(Heap& hp, HeapCrossRef &cr)
alpar@100
   580
    {
alpar@100
   581
      if(local_heap_cross_ref) {
alpar@209
   582
        delete _heap_cross_ref;
alpar@209
   583
        local_heap_cross_ref=false;
alpar@100
   584
      }
alpar@100
   585
      _heap_cross_ref = &cr;
alpar@100
   586
      if(local_heap) {
alpar@209
   587
        delete _heap;
alpar@209
   588
        local_heap=false;
alpar@100
   589
      }
alpar@100
   590
      _heap = &hp;
alpar@100
   591
      return *this;
alpar@100
   592
    }
alpar@100
   593
alpar@100
   594
  private:
kpeter@244
   595
alpar@100
   596
    void finalizeNodeData(Node v,Value dst)
alpar@100
   597
    {
alpar@100
   598
      _processed->set(v,true);
alpar@100
   599
      _dist->set(v, dst);
alpar@100
   600
    }
alpar@100
   601
alpar@100
   602
  public:
alpar@100
   603
kpeter@421
   604
    ///\name Execution Control
kpeter@421
   605
    ///The simplest way to execute the %Dijkstra algorithm is to use
kpeter@421
   606
    ///one of the member functions called \ref run(Node) "run()".\n
kpeter@421
   607
    ///If you need more control on the execution, first you have to call
kpeter@421
   608
    ///\ref init(), then you can add several source nodes with
kpeter@421
   609
    ///\ref addSource(). Finally the actual path computation can be
kpeter@421
   610
    ///performed with one of the \ref start() functions.
alpar@100
   611
alpar@100
   612
    ///@{
alpar@100
   613
kpeter@421
   614
    ///\brief Initializes the internal data structures.
kpeter@421
   615
    ///
alpar@100
   616
    ///Initializes the internal data structures.
alpar@100
   617
    void init()
alpar@100
   618
    {
alpar@100
   619
      create_maps();
alpar@100
   620
      _heap->clear();
alpar@100
   621
      for ( NodeIt u(*G) ; u!=INVALID ; ++u ) {
alpar@209
   622
        _pred->set(u,INVALID);
alpar@209
   623
        _processed->set(u,false);
alpar@209
   624
        _heap_cross_ref->set(u,Heap::PRE_HEAP);
alpar@100
   625
      }
alpar@100
   626
    }
alpar@209
   627
alpar@100
   628
    ///Adds a new source node.
alpar@100
   629
alpar@100
   630
    ///Adds a new source node to the priority heap.
alpar@100
   631
    ///The optional second parameter is the initial distance of the node.
alpar@100
   632
    ///
kpeter@244
   633
    ///The function checks if the node has already been added to the heap and
alpar@100
   634
    ///it is pushed to the heap only if either it was not in the heap
alpar@100
   635
    ///or the shortest path found till then is shorter than \c dst.
alpar@100
   636
    void addSource(Node s,Value dst=OperationTraits::zero())
alpar@100
   637
    {
alpar@100
   638
      if(_heap->state(s) != Heap::IN_HEAP) {
alpar@209
   639
        _heap->push(s,dst);
alpar@100
   640
      } else if(OperationTraits::less((*_heap)[s], dst)) {
alpar@209
   641
        _heap->set(s,dst);
alpar@209
   642
        _pred->set(s,INVALID);
alpar@100
   643
      }
alpar@100
   644
    }
alpar@209
   645
alpar@100
   646
    ///Processes the next node in the priority heap
alpar@100
   647
alpar@100
   648
    ///Processes the next node in the priority heap.
alpar@100
   649
    ///
alpar@100
   650
    ///\return The processed node.
alpar@100
   651
    ///
kpeter@244
   652
    ///\warning The priority heap must not be empty.
alpar@100
   653
    Node processNextNode()
alpar@100
   654
    {
alpar@209
   655
      Node v=_heap->top();
alpar@100
   656
      Value oldvalue=_heap->prio();
alpar@100
   657
      _heap->pop();
alpar@100
   658
      finalizeNodeData(v,oldvalue);
alpar@209
   659
alpar@100
   660
      for(OutArcIt e(*G,v); e!=INVALID; ++e) {
alpar@209
   661
        Node w=G->target(e);
alpar@209
   662
        switch(_heap->state(w)) {
alpar@209
   663
        case Heap::PRE_HEAP:
alpar@209
   664
          _heap->push(w,OperationTraits::plus(oldvalue, (*length)[e]));
alpar@209
   665
          _pred->set(w,e);
alpar@209
   666
          break;
alpar@209
   667
        case Heap::IN_HEAP:
alpar@209
   668
          {
alpar@209
   669
            Value newvalue = OperationTraits::plus(oldvalue, (*length)[e]);
alpar@209
   670
            if ( OperationTraits::less(newvalue, (*_heap)[w]) ) {
alpar@209
   671
              _heap->decrease(w, newvalue);
alpar@209
   672
              _pred->set(w,e);
alpar@209
   673
            }
alpar@209
   674
          }
alpar@209
   675
          break;
alpar@209
   676
        case Heap::POST_HEAP:
alpar@209
   677
          break;
alpar@209
   678
        }
alpar@100
   679
      }
alpar@100
   680
      return v;
alpar@100
   681
    }
alpar@100
   682
kpeter@244
   683
    ///The next node to be processed.
alpar@209
   684
kpeter@244
   685
    ///Returns the next node to be processed or \c INVALID if the
kpeter@244
   686
    ///priority heap is empty.
kpeter@244
   687
    Node nextNode() const
alpar@209
   688
    {
alpar@100
   689
      return !_heap->empty()?_heap->top():INVALID;
alpar@100
   690
    }
alpar@209
   691
kpeter@421
   692
    ///Returns \c false if there are nodes to be processed.
kpeter@421
   693
kpeter@421
   694
    ///Returns \c false if there are nodes to be processed
kpeter@421
   695
    ///in the priority heap.
kpeter@244
   696
    bool emptyQueue() const { return _heap->empty(); }
kpeter@244
   697
kpeter@421
   698
    ///Returns the number of the nodes to be processed.
alpar@100
   699
kpeter@421
   700
    ///Returns the number of the nodes to be processed
kpeter@421
   701
    ///in the priority heap.
kpeter@244
   702
    int queueSize() const { return _heap->size(); }
alpar@209
   703
alpar@100
   704
    ///Executes the algorithm.
alpar@100
   705
alpar@100
   706
    ///Executes the algorithm.
alpar@100
   707
    ///
kpeter@244
   708
    ///This method runs the %Dijkstra algorithm from the root node(s)
kpeter@244
   709
    ///in order to compute the shortest path to each node.
kpeter@244
   710
    ///
kpeter@244
   711
    ///The algorithm computes
kpeter@244
   712
    ///- the shortest path tree (forest),
kpeter@244
   713
    ///- the distance of each node from the root(s).
kpeter@244
   714
    ///
kpeter@244
   715
    ///\pre init() must be called and at least one root node should be
kpeter@244
   716
    ///added with addSource() before using this function.
kpeter@244
   717
    ///
kpeter@244
   718
    ///\note <tt>d.start()</tt> is just a shortcut of the following code.
kpeter@244
   719
    ///\code
kpeter@244
   720
    ///  while ( !d.emptyQueue() ) {
kpeter@244
   721
    ///    d.processNextNode();
kpeter@244
   722
    ///  }
kpeter@244
   723
    ///\endcode
kpeter@244
   724
    void start()
kpeter@244
   725
    {
kpeter@244
   726
      while ( !emptyQueue() ) processNextNode();
kpeter@244
   727
    }
kpeter@244
   728
kpeter@286
   729
    ///Executes the algorithm until the given target node is processed.
kpeter@244
   730
kpeter@286
   731
    ///Executes the algorithm until the given target node is processed.
alpar@100
   732
    ///
alpar@100
   733
    ///This method runs the %Dijkstra algorithm from the root node(s)
kpeter@286
   734
    ///in order to compute the shortest path to \c t.
alpar@100
   735
    ///
kpeter@244
   736
    ///The algorithm computes
kpeter@286
   737
    ///- the shortest path to \c t,
kpeter@286
   738
    ///- the distance of \c t from the root(s).
alpar@100
   739
    ///
kpeter@244
   740
    ///\pre init() must be called and at least one root node should be
kpeter@244
   741
    ///added with addSource() before using this function.
kpeter@286
   742
    void start(Node t)
alpar@100
   743
    {
kpeter@286
   744
      while ( !_heap->empty() && _heap->top()!=t ) processNextNode();
kpeter@286
   745
      if ( !_heap->empty() ) {
kpeter@286
   746
        finalizeNodeData(_heap->top(),_heap->prio());
kpeter@286
   747
        _heap->pop();
kpeter@286
   748
      }
alpar@100
   749
    }
alpar@209
   750
alpar@100
   751
    ///Executes the algorithm until a condition is met.
alpar@100
   752
alpar@100
   753
    ///Executes the algorithm until a condition is met.
alpar@100
   754
    ///
kpeter@244
   755
    ///This method runs the %Dijkstra algorithm from the root node(s) in
kpeter@244
   756
    ///order to compute the shortest path to a node \c v with
kpeter@244
   757
    /// <tt>nm[v]</tt> true, if such a node can be found.
alpar@100
   758
    ///
kpeter@244
   759
    ///\param nm A \c bool (or convertible) node map. The algorithm
alpar@100
   760
    ///will stop when it reaches a node \c v with <tt>nm[v]</tt> true.
alpar@100
   761
    ///
alpar@100
   762
    ///\return The reached node \c v with <tt>nm[v]</tt> true or
alpar@100
   763
    ///\c INVALID if no such node was found.
kpeter@244
   764
    ///
kpeter@244
   765
    ///\pre init() must be called and at least one root node should be
kpeter@244
   766
    ///added with addSource() before using this function.
alpar@100
   767
    template<class NodeBoolMap>
alpar@100
   768
    Node start(const NodeBoolMap &nm)
alpar@100
   769
    {
alpar@100
   770
      while ( !_heap->empty() && !nm[_heap->top()] ) processNextNode();
alpar@100
   771
      if ( _heap->empty() ) return INVALID;
alpar@100
   772
      finalizeNodeData(_heap->top(),_heap->prio());
alpar@100
   773
      return _heap->top();
alpar@100
   774
    }
alpar@209
   775
kpeter@286
   776
    ///Runs the algorithm from the given source node.
alpar@209
   777
kpeter@244
   778
    ///This method runs the %Dijkstra algorithm from node \c s
kpeter@244
   779
    ///in order to compute the shortest path to each node.
alpar@100
   780
    ///
kpeter@244
   781
    ///The algorithm computes
kpeter@244
   782
    ///- the shortest path tree,
kpeter@244
   783
    ///- the distance of each node from the root.
kpeter@244
   784
    ///
kpeter@244
   785
    ///\note <tt>d.run(s)</tt> is just a shortcut of the following code.
alpar@100
   786
    ///\code
alpar@100
   787
    ///  d.init();
alpar@100
   788
    ///  d.addSource(s);
alpar@100
   789
    ///  d.start();
alpar@100
   790
    ///\endcode
alpar@100
   791
    void run(Node s) {
alpar@100
   792
      init();
alpar@100
   793
      addSource(s);
alpar@100
   794
      start();
alpar@100
   795
    }
alpar@209
   796
alpar@100
   797
    ///Finds the shortest path between \c s and \c t.
alpar@209
   798
kpeter@244
   799
    ///This method runs the %Dijkstra algorithm from node \c s
kpeter@286
   800
    ///in order to compute the shortest path to node \c t
kpeter@286
   801
    ///(it stops searching when \c t is processed).
alpar@100
   802
    ///
kpeter@286
   803
    ///\return \c true if \c t is reachable form \c s.
kpeter@244
   804
    ///
kpeter@244
   805
    ///\note Apart from the return value, <tt>d.run(s,t)</tt> is just a
kpeter@244
   806
    ///shortcut of the following code.
alpar@100
   807
    ///\code
alpar@100
   808
    ///  d.init();
alpar@100
   809
    ///  d.addSource(s);
alpar@100
   810
    ///  d.start(t);
alpar@100
   811
    ///\endcode
kpeter@286
   812
    bool run(Node s,Node t) {
alpar@100
   813
      init();
alpar@100
   814
      addSource(s);
alpar@100
   815
      start(t);
kpeter@286
   816
      return (*_heap_cross_ref)[t] == Heap::POST_HEAP;
alpar@100
   817
    }
alpar@209
   818
alpar@100
   819
    ///@}
alpar@100
   820
alpar@100
   821
    ///\name Query Functions
kpeter@421
   822
    ///The results of the %Dijkstra algorithm can be obtained using these
alpar@100
   823
    ///functions.\n
kpeter@421
   824
    ///Either \ref run(Node) "run()" or \ref start() should be called
kpeter@421
   825
    ///before using them.
alpar@209
   826
alpar@100
   827
    ///@{
alpar@100
   828
kpeter@244
   829
    ///The shortest path to a node.
alpar@209
   830
kpeter@244
   831
    ///Returns the shortest path to a node.
kpeter@244
   832
    ///
kpeter@421
   833
    ///\warning \c t should be reached from the root(s).
kpeter@244
   834
    ///
kpeter@421
   835
    ///\pre Either \ref run(Node) "run()" or \ref init()
kpeter@421
   836
    ///must be called before using this function.
kpeter@244
   837
    Path path(Node t) const { return Path(*G, *_pred, t); }
alpar@100
   838
kpeter@244
   839
    ///The distance of a node from the root(s).
alpar@100
   840
kpeter@244
   841
    ///Returns the distance of a node from the root(s).
kpeter@244
   842
    ///
kpeter@421
   843
    ///\warning If node \c v is not reached from the root(s), then
kpeter@244
   844
    ///the return value of this function is undefined.
kpeter@244
   845
    ///
kpeter@421
   846
    ///\pre Either \ref run(Node) "run()" or \ref init()
kpeter@421
   847
    ///must be called before using this function.
alpar@100
   848
    Value dist(Node v) const { return (*_dist)[v]; }
alpar@100
   849
kpeter@244
   850
    ///Returns the 'previous arc' of the shortest path tree for a node.
alpar@100
   851
kpeter@244
   852
    ///This function returns the 'previous arc' of the shortest path
kpeter@244
   853
    ///tree for the node \c v, i.e. it returns the last arc of a
kpeter@421
   854
    ///shortest path from a root to \c v. It is \c INVALID if \c v
kpeter@421
   855
    ///is not reached from the root(s) or if \c v is a root.
kpeter@244
   856
    ///
kpeter@244
   857
    ///The shortest path tree used here is equal to the shortest path
kpeter@244
   858
    ///tree used in \ref predNode().
kpeter@244
   859
    ///
kpeter@421
   860
    ///\pre Either \ref run(Node) "run()" or \ref init()
kpeter@421
   861
    ///must be called before using this function.
alpar@100
   862
    Arc predArc(Node v) const { return (*_pred)[v]; }
alpar@100
   863
kpeter@244
   864
    ///Returns the 'previous node' of the shortest path tree for a node.
alpar@100
   865
kpeter@244
   866
    ///This function returns the 'previous node' of the shortest path
kpeter@244
   867
    ///tree for the node \c v, i.e. it returns the last but one node
kpeter@421
   868
    ///from a shortest path from a root to \c v. It is \c INVALID
kpeter@421
   869
    ///if \c v is not reached from the root(s) or if \c v is a root.
kpeter@244
   870
    ///
kpeter@244
   871
    ///The shortest path tree used here is equal to the shortest path
kpeter@244
   872
    ///tree used in \ref predArc().
kpeter@244
   873
    ///
kpeter@421
   874
    ///\pre Either \ref run(Node) "run()" or \ref init()
kpeter@421
   875
    ///must be called before using this function.
alpar@100
   876
    Node predNode(Node v) const { return (*_pred)[v]==INVALID ? INVALID:
alpar@209
   877
                                  G->source((*_pred)[v]); }
alpar@209
   878
kpeter@244
   879
    ///\brief Returns a const reference to the node map that stores the
kpeter@244
   880
    ///distances of the nodes.
kpeter@244
   881
    ///
kpeter@244
   882
    ///Returns a const reference to the node map that stores the distances
kpeter@244
   883
    ///of the nodes calculated by the algorithm.
kpeter@244
   884
    ///
kpeter@421
   885
    ///\pre Either \ref run(Node) "run()" or \ref init()
kpeter@244
   886
    ///must be called before using this function.
alpar@100
   887
    const DistMap &distMap() const { return *_dist;}
alpar@209
   888
kpeter@244
   889
    ///\brief Returns a const reference to the node map that stores the
kpeter@244
   890
    ///predecessor arcs.
kpeter@244
   891
    ///
kpeter@244
   892
    ///Returns a const reference to the node map that stores the predecessor
kpeter@244
   893
    ///arcs, which form the shortest path tree.
kpeter@244
   894
    ///
kpeter@421
   895
    ///\pre Either \ref run(Node) "run()" or \ref init()
kpeter@244
   896
    ///must be called before using this function.
alpar@100
   897
    const PredMap &predMap() const { return *_pred;}
alpar@209
   898
kpeter@421
   899
    ///Checks if a node is reached from the root(s).
alpar@100
   900
kpeter@421
   901
    ///Returns \c true if \c v is reached from the root(s).
kpeter@421
   902
    ///
kpeter@421
   903
    ///\pre Either \ref run(Node) "run()" or \ref init()
kpeter@244
   904
    ///must be called before using this function.
kpeter@244
   905
    bool reached(Node v) const { return (*_heap_cross_ref)[v] !=
kpeter@244
   906
                                        Heap::PRE_HEAP; }
alpar@100
   907
alpar@100
   908
    ///Checks if a node is processed.
alpar@100
   909
alpar@100
   910
    ///Returns \c true if \c v is processed, i.e. the shortest
alpar@100
   911
    ///path to \c v has already found.
kpeter@421
   912
    ///
kpeter@421
   913
    ///\pre Either \ref run(Node) "run()" or \ref init()
kpeter@244
   914
    ///must be called before using this function.
kpeter@244
   915
    bool processed(Node v) const { return (*_heap_cross_ref)[v] ==
kpeter@244
   916
                                          Heap::POST_HEAP; }
kpeter@244
   917
kpeter@244
   918
    ///The current distance of a node from the root(s).
kpeter@244
   919
kpeter@244
   920
    ///Returns the current distance of a node from the root(s).
kpeter@244
   921
    ///It may be decreased in the following processes.
kpeter@421
   922
    ///
kpeter@421
   923
    ///\pre Either \ref run(Node) "run()" or \ref init()
kpeter@286
   924
    ///must be called before using this function and
kpeter@286
   925
    ///node \c v must be reached but not necessarily processed.
kpeter@286
   926
    Value currentDist(Node v) const {
kpeter@286
   927
      return processed(v) ? (*_dist)[v] : (*_heap)[v];
kpeter@286
   928
    }
alpar@209
   929
alpar@100
   930
    ///@}
alpar@100
   931
  };
alpar@100
   932
alpar@100
   933
kpeter@244
   934
  ///Default traits class of dijkstra() function.
alpar@100
   935
kpeter@244
   936
  ///Default traits class of dijkstra() function.
kpeter@244
   937
  ///\tparam GR The type of the digraph.
kpeter@244
   938
  ///\tparam LM The type of the length map.
alpar@100
   939
  template<class GR, class LM>
alpar@100
   940
  struct DijkstraWizardDefaultTraits
alpar@100
   941
  {
kpeter@244
   942
    ///The type of the digraph the algorithm runs on.
alpar@100
   943
    typedef GR Digraph;
alpar@100
   944
    ///The type of the map that stores the arc lengths.
alpar@100
   945
alpar@100
   946
    ///The type of the map that stores the arc lengths.
alpar@100
   947
    ///It must meet the \ref concepts::ReadMap "ReadMap" concept.
alpar@100
   948
    typedef LM LengthMap;
kpeter@244
   949
    ///The type of the length of the arcs.
alpar@100
   950
    typedef typename LM::Value Value;
kpeter@244
   951
alpar@100
   952
    /// Operation traits for Dijkstra algorithm.
alpar@100
   953
kpeter@244
   954
    /// This class defines the operations that are used in the algorithm.
alpar@100
   955
    /// \see DijkstraDefaultOperationTraits
alpar@100
   956
    typedef DijkstraDefaultOperationTraits<Value> OperationTraits;
alpar@100
   957
kpeter@244
   958
    /// The cross reference type used by the heap.
alpar@100
   959
kpeter@244
   960
    /// The cross reference type used by the heap.
alpar@100
   961
    /// Usually it is \c Digraph::NodeMap<int>.
alpar@100
   962
    typedef typename Digraph::template NodeMap<int> HeapCrossRef;
kpeter@244
   963
    ///Instantiates a \ref HeapCrossRef.
alpar@100
   964
alpar@209
   965
    ///This function instantiates a \ref HeapCrossRef.
kpeter@244
   966
    /// \param g is the digraph, to which we would like to define the
alpar@100
   967
    /// HeapCrossRef.
kpeter@244
   968
    static HeapCrossRef *createHeapCrossRef(const Digraph &g)
alpar@100
   969
    {
kpeter@244
   970
      return new HeapCrossRef(g);
alpar@100
   971
    }
alpar@209
   972
kpeter@244
   973
    ///The heap type used by the Dijkstra algorithm.
alpar@100
   974
kpeter@244
   975
    ///The heap type used by the Dijkstra algorithm.
alpar@100
   976
    ///
alpar@100
   977
    ///\sa BinHeap
alpar@100
   978
    ///\sa Dijkstra
kpeter@244
   979
    typedef BinHeap<Value, typename Digraph::template NodeMap<int>,
alpar@209
   980
                    std::less<Value> > Heap;
alpar@100
   981
kpeter@244
   982
    ///Instantiates a \ref Heap.
kpeter@244
   983
kpeter@244
   984
    ///This function instantiates a \ref Heap.
kpeter@244
   985
    /// \param r is the HeapCrossRef which is used.
kpeter@244
   986
    static Heap *createHeap(HeapCrossRef& r)
alpar@100
   987
    {
kpeter@244
   988
      return new Heap(r);
alpar@100
   989
    }
alpar@100
   990
kpeter@244
   991
    ///\brief The type of the map that stores the predecessor
alpar@100
   992
    ///arcs of the shortest paths.
alpar@209
   993
    ///
kpeter@244
   994
    ///The type of the map that stores the predecessor
alpar@100
   995
    ///arcs of the shortest paths.
alpar@100
   996
    ///It must meet the \ref concepts::WriteMap "WriteMap" concept.
kpeter@278
   997
    typedef typename Digraph::template NodeMap<typename Digraph::Arc> PredMap;
kpeter@301
   998
    ///Instantiates a PredMap.
alpar@209
   999
kpeter@301
  1000
    ///This function instantiates a PredMap.
kpeter@244
  1001
    ///\param g is the digraph, to which we would like to define the
kpeter@301
  1002
    ///PredMap.
kpeter@244
  1003
    static PredMap *createPredMap(const Digraph &g)
alpar@100
  1004
    {
kpeter@278
  1005
      return new PredMap(g);
alpar@100
  1006
    }
alpar@209
  1007
kpeter@244
  1008
    ///The type of the map that indicates which nodes are processed.
kpeter@244
  1009
kpeter@244
  1010
    ///The type of the map that indicates which nodes are processed.
alpar@100
  1011
    ///It must meet the \ref concepts::WriteMap "WriteMap" concept.
alpar@100
  1012
    ///By default it is a NullMap.
alpar@100
  1013
    typedef NullMap<typename Digraph::Node,bool> ProcessedMap;
kpeter@301
  1014
    ///Instantiates a ProcessedMap.
alpar@209
  1015
kpeter@301
  1016
    ///This function instantiates a ProcessedMap.
alpar@100
  1017
    ///\param g is the digraph, to which
kpeter@301
  1018
    ///we would like to define the ProcessedMap.
alpar@100
  1019
#ifdef DOXYGEN
kpeter@244
  1020
    static ProcessedMap *createProcessedMap(const Digraph &g)
alpar@100
  1021
#else
kpeter@244
  1022
    static ProcessedMap *createProcessedMap(const Digraph &)
alpar@100
  1023
#endif
alpar@100
  1024
    {
alpar@100
  1025
      return new ProcessedMap();
alpar@100
  1026
    }
alpar@209
  1027
kpeter@244
  1028
    ///The type of the map that stores the distances of the nodes.
kpeter@244
  1029
kpeter@244
  1030
    ///The type of the map that stores the distances of the nodes.
alpar@100
  1031
    ///It must meet the \ref concepts::WriteMap "WriteMap" concept.
kpeter@278
  1032
    typedef typename Digraph::template NodeMap<typename LM::Value> DistMap;
kpeter@301
  1033
    ///Instantiates a DistMap.
alpar@209
  1034
kpeter@301
  1035
    ///This function instantiates a DistMap.
alpar@210
  1036
    ///\param g is the digraph, to which we would like to define
kpeter@301
  1037
    ///the DistMap
kpeter@244
  1038
    static DistMap *createDistMap(const Digraph &g)
alpar@100
  1039
    {
kpeter@278
  1040
      return new DistMap(g);
alpar@100
  1041
    }
kpeter@278
  1042
kpeter@278
  1043
    ///The type of the shortest paths.
kpeter@278
  1044
kpeter@278
  1045
    ///The type of the shortest paths.
kpeter@278
  1046
    ///It must meet the \ref concepts::Path "Path" concept.
kpeter@278
  1047
    typedef lemon::Path<Digraph> Path;
alpar@100
  1048
  };
alpar@209
  1049
kpeter@313
  1050
  /// Default traits class used by DijkstraWizard
alpar@100
  1051
alpar@100
  1052
  /// To make it easier to use Dijkstra algorithm
kpeter@244
  1053
  /// we have created a wizard class.
alpar@100
  1054
  /// This \ref DijkstraWizard class needs default traits,
kpeter@244
  1055
  /// as well as the \ref Dijkstra class.
alpar@100
  1056
  /// The \ref DijkstraWizardBase is a class to be the default traits of the
alpar@100
  1057
  /// \ref DijkstraWizard class.
alpar@100
  1058
  template<class GR,class LM>
alpar@100
  1059
  class DijkstraWizardBase : public DijkstraWizardDefaultTraits<GR,LM>
alpar@100
  1060
  {
alpar@100
  1061
    typedef DijkstraWizardDefaultTraits<GR,LM> Base;
alpar@100
  1062
  protected:
kpeter@244
  1063
    //The type of the nodes in the digraph.
alpar@100
  1064
    typedef typename Base::Digraph::Node Node;
alpar@100
  1065
kpeter@244
  1066
    //Pointer to the digraph the algorithm runs on.
alpar@100
  1067
    void *_g;
kpeter@278
  1068
    //Pointer to the length map.
alpar@100
  1069
    void *_length;
kpeter@251
  1070
    //Pointer to the map of processed nodes.
kpeter@251
  1071
    void *_processed;
kpeter@244
  1072
    //Pointer to the map of predecessors arcs.
alpar@100
  1073
    void *_pred;
kpeter@244
  1074
    //Pointer to the map of distances.
alpar@100
  1075
    void *_dist;
kpeter@278
  1076
    //Pointer to the shortest path to the target node.
kpeter@278
  1077
    void *_path;
kpeter@278
  1078
    //Pointer to the distance of the target node.
kpeter@278
  1079
    void *_di;
alpar@100
  1080
kpeter@244
  1081
  public:
alpar@100
  1082
    /// Constructor.
alpar@209
  1083
alpar@100
  1084
    /// This constructor does not require parameters, therefore it initiates
kpeter@278
  1085
    /// all of the attributes to \c 0.
kpeter@251
  1086
    DijkstraWizardBase() : _g(0), _length(0), _processed(0), _pred(0),
kpeter@278
  1087
                           _dist(0), _path(0), _di(0) {}
alpar@100
  1088
alpar@100
  1089
    /// Constructor.
alpar@209
  1090
kpeter@278
  1091
    /// This constructor requires two parameters,
kpeter@278
  1092
    /// others are initiated to \c 0.
kpeter@244
  1093
    /// \param g The digraph the algorithm runs on.
kpeter@244
  1094
    /// \param l The length map.
kpeter@278
  1095
    DijkstraWizardBase(const GR &g,const LM &l) :
alpar@209
  1096
      _g(reinterpret_cast<void*>(const_cast<GR*>(&g))),
alpar@209
  1097
      _length(reinterpret_cast<void*>(const_cast<LM*>(&l))),
kpeter@278
  1098
      _processed(0), _pred(0), _dist(0), _path(0), _di(0) {}
alpar@100
  1099
alpar@100
  1100
  };
alpar@209
  1101
kpeter@278
  1102
  /// Auxiliary class for the function-type interface of Dijkstra algorithm.
alpar@100
  1103
kpeter@278
  1104
  /// This auxiliary class is created to implement the
kpeter@278
  1105
  /// \ref dijkstra() "function-type interface" of \ref Dijkstra algorithm.
kpeter@421
  1106
  /// It does not have own \ref run(Node) "run()" method, it uses the
kpeter@421
  1107
  /// functions and features of the plain \ref Dijkstra.
alpar@100
  1108
  ///
kpeter@278
  1109
  /// This class should only be used through the \ref dijkstra() function,
kpeter@278
  1110
  /// which makes it easier to use the algorithm.
alpar@100
  1111
  template<class TR>
alpar@100
  1112
  class DijkstraWizard : public TR
alpar@100
  1113
  {
alpar@100
  1114
    typedef TR Base;
alpar@100
  1115
kpeter@244
  1116
    ///The type of the digraph the algorithm runs on.
alpar@100
  1117
    typedef typename TR::Digraph Digraph;
kpeter@244
  1118
alpar@100
  1119
    typedef typename Digraph::Node Node;
alpar@100
  1120
    typedef typename Digraph::NodeIt NodeIt;
alpar@100
  1121
    typedef typename Digraph::Arc Arc;
alpar@100
  1122
    typedef typename Digraph::OutArcIt OutArcIt;
alpar@209
  1123
alpar@100
  1124
    ///The type of the map that stores the arc lengths.
alpar@100
  1125
    typedef typename TR::LengthMap LengthMap;
alpar@100
  1126
    ///The type of the length of the arcs.
alpar@100
  1127
    typedef typename LengthMap::Value Value;
kpeter@244
  1128
    ///\brief The type of the map that stores the predecessor
alpar@100
  1129
    ///arcs of the shortest paths.
alpar@100
  1130
    typedef typename TR::PredMap PredMap;
kpeter@244
  1131
    ///The type of the map that stores the distances of the nodes.
alpar@100
  1132
    typedef typename TR::DistMap DistMap;
kpeter@244
  1133
    ///The type of the map that indicates which nodes are processed.
kpeter@244
  1134
    typedef typename TR::ProcessedMap ProcessedMap;
kpeter@278
  1135
    ///The type of the shortest paths
kpeter@278
  1136
    typedef typename TR::Path Path;
alpar@100
  1137
    ///The heap type used by the dijkstra algorithm.
alpar@100
  1138
    typedef typename TR::Heap Heap;
kpeter@244
  1139
alpar@100
  1140
  public:
kpeter@244
  1141
alpar@100
  1142
    /// Constructor.
alpar@100
  1143
    DijkstraWizard() : TR() {}
alpar@100
  1144
alpar@100
  1145
    /// Constructor that requires parameters.
alpar@100
  1146
alpar@100
  1147
    /// Constructor that requires parameters.
alpar@100
  1148
    /// These parameters will be the default values for the traits class.
kpeter@278
  1149
    /// \param g The digraph the algorithm runs on.
kpeter@278
  1150
    /// \param l The length map.
kpeter@278
  1151
    DijkstraWizard(const Digraph &g, const LengthMap &l) :
kpeter@278
  1152
      TR(g,l) {}
alpar@100
  1153
alpar@100
  1154
    ///Copy constructor
alpar@100
  1155
    DijkstraWizard(const TR &b) : TR(b) {}
alpar@100
  1156
alpar@100
  1157
    ~DijkstraWizard() {}
alpar@100
  1158
kpeter@278
  1159
    ///Runs Dijkstra algorithm from the given source node.
alpar@209
  1160
kpeter@278
  1161
    ///This method runs %Dijkstra algorithm from the given source node
kpeter@278
  1162
    ///in order to compute the shortest path to each node.
kpeter@278
  1163
    void run(Node s)
alpar@100
  1164
    {
alpar@209
  1165
      Dijkstra<Digraph,LengthMap,TR>
kpeter@278
  1166
        dijk(*reinterpret_cast<const Digraph*>(Base::_g),
kpeter@278
  1167
             *reinterpret_cast<const LengthMap*>(Base::_length));
kpeter@278
  1168
      if (Base::_pred)
kpeter@278
  1169
        dijk.predMap(*reinterpret_cast<PredMap*>(Base::_pred));
kpeter@278
  1170
      if (Base::_dist)
kpeter@278
  1171
        dijk.distMap(*reinterpret_cast<DistMap*>(Base::_dist));
kpeter@278
  1172
      if (Base::_processed)
kpeter@278
  1173
        dijk.processedMap(*reinterpret_cast<ProcessedMap*>(Base::_processed));
kpeter@278
  1174
      dijk.run(s);
alpar@100
  1175
    }
alpar@100
  1176
kpeter@278
  1177
    ///Finds the shortest path between \c s and \c t.
alpar@100
  1178
kpeter@278
  1179
    ///This method runs the %Dijkstra algorithm from node \c s
kpeter@278
  1180
    ///in order to compute the shortest path to node \c t
kpeter@278
  1181
    ///(it stops searching when \c t is processed).
kpeter@278
  1182
    ///
kpeter@278
  1183
    ///\return \c true if \c t is reachable form \c s.
kpeter@278
  1184
    bool run(Node s, Node t)
alpar@100
  1185
    {
kpeter@278
  1186
      Dijkstra<Digraph,LengthMap,TR>
kpeter@278
  1187
        dijk(*reinterpret_cast<const Digraph*>(Base::_g),
kpeter@278
  1188
             *reinterpret_cast<const LengthMap*>(Base::_length));
kpeter@278
  1189
      if (Base::_pred)
kpeter@278
  1190
        dijk.predMap(*reinterpret_cast<PredMap*>(Base::_pred));
kpeter@278
  1191
      if (Base::_dist)
kpeter@278
  1192
        dijk.distMap(*reinterpret_cast<DistMap*>(Base::_dist));
kpeter@278
  1193
      if (Base::_processed)
kpeter@278
  1194
        dijk.processedMap(*reinterpret_cast<ProcessedMap*>(Base::_processed));
kpeter@278
  1195
      dijk.run(s,t);
kpeter@278
  1196
      if (Base::_path)
kpeter@278
  1197
        *reinterpret_cast<Path*>(Base::_path) = dijk.path(t);
kpeter@278
  1198
      if (Base::_di)
kpeter@278
  1199
        *reinterpret_cast<Value*>(Base::_di) = dijk.dist(t);
kpeter@278
  1200
      return dijk.reached(t);
kpeter@244
  1201
    }
kpeter@244
  1202
alpar@100
  1203
    template<class T>
kpeter@257
  1204
    struct SetPredMapBase : public Base {
alpar@100
  1205
      typedef T PredMap;
alpar@100
  1206
      static PredMap *createPredMap(const Digraph &) { return 0; };
kpeter@257
  1207
      SetPredMapBase(const TR &b) : TR(b) {}
alpar@100
  1208
    };
kpeter@278
  1209
    ///\brief \ref named-func-param "Named parameter"
kpeter@301
  1210
    ///for setting PredMap object.
alpar@100
  1211
    ///
kpeter@278
  1212
    ///\ref named-func-param "Named parameter"
kpeter@301
  1213
    ///for setting PredMap object.
alpar@100
  1214
    template<class T>
kpeter@257
  1215
    DijkstraWizard<SetPredMapBase<T> > predMap(const T &t)
alpar@100
  1216
    {
alpar@100
  1217
      Base::_pred=reinterpret_cast<void*>(const_cast<T*>(&t));
kpeter@257
  1218
      return DijkstraWizard<SetPredMapBase<T> >(*this);
alpar@100
  1219
    }
alpar@209
  1220
alpar@100
  1221
    template<class T>
kpeter@278
  1222
    struct SetDistMapBase : public Base {
kpeter@278
  1223
      typedef T DistMap;
kpeter@278
  1224
      static DistMap *createDistMap(const Digraph &) { return 0; };
kpeter@278
  1225
      SetDistMapBase(const TR &b) : TR(b) {}
kpeter@278
  1226
    };
kpeter@278
  1227
    ///\brief \ref named-func-param "Named parameter"
kpeter@301
  1228
    ///for setting DistMap object.
kpeter@278
  1229
    ///
kpeter@278
  1230
    ///\ref named-func-param "Named parameter"
kpeter@301
  1231
    ///for setting DistMap object.
kpeter@278
  1232
    template<class T>
kpeter@278
  1233
    DijkstraWizard<SetDistMapBase<T> > distMap(const T &t)
kpeter@278
  1234
    {
kpeter@278
  1235
      Base::_dist=reinterpret_cast<void*>(const_cast<T*>(&t));
kpeter@278
  1236
      return DijkstraWizard<SetDistMapBase<T> >(*this);
kpeter@278
  1237
    }
kpeter@278
  1238
kpeter@278
  1239
    template<class T>
kpeter@257
  1240
    struct SetProcessedMapBase : public Base {
kpeter@244
  1241
      typedef T ProcessedMap;
kpeter@244
  1242
      static ProcessedMap *createProcessedMap(const Digraph &) { return 0; };
kpeter@257
  1243
      SetProcessedMapBase(const TR &b) : TR(b) {}
kpeter@244
  1244
    };
kpeter@278
  1245
    ///\brief \ref named-func-param "Named parameter"
kpeter@301
  1246
    ///for setting ProcessedMap object.
kpeter@244
  1247
    ///
kpeter@278
  1248
    /// \ref named-func-param "Named parameter"
kpeter@301
  1249
    ///for setting ProcessedMap object.
kpeter@244
  1250
    template<class T>
kpeter@257
  1251
    DijkstraWizard<SetProcessedMapBase<T> > processedMap(const T &t)
kpeter@244
  1252
    {
kpeter@244
  1253
      Base::_processed=reinterpret_cast<void*>(const_cast<T*>(&t));
kpeter@257
  1254
      return DijkstraWizard<SetProcessedMapBase<T> >(*this);
kpeter@244
  1255
    }
kpeter@244
  1256
kpeter@244
  1257
    template<class T>
kpeter@278
  1258
    struct SetPathBase : public Base {
kpeter@278
  1259
      typedef T Path;
kpeter@278
  1260
      SetPathBase(const TR &b) : TR(b) {}
alpar@100
  1261
    };
kpeter@278
  1262
    ///\brief \ref named-func-param "Named parameter"
kpeter@278
  1263
    ///for getting the shortest path to the target node.
alpar@100
  1264
    ///
kpeter@278
  1265
    ///\ref named-func-param "Named parameter"
kpeter@278
  1266
    ///for getting the shortest path to the target node.
alpar@100
  1267
    template<class T>
kpeter@278
  1268
    DijkstraWizard<SetPathBase<T> > path(const T &t)
alpar@100
  1269
    {
kpeter@278
  1270
      Base::_path=reinterpret_cast<void*>(const_cast<T*>(&t));
kpeter@278
  1271
      return DijkstraWizard<SetPathBase<T> >(*this);
kpeter@278
  1272
    }
kpeter@278
  1273
kpeter@278
  1274
    ///\brief \ref named-func-param "Named parameter"
kpeter@278
  1275
    ///for getting the distance of the target node.
kpeter@278
  1276
    ///
kpeter@278
  1277
    ///\ref named-func-param "Named parameter"
kpeter@278
  1278
    ///for getting the distance of the target node.
kpeter@278
  1279
    DijkstraWizard dist(const Value &d)
kpeter@278
  1280
    {
kpeter@278
  1281
      Base::_di=reinterpret_cast<void*>(const_cast<Value*>(&d));
kpeter@278
  1282
      return *this;
alpar@100
  1283
    }
alpar@209
  1284
alpar@100
  1285
  };
alpar@209
  1286
kpeter@278
  1287
  ///Function-type interface for Dijkstra algorithm.
alpar@100
  1288
alpar@100
  1289
  /// \ingroup shortest_path
kpeter@278
  1290
  ///Function-type interface for Dijkstra algorithm.
alpar@100
  1291
  ///
kpeter@278
  1292
  ///This function also has several \ref named-func-param "named parameters",
alpar@100
  1293
  ///they are declared as the members of class \ref DijkstraWizard.
kpeter@278
  1294
  ///The following examples show how to use these parameters.
alpar@100
  1295
  ///\code
kpeter@278
  1296
  ///  // Compute shortest path from node s to each node
kpeter@278
  1297
  ///  dijkstra(g,length).predMap(preds).distMap(dists).run(s);
kpeter@278
  1298
  ///
kpeter@278
  1299
  ///  // Compute shortest path from s to t
kpeter@278
  1300
  ///  bool reached = dijkstra(g,length).path(p).dist(d).run(s,t);
alpar@100
  1301
  ///\endcode
kpeter@421
  1302
  ///\warning Don't forget to put the \ref DijkstraWizard::run(Node) "run()"
alpar@100
  1303
  ///to the end of the parameter list.
alpar@100
  1304
  ///\sa DijkstraWizard
alpar@100
  1305
  ///\sa Dijkstra
alpar@100
  1306
  template<class GR, class LM>
alpar@100
  1307
  DijkstraWizard<DijkstraWizardBase<GR,LM> >
kpeter@278
  1308
  dijkstra(const GR &digraph, const LM &length)
alpar@100
  1309
  {
kpeter@278
  1310
    return DijkstraWizard<DijkstraWizardBase<GR,LM> >(digraph,length);
alpar@100
  1311
  }
alpar@100
  1312
alpar@100
  1313
} //END OF NAMESPACE LEMON
alpar@100
  1314
alpar@100
  1315
#endif