src/lemon/dijkstra.h
changeset 1210 f02396423239
parent 1196 4bebc22ab77c
child 1218 5331168bbb18
equal deleted inserted replaced
10:ef0f49a4d0e0 11:0b6f35ead62a
   727   class DijkstraWizardBase : public DijkstraDefaultTraits<GR,LM>
   727   class DijkstraWizardBase : public DijkstraDefaultTraits<GR,LM>
   728   {
   728   {
   729 
   729 
   730     typedef DijkstraDefaultTraits<GR,LM> Base;
   730     typedef DijkstraDefaultTraits<GR,LM> Base;
   731   protected:
   731   protected:
       
   732     /// Type of the nodes in the graph.
       
   733     typedef typename Base::Graph::Node Node;
       
   734 
   732     /// Pointer to the underlying graph.
   735     /// Pointer to the underlying graph.
   733     void *_g;
   736     void *_g;
   734     /// Pointer to the length map
   737     /// Pointer to the length map
   735     void *_length;
   738     void *_length;
   736     ///Pointer to the map of predecessors edges.
   739     ///Pointer to the map of predecessors edges.
   738     ///Pointer to the map of predecessors nodes.
   741     ///Pointer to the map of predecessors nodes.
   739     void *_predNode;
   742     void *_predNode;
   740     ///Pointer to the map of distances.
   743     ///Pointer to the map of distances.
   741     void *_dist;
   744     void *_dist;
   742     ///Pointer to the source node.
   745     ///Pointer to the source node.
   743     void *_source;
   746     Node _source;
   744 
       
   745     /// Type of the nodes in the graph.
       
   746     typedef typename Base::Graph::Node Node;
       
   747 
   747 
   748     public:
   748     public:
   749     /// Constructor.
   749     /// Constructor.
   750     
   750     
   751     /// This constructor does not require parameters, therefore it initiates
   751     /// This constructor does not require parameters, therefore it initiates
   752     /// all of the attributes to default values (0, INVALID).
   752     /// all of the attributes to default values (0, INVALID).
   753     DijkstraWizardBase() : _g(0), _length(0), _pred(0), _predNode(0),
   753     DijkstraWizardBase() : _g(0), _length(0), _pred(0), _predNode(0),
   754 		       _dist(0), _source(0) {}
   754 		       _dist(0), _source(INVALID) {}
   755 
   755 
   756     /// Constructor.
   756     /// Constructor.
   757     
   757     
   758     /// This constructor requires some parameters,
   758     /// This constructor requires some parameters,
   759     /// listed in the parameters list.
   759     /// listed in the parameters list.
   761     /// \param g is the initial value of  \ref _g
   761     /// \param g is the initial value of  \ref _g
   762     /// \param l is the initial value of  \ref _length
   762     /// \param l is the initial value of  \ref _length
   763     /// \param s is the initial value of  \ref _source
   763     /// \param s is the initial value of  \ref _source
   764     DijkstraWizardBase(const GR &g,const LM &l, Node s=INVALID) :
   764     DijkstraWizardBase(const GR &g,const LM &l, Node s=INVALID) :
   765       _g((void *)&g), _length((void *)&l), _pred(0), _predNode(0),
   765       _g((void *)&g), _length((void *)&l), _pred(0), _predNode(0),
   766 		  _dist(0), _source((s==INVALID)?0:(void *)&s) {}
   766 		  _dist(0), _source(s) {}
   767 
   767 
   768   };
   768   };
   769   
   769   
   770   /// A class to make easier the usage of Dijkstra algorithm
   770   /// A class to make easier the usage of Dijkstra algorithm
   771 
   771 
   838     
   838     
   839     ///Runs Dijkstra algorithm from a given node.
   839     ///Runs Dijkstra algorithm from a given node.
   840     ///The node can be given by the \ref source function.
   840     ///The node can be given by the \ref source function.
   841     void run()
   841     void run()
   842     {
   842     {
   843       if(Base::_source==0) throw UninitializedParameter();
   843       if(Base::_source==INVALID) throw UninitializedParameter();
   844       Dijkstra<Graph,LengthMap,TR> 
   844       Dijkstra<Graph,LengthMap,TR> 
   845 	Dij(*(Graph*)Base::_g,*(LengthMap*)Base::_length);
   845 	Dij(*(Graph*)Base::_g,*(LengthMap*)Base::_length);
   846       if(Base::_pred) Dij.predMap(*(PredMap*)Base::_pred);
   846       if(Base::_pred) Dij.predMap(*(PredMap*)Base::_pred);
   847       if(Base::_predNode) Dij.predNodeMap(*(PredNodeMap*)Base::_predNode);
   847       if(Base::_predNode) Dij.predNodeMap(*(PredNodeMap*)Base::_predNode);
   848       if(Base::_dist) Dij.distMap(*(DistMap*)Base::_dist);
   848       if(Base::_dist) Dij.distMap(*(DistMap*)Base::_dist);
   849       Dij.run(*(Node*)Base::_source);
   849       Dij.run(Base::_source);
   850     }
   850     }
   851 
   851 
   852     ///Runs Dijkstra algorithm from the given node.
   852     ///Runs Dijkstra algorithm from the given node.
   853 
   853 
   854     ///Runs Dijkstra algorithm from the given node.
   854     ///Runs Dijkstra algorithm from the given node.
   855     ///\param s is the given source.
   855     ///\param s is the given source.
   856     void run(Node s)
   856     void run(Node s)
   857     {
   857     {
   858       Base::_source=(void *)&s;
   858       Base::_source=s;
   859       run();
   859       run();
   860     }
   860     }
   861 
   861 
   862     template<class T>
   862     template<class T>
   863     struct DefPredMapBase : public Base {
   863     struct DefPredMapBase : public Base {
   924 
   924 
   925     /// Sets the source node, from which the Dijkstra algorithm runs.
   925     /// Sets the source node, from which the Dijkstra algorithm runs.
   926     /// \param s is the source node.
   926     /// \param s is the source node.
   927     DijkstraWizard<TR> &source(Node s) 
   927     DijkstraWizard<TR> &source(Node s) 
   928     {
   928     {
   929       Base::_source=(void *)&s;
   929       Base::_source=s;
   930       return *this;
   930       return *this;
   931     }
   931     }
   932     
   932     
   933   };
   933   };
   934   
   934