lemon/dijkstra.h
changeset 1727 0c7d717b9538
parent 1710 f531c16dd923
child 1734 2fb5ceac10e7
equal deleted inserted replaced
7:e46b6c1e45c6 8:40d4323e2fbd
    48     ///The type of the map that stores the edge lengths.
    48     ///The type of the map that stores the edge lengths.
    49     ///It must meet the \ref concept::ReadMap "ReadMap" concept.
    49     ///It must meet the \ref concept::ReadMap "ReadMap" concept.
    50     typedef LM LengthMap;
    50     typedef LM LengthMap;
    51     //The type of the length of the edges.
    51     //The type of the length of the edges.
    52     typedef typename LM::Value Value;
    52     typedef typename LM::Value Value;
       
    53     /// The cross reference type used by heap.
       
    54 
       
    55     /// The cross reference type used by heap.
       
    56     /// Usually it is \c Graph::NodeMap<int>.
       
    57     typedef typename Graph::template NodeMap<int> HeapCrossRef;
       
    58     ///Instantiates a HeapCrossRef.
       
    59 
       
    60     ///This function instantiates a \ref HeapCrossRef. 
       
    61     /// \param G is the graph, to which we would like to define the 
       
    62     /// HeapCrossRef.
       
    63     /// \todo The graph alone may be insufficient for the initialization
       
    64     static HeapCrossRef *createHeapCrossRef(const GR &G) 
       
    65     {
       
    66       return new HeapCrossRef(G);
       
    67     }
       
    68     
    53     ///The heap type used by Dijkstra algorithm.
    69     ///The heap type used by Dijkstra algorithm.
    54 
    70 
    55     ///The heap type used by Dijkstra algorithm.
    71     ///The heap type used by Dijkstra algorithm.
    56     ///
    72     ///
    57     ///\sa BinHeap
    73     ///\sa BinHeap
    58     ///\sa Dijkstra
    74     ///\sa Dijkstra
    59     typedef BinHeap<typename Graph::Node, typename LM::Value,
    75     typedef BinHeap<typename Graph::Node, typename LM::Value,
    60 		    typename GR::template NodeMap<int>,
    76 		    typename GR::template NodeMap<int>,
    61 		    std::less<Value> > Heap;
    77 		    std::less<Value> > Heap;
       
    78 
       
    79     static Heap *createHeap(HeapCrossRef& R) 
       
    80     {
       
    81       return new Heap(R);
       
    82     }
    62 
    83 
    63     ///\brief The type of the map that stores the last
    84     ///\brief The type of the map that stores the last
    64     ///edges of the shortest paths.
    85     ///edges of the shortest paths.
    65     /// 
    86     /// 
    66     ///The type of the map that stores the last
    87     ///The type of the map that stores the last
   193     typedef typename TR::PredMap PredMap;
   214     typedef typename TR::PredMap PredMap;
   194     ///The type of the map indicating if a node is processed.
   215     ///The type of the map indicating if a node is processed.
   195     typedef typename TR::ProcessedMap ProcessedMap;
   216     typedef typename TR::ProcessedMap ProcessedMap;
   196     ///The type of the map that stores the dists of the nodes.
   217     ///The type of the map that stores the dists of the nodes.
   197     typedef typename TR::DistMap DistMap;
   218     typedef typename TR::DistMap DistMap;
       
   219     ///The cross reference type used for the current heap.
       
   220     typedef typename TR::HeapCrossRef HeapCrossRef;
   198     ///The heap type used by the dijkstra algorithm.
   221     ///The heap type used by the dijkstra algorithm.
   199     typedef typename TR::Heap Heap;
   222     typedef typename TR::Heap Heap;
   200   private:
   223   private:
   201     /// Pointer to the underlying graph.
   224     /// Pointer to the underlying graph.
   202     const Graph *G;
   225     const Graph *G;
   212     bool local_dist;
   235     bool local_dist;
   213     ///Pointer to the map of processed status of the nodes.
   236     ///Pointer to the map of processed status of the nodes.
   214     ProcessedMap *_processed;
   237     ProcessedMap *_processed;
   215     ///Indicates if \ref _processed is locally allocated (\c true) or not.
   238     ///Indicates if \ref _processed is locally allocated (\c true) or not.
   216     bool local_processed;
   239     bool local_processed;
       
   240     ///Pointer to the heap cross references.
       
   241     HeapCrossRef *_heap_cross_ref;
       
   242     ///Indicates if \ref _heap_cross_ref is locally allocated (\c true) or not.
       
   243     bool local_heap_cross_ref;
       
   244     ///Pointer to the heap.
       
   245     Heap *_heap;
       
   246     ///Indicates if \ref _heap is locally allocated (\c true) or not.
       
   247     bool local_heap;
   217 
   248 
   218     ///Creates the maps if necessary.
   249     ///Creates the maps if necessary.
   219     
   250     
   220     ///\todo Error if \c G or are \c NULL. What about \c length?
   251     ///\todo Error if \c G or are \c NULL. What about \c length?
   221     ///\todo Better memory allocation (instead of new).
   252     ///\todo Better memory allocation (instead of new).
   230 	_dist = Traits::createDistMap(*G);
   261 	_dist = Traits::createDistMap(*G);
   231       }
   262       }
   232       if(!_processed) {
   263       if(!_processed) {
   233 	local_processed = true;
   264 	local_processed = true;
   234 	_processed = Traits::createProcessedMap(*G);
   265 	_processed = Traits::createProcessedMap(*G);
       
   266       }
       
   267       if (!_heap_cross_ref) {
       
   268 	local_heap_cross_ref = true;
       
   269 	_heap_cross_ref = Traits::createHeapCrossRef(*G);
       
   270       }
       
   271       if (!_heap) {
       
   272 	local_heap = true;
       
   273 	_heap = Traits::createHeap(*_heap_cross_ref);
   235       }
   274       }
   236     }
   275     }
   237     
   276     
   238   public :
   277   public :
   239 
   278 
   313     template <class T>
   352     template <class T>
   314     struct DefProcessedMapToBeDefaultMap 
   353     struct DefProcessedMapToBeDefaultMap 
   315       : public Dijkstra< Graph, LengthMap, DefGraphProcessedMapTraits> {
   354       : public Dijkstra< Graph, LengthMap, DefGraphProcessedMapTraits> {
   316       typedef Dijkstra< Graph, LengthMap, DefGraphProcessedMapTraits> Create;
   355       typedef Dijkstra< Graph, LengthMap, DefGraphProcessedMapTraits> Create;
   317     };
   356     };
       
   357 
       
   358     template <class H, class CR>
       
   359     struct DefHeapTraits : public Traits {
       
   360       typedef CR HeapCrossRef;
       
   361       typedef H Heap;
       
   362       static HeapCrossRef *createHeapCrossRef(const Graph &G) {
       
   363 	return new HeapCrossRef(G);
       
   364       }
       
   365       static Heap *createHeap(HeapCrossRef &R) 
       
   366       {
       
   367 	return new Heap(R);
       
   368       }
       
   369     };
       
   370     ///\ref named-templ-param "Named parameter" for setting heap and cross 
       
   371     ///reference type
       
   372 
       
   373     ///\ref named-templ-param "Named parameter" for setting heap and cross 
       
   374     ///reference type
       
   375     ///
       
   376     template <class H, class CR = typename Graph::template NodeMap<int> >
       
   377     struct DefHeap
       
   378       : public Dijkstra< Graph,	LengthMap, DefHeapTraits<H, CR> > { 
       
   379       typedef Dijkstra< Graph,	LengthMap, DefHeapTraits<H, CR> > Create;
       
   380     };
   318     
   381     
   319     ///@}
   382     ///@}
   320 
   383 
   321 
   384 
   322   private:
       
   323     typename Graph::template NodeMap<int> _heap_map;
       
   324     Heap _heap;
       
   325   protected:
   385   protected:
   326 
   386 
   327     Dijkstra() {}
   387     Dijkstra() {}
   328 
   388 
   329   public:      
   389   public:      
   335     Dijkstra(const Graph& _G, const LengthMap& _length) :
   395     Dijkstra(const Graph& _G, const LengthMap& _length) :
   336       G(&_G), length(&_length),
   396       G(&_G), length(&_length),
   337       _pred(NULL), local_pred(false),
   397       _pred(NULL), local_pred(false),
   338       _dist(NULL), local_dist(false),
   398       _dist(NULL), local_dist(false),
   339       _processed(NULL), local_processed(false),
   399       _processed(NULL), local_processed(false),
   340       _heap_map(*G,-1),_heap(_heap_map)
   400       _heap_cross_ref(NULL), local_heap_cross_ref(false),
       
   401       _heap(NULL), local_heap(false)
   341     { }
   402     { }
   342     
   403     
   343     ///Destructor.
   404     ///Destructor.
   344     ~Dijkstra() 
   405     ~Dijkstra() 
   345     {
   406     {
   346       if(local_pred) delete _pred;
   407       if(local_pred) delete _pred;
   347       if(local_dist) delete _dist;
   408       if(local_dist) delete _dist;
   348       if(local_processed) delete _processed;
   409       if(local_processed) delete _processed;
       
   410       if(local_heap_cross_ref) delete _heap_cross_ref;
       
   411       if(local_heap) delete _heap;
   349     }
   412     }
   350 
   413 
   351     ///Sets the length map.
   414     ///Sets the length map.
   352 
   415 
   353     ///Sets the length map.
   416     ///Sets the length map.
   414 
   477 
   415     ///Initializes the internal data structures.
   478     ///Initializes the internal data structures.
   416 
   479 
   417     ///Initializes the internal data structures.
   480     ///Initializes the internal data structures.
   418     ///
   481     ///
   419     ///\todo _heap_map's type could also be in the traits class.
       
   420     ///\todo The heaps should be able to make themselves empty directly.
       
   421     void init()
   482     void init()
   422     {
   483     {
   423       create_maps();
   484       create_maps();
   424       while(!_heap.empty()) _heap.pop();
   485       _heap->clear();
   425       for ( NodeIt u(*G) ; u!=INVALID ; ++u ) {
   486       for ( NodeIt u(*G) ; u!=INVALID ; ++u ) {
   426 	_pred->set(u,INVALID);
   487 	_pred->set(u,INVALID);
   427 	_processed->set(u,false);
   488 	_processed->set(u,false);
   428 	_heap_map.set(u,Heap::PRE_HEAP);
   489 	_heap_cross_ref->set(u,Heap::PRE_HEAP);
   429       }
   490       }
   430     }
   491     }
   431     
   492     
   432     ///Adds a new source node.
   493     ///Adds a new source node.
   433 
   494 
   438     ///It checks if the node has already been added to the heap and
   499     ///It checks if the node has already been added to the heap and
   439     ///It is pushed to the heap only if either it was not in the heap
   500     ///It is pushed to the heap only if either it was not in the heap
   440     ///or the shortest path found till then is longer then \c dst.
   501     ///or the shortest path found till then is longer then \c dst.
   441     void addSource(Node s,Value dst=0)
   502     void addSource(Node s,Value dst=0)
   442     {
   503     {
   443       if(_heap.state(s) != Heap::IN_HEAP) _heap.push(s,dst);
   504       if(_heap->state(s) != Heap::IN_HEAP) {
   444       else if(_heap[s]<dst) {
   505 	_heap->push(s,dst);
   445 	_heap.push(s,dst);
   506       } else if((*_heap)[s]<dst) {
       
   507 	_heap->push(s,dst);
   446 	_pred->set(s,INVALID);
   508 	_pred->set(s,INVALID);
   447       }
   509       }
   448     }
   510     }
   449     
   511     
   450     ///Processes the next node in the priority heap
   512     ///Processes the next node in the priority heap
   454     ///\return The processed node.
   516     ///\return The processed node.
   455     ///
   517     ///
   456     ///\warning The priority heap must not be empty!
   518     ///\warning The priority heap must not be empty!
   457     Node processNextNode()
   519     Node processNextNode()
   458     {
   520     {
   459       Node v=_heap.top(); 
   521       Node v=_heap->top(); 
   460       Value oldvalue=_heap[v];
   522       Value oldvalue=_heap->prio();
   461       _heap.pop();
   523       _heap->pop();
   462       finalizeNodeData(v,oldvalue);
   524       finalizeNodeData(v,oldvalue);
   463       
   525       
   464       for(OutEdgeIt e(*G,v); e!=INVALID; ++e) {
   526       for(OutEdgeIt e(*G,v); e!=INVALID; ++e) {
   465 	Node w=G->target(e); 
   527 	Node w=G->target(e); 
   466 	switch(_heap.state(w)) {
   528 	switch(_heap->state(w)) {
   467 	case Heap::PRE_HEAP:
   529 	case Heap::PRE_HEAP:
   468 	  _heap.push(w,oldvalue+(*length)[e]); 
   530 	  _heap->push(w,oldvalue+(*length)[e]); 
   469 	  _pred->set(w,e);
   531 	  _pred->set(w,e);
   470 	  break;
   532 	  break;
   471 	case Heap::IN_HEAP:
   533 	case Heap::IN_HEAP:
   472 	  if ( oldvalue+(*length)[e] < _heap[w] ) {
   534 	  if ( oldvalue+(*length)[e] < (*_heap)[w] ) {
   473 	    _heap.decrease(w, oldvalue+(*length)[e]); 
   535 	    _heap->decrease(w, oldvalue+(*length)[e]); 
   474 	    _pred->set(w,e);
   536 	    _pred->set(w,e);
   475 	  }
   537 	  }
   476 	  break;
   538 	  break;
   477 	case Heap::POST_HEAP:
   539 	case Heap::POST_HEAP:
   478 	  break;
   540 	  break;
   487     ///
   549     ///
   488     ///\return The next node to be processed or INVALID if the priority heap
   550     ///\return The next node to be processed or INVALID if the priority heap
   489     /// is empty.
   551     /// is empty.
   490     Node nextNode()
   552     Node nextNode()
   491     { 
   553     { 
   492       return _heap.empty()?_heap.top():INVALID;
   554       return _heap->empty()?_heap->top():INVALID;
   493     }
   555     }
   494  
   556  
   495     ///\brief Returns \c false if there are nodes
   557     ///\brief Returns \c false if there are nodes
   496     ///to be processed in the priority heap
   558     ///to be processed in the priority heap
   497     ///
   559     ///
   498     ///Returns \c false if there are nodes
   560     ///Returns \c false if there are nodes
   499     ///to be processed in the priority heap
   561     ///to be processed in the priority heap
   500     bool emptyQueue() { return _heap.empty(); }
   562     bool emptyQueue() { return _heap->empty(); }
   501     ///Returns the number of the nodes to be processed in the priority heap
   563     ///Returns the number of the nodes to be processed in the priority heap
   502 
   564 
   503     ///Returns the number of the nodes to be processed in the priority heap
   565     ///Returns the number of the nodes to be processed in the priority heap
   504     ///
   566     ///
   505     int queueSize() { return _heap.size(); }
   567     int queueSize() { return _heap->size(); }
   506     
   568     
   507     ///Executes the algorithm.
   569     ///Executes the algorithm.
   508 
   570 
   509     ///Executes the algorithm.
   571     ///Executes the algorithm.
   510     ///
   572     ///
   518     ///- The shortest path tree.
   580     ///- The shortest path tree.
   519     ///- The distance of each node from the root(s).
   581     ///- The distance of each node from the root(s).
   520     ///
   582     ///
   521     void start()
   583     void start()
   522     {
   584     {
   523       while ( !_heap.empty() ) processNextNode();
   585       while ( !_heap->empty() ) processNextNode();
   524     }
   586     }
   525     
   587     
   526     ///Executes the algorithm until \c dest is reached.
   588     ///Executes the algorithm until \c dest is reached.
   527 
   589 
   528     ///Executes the algorithm until \c dest is reached.
   590     ///Executes the algorithm until \c dest is reached.
   537     ///- The shortest path to \c  dest.
   599     ///- The shortest path to \c  dest.
   538     ///- The distance of \c dest from the root(s).
   600     ///- The distance of \c dest from the root(s).
   539     ///
   601     ///
   540     void start(Node dest)
   602     void start(Node dest)
   541     {
   603     {
   542       while ( !_heap.empty() && _heap.top()!=dest ) processNextNode();
   604       while ( !_heap->empty() && _heap->top()!=dest ) processNextNode();
   543       if ( !_heap.empty() ) finalizeNodeData(_heap.top(),_heap.prio());
   605       if ( !_heap->empty() ) finalizeNodeData(_heap->top(),_heap->prio());
   544     }
   606     }
   545     
   607     
   546     ///Executes the algorithm until a condition is met.
   608     ///Executes the algorithm until a condition is met.
   547 
   609 
   548     ///Executes the algorithm until a condition is met.
   610     ///Executes the algorithm until a condition is met.
   553     ///\param nm must be a bool (or convertible) node map. The algorithm
   615     ///\param nm must be a bool (or convertible) node map. The algorithm
   554     ///will stop when it reaches a node \c v with <tt>nm[v]==true</tt>.
   616     ///will stop when it reaches a node \c v with <tt>nm[v]==true</tt>.
   555     template<class NodeBoolMap>
   617     template<class NodeBoolMap>
   556     void start(const NodeBoolMap &nm)
   618     void start(const NodeBoolMap &nm)
   557     {
   619     {
   558       while ( !_heap.empty() && !nm[_heap.top()] ) processNextNode();
   620       while ( !_heap->empty() && !nm[_heap->top()] ) processNextNode();
   559       if ( !_heap.empty() ) finalizeNodeData(_heap.top(),_heap.prio());
   621       if ( !_heap->empty() ) finalizeNodeData(_heap->top(),_heap->prio());
   560     }
   622     }
   561     
   623     
   562     ///Runs %Dijkstra algorithm from node \c s.
   624     ///Runs %Dijkstra algorithm from node \c s.
   563     
   625     
   564     ///This method runs the %Dijkstra algorithm from a root node \c s
   626     ///This method runs the %Dijkstra algorithm from a root node \c s
   681 
   743 
   682     ///Returns \c true if \c v is reachable from the root.
   744     ///Returns \c true if \c v is reachable from the root.
   683     ///\warning The source nodes are inditated as unreached.
   745     ///\warning The source nodes are inditated as unreached.
   684     ///\pre \ref run() must be called before using this function.
   746     ///\pre \ref run() must be called before using this function.
   685     ///
   747     ///
   686     bool reached(Node v) { return _heap_map[v]!=Heap::PRE_HEAP; }
   748     bool reached(Node v) { return (*_heap_cross_ref)[v] != Heap::PRE_HEAP; }
   687     
   749     
   688     ///@}
   750     ///@}
   689   };
   751   };
   690 
   752 
   691 
   753 
   709     typedef LM LengthMap;
   771     typedef LM LengthMap;
   710     //The type of the length of the edges.
   772     //The type of the length of the edges.
   711     typedef typename LM::Value Value;
   773     typedef typename LM::Value Value;
   712     ///The heap type used by Dijkstra algorithm.
   774     ///The heap type used by Dijkstra algorithm.
   713 
   775 
       
   776     /// The cross reference type used by heap.
       
   777 
       
   778     /// The cross reference type used by heap.
       
   779     /// Usually it is \c Graph::NodeMap<int>.
       
   780     typedef typename Graph::template NodeMap<int> HeapCrossRef;
       
   781     ///Instantiates a HeapCrossRef.
       
   782 
       
   783     ///This function instantiates a \ref HeapCrossRef. 
       
   784     /// \param G is the graph, to which we would like to define the 
       
   785     /// HeapCrossRef.
       
   786     /// \todo The graph alone may be insufficient for the initialization
       
   787     static HeapCrossRef *createHeapCrossRef(const GR &G) 
       
   788     {
       
   789       return new HeapCrossRef(G);
       
   790     }
       
   791     
       
   792     ///The heap type used by Dijkstra algorithm.
       
   793 
   714     ///The heap type used by Dijkstra algorithm.
   794     ///The heap type used by Dijkstra algorithm.
   715     ///
   795     ///
   716     ///\sa BinHeap
   796     ///\sa BinHeap
   717     ///\sa Dijkstra
   797     ///\sa Dijkstra
   718     typedef BinHeap<typename Graph::Node,
   798     typedef BinHeap<typename Graph::Node, typename LM::Value,
   719 		    typename LM::Value,
       
   720 		    typename GR::template NodeMap<int>,
   799 		    typename GR::template NodeMap<int>,
   721 		    std::less<Value> > Heap;
   800 		    std::less<Value> > Heap;
       
   801 
       
   802     static Heap *createHeap(HeapCrossRef& R) 
       
   803     {
       
   804       return new Heap(R);
       
   805     }
   722 
   806 
   723     ///\brief The type of the map that stores the last
   807     ///\brief The type of the map that stores the last
   724     ///edges of the shortest paths.
   808     ///edges of the shortest paths.
   725     /// 
   809     /// 
   726     ///The type of the map that stores the last
   810     ///The type of the map that stores the last
   805     void *_g;
   889     void *_g;
   806     /// Pointer to the length map
   890     /// Pointer to the length map
   807     void *_length;
   891     void *_length;
   808     ///Pointer to the map of predecessors edges.
   892     ///Pointer to the map of predecessors edges.
   809     void *_pred;
   893     void *_pred;
   810 //     ///Pointer to the map of predecessors nodes.
       
   811 //     void *_predNode;
       
   812     ///Pointer to the map of distances.
   894     ///Pointer to the map of distances.
   813     void *_dist;
   895     void *_dist;
   814     ///Pointer to the source node.
   896     ///Pointer to the source node.
   815     Node _source;
   897     Node _source;
   816 
   898 
   818     /// Constructor.
   900     /// Constructor.
   819     
   901     
   820     /// This constructor does not require parameters, therefore it initiates
   902     /// This constructor does not require parameters, therefore it initiates
   821     /// all of the attributes to default values (0, INVALID).
   903     /// all of the attributes to default values (0, INVALID).
   822     DijkstraWizardBase() : _g(0), _length(0), _pred(0),
   904     DijkstraWizardBase() : _g(0), _length(0), _pred(0),
   823 // 			   _predNode(0),
       
   824 			   _dist(0), _source(INVALID) {}
   905 			   _dist(0), _source(INVALID) {}
   825 
   906 
   826     /// Constructor.
   907     /// Constructor.
   827     
   908     
   828     /// This constructor requires some parameters,
   909     /// This constructor requires some parameters,
   831     /// \param g is the initial value of  \ref _g
   912     /// \param g is the initial value of  \ref _g
   832     /// \param l is the initial value of  \ref _length
   913     /// \param l is the initial value of  \ref _length
   833     /// \param s is the initial value of  \ref _source
   914     /// \param s is the initial value of  \ref _source
   834     DijkstraWizardBase(const GR &g,const LM &l, Node s=INVALID) :
   915     DijkstraWizardBase(const GR &g,const LM &l, Node s=INVALID) :
   835       _g((void *)&g), _length((void *)&l), _pred(0),
   916       _g((void *)&g), _length((void *)&l), _pred(0),
   836 //       _predNode(0),
       
   837       _dist(0), _source(s) {}
   917       _dist(0), _source(s) {}
   838 
   918 
   839   };
   919   };
   840   
   920   
   841   /// A class to make the usage of Dijkstra algorithm easier
   921   /// A class to make the usage of Dijkstra algorithm easier
   853   /// operator. In the case of \ref DijkstraWizard only
   933   /// operator. In the case of \ref DijkstraWizard only
   854   /// a function have to be called and it will
   934   /// a function have to be called and it will
   855   /// return the needed class.
   935   /// return the needed class.
   856   ///
   936   ///
   857   /// It does not have own \ref run method. When its \ref run method is called
   937   /// It does not have own \ref run method. When its \ref run method is called
   858   /// it initiates a plain \ref Dijkstra class, and calls the \ref Dijkstra::run
   938   /// it initiates a plain \ref Dijkstra class, and calls the \ref 
   859   /// method of it.
   939   /// Dijkstra::run method of it.
   860   template<class TR>
   940   template<class TR>
   861   class DijkstraWizard : public TR
   941   class DijkstraWizard : public TR
   862   {
   942   {
   863     typedef TR Base;
   943     typedef TR Base;
   864 
   944 
   878     ///The type of the length of the edges.
   958     ///The type of the length of the edges.
   879     typedef typename LengthMap::Value Value;
   959     typedef typename LengthMap::Value Value;
   880     ///\brief The type of the map that stores the last
   960     ///\brief The type of the map that stores the last
   881     ///edges of the shortest paths.
   961     ///edges of the shortest paths.
   882     typedef typename TR::PredMap PredMap;
   962     typedef typename TR::PredMap PredMap;
   883 //     ///\brief The type of the map that stores the last but one
       
   884 //     ///nodes of the shortest paths.
       
   885 //     typedef typename TR::PredNodeMap PredNodeMap;
       
   886     ///The type of the map that stores the dists of the nodes.
   963     ///The type of the map that stores the dists of the nodes.
   887     typedef typename TR::DistMap DistMap;
   964     typedef typename TR::DistMap DistMap;
   888 
       
   889     ///The heap type used by the dijkstra algorithm.
   965     ///The heap type used by the dijkstra algorithm.
   890     typedef typename TR::Heap Heap;
   966     typedef typename TR::Heap Heap;
   891 public:
   967 public:
   892     /// Constructor.
   968     /// Constructor.
   893     DijkstraWizard() : TR() {}
   969     DijkstraWizard() : TR() {}
   912     {
   988     {
   913       if(Base::_source==INVALID) throw UninitializedParameter();
   989       if(Base::_source==INVALID) throw UninitializedParameter();
   914       Dijkstra<Graph,LengthMap,TR> 
   990       Dijkstra<Graph,LengthMap,TR> 
   915 	dij(*(Graph*)Base::_g,*(LengthMap*)Base::_length);
   991 	dij(*(Graph*)Base::_g,*(LengthMap*)Base::_length);
   916       if(Base::_pred) dij.predMap(*(PredMap*)Base::_pred);
   992       if(Base::_pred) dij.predMap(*(PredMap*)Base::_pred);
   917 //       if(Base::_predNode) Dij.predNodeMap(*(PredNodeMap*)Base::_predNode);
       
   918       if(Base::_dist) dij.distMap(*(DistMap*)Base::_dist);
   993       if(Base::_dist) dij.distMap(*(DistMap*)Base::_dist);
   919       dij.run(Base::_source);
   994       dij.run(Base::_source);
   920     }
   995     }
   921 
   996 
   922     ///Runs Dijkstra algorithm from the given node.
   997     ///Runs Dijkstra algorithm from the given node.
   947     {
  1022     {
   948       Base::_pred=(void *)&t;
  1023       Base::_pred=(void *)&t;
   949       return DijkstraWizard<DefPredMapBase<T> >(*this);
  1024       return DijkstraWizard<DefPredMapBase<T> >(*this);
   950     }
  1025     }
   951     
  1026     
   952 
       
   953 //     template<class T>
       
   954 //     struct DefPredNodeMapBase : public Base {
       
   955 //       typedef T PredNodeMap;
       
   956 //       static PredNodeMap *createPredNodeMap(const Graph &G) { return 0; };
       
   957 //       DefPredNodeMapBase(const TR &b) : TR(b) {}
       
   958 //     };
       
   959     
       
   960 //     ///\brief \ref named-templ-param "Named parameter"
       
   961 //     ///function for setting PredNodeMap type
       
   962 //     ///
       
   963 //     /// \ref named-templ-param "Named parameter"
       
   964 //     ///function for setting PredNodeMap type
       
   965 //     ///
       
   966 //     template<class T>
       
   967 //     DijkstraWizard<DefPredNodeMapBase<T> > predNodeMap(const T &t) 
       
   968 //     {
       
   969 //       Base::_predNode=(void *)&t;
       
   970 //       return DijkstraWizard<DefPredNodeMapBase<T> >(*this);
       
   971 //     }
       
   972    
       
   973     template<class T>
  1027     template<class T>
   974     struct DefDistMapBase : public Base {
  1028     struct DefDistMapBase : public Base {
   975       typedef T DistMap;
  1029       typedef T DistMap;
   976       static DistMap *createDistMap(const Graph &) { return 0; };
  1030       static DistMap *createDistMap(const Graph &) { return 0; };
   977       DefDistMapBase(const TR &b) : TR(b) {}
  1031       DefDistMapBase(const TR &b) : TR(b) {}