[Lemon-commits] [lemon_svn] alpar: r1515 - hugo/trunk/src/work/alpar

Lemon SVN svn at lemon.cs.elte.hu
Mon Nov 6 20:45:58 CET 2006


Author: alpar
Date: Wed Feb  2 12:54:55 2005
New Revision: 1515

Modified:
   hugo/trunk/src/work/alpar/dijkstra.h

Log:
- More or less follows the new naming convetions
- New implementation for dijkstra();

Modified: hugo/trunk/src/work/alpar/dijkstra.h
==============================================================================
--- hugo/trunk/src/work/alpar/dijkstra.h	(original)
+++ hugo/trunk/src/work/alpar/dijkstra.h	Wed Feb  2 12:54:55 2005
@@ -143,7 +143,7 @@
 	    typename LM=typename GR::template EdgeMap<int>,
 	    typename TR=DijkstraDefaultTraits<GR,LM> >
 #endif
-  class Dijkstra{
+  class Dijkstra {
   public:
     typedef TR Traits;
     ///The type of the underlying graph.
@@ -213,9 +213,9 @@
     }
     
   public :
-
+ 
     template <class T>
-    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 T>
-    class SetPredMap : public Dijkstra< Graph,
+    class DefPredMap : public Dijkstra< Graph,
 					LengthMap,
-					SetPredMapTraits<T> > { };
+					DefPredMapTraits<T> > { };
     
     template <class T>
-    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 T>
-    class SetPredNodeMap : public Dijkstra< Graph,
+    class DefPredNodeMap : public Dijkstra< Graph,
 					    LengthMap,
-					    SetPredNodeMapTraits<T> > { };
+					    DefPredNodeMapTraits<T> > { };
     
     template <class T>
-    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 T>
-    class SetDistMap : public Dijkstra< Graph,
+    class DefDistMap : public Dijkstra< Graph,
 					LengthMap,
-					SetDistMapTraits<T> > { };
+					DefDistMapTraits<T> > { };
     
     ///Constructor.
     
@@ -300,7 +300,7 @@
 
     ///Sets the length map.
     ///\return <tt> (*this) </tt>
-    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 <tt> (*this) </tt>
-    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 <tt> (*this) </tt>
-    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 <tt> (*this) </tt>
-    Dijkstra &setDistMap(DistMap &m) 
+    Dijkstra &distMap(DistMap &m) 
     {
       if(local_distance) {
 	delete distance;
@@ -473,14 +473,45 @@
     
   };
 
+  template<class GR,class LM>
+  class DijkstraWizardBase : public DijkstraDefaultTraits<GR,LM>
+  {
+
+    typedef DijkstraDefaultTraits<GR,LM> 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 TR>
-  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;
-
-    /// 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() : TR() {}
+
+    DijkstraWizard(const Graph &g,const LengthMap &l, Node s=INVALID) :
+      TR(g,l,s) {}
+
+    DijkstraWizard(const TR &b) : TR(b) {}
+
+    ~DijkstraWizard() {}
 
-    _Dijkstra(const Graph &g,const LengthMap &l, Node s) :
-      G(&g), length(&l), predecessor(0), pred_node(0),
-		  distance(0), source(s) {}
-
-    ~_Dijkstra() 
-    {
-      Dijkstra<Graph,LengthMap,TR> Dij(*G,*length);
-      if(predecessor) Dij.setPredMap(*predecessor);
-      if(pred_node) Dij.setPredNodeMap(*pred_node);
-      if(distance) Dij.setDistMap(*distance);
-      Dij.run(source);
+    ///\e
+    void run()
+    {
+      Dijkstra<Graph,LengthMap,TR> 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<class T>
-    struct SetPredMapTraits : public Traits {typedef T PredMap;};
+    struct DefPredMapBase : public Base {
+      typedef T PredMap;
+      static PredMap *createPredMap(const Graph &G) {};
+    };
     
     ///\e
     template<class T>
-    _Dijkstra<SetPredMapTraits<T> > setPredMap(const T &t) 
+    DijkstraWizard<DefPredMapBase<T> > predMap(const T &t) 
     {
-      _Dijkstra<SetPredMapTraits<T> > 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<DefPredMapBase<T> >(*this);
     }
     
+
     template<class T>
-    struct SetPredNodeMapTraits :public Traits {typedef T PredNodeMap;};
+    struct DefPredNodeMapBase : public Base {
+      typedef T PredNodeMap;
+      static PredNodeMap *createPredNodeMap(const Graph &G) {};
+    };
+    
     ///\e
     template<class T>
-    _Dijkstra<SetPredNodeMapTraits<T> > setPredNodeMap(const T &t) 
+    DijkstraWizard<DefPredNodeMapBase<T> > predNodeMap(const T &t) 
     {
-      _Dijkstra<SetPredNodeMapTraits<T> > 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<DefPredNodeMapBase<T> >(*this);
     }
-    
+   
     template<class T>
-    struct SetDistMapTraits : public Traits {typedef T DistMap;};
+    struct DefDistMapBase : public Base {
+      typedef T DistMap;
+      static DistMap *createDistMap(const Graph &G) {};
+    };
+    
     ///\e
     template<class T>
-    _Dijkstra<SetDistMapTraits<T> > setDistMap(const T &t) 
+    DijkstraWizard<DefDistMapBase<T> > distMap(const T &t) 
     {
-      _Dijkstra<SetPredMapTraits<T> > 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<DefDistMapBase<T> >(*this);
     }
-    
+
     ///\e
-    _Dijkstra<TR> &setSource(Node s) 
+    DijkstraWizard<TR> &setSource(Node s) 
     {
-      source=s;
+      source=(void *)&s;
       return *this;
     }
     
@@ -602,10 +623,10 @@
   ///\todo Please document...
   ///
   template<class GR, class LM>
-  _Dijkstra<DijkstraDefaultTraits<GR,LM> >
-  dijkstra(const GR &g,const LM &l,typename GR::Node s)
+  DijkstraWizard<DijkstraWizardBase<GR,LM> >
+  dijkstra(const GR &g,const LM &l,typename GR::Node s=INVALID)
   {
-    return _Dijkstra<DijkstraDefaultTraits<GR,LM> >(g,l,s);
+    return DijkstraWizard<DijkstraWizardBase<GR,LM> >(g,l,s);
   }
 
 /// @}



More information about the Lemon-commits mailing list