# HG changeset patch # User alpar # Date 1107345295 0 # Node ID f97e1cbbd45390b6f4b6f8da33da6793835dba16 # Parent 444f69240539534fcb9cb0c3372ee8b3f71acee5 - More or less follows the new naming convetions - New implementation for dijkstra(); diff -r 444f69240539 -r f97e1cbbd453 src/work/alpar/dijkstra.h --- a/src/work/alpar/dijkstra.h Tue Feb 01 15:56:37 2005 +0000 +++ b/src/work/alpar/dijkstra.h Wed Feb 02 11:54:55 2005 +0000 @@ -143,7 +143,7 @@ typename LM=typename GR::template EdgeMap, typename TR=DijkstraDefaultTraits > #endif - class Dijkstra{ + class Dijkstra { public: typedef TR Traits; ///The type of the underlying graph. @@ -213,9 +213,9 @@ } public : - + template - struct SetPredMapTraits : public Traits { + struct DefPredMapTraits : public Traits { typedef T PredMap; ///\todo An exception should be thrown. /// @@ -231,12 +231,12 @@ ///\ref named-templ-param "Named parameter" for setting PredMap type /// template - class SetPredMap : public Dijkstra< Graph, + class DefPredMap : public Dijkstra< Graph, LengthMap, - SetPredMapTraits > { }; + DefPredMapTraits > { }; template - struct SetPredNodeMapTraits : public Traits { + struct DefPredNodeMapTraits : public Traits { typedef T PredNodeMap; ///\todo An exception should be thrown. /// @@ -252,12 +252,12 @@ ///\ref named-templ-param "Named parameter" for setting PredNodeMap type /// template - class SetPredNodeMap : public Dijkstra< Graph, + class DefPredNodeMap : public Dijkstra< Graph, LengthMap, - SetPredNodeMapTraits > { }; + DefPredNodeMapTraits > { }; template - struct SetDistMapTraits : public Traits { + struct DefDistMapTraits : public Traits { typedef T DistMap; ///\todo An exception should be thrown. /// @@ -273,9 +273,9 @@ ///\ref named-templ-param "Named parameter" for setting DistMap type /// template - class SetDistMap : public Dijkstra< Graph, + class DefDistMap : public Dijkstra< Graph, LengthMap, - SetDistMapTraits > { }; + DefDistMapTraits > { }; ///Constructor. @@ -300,7 +300,7 @@ ///Sets the length map. ///\return (*this) - Dijkstra &setLengthMap(const LengthMap &m) + Dijkstra &lengthMap(const LengthMap &m) { length = &m; return *this; @@ -313,7 +313,7 @@ ///it will allocate one. The destuctor deallocates this ///automatically allocated map, of course. ///\return (*this) - Dijkstra &setPredMap(PredMap &m) + Dijkstra &predMap(PredMap &m) { if(local_predecessor) { delete predecessor; @@ -330,7 +330,7 @@ ///it will allocate one. The destuctor deallocates this ///automatically allocated map, of course. ///\return (*this) - Dijkstra &setPredNodeMap(PredNodeMap &m) + Dijkstra &predNodeMap(PredNodeMap &m) { if(local_pred_node) { delete pred_node; @@ -347,7 +347,7 @@ ///it will allocate one. The destuctor deallocates this ///automatically allocated map, of course. ///\return (*this) - Dijkstra &setDistMap(DistMap &m) + Dijkstra &distMap(DistMap &m) { if(local_distance) { delete distance; @@ -473,14 +473,45 @@ }; + template + class DijkstraWizardBase : public DijkstraDefaultTraits + { + + typedef DijkstraDefaultTraits Base; + protected: + /// Pointer to the underlying graph. + void *_g; + /// Pointer to the length map + void *_length; + ///Pointer to the map of predecessors edges. + void *_pred; + ///Pointer to the map of predecessors nodes. + void *_predNode; + ///Pointer to the map of distances. + void *_dist; + ///Pointer to the source node. + void *_source; + + typedef typename Base::Graph::Node Node; + + public: + DijkstraWizardBase() : _g(0), _length(0), _pred(0), _predNode(0), + _dist(0), _source(INVALID) {} + + DijkstraWizardBase(const GR &g,const LM &l, Node s=INVALID) : + _g((void *)&g), _length((void *)&l), _pred(0), _predNode(0), + _dist(0), _source((void *)&s) {} + + }; + ///\e ///\e /// template - class _Dijkstra + class DijkstraWizard : public TR { - typedef TR Traits; + typedef TR Base; ///The type of the underlying graph. typedef typename TR::Graph Graph; @@ -508,90 +539,80 @@ ///The heap type used by the dijkstra algorithm. typedef typename TR::Heap Heap; +public: + DijkstraWizard() : TR() {} - /// Pointer to the underlying graph. - const Graph *G; - /// Pointer to the length map - const LengthMap *length; - ///Pointer to the map of predecessors edges. - PredMap *predecessor; - ///Pointer to the map of predecessors nodes. - PredNodeMap *pred_node; - ///Pointer to the map of distances. - DistMap *distance; - - Node source; - -public: - _Dijkstra() : G(0), length(0), predecessor(0), pred_node(0), - distance(0), source(INVALID) {} + DijkstraWizard(const Graph &g,const LengthMap &l, Node s=INVALID) : + TR(g,l,s) {} - _Dijkstra(const Graph &g,const LengthMap &l, Node s) : - G(&g), length(&l), predecessor(0), pred_node(0), - distance(0), source(s) {} + DijkstraWizard(const TR &b) : TR(b) {} - ~_Dijkstra() + ~DijkstraWizard() {} + + ///\e + void run() { - Dijkstra Dij(*G,*length); - if(predecessor) Dij.setPredMap(*predecessor); - if(pred_node) Dij.setPredNodeMap(*pred_node); - if(distance) Dij.setDistMap(*distance); - Dij.run(source); + Dijkstra Dij(*(Graph*)_g,*(LengthMap*)_length); + if(_pred) Dij.predMap(*(PredMap*)_pred); + if(_predNode) Dij.predNodeMap(*(PredNodeMap*)_predNode); + if(_dist) Dij.distMap(*(DistMap*)_dist); + Dij.run(*(Node*)_source); + } + + ///\e + void run(Node s) + { + _source=(void *)&s; + run(); } template - struct SetPredMapTraits : public Traits {typedef T PredMap;}; + struct DefPredMapBase : public Base { + typedef T PredMap; + static PredMap *createPredMap(const Graph &G) {}; + }; ///\e template - _Dijkstra > setPredMap(const T &t) + DijkstraWizard > predMap(const T &t) { - _Dijkstra > r; - r.G=G; - r.length=length; - r.predecessor=&t; - r.pred_node=pred_node; - r.distance=distance; - r.source=source; - return r; + _pred=(void *)&t; + return DijkstraWizard >(*this); } + template - struct SetPredNodeMapTraits :public Traits {typedef T PredNodeMap;}; + struct DefPredNodeMapBase : public Base { + typedef T PredNodeMap; + static PredNodeMap *createPredNodeMap(const Graph &G) {}; + }; + ///\e template - _Dijkstra > setPredNodeMap(const T &t) + DijkstraWizard > predNodeMap(const T &t) { - _Dijkstra > r; - r.G=G; - r.length=length; - r.predecessor=predecessor; - r.pred_node=&t; - r.distance=distance; - r.source=source; - return r; + _predNode=(void *)&t; + return DijkstraWizard >(*this); } + + template + struct DefDistMapBase : public Base { + typedef T DistMap; + static DistMap *createDistMap(const Graph &G) {}; + }; - template - struct SetDistMapTraits : public Traits {typedef T DistMap;}; ///\e template - _Dijkstra > setDistMap(const T &t) + DijkstraWizard > distMap(const T &t) { - _Dijkstra > r; - r.G=G; - r.length=length; - r.predecessor=predecessor; - r.pred_node=pred_node; - r.distance=&t; - r.source=source; - return r; + _dist=(void *)&t; + return DijkstraWizard >(*this); } - + ///\e - _Dijkstra &setSource(Node s) + DijkstraWizard &setSource(Node s) { - source=s; + source=(void *)&s; return *this; } @@ -602,10 +623,10 @@ ///\todo Please document... /// template - _Dijkstra > - dijkstra(const GR &g,const LM &l,typename GR::Node s) + DijkstraWizard > + dijkstra(const GR &g,const LM &l,typename GR::Node s=INVALID) { - return _Dijkstra >(g,l,s); + return DijkstraWizard >(g,l,s); } /// @}