lemon/dfs.h
changeset 2388 c6d537888fe5
parent 2376 0ed45a6c74b1
child 2391 14a343be7a5a
equal deleted inserted replaced
35:2b1582a41326 36:96a644fb0ec3
   856     /// listed in the parameters list.
   856     /// listed in the parameters list.
   857     /// Others are initiated to 0.
   857     /// Others are initiated to 0.
   858     /// \param g is the initial value of  \ref _g
   858     /// \param g is the initial value of  \ref _g
   859     /// \param s is the initial value of  \ref _source
   859     /// \param s is the initial value of  \ref _source
   860     DfsWizardBase(const GR &g, Node s=INVALID) :
   860     DfsWizardBase(const GR &g, Node s=INVALID) :
   861       _g((void *)&g), _reached(0), _processed(0), _pred(0),
   861       _g(reinterpret_cast<void*>(const_cast<GR*>(&g))), 
   862       _dist(0), _source(s) {}
   862       _reached(0), _processed(0), _pred(0), _dist(0), _source(s) {}
   863 
   863 
   864   };
   864   };
   865   
   865   
   866   /// A class to make the usage of the Dfs algorithm easier
   866   /// A class to make the usage of the Dfs algorithm easier
   867 
   867 
   931     ///Runs Dfs algorithm from a given node.
   931     ///Runs Dfs algorithm from a given node.
   932     ///The node can be given by the \ref source function.
   932     ///The node can be given by the \ref source function.
   933     void run()
   933     void run()
   934     {
   934     {
   935       if(Base::_source==INVALID) throw UninitializedParameter();
   935       if(Base::_source==INVALID) throw UninitializedParameter();
   936       Dfs<Graph,TR> alg(*(Graph*)Base::_g);
   936       Dfs<Graph,TR> alg(*reinterpret_cast<const Graph*>(Base::_g));
   937       if(Base::_reached) alg.reachedMap(*(ReachedMap*)Base::_reached);
   937       if(Base::_reached) 
   938       if(Base::_processed) alg.processedMap(*(ProcessedMap*)Base::_processed);
   938         alg.reachedMap(*reinterpret_cast<ReachedMap*>(Base::_reached));
   939       if(Base::_pred) alg.predMap(*(PredMap*)Base::_pred);
   939       if(Base::_processed) 
   940       if(Base::_dist) alg.distMap(*(DistMap*)Base::_dist);
   940         alg.processedMap(*reinterpret_cast<ProcessedMap*>(Base::_processed));
       
   941       if(Base::_pred) 
       
   942         alg.predMap(*reinterpret_cast<PredMap*>(Base::_pred));
       
   943       if(Base::_dist) 
       
   944         alg.distMap(*reinterpret_cast<DistMap*>(Base::_dist));
   941       alg.run(Base::_source);
   945       alg.run(Base::_source);
   942     }
   946     }
   943 
   947 
   944     ///Runs Dfs algorithm from the given node.
   948     ///Runs Dfs algorithm from the given node.
   945 
   949 
   965     ///function for setting PredMap type
   969     ///function for setting PredMap type
   966     ///
   970     ///
   967     template<class T>
   971     template<class T>
   968     DfsWizard<DefPredMapBase<T> > predMap(const T &t) 
   972     DfsWizard<DefPredMapBase<T> > predMap(const T &t) 
   969     {
   973     {
   970       Base::_pred=(void *)&t;
   974       Base::_pred=reinterpret_cast<void*>(const_cast<T*>(&t));
   971       return DfsWizard<DefPredMapBase<T> >(*this);
   975       return DfsWizard<DefPredMapBase<T> >(*this);
   972     }
   976     }
   973     
   977     
   974  
   978  
   975     template<class T>
   979     template<class T>
   986     ///function for setting ReachedMap
   990     ///function for setting ReachedMap
   987     ///
   991     ///
   988     template<class T>
   992     template<class T>
   989     DfsWizard<DefReachedMapBase<T> > reachedMap(const T &t) 
   993     DfsWizard<DefReachedMapBase<T> > reachedMap(const T &t) 
   990     {
   994     {
   991       Base::_pred=(void *)&t;
   995       Base::_pred=reinterpret_cast<void*>(const_cast<T*>(&t));
   992       return DfsWizard<DefReachedMapBase<T> >(*this);
   996       return DfsWizard<DefReachedMapBase<T> >(*this);
   993     }
   997     }
   994     
   998     
   995 
   999 
   996     template<class T>
  1000     template<class T>
  1007     ///function for setting ProcessedMap
  1011     ///function for setting ProcessedMap
  1008     ///
  1012     ///
  1009     template<class T>
  1013     template<class T>
  1010     DfsWizard<DefProcessedMapBase<T> > processedMap(const T &t) 
  1014     DfsWizard<DefProcessedMapBase<T> > processedMap(const T &t) 
  1011     {
  1015     {
  1012       Base::_pred=(void *)&t;
  1016       Base::_pred=reinterpret_cast<void*>(const_cast<T*>(&t));
  1013       return DfsWizard<DefProcessedMapBase<T> >(*this);
  1017       return DfsWizard<DefProcessedMapBase<T> >(*this);
  1014     }
  1018     }
  1015     
  1019     
  1016     template<class T>
  1020     template<class T>
  1017     struct DefDistMapBase : public Base {
  1021     struct DefDistMapBase : public Base {
  1027     ///function for setting DistMap type
  1031     ///function for setting DistMap type
  1028     ///
  1032     ///
  1029     template<class T>
  1033     template<class T>
  1030     DfsWizard<DefDistMapBase<T> > distMap(const T &t) 
  1034     DfsWizard<DefDistMapBase<T> > distMap(const T &t) 
  1031     {
  1035     {
  1032       Base::_dist=(void *)&t;
  1036       Base::_dist=reinterpret_cast<void*>(const_cast<T*>(&t));
  1033       return DfsWizard<DefDistMapBase<T> >(*this);
  1037       return DfsWizard<DefDistMapBase<T> >(*this);
  1034     }
  1038     }
  1035     
  1039     
  1036     /// Sets the source node, from which the Dfs algorithm runs.
  1040     /// Sets the source node, from which the Dfs algorithm runs.
  1037 
  1041