lemon/dijkstra.h
changeset 2386 81b47fc5c444
parent 2376 0ed45a6c74b1
child 2391 14a343be7a5a
equal deleted inserted replaced
29:495bd837edac 30:d15242336847
   485     ///Sets the heap and the cross reference used by algorithm.
   485     ///Sets the heap and the cross reference used by algorithm.
   486     ///If you don't use this function before calling \ref run(),
   486     ///If you don't use this function before calling \ref run(),
   487     ///it will allocate one. The destuctor deallocates this
   487     ///it will allocate one. The destuctor deallocates this
   488     ///automatically allocated heap and cross reference, of course.
   488     ///automatically allocated heap and cross reference, of course.
   489     ///\return <tt> (*this) </tt>
   489     ///\return <tt> (*this) </tt>
   490     Dijkstra &heap(Heap& heap, HeapCrossRef &crossRef)
   490     Dijkstra &heap(Heap& hp, HeapCrossRef &cr)
   491     {
   491     {
   492       if(local_heap_cross_ref) {
   492       if(local_heap_cross_ref) {
   493 	delete _heap_cross_ref;
   493 	delete _heap_cross_ref;
   494 	local_heap_cross_ref=false;
   494 	local_heap_cross_ref=false;
   495       }
   495       }
   496       _heap_cross_ref = &crossRef;
   496       _heap_cross_ref = &cr;
   497       if(local_heap) {
   497       if(local_heap) {
   498 	delete _heap;
   498 	delete _heap;
   499 	local_heap=false;
   499 	local_heap=false;
   500       }
   500       }
   501       _heap = &heap;
   501       _heap = &hp;
   502       return *this;
   502       return *this;
   503     }
   503     }
   504 
   504 
   505   private:
   505   private:
   506     void finalizeNodeData(Node v,Value dst)
   506     void finalizeNodeData(Node v,Value dst)
   960     /// Others are initiated to 0.
   960     /// Others are initiated to 0.
   961     /// \param g is the initial value of  \ref _g
   961     /// \param g is the initial value of  \ref _g
   962     /// \param l is the initial value of  \ref _length
   962     /// \param l is the initial value of  \ref _length
   963     /// \param s is the initial value of  \ref _source
   963     /// \param s is the initial value of  \ref _source
   964     DijkstraWizardBase(const GR &g,const LM &l, Node s=INVALID) :
   964     DijkstraWizardBase(const GR &g,const LM &l, Node s=INVALID) :
   965       _g((void *)&g), _length((void *)&l), _pred(0),
   965       _g(reinterpret_cast<void*>(const_cast<GR*>(&g))), 
   966       _dist(0), _source(s) {}
   966       _length(reinterpret_cast<void*>(const_cast<LM*>(&l))), 
       
   967       _pred(0), _dist(0), _source(s) {}
   967 
   968 
   968   };
   969   };
   969   
   970   
   970   /// A class to make the usage of Dijkstra algorithm easier
   971   /// A class to make the usage of Dijkstra algorithm easier
   971 
   972 
  1035     ///The node can be given by the \ref source function.
  1036     ///The node can be given by the \ref source function.
  1036     void run()
  1037     void run()
  1037     {
  1038     {
  1038       if(Base::_source==INVALID) throw UninitializedParameter();
  1039       if(Base::_source==INVALID) throw UninitializedParameter();
  1039       Dijkstra<Graph,LengthMap,TR> 
  1040       Dijkstra<Graph,LengthMap,TR> 
  1040 	dij(*(Graph*)Base::_g,*(LengthMap*)Base::_length);
  1041 	dij(*reinterpret_cast<const Graph*>(Base::_g),
  1041       if(Base::_pred) dij.predMap(*(PredMap*)Base::_pred);
  1042             *reinterpret_cast<const LengthMap*>(Base::_length));
  1042       if(Base::_dist) dij.distMap(*(DistMap*)Base::_dist);
  1043       if(Base::_pred) dij.predMap(*reinterpret_cast<PredMap*>(Base::_pred));
       
  1044       if(Base::_dist) dij.distMap(*reinterpret_cast<DistMap*>(Base::_dist));
  1043       dij.run(Base::_source);
  1045       dij.run(Base::_source);
  1044     }
  1046     }
  1045 
  1047 
  1046     ///Runs Dijkstra algorithm from the given node.
  1048     ///Runs Dijkstra algorithm from the given node.
  1047 
  1049 
  1067     ///function for setting PredMap type
  1069     ///function for setting PredMap type
  1068     ///
  1070     ///
  1069     template<class T>
  1071     template<class T>
  1070     DijkstraWizard<DefPredMapBase<T> > predMap(const T &t) 
  1072     DijkstraWizard<DefPredMapBase<T> > predMap(const T &t) 
  1071     {
  1073     {
  1072       Base::_pred=(void *)&t;
  1074       Base::_pred=reinterpret_cast<void*>(const_cast<T*>(&t));
  1073       return DijkstraWizard<DefPredMapBase<T> >(*this);
  1075       return DijkstraWizard<DefPredMapBase<T> >(*this);
  1074     }
  1076     }
  1075     
  1077     
  1076     template<class T>
  1078     template<class T>
  1077     struct DefDistMapBase : public Base {
  1079     struct DefDistMapBase : public Base {
  1087     ///function for setting DistMap type
  1089     ///function for setting DistMap type
  1088     ///
  1090     ///
  1089     template<class T>
  1091     template<class T>
  1090     DijkstraWizard<DefDistMapBase<T> > distMap(const T &t) 
  1092     DijkstraWizard<DefDistMapBase<T> > distMap(const T &t) 
  1091     {
  1093     {
  1092       Base::_dist=(void *)&t;
  1094       Base::_dist=reinterpret_cast<void*>(const_cast<T*>(&t));
  1093       return DijkstraWizard<DefDistMapBase<T> >(*this);
  1095       return DijkstraWizard<DefDistMapBase<T> >(*this);
  1094     }
  1096     }
  1095     
  1097     
  1096     /// Sets the source node, from which the Dijkstra algorithm runs.
  1098     /// Sets the source node, from which the Dijkstra algorithm runs.
  1097 
  1099