- More or less follows the new naming convetions
authoralpar
Wed, 02 Feb 2005 11:54:55 +0000
changeset 1116f97e1cbbd453
parent 1115 444f69240539
child 1117 5767cc417f62
- More or less follows the new naming convetions
- New implementation for dijkstra();
src/work/alpar/dijkstra.h
     1.1 --- a/src/work/alpar/dijkstra.h	Tue Feb 01 15:56:37 2005 +0000
     1.2 +++ b/src/work/alpar/dijkstra.h	Wed Feb 02 11:54:55 2005 +0000
     1.3 @@ -143,7 +143,7 @@
     1.4  	    typename LM=typename GR::template EdgeMap<int>,
     1.5  	    typename TR=DijkstraDefaultTraits<GR,LM> >
     1.6  #endif
     1.7 -  class Dijkstra{
     1.8 +  class Dijkstra {
     1.9    public:
    1.10      typedef TR Traits;
    1.11      ///The type of the underlying graph.
    1.12 @@ -213,9 +213,9 @@
    1.13      }
    1.14      
    1.15    public :
    1.16 -
    1.17 + 
    1.18      template <class T>
    1.19 -    struct SetPredMapTraits : public Traits {
    1.20 +    struct DefPredMapTraits : public Traits {
    1.21        typedef T PredMap;
    1.22        ///\todo An exception should be thrown.
    1.23        ///
    1.24 @@ -231,12 +231,12 @@
    1.25      ///\ref named-templ-param "Named parameter" for setting PredMap type
    1.26      ///
    1.27      template <class T>
    1.28 -    class SetPredMap : public Dijkstra< Graph,
    1.29 +    class DefPredMap : public Dijkstra< Graph,
    1.30  					LengthMap,
    1.31 -					SetPredMapTraits<T> > { };
    1.32 +					DefPredMapTraits<T> > { };
    1.33      
    1.34      template <class T>
    1.35 -    struct SetPredNodeMapTraits : public Traits {
    1.36 +    struct DefPredNodeMapTraits : public Traits {
    1.37        typedef T PredNodeMap;
    1.38        ///\todo An exception should be thrown.
    1.39        ///
    1.40 @@ -252,12 +252,12 @@
    1.41      ///\ref named-templ-param "Named parameter" for setting PredNodeMap type
    1.42      ///
    1.43      template <class T>
    1.44 -    class SetPredNodeMap : public Dijkstra< Graph,
    1.45 +    class DefPredNodeMap : public Dijkstra< Graph,
    1.46  					    LengthMap,
    1.47 -					    SetPredNodeMapTraits<T> > { };
    1.48 +					    DefPredNodeMapTraits<T> > { };
    1.49      
    1.50      template <class T>
    1.51 -    struct SetDistMapTraits : public Traits {
    1.52 +    struct DefDistMapTraits : public Traits {
    1.53        typedef T DistMap;
    1.54        ///\todo An exception should be thrown.
    1.55        ///
    1.56 @@ -273,9 +273,9 @@
    1.57      ///\ref named-templ-param "Named parameter" for setting DistMap type
    1.58      ///
    1.59      template <class T>
    1.60 -    class SetDistMap : public Dijkstra< Graph,
    1.61 +    class DefDistMap : public Dijkstra< Graph,
    1.62  					LengthMap,
    1.63 -					SetDistMapTraits<T> > { };
    1.64 +					DefDistMapTraits<T> > { };
    1.65      
    1.66      ///Constructor.
    1.67      
    1.68 @@ -300,7 +300,7 @@
    1.69  
    1.70      ///Sets the length map.
    1.71      ///\return <tt> (*this) </tt>
    1.72 -    Dijkstra &setLengthMap(const LengthMap &m) 
    1.73 +    Dijkstra &lengthMap(const LengthMap &m) 
    1.74      {
    1.75        length = &m;
    1.76        return *this;
    1.77 @@ -313,7 +313,7 @@
    1.78      ///it will allocate one. The destuctor deallocates this
    1.79      ///automatically allocated map, of course.
    1.80      ///\return <tt> (*this) </tt>
    1.81 -    Dijkstra &setPredMap(PredMap &m) 
    1.82 +    Dijkstra &predMap(PredMap &m) 
    1.83      {
    1.84        if(local_predecessor) {
    1.85  	delete predecessor;
    1.86 @@ -330,7 +330,7 @@
    1.87      ///it will allocate one. The destuctor deallocates this
    1.88      ///automatically allocated map, of course.
    1.89      ///\return <tt> (*this) </tt>
    1.90 -    Dijkstra &setPredNodeMap(PredNodeMap &m) 
    1.91 +    Dijkstra &predNodeMap(PredNodeMap &m) 
    1.92      {
    1.93        if(local_pred_node) {
    1.94  	delete pred_node;
    1.95 @@ -347,7 +347,7 @@
    1.96      ///it will allocate one. The destuctor deallocates this
    1.97      ///automatically allocated map, of course.
    1.98      ///\return <tt> (*this) </tt>
    1.99 -    Dijkstra &setDistMap(DistMap &m) 
   1.100 +    Dijkstra &distMap(DistMap &m) 
   1.101      {
   1.102        if(local_distance) {
   1.103  	delete distance;
   1.104 @@ -473,14 +473,45 @@
   1.105      
   1.106    };
   1.107  
   1.108 +  template<class GR,class LM>
   1.109 +  class DijkstraWizardBase : public DijkstraDefaultTraits<GR,LM>
   1.110 +  {
   1.111 +
   1.112 +    typedef DijkstraDefaultTraits<GR,LM> Base;
   1.113 +  protected:
   1.114 +    /// Pointer to the underlying graph.
   1.115 +    void *_g;
   1.116 +    /// Pointer to the length map
   1.117 +    void *_length;
   1.118 +    ///Pointer to the map of predecessors edges.
   1.119 +    void *_pred;
   1.120 +    ///Pointer to the map of predecessors nodes.
   1.121 +    void *_predNode;
   1.122 +    ///Pointer to the map of distances.
   1.123 +    void *_dist;
   1.124 +    ///Pointer to the source node.
   1.125 +    void *_source;
   1.126 +
   1.127 +    typedef typename Base::Graph::Node Node;
   1.128 +
   1.129 +    public:
   1.130 +    DijkstraWizardBase() : _g(0), _length(0), _pred(0), _predNode(0),
   1.131 +		       _dist(0), _source(INVALID) {}
   1.132 +
   1.133 +    DijkstraWizardBase(const GR &g,const LM &l, Node s=INVALID) :
   1.134 +      _g((void *)&g), _length((void *)&l), _pred(0), _predNode(0),
   1.135 +		  _dist(0), _source((void *)&s) {}
   1.136 +
   1.137 +  };
   1.138 +  
   1.139    ///\e
   1.140  
   1.141    ///\e
   1.142    ///
   1.143    template<class TR>
   1.144 -  class _Dijkstra 
   1.145 +  class DijkstraWizard : public TR
   1.146    {
   1.147 -    typedef TR Traits;
   1.148 +    typedef TR Base;
   1.149  
   1.150      ///The type of the underlying graph.
   1.151      typedef typename TR::Graph Graph;
   1.152 @@ -508,90 +539,80 @@
   1.153  
   1.154      ///The heap type used by the dijkstra algorithm.
   1.155      typedef typename TR::Heap Heap;
   1.156 +public:
   1.157 +    DijkstraWizard() : TR() {}
   1.158  
   1.159 -    /// Pointer to the underlying graph.
   1.160 -    const Graph *G;
   1.161 -    /// Pointer to the length map
   1.162 -    const LengthMap *length;
   1.163 -    ///Pointer to the map of predecessors edges.
   1.164 -    PredMap *predecessor;
   1.165 -    ///Pointer to the map of predecessors nodes.
   1.166 -    PredNodeMap *pred_node;
   1.167 -    ///Pointer to the map of distances.
   1.168 -    DistMap *distance;
   1.169 -    
   1.170 -    Node source;
   1.171 -    
   1.172 -public:
   1.173 -    _Dijkstra() : G(0), length(0), predecessor(0), pred_node(0),
   1.174 -		  distance(0), source(INVALID) {}
   1.175 +    DijkstraWizard(const Graph &g,const LengthMap &l, Node s=INVALID) :
   1.176 +      TR(g,l,s) {}
   1.177  
   1.178 -    _Dijkstra(const Graph &g,const LengthMap &l, Node s) :
   1.179 -      G(&g), length(&l), predecessor(0), pred_node(0),
   1.180 -		  distance(0), source(s) {}
   1.181 +    DijkstraWizard(const TR &b) : TR(b) {}
   1.182  
   1.183 -    ~_Dijkstra() 
   1.184 +    ~DijkstraWizard() {}
   1.185 +
   1.186 +    ///\e
   1.187 +    void run()
   1.188      {
   1.189 -      Dijkstra<Graph,LengthMap,TR> Dij(*G,*length);
   1.190 -      if(predecessor) Dij.setPredMap(*predecessor);
   1.191 -      if(pred_node) Dij.setPredNodeMap(*pred_node);
   1.192 -      if(distance) Dij.setDistMap(*distance);
   1.193 -      Dij.run(source);
   1.194 +      Dijkstra<Graph,LengthMap,TR> Dij(*(Graph*)_g,*(LengthMap*)_length);
   1.195 +      if(_pred) Dij.predMap(*(PredMap*)_pred);
   1.196 +      if(_predNode) Dij.predNodeMap(*(PredNodeMap*)_predNode);
   1.197 +      if(_dist) Dij.distMap(*(DistMap*)_dist);
   1.198 +      Dij.run(*(Node*)_source);
   1.199 +    }
   1.200 +
   1.201 +    ///\e
   1.202 +    void run(Node s)
   1.203 +    {
   1.204 +      _source=(void *)&s;
   1.205 +      run();
   1.206      }
   1.207  
   1.208      template<class T>
   1.209 -    struct SetPredMapTraits : public Traits {typedef T PredMap;};
   1.210 +    struct DefPredMapBase : public Base {
   1.211 +      typedef T PredMap;
   1.212 +      static PredMap *createPredMap(const Graph &G) {};
   1.213 +    };
   1.214      
   1.215      ///\e
   1.216      template<class T>
   1.217 -    _Dijkstra<SetPredMapTraits<T> > setPredMap(const T &t) 
   1.218 +    DijkstraWizard<DefPredMapBase<T> > predMap(const T &t) 
   1.219      {
   1.220 -      _Dijkstra<SetPredMapTraits<T> > r;
   1.221 -      r.G=G;
   1.222 -      r.length=length;
   1.223 -      r.predecessor=&t;
   1.224 -      r.pred_node=pred_node;
   1.225 -      r.distance=distance;
   1.226 -      r.source=source;
   1.227 -      return r;
   1.228 +      _pred=(void *)&t;
   1.229 +      return DijkstraWizard<DefPredMapBase<T> >(*this);
   1.230      }
   1.231      
   1.232 +
   1.233      template<class T>
   1.234 -    struct SetPredNodeMapTraits :public Traits {typedef T PredNodeMap;};
   1.235 +    struct DefPredNodeMapBase : public Base {
   1.236 +      typedef T PredNodeMap;
   1.237 +      static PredNodeMap *createPredNodeMap(const Graph &G) {};
   1.238 +    };
   1.239 +    
   1.240      ///\e
   1.241      template<class T>
   1.242 -    _Dijkstra<SetPredNodeMapTraits<T> > setPredNodeMap(const T &t) 
   1.243 +    DijkstraWizard<DefPredNodeMapBase<T> > predNodeMap(const T &t) 
   1.244      {
   1.245 -      _Dijkstra<SetPredNodeMapTraits<T> > r;
   1.246 -      r.G=G;
   1.247 -      r.length=length;
   1.248 -      r.predecessor=predecessor;
   1.249 -      r.pred_node=&t;
   1.250 -      r.distance=distance;
   1.251 -      r.source=source;
   1.252 -      return r;
   1.253 +      _predNode=(void *)&t;
   1.254 +      return DijkstraWizard<DefPredNodeMapBase<T> >(*this);
   1.255      }
   1.256 +   
   1.257 +    template<class T>
   1.258 +    struct DefDistMapBase : public Base {
   1.259 +      typedef T DistMap;
   1.260 +      static DistMap *createDistMap(const Graph &G) {};
   1.261 +    };
   1.262      
   1.263 -    template<class T>
   1.264 -    struct SetDistMapTraits : public Traits {typedef T DistMap;};
   1.265      ///\e
   1.266      template<class T>
   1.267 -    _Dijkstra<SetDistMapTraits<T> > setDistMap(const T &t) 
   1.268 +    DijkstraWizard<DefDistMapBase<T> > distMap(const T &t) 
   1.269      {
   1.270 -      _Dijkstra<SetPredMapTraits<T> > r;
   1.271 -      r.G=G;
   1.272 -      r.length=length;
   1.273 -      r.predecessor=predecessor;
   1.274 -      r.pred_node=pred_node;
   1.275 -      r.distance=&t;
   1.276 -      r.source=source;
   1.277 -      return r;
   1.278 +      _dist=(void *)&t;
   1.279 +      return DijkstraWizard<DefDistMapBase<T> >(*this);
   1.280      }
   1.281 -    
   1.282 +
   1.283      ///\e
   1.284 -    _Dijkstra<TR> &setSource(Node s) 
   1.285 +    DijkstraWizard<TR> &setSource(Node s) 
   1.286      {
   1.287 -      source=s;
   1.288 +      source=(void *)&s;
   1.289        return *this;
   1.290      }
   1.291      
   1.292 @@ -602,10 +623,10 @@
   1.293    ///\todo Please document...
   1.294    ///
   1.295    template<class GR, class LM>
   1.296 -  _Dijkstra<DijkstraDefaultTraits<GR,LM> >
   1.297 -  dijkstra(const GR &g,const LM &l,typename GR::Node s)
   1.298 +  DijkstraWizard<DijkstraWizardBase<GR,LM> >
   1.299 +  dijkstra(const GR &g,const LM &l,typename GR::Node s=INVALID)
   1.300    {
   1.301 -    return _Dijkstra<DijkstraDefaultTraits<GR,LM> >(g,l,s);
   1.302 +    return DijkstraWizard<DijkstraWizardBase<GR,LM> >(g,l,s);
   1.303    }
   1.304  
   1.305  /// @}