src/lemon/dijkstra.h
changeset 1151 b217fc69f913
parent 1132 ab5c81fcc31a
child 1155 fe0fcdb5687b
equal deleted inserted replaced
4:336ccb68d28b 5:b09854556d55
    28 #include <lemon/maps.h>
    28 #include <lemon/maps.h>
    29 
    29 
    30 namespace lemon {
    30 namespace lemon {
    31 
    31 
    32 
    32 
    33 /// \addtogroup flowalgs
    33   
    34 /// @{
       
    35 
       
    36   ///Default traits class of Dijkstra class.
    34   ///Default traits class of Dijkstra class.
    37 
    35 
    38   ///Default traits class of Dijkstra class.
    36   ///Default traits class of Dijkstra class.
    39   ///\param GR Graph type.
    37   ///\param GR Graph type.
    40   ///\param LM Type of length map.
    38   ///\param LM Type of length map.
   127     }
   125     }
   128   };
   126   };
   129   
   127   
   130   ///%Dijkstra algorithm class.
   128   ///%Dijkstra algorithm class.
   131   
   129   
       
   130   /// \ingroup flowalgs
   132   ///This class provides an efficient implementation of %Dijkstra algorithm.
   131   ///This class provides an efficient implementation of %Dijkstra algorithm.
   133   ///The edge lengths are passed to the algorithm using a
   132   ///The edge lengths are passed to the algorithm using a
   134   ///\ref concept::ReadMap "ReadMap",
   133   ///\ref concept::ReadMap "ReadMap",
   135   ///so it is easy to change it to any kind of length.
   134   ///so it is easy to change it to any kind of length.
   136   ///
   135   ///
   494     {
   493     {
   495       source = s;
   494       source = s;
   496       if(_heap.state(s) != Heap::IN_HEAP) _heap.push(s,dst);
   495       if(_heap.state(s) != Heap::IN_HEAP) _heap.push(s,dst);
   497     }
   496     }
   498     
   497     
   499     void processNode()
   498     void processNextNode()
   500     {
   499     {
   501       Node v=_heap.top(); 
   500       Node v=_heap.top(); 
   502       Value oldvalue=_heap[v];
   501       Value oldvalue=_heap[v];
   503       _heap.pop();
   502       _heap.pop();
   504       finalizeNodeData(v,oldvalue);
   503       finalizeNodeData(v,oldvalue);
   538     ///- The shortest path tree.
   537     ///- The shortest path tree.
   539     ///- The distance of each node from the root(s).
   538     ///- The distance of each node from the root(s).
   540     ///
   539     ///
   541     void start()
   540     void start()
   542     {
   541     {
   543       while ( !_heap.empty() ) processNode();
   542       while ( !_heap.empty() ) processNextNode();
   544     }
   543     }
   545     
   544     
   546     ///Executes the algorithm until \c dest is reached.
   545     ///Executes the algorithm until \c dest is reached.
   547 
   546 
   548     ///Executes the algorithm until \c dest is reached.
   547     ///Executes the algorithm until \c dest is reached.
   557     ///- The shortest path to \c  dest.
   556     ///- The shortest path to \c  dest.
   558     ///- The distance of \c dest from the root(s).
   557     ///- The distance of \c dest from the root(s).
   559     ///
   558     ///
   560     void start(Node dest)
   559     void start(Node dest)
   561     {
   560     {
   562       while ( !_heap.empty() && _heap.top()!=dest ) processNode();
   561       while ( !_heap.empty() && _heap.top()!=dest ) processNextNode();
   563       if ( _heap.top()==dest ) finalizeNodeData(_heap.top());
   562       if ( _heap.top()==dest ) finalizeNodeData(_heap.top());
   564     }
   563     }
   565     
   564     
   566     ///Executes the algorithm until a condition is met.
   565     ///Executes the algorithm until a condition is met.
   567 
   566 
   573     ///\param nm must be a bool (or convertible) node map. The algorithm
   572     ///\param nm must be a bool (or convertible) node map. The algorithm
   574     ///will stop when it reaches a node \c v with <tt>nm[v]==true</tt>.
   573     ///will stop when it reaches a node \c v with <tt>nm[v]==true</tt>.
   575     template<class NM>
   574     template<class NM>
   576     void start(const NM &nm)
   575     void start(const NM &nm)
   577     {
   576     {
   578       while ( !_heap.empty() && !mn[_heap.top()] ) processNode();
   577       while ( !_heap.empty() && !mn[_heap.top()] ) processNextNode();
   579       if ( !_heap.empty() ) finalizeNodeData(_heap.top());
   578       if ( !_heap.empty() ) finalizeNodeData(_heap.top());
   580     }
   579     }
   581     
   580     
   582     ///Runs %Dijkstra algorithm from node \c s.
   581     ///Runs %Dijkstra algorithm from node \c s.
   583     
   582     
   693     ///@}
   692     ///@}
   694   };
   693   };
   695 
   694 
   696   /// Default traits used by \ref DijkstraWizard
   695   /// Default traits used by \ref DijkstraWizard
   697 
   696 
   698   /// To make it easier to use Dijkstra algorithm we have created a wizard class.
   697   /// To make it easier to use Dijkstra algorithm
   699   /// This \ref DijkstraWizard class needs default traits, as well as the \ref Dijkstra class.
   698   ///we have created a wizard class.
       
   699   /// This \ref DijkstraWizard class needs default traits,
       
   700   ///as well as the \ref Dijkstra class.
   700   /// The \ref DijkstraWizardBase is a class to be the default traits of the
   701   /// The \ref DijkstraWizardBase is a class to be the default traits of the
   701   /// \ref DijkstraWizard class.
   702   /// \ref DijkstraWizard class.
   702   template<class GR,class LM>
   703   template<class GR,class LM>
   703   class DijkstraWizardBase : public DijkstraDefaultTraits<GR,LM>
   704   class DijkstraWizardBase : public DijkstraDefaultTraits<GR,LM>
   704   {
   705   {
   742 
   743 
   743   };
   744   };
   744   
   745   
   745   /// A class to make easier the usage of Dijkstra algorithm
   746   /// A class to make easier the usage of Dijkstra algorithm
   746 
   747 
       
   748   /// \ingroup flowalgs
   747   /// This class is created to make it easier to use Dijkstra algorithm.
   749   /// This class is created to make it easier to use Dijkstra algorithm.
   748   /// It uses the functions and features of the plain \ref Dijkstra,
   750   /// It uses the functions and features of the plain \ref Dijkstra,
   749   /// but it is much more simple to use it.
   751   /// but it is much simpler to use it.
   750   ///
   752   ///
   751   /// Simplicity means that the way to change the types defined
   753   /// Simplicity means that the way to change the types defined
   752   /// in the traits class is based on functions that returns the new class
   754   /// in the traits class is based on functions that returns the new class
   753   /// and not on templatable built-in classes. When using the plain \ref Dijkstra
   755   /// and not on templatable built-in classes.
   754   /// the new class with the modified type comes from the original class by using the ::
   756   /// When using the plain \ref Dijkstra
   755   /// operator. In the case of \ref DijkstraWizard only a function have to be called and it will
   757   /// the new class with the modified type comes from
       
   758   /// the original class by using the ::
       
   759   /// operator. In the case of \ref DijkstraWizard only
       
   760   /// a function have to be called and it will
   756   /// return the needed class.
   761   /// return the needed class.
   757   ///
   762   ///
   758   /// It does not have own \ref run method. When its \ref run method is called
   763   /// It does not have own \ref run method. When its \ref run method is called
   759   /// it initiates a plain \ref Dijkstra class, and calls the \ref Dijkstra::run
   764   /// it initiates a plain \ref Dijkstra class, and calls the \ref Dijkstra::run
   760   /// method of it.
   765   /// method of it.
   896     
   901     
   897   };
   902   };
   898   
   903   
   899   ///\e
   904   ///\e
   900 
   905 
       
   906   /// \ingroup flowalgs
   901   ///\todo Please document...
   907   ///\todo Please document...
   902   ///
   908   ///
   903   template<class GR, class LM>
   909   template<class GR, class LM>
   904   DijkstraWizard<DijkstraWizardBase<GR,LM> >
   910   DijkstraWizard<DijkstraWizardBase<GR,LM> >
   905   dijkstra(const GR &g,const LM &l,typename GR::Node s=INVALID)
   911   dijkstra(const GR &g,const LM &l,typename GR::Node s=INVALID)