COIN-OR::LEMON - Graph Library

Changes in / [279:6307bbbf285b:277:7abfb55f1ecc] in lemon-1.2


Ignore:
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • lemon/bfs.h

    r278 r258  
    2929#include <lemon/error.h>
    3030#include <lemon/maps.h>
    31 #include <lemon/path.h>
    3231
    3332namespace lemon {
     
    117116  ///This class provides an efficient implementation of the %BFS algorithm.
    118117  ///
    119   ///There is also a \ref bfs() "function-type interface" for the BFS
     118  ///There is also a \ref bfs() "function type interface" for the BFS
    120119  ///algorithm, which is convenient in the simplier cases and it can be
    121120  ///used easier.
     
    843842    ///arcs of the shortest paths.
    844843    ///It must meet the \ref concepts::WriteMap "WriteMap" concept.
    845     typedef typename Digraph::template NodeMap<typename Digraph::Arc> PredMap;
     844    typedef NullMap<typename Digraph::Node,typename Digraph::Arc> PredMap;
    846845    ///Instantiates a \ref PredMap.
    847846
     
    850849    ///\ref PredMap.
    851850    ///\todo The digraph alone may be insufficient to initialize
     851#ifdef DOXYGEN
    852852    static PredMap *createPredMap(const Digraph &g)
    853     {
    854       return new PredMap(g);
     853#else
     854    static PredMap *createPredMap(const Digraph &)
     855#endif
     856    {
     857      return new PredMap();
    855858    }
    856859
     
    859862    ///The type of the map that indicates which nodes are processed.
    860863    ///It must meet the \ref concepts::WriteMap "WriteMap" concept.
    861     ///By default it is a NullMap.
    862864    typedef NullMap<typename Digraph::Node,bool> ProcessedMap;
    863865    ///Instantiates a \ref ProcessedMap.
     
    894896    ///The type of the map that stores the distances of the nodes.
    895897    ///It must meet the \ref concepts::WriteMap "WriteMap" concept.
    896     typedef typename Digraph::template NodeMap<int> DistMap;
     898    ///
     899    typedef NullMap<typename Digraph::Node,int> DistMap;
    897900    ///Instantiates a \ref DistMap.
    898901
     
    900903    ///\param g is the digraph, to which we would like to define
    901904    ///the \ref DistMap
     905#ifdef DOXYGEN
    902906    static DistMap *createDistMap(const Digraph &g)
    903     {
    904       return new DistMap(g);
    905     }
    906 
    907     ///The type of the shortest paths.
    908 
    909     ///The type of the shortest paths.
    910     ///It must meet the \ref concepts::Path "Path" concept.
    911     typedef lemon::Path<Digraph> Path;
     907#else
     908    static DistMap *createDistMap(const Digraph &)
     909#endif
     910    {
     911      return new DistMap();
     912    }
    912913  };
    913914
     
    939940    //Pointer to the map of distances.
    940941    void *_dist;
    941     //Pointer to the shortest path to the target node.
    942     void *_path;
    943     //Pointer to the distance of the target node.
    944     int *_di;
     942    //Pointer to the source node.
     943    Node _source;
    945944
    946945    public:
     
    948947
    949948    /// This constructor does not require parameters, therefore it initiates
    950     /// all of the attributes to \c 0.
     949    /// all of the attributes to default values (0, INVALID).
    951950    BfsWizardBase() : _g(0), _reached(0), _processed(0), _pred(0),
    952                       _dist(0), _path(0), _di(0) {}
     951                      _dist(0), _source(INVALID) {}
    953952
    954953    /// Constructor.
    955954
    956     /// This constructor requires one parameter,
    957     /// others are initiated to \c 0.
     955    /// This constructor requires some parameters,
     956    /// listed in the parameters list.
     957    /// Others are initiated to 0.
    958958    /// \param g The digraph the algorithm runs on.
    959     BfsWizardBase(const GR &g) :
     959    /// \param s The source node.
     960    BfsWizardBase(const GR &g, Node s=INVALID) :
    960961      _g(reinterpret_cast<void*>(const_cast<GR*>(&g))),
    961       _reached(0), _processed(0), _pred(0), _dist(0),  _path(0), _di(0) {}
     962      _reached(0), _processed(0), _pred(0), _dist(0), _source(s) {}
    962963
    963964  };
    964965
    965   /// Auxiliary class for the function-type interface of BFS algorithm.
    966 
    967   /// This auxiliary class is created to implement the
    968   /// \ref bfs() "function-type interface" of \ref Bfs algorithm.
    969   /// It does not have own \ref run() method, it uses the functions
    970   /// and features of the plain \ref Bfs.
     966  /// Auxiliary class for the function type interface of BFS algorithm.
     967
     968  /// This auxiliary class is created to implement the function type
     969  /// interface of \ref Bfs algorithm. It uses the functions and features
     970  /// of the plain \ref Bfs, but it is much simpler to use it.
     971  /// It should only be used through the \ref bfs() function, which makes
     972  /// it easier to use the algorithm.
    971973  ///
    972   /// This class should only be used through the \ref bfs() function,
    973   /// which makes it easier to use the algorithm.
     974  /// Simplicity means that the way to change the types defined
     975  /// in the traits class is based on functions that returns the new class
     976  /// and not on templatable built-in classes.
     977  /// When using the plain \ref Bfs
     978  /// the new class with the modified type comes from
     979  /// the original class by using the ::
     980  /// operator. In the case of \ref BfsWizard only
     981  /// a function have to be called, and it will
     982  /// return the needed class.
     983  ///
     984  /// It does not have own \ref run() method. When its \ref run() method
     985  /// is called, it initiates a plain \ref Bfs object, and calls the
     986  /// \ref Bfs::run() method of it.
    974987  template<class TR>
    975988  class BfsWizard : public TR
     
    9941007    ///\brief The type of the map that indicates which nodes are processed.
    9951008    typedef typename TR::ProcessedMap ProcessedMap;
    996     ///The type of the shortest paths
    997     typedef typename TR::Path Path;
    9981009
    9991010  public:
     
    10061017    /// Constructor that requires parameters.
    10071018    /// These parameters will be the default values for the traits class.
    1008     /// \param g The digraph the algorithm runs on.
    1009     BfsWizard(const Digraph &g) :
    1010       TR(g) {}
     1019    BfsWizard(const Digraph &g, Node s=INVALID) :
     1020      TR(g,s) {}
    10111021
    10121022    ///Copy constructor
     
    10151025    ~BfsWizard() {}
    10161026
    1017     ///Runs BFS algorithm from the given source node.
    1018 
    1019     ///This method runs BFS algorithm from node \c s
    1020     ///in order to compute the shortest path to each node.
     1027    ///Runs BFS algorithm from a source node.
     1028
     1029    ///Runs BFS algorithm from a source node.
     1030    ///The node can be given with the \ref source() function.
     1031    void run()
     1032    {
     1033      if(Base::_source==INVALID) throw UninitializedParameter();
     1034      Bfs<Digraph,TR> alg(*reinterpret_cast<const Digraph*>(Base::_g));
     1035      if(Base::_reached)
     1036        alg.reachedMap(*reinterpret_cast<ReachedMap*>(Base::_reached));
     1037      if(Base::_processed)
     1038        alg.processedMap(*reinterpret_cast<ProcessedMap*>(Base::_processed));
     1039      if(Base::_pred)
     1040        alg.predMap(*reinterpret_cast<PredMap*>(Base::_pred));
     1041      if(Base::_dist)
     1042        alg.distMap(*reinterpret_cast<DistMap*>(Base::_dist));
     1043      alg.run(Base::_source);
     1044    }
     1045
     1046    ///Runs BFS algorithm from the given node.
     1047
     1048    ///Runs BFS algorithm from the given node.
     1049    ///\param s is the given source.
    10211050    void run(Node s)
    10221051    {
    1023       Bfs<Digraph,TR> alg(*reinterpret_cast<const Digraph*>(Base::_g));
    1024       if (Base::_pred)
    1025         alg.predMap(*reinterpret_cast<PredMap*>(Base::_pred));
    1026       if (Base::_dist)
    1027         alg.distMap(*reinterpret_cast<DistMap*>(Base::_dist));
    1028       if (Base::_reached)
    1029         alg.reachedMap(*reinterpret_cast<ReachedMap*>(Base::_reached));
    1030       if (Base::_processed)
    1031         alg.processedMap(*reinterpret_cast<ProcessedMap*>(Base::_processed));
    1032       if (s!=INVALID)
    1033         alg.run(s);
    1034       else
    1035         alg.run();
    1036     }
    1037 
    1038     ///Finds the shortest path between \c s and \c t.
    1039 
    1040     ///This method runs BFS algorithm from node \c s
    1041     ///in order to compute the shortest path to node \c t
    1042     ///(it stops searching when \c t is processed).
    1043     ///
    1044     ///\return \c true if \c t is reachable form \c s.
    1045     bool run(Node s, Node t)
    1046     {
    1047       if (s==INVALID || t==INVALID) throw UninitializedParameter();
    1048       Bfs<Digraph,TR> alg(*reinterpret_cast<const Digraph*>(Base::_g));
    1049       if (Base::_pred)
    1050         alg.predMap(*reinterpret_cast<PredMap*>(Base::_pred));
    1051       if (Base::_dist)
    1052         alg.distMap(*reinterpret_cast<DistMap*>(Base::_dist));
    1053       if (Base::_reached)
    1054         alg.reachedMap(*reinterpret_cast<ReachedMap*>(Base::_reached));
    1055       if (Base::_processed)
    1056         alg.processedMap(*reinterpret_cast<ProcessedMap*>(Base::_processed));
    1057       alg.run(s,t);
    1058       if (Base::_path)
    1059         *reinterpret_cast<Path*>(Base::_path) = alg.path(t);
    1060       if (Base::_di)
    1061         *Base::_di = alg.dist(t);
    1062       return alg.reached(t);
    1063     }
    1064 
    1065     ///Runs BFS algorithm to visit all nodes in the digraph.
    1066 
    1067     ///This method runs BFS algorithm in order to compute
    1068     ///the shortest path to each node.
    1069     void run()
    1070     {
    1071       run(INVALID);
     1052      Base::_source=s;
     1053      run();
     1054    }
     1055
     1056    /// Sets the source node, from which the Bfs algorithm runs.
     1057
     1058    /// Sets the source node, from which the Bfs algorithm runs.
     1059    /// \param s is the source node.
     1060    BfsWizard<TR> &source(Node s)
     1061    {
     1062      Base::_source=s;
     1063      return *this;
    10721064    }
    10731065
     
    10781070      SetPredMapBase(const TR &b) : TR(b) {}
    10791071    };
    1080     ///\brief \ref named-func-param "Named parameter"
     1072    ///\brief \ref named-templ-param "Named parameter"
    10811073    ///for setting \ref PredMap object.
    10821074    ///
    1083     ///\ref named-func-param "Named parameter"
     1075    /// \ref named-templ-param "Named parameter"
    10841076    ///for setting \ref PredMap object.
    10851077    template<class T>
     
    10961088      SetReachedMapBase(const TR &b) : TR(b) {}
    10971089    };
    1098     ///\brief \ref named-func-param "Named parameter"
     1090    ///\brief \ref named-templ-param "Named parameter"
    10991091    ///for setting \ref ReachedMap object.
    11001092    ///
    1101     /// \ref named-func-param "Named parameter"
     1093    /// \ref named-templ-param "Named parameter"
    11021094    ///for setting \ref ReachedMap object.
    11031095    template<class T>
     
    11061098      Base::_reached=reinterpret_cast<void*>(const_cast<T*>(&t));
    11071099      return BfsWizard<SetReachedMapBase<T> >(*this);
     1100    }
     1101
     1102    template<class T>
     1103    struct SetProcessedMapBase : public Base {
     1104      typedef T ProcessedMap;
     1105      static ProcessedMap *createProcessedMap(const Digraph &) { return 0; };
     1106      SetProcessedMapBase(const TR &b) : TR(b) {}
     1107    };
     1108    ///\brief \ref named-templ-param "Named parameter"
     1109    ///for setting \ref ProcessedMap object.
     1110    ///
     1111    /// \ref named-templ-param "Named parameter"
     1112    ///for setting \ref ProcessedMap object.
     1113    template<class T>
     1114    BfsWizard<SetProcessedMapBase<T> > processedMap(const T &t)
     1115    {
     1116      Base::_processed=reinterpret_cast<void*>(const_cast<T*>(&t));
     1117      return BfsWizard<SetProcessedMapBase<T> >(*this);
    11081118    }
    11091119
     
    11141124      SetDistMapBase(const TR &b) : TR(b) {}
    11151125    };
    1116     ///\brief \ref named-func-param "Named parameter"
     1126    ///\brief \ref named-templ-param "Named parameter"
    11171127    ///for setting \ref DistMap object.
    11181128    ///
    1119     /// \ref named-func-param "Named parameter"
     1129    /// \ref named-templ-param "Named parameter"
    11201130    ///for setting \ref DistMap object.
    11211131    template<class T>
     
    11261136    }
    11271137
    1128     template<class T>
    1129     struct SetProcessedMapBase : public Base {
    1130       typedef T ProcessedMap;
    1131       static ProcessedMap *createProcessedMap(const Digraph &) { return 0; };
    1132       SetProcessedMapBase(const TR &b) : TR(b) {}
    1133     };
    1134     ///\brief \ref named-func-param "Named parameter"
    1135     ///for setting \ref ProcessedMap object.
    1136     ///
    1137     /// \ref named-func-param "Named parameter"
    1138     ///for setting \ref ProcessedMap object.
    1139     template<class T>
    1140     BfsWizard<SetProcessedMapBase<T> > processedMap(const T &t)
    1141     {
    1142       Base::_processed=reinterpret_cast<void*>(const_cast<T*>(&t));
    1143       return BfsWizard<SetProcessedMapBase<T> >(*this);
    1144     }
    1145 
    1146     template<class T>
    1147     struct SetPathBase : public Base {
    1148       typedef T Path;
    1149       SetPathBase(const TR &b) : TR(b) {}
    1150     };
    1151     ///\brief \ref named-func-param "Named parameter"
    1152     ///for getting the shortest path to the target node.
    1153     ///
    1154     ///\ref named-func-param "Named parameter"
    1155     ///for getting the shortest path to the target node.
    1156     template<class T>
    1157     BfsWizard<SetPathBase<T> > path(const T &t)
    1158     {
    1159       Base::_path=reinterpret_cast<void*>(const_cast<T*>(&t));
    1160       return BfsWizard<SetPathBase<T> >(*this);
    1161     }
    1162 
    1163     ///\brief \ref named-func-param "Named parameter"
    1164     ///for getting the distance of the target node.
    1165     ///
    1166     ///\ref named-func-param "Named parameter"
    1167     ///for getting the distance of the target node.
    1168     BfsWizard dist(const int &d)
    1169     {
    1170       Base::_di=const_cast<int*>(&d);
    1171       return *this;
    1172     }
    1173 
    11741138  };
    11751139
    1176   ///Function-type interface for BFS algorithm.
     1140  ///Function type interface for Bfs algorithm.
    11771141
    11781142  /// \ingroup search
    1179   ///Function-type interface for BFS algorithm.
     1143  ///Function type interface for Bfs algorithm.
    11801144  ///
    1181   ///This function also has several \ref named-func-param "named parameters",
     1145  ///This function also has several
     1146  ///\ref named-templ-func-param "named parameters",
    11821147  ///they are declared as the members of class \ref BfsWizard.
    1183   ///The following examples show how to use these parameters.
     1148  ///The following
     1149  ///example shows how to use these parameters.
    11841150  ///\code
    1185   ///  // Compute shortest path from node s to each node
    1186   ///  bfs(g).predMap(preds).distMap(dists).run(s);
    1187   ///
    1188   ///  // Compute shortest path from s to t
    1189   ///  bool reached = bfs(g).path(p).dist(d).run(s,t);
     1151  ///  bfs(g,source).predMap(preds).run();
    11901152  ///\endcode
    11911153  ///\warning Don't forget to put the \ref BfsWizard::run() "run()"
     
    11951157  template<class GR>
    11961158  BfsWizard<BfsWizardBase<GR> >
    1197   bfs(const GR &digraph)
     1159  bfs(const GR &g,typename GR::Node s=INVALID)
    11981160  {
    1199     return BfsWizard<BfsWizardBase<GR> >(digraph);
     1161    return BfsWizard<BfsWizardBase<GR> >(g,s);
    12001162  }
    12011163
  • lemon/concepts/path.h

    r278 r236  
    6767      /// \brief Template assigment
    6868      template <typename CPath>
    69       Path& operator=(const CPath& cpath) {
    70         ignore_unused_variable_warning(cpath);
    71         return *this;
    72       }
     69      Path& operator=(const CPath& cpath) {}
    7370
    7471      /// Length of the path ie. the number of arcs in the path.
  • lemon/dfs.h

    r278 r258  
    3030#include <lemon/assert.h>
    3131#include <lemon/maps.h>
    32 #include <lemon/path.h>
    3332
    3433namespace lemon {
     
    118117  ///This class provides an efficient implementation of the %DFS algorithm.
    119118  ///
    120   ///There is also a \ref dfs() "function-type interface" for the DFS
     119  ///There is also a \ref dfs() "function type interface" for the DFS
    121120  ///algorithm, which is convenient in the simplier cases and it can be
    122121  ///used easier.
     
    777776    ///arcs of the %DFS paths.
    778777    ///It must meet the \ref concepts::WriteMap "WriteMap" concept.
    779     typedef typename Digraph::template NodeMap<typename Digraph::Arc> PredMap;
     778    ///
     779    typedef NullMap<typename Digraph::Node,typename Digraph::Arc> PredMap;
    780780    ///Instantiates a \ref PredMap.
    781781
     
    784784    ///\ref PredMap.
    785785    ///\todo The digraph alone may be insufficient to initialize
     786#ifdef DOXYGEN
    786787    static PredMap *createPredMap(const Digraph &g)
    787     {
    788       return new PredMap(g);
     788#else
     789    static PredMap *createPredMap(const Digraph &)
     790#endif
     791    {
     792      return new PredMap();
    789793    }
    790794
     
    793797    ///The type of the map that indicates which nodes are processed.
    794798    ///It must meet the \ref concepts::WriteMap "WriteMap" concept.
    795     ///By default it is a NullMap.
    796799    typedef NullMap<typename Digraph::Node,bool> ProcessedMap;
    797800    ///Instantiates a \ref ProcessedMap.
     
    828831    ///The type of the map that stores the distances of the nodes.
    829832    ///It must meet the \ref concepts::WriteMap "WriteMap" concept.
    830     typedef typename Digraph::template NodeMap<int> DistMap;
     833    ///
     834    typedef NullMap<typename Digraph::Node,int> DistMap;
    831835    ///Instantiates a \ref DistMap.
    832836
     
    834838    ///\param g is the digraph, to which we would like to define
    835839    ///the \ref DistMap
     840#ifdef DOXYGEN
    836841    static DistMap *createDistMap(const Digraph &g)
    837     {
    838       return new DistMap(g);
    839     }
    840 
    841     ///The type of the DFS paths.
    842 
    843     ///The type of the DFS paths.
    844     ///It must meet the \ref concepts::Path "Path" concept.
    845     typedef lemon::Path<Digraph> Path;
     842#else
     843    static DistMap *createDistMap(const Digraph &)
     844#endif
     845    {
     846      return new DistMap();
     847    }
    846848  };
    847849
     
    873875    //Pointer to the map of distances.
    874876    void *_dist;
    875     //Pointer to the DFS path to the target node.
    876     void *_path;
    877     //Pointer to the distance of the target node.
    878     int *_di;
     877    //Pointer to the source node.
     878    Node _source;
    879879
    880880    public:
     
    882882
    883883    /// This constructor does not require parameters, therefore it initiates
    884     /// all of the attributes to \c 0.
     884    /// all of the attributes to default values (0, INVALID).
    885885    DfsWizardBase() : _g(0), _reached(0), _processed(0), _pred(0),
    886                       _dist(0), _path(0), _di(0) {}
     886                      _dist(0), _source(INVALID) {}
    887887
    888888    /// Constructor.
    889889
    890     /// This constructor requires one parameter,
    891     /// others are initiated to \c 0.
     890    /// This constructor requires some parameters,
     891    /// listed in the parameters list.
     892    /// Others are initiated to 0.
    892893    /// \param g The digraph the algorithm runs on.
    893     DfsWizardBase(const GR &g) :
     894    /// \param s The source node.
     895    DfsWizardBase(const GR &g, Node s=INVALID) :
    894896      _g(reinterpret_cast<void*>(const_cast<GR*>(&g))),
    895       _reached(0), _processed(0), _pred(0), _dist(0),  _path(0), _di(0) {}
     897      _reached(0), _processed(0), _pred(0), _dist(0), _source(s) {}
    896898
    897899  };
    898900
    899   /// Auxiliary class for the function-type interface of DFS algorithm.
    900 
    901   /// This auxiliary class is created to implement the
    902   /// \ref dfs() "function-type interface" of \ref Dfs algorithm.
    903   /// It does not have own \ref run() method, it uses the functions
    904   /// and features of the plain \ref Dfs.
     901  /// Auxiliary class for the function type interface of DFS algorithm.
     902
     903  /// This auxiliary class is created to implement the function type
     904  /// interface of \ref Dfs algorithm. It uses the functions and features
     905  /// of the plain \ref Dfs, but it is much simpler to use it.
     906  /// It should only be used through the \ref dfs() function, which makes
     907  /// it easier to use the algorithm.
    905908  ///
    906   /// This class should only be used through the \ref dfs() function,
    907   /// which makes it easier to use the algorithm.
     909  /// Simplicity means that the way to change the types defined
     910  /// in the traits class is based on functions that returns the new class
     911  /// and not on templatable built-in classes.
     912  /// When using the plain \ref Dfs
     913  /// the new class with the modified type comes from
     914  /// the original class by using the ::
     915  /// operator. In the case of \ref DfsWizard only
     916  /// a function have to be called, and it will
     917  /// return the needed class.
     918  ///
     919  /// It does not have own \ref run() method. When its \ref run() method
     920  /// is called, it initiates a plain \ref Dfs object, and calls the
     921  /// \ref Dfs::run() method of it.
    908922  template<class TR>
    909923  class DfsWizard : public TR
     
    920934
    921935    ///\brief The type of the map that stores the predecessor
    922     ///arcs of the DFS paths.
     936    ///arcs of the shortest paths.
    923937    typedef typename TR::PredMap PredMap;
    924938    ///\brief The type of the map that stores the distances of the nodes.
     
    928942    ///\brief The type of the map that indicates which nodes are processed.
    929943    typedef typename TR::ProcessedMap ProcessedMap;
    930     ///The type of the DFS paths
    931     typedef typename TR::Path Path;
    932944
    933945  public:
     
    940952    /// Constructor that requires parameters.
    941953    /// These parameters will be the default values for the traits class.
    942     /// \param g The digraph the algorithm runs on.
    943     DfsWizard(const Digraph &g) :
    944       TR(g) {}
     954    DfsWizard(const Digraph &g, Node s=INVALID) :
     955      TR(g,s) {}
    945956
    946957    ///Copy constructor
     
    949960    ~DfsWizard() {}
    950961
    951     ///Runs DFS algorithm from the given source node.
    952 
    953     ///This method runs DFS algorithm from node \c s
    954     ///in order to compute the DFS path to each node.
     962    ///Runs DFS algorithm from a source node.
     963
     964    ///Runs DFS algorithm from a source node.
     965    ///The node can be given with the \ref source() function.
     966    void run()
     967    {
     968      if(Base::_source==INVALID) throw UninitializedParameter();
     969      Dfs<Digraph,TR> alg(*reinterpret_cast<const Digraph*>(Base::_g));
     970      if(Base::_reached)
     971        alg.reachedMap(*reinterpret_cast<ReachedMap*>(Base::_reached));
     972      if(Base::_processed)
     973        alg.processedMap(*reinterpret_cast<ProcessedMap*>(Base::_processed));
     974      if(Base::_pred)
     975        alg.predMap(*reinterpret_cast<PredMap*>(Base::_pred));
     976      if(Base::_dist)
     977        alg.distMap(*reinterpret_cast<DistMap*>(Base::_dist));
     978      alg.run(Base::_source);
     979    }
     980
     981    ///Runs DFS algorithm from the given node.
     982
     983    ///Runs DFS algorithm from the given node.
     984    ///\param s is the given source.
    955985    void run(Node s)
    956986    {
    957       Dfs<Digraph,TR> alg(*reinterpret_cast<const Digraph*>(Base::_g));
    958       if (Base::_pred)
    959         alg.predMap(*reinterpret_cast<PredMap*>(Base::_pred));
    960       if (Base::_dist)
    961         alg.distMap(*reinterpret_cast<DistMap*>(Base::_dist));
    962       if (Base::_reached)
    963         alg.reachedMap(*reinterpret_cast<ReachedMap*>(Base::_reached));
    964       if (Base::_processed)
    965         alg.processedMap(*reinterpret_cast<ProcessedMap*>(Base::_processed));
    966       if (s!=INVALID)
    967         alg.run(s);
    968       else
    969         alg.run();
    970     }
    971 
    972     ///Finds the DFS path between \c s and \c t.
    973 
    974     ///This method runs DFS algorithm from node \c s
    975     ///in order to compute the DFS path to node \c t
    976     ///(it stops searching when \c t is processed).
    977     ///
    978     ///\return \c true if \c t is reachable form \c s.
    979     bool run(Node s, Node t)
    980     {
    981       if (s==INVALID || t==INVALID) throw UninitializedParameter();
    982       Dfs<Digraph,TR> alg(*reinterpret_cast<const Digraph*>(Base::_g));
    983       if (Base::_pred)
    984         alg.predMap(*reinterpret_cast<PredMap*>(Base::_pred));
    985       if (Base::_dist)
    986         alg.distMap(*reinterpret_cast<DistMap*>(Base::_dist));
    987       if (Base::_reached)
    988         alg.reachedMap(*reinterpret_cast<ReachedMap*>(Base::_reached));
    989       if (Base::_processed)
    990         alg.processedMap(*reinterpret_cast<ProcessedMap*>(Base::_processed));
    991       alg.run(s,t);
    992       if (Base::_path)
    993         *reinterpret_cast<Path*>(Base::_path) = alg.path(t);
    994       if (Base::_di)
    995         *Base::_di = alg.dist(t);
    996       return alg.reached(t);
    997       }
    998 
    999     ///Runs DFS algorithm to visit all nodes in the digraph.
    1000 
    1001     ///This method runs DFS algorithm in order to compute
    1002     ///the DFS path to each node.
    1003     void run()
    1004     {
    1005       run(INVALID);
     987      Base::_source=s;
     988      run();
     989    }
     990
     991    /// Sets the source node, from which the Dfs algorithm runs.
     992
     993    /// Sets the source node, from which the Dfs algorithm runs.
     994    /// \param s is the source node.
     995    DfsWizard<TR> &source(Node s)
     996    {
     997      Base::_source=s;
     998      return *this;
    1006999    }
    10071000
     
    10121005      SetPredMapBase(const TR &b) : TR(b) {}
    10131006    };
    1014     ///\brief \ref named-func-param "Named parameter"
     1007    ///\brief \ref named-templ-param "Named parameter"
    10151008    ///for setting \ref PredMap object.
    10161009    ///
    1017     ///\ref named-func-param "Named parameter"
     1010    ///\ref named-templ-param "Named parameter"
    10181011    ///for setting \ref PredMap object.
    10191012    template<class T>
     
    10301023      SetReachedMapBase(const TR &b) : TR(b) {}
    10311024    };
    1032     ///\brief \ref named-func-param "Named parameter"
     1025    ///\brief \ref named-templ-param "Named parameter"
    10331026    ///for setting \ref ReachedMap object.
    10341027    ///
    1035     /// \ref named-func-param "Named parameter"
     1028    /// \ref named-templ-param "Named parameter"
    10361029    ///for setting \ref ReachedMap object.
    10371030    template<class T>
     
    10401033      Base::_reached=reinterpret_cast<void*>(const_cast<T*>(&t));
    10411034      return DfsWizard<SetReachedMapBase<T> >(*this);
     1035    }
     1036
     1037    template<class T>
     1038    struct SetProcessedMapBase : public Base {
     1039      typedef T ProcessedMap;
     1040      static ProcessedMap *createProcessedMap(const Digraph &) { return 0; };
     1041      SetProcessedMapBase(const TR &b) : TR(b) {}
     1042    };
     1043    ///\brief \ref named-templ-param "Named parameter"
     1044    ///for setting \ref ProcessedMap object.
     1045    ///
     1046    /// \ref named-templ-param "Named parameter"
     1047    ///for setting \ref ProcessedMap object.
     1048    template<class T>
     1049    DfsWizard<SetProcessedMapBase<T> > processedMap(const T &t)
     1050    {
     1051      Base::_processed=reinterpret_cast<void*>(const_cast<T*>(&t));
     1052      return DfsWizard<SetProcessedMapBase<T> >(*this);
    10421053    }
    10431054
     
    10481059      SetDistMapBase(const TR &b) : TR(b) {}
    10491060    };
    1050     ///\brief \ref named-func-param "Named parameter"
     1061    ///\brief \ref named-templ-param "Named parameter"
    10511062    ///for setting \ref DistMap object.
    10521063    ///
    1053     /// \ref named-func-param "Named parameter"
     1064    ///\ref named-templ-param "Named parameter"
    10541065    ///for setting \ref DistMap object.
    10551066    template<class T>
     
    10601071    }
    10611072
    1062     template<class T>
    1063     struct SetProcessedMapBase : public Base {
    1064       typedef T ProcessedMap;
    1065       static ProcessedMap *createProcessedMap(const Digraph &) { return 0; };
    1066       SetProcessedMapBase(const TR &b) : TR(b) {}
    1067     };
    1068     ///\brief \ref named-func-param "Named parameter"
    1069     ///for setting \ref ProcessedMap object.
    1070     ///
    1071     /// \ref named-func-param "Named parameter"
    1072     ///for setting \ref ProcessedMap object.
    1073     template<class T>
    1074     DfsWizard<SetProcessedMapBase<T> > processedMap(const T &t)
    1075     {
    1076       Base::_processed=reinterpret_cast<void*>(const_cast<T*>(&t));
    1077       return DfsWizard<SetProcessedMapBase<T> >(*this);
    1078     }
    1079 
    1080     template<class T>
    1081     struct SetPathBase : public Base {
    1082       typedef T Path;
    1083       SetPathBase(const TR &b) : TR(b) {}
    1084     };
    1085     ///\brief \ref named-func-param "Named parameter"
    1086     ///for getting the DFS path to the target node.
    1087     ///
    1088     ///\ref named-func-param "Named parameter"
    1089     ///for getting the DFS path to the target node.
    1090     template<class T>
    1091     DfsWizard<SetPathBase<T> > path(const T &t)
    1092     {
    1093       Base::_path=reinterpret_cast<void*>(const_cast<T*>(&t));
    1094       return DfsWizard<SetPathBase<T> >(*this);
    1095     }
    1096 
    1097     ///\brief \ref named-func-param "Named parameter"
    1098     ///for getting the distance of the target node.
    1099     ///
    1100     ///\ref named-func-param "Named parameter"
    1101     ///for getting the distance of the target node.
    1102     DfsWizard dist(const int &d)
    1103     {
    1104       Base::_di=const_cast<int*>(&d);
    1105       return *this;
    1106     }
    1107 
    11081073  };
    11091074
    1110   ///Function-type interface for DFS algorithm.
     1075  ///Function type interface for Dfs algorithm.
    11111076
    11121077  ///\ingroup search
    1113   ///Function-type interface for DFS algorithm.
     1078  ///Function type interface for Dfs algorithm.
    11141079  ///
    1115   ///This function also has several \ref named-func-param "named parameters",
     1080  ///This function also has several
     1081  ///\ref named-templ-func-param "named parameters",
    11161082  ///they are declared as the members of class \ref DfsWizard.
    1117   ///The following examples show how to use these parameters.
     1083  ///The following
     1084  ///example shows how to use these parameters.
    11181085  ///\code
    1119   ///  // Compute the DFS tree
    1120   ///  dfs(g).predMap(preds).distMap(dists).run(s);
    1121   ///
    1122   ///  // Compute the DFS path from s to t
    1123   ///  bool reached = dfs(g).path(p).dist(d).run(s,t);
     1086  ///  dfs(g,source).predMap(preds).run();
    11241087  ///\endcode
    1125 
    11261088  ///\warning Don't forget to put the \ref DfsWizard::run() "run()"
    11271089  ///to the end of the parameter list.
     
    11301092  template<class GR>
    11311093  DfsWizard<DfsWizardBase<GR> >
    1132   dfs(const GR &digraph)
     1094  dfs(const GR &g,typename GR::Node s=INVALID)
    11331095  {
    1134     return DfsWizard<DfsWizardBase<GR> >(digraph);
     1096    return DfsWizard<DfsWizardBase<GR> >(g,s);
    11351097  }
    11361098
  • lemon/dijkstra.h

    r278 r258  
    3131#include <lemon/error.h>
    3232#include <lemon/maps.h>
    33 #include <lemon/path.h>
    3433
    3534namespace lemon {
     
    201200  ///It is also possible to change the underlying priority heap.
    202201  ///
    203   ///There is also a \ref dijkstra() "function-type interface" for the
     202  ///There is also a \ref dijkstra() "function type interface" for the
    204203  ///%Dijkstra algorithm, which is convenient in the simplier cases and
    205204  ///it can be used easier.
     
    989988    ///arcs of the shortest paths.
    990989    ///It must meet the \ref concepts::WriteMap "WriteMap" concept.
    991     typedef typename Digraph::template NodeMap<typename Digraph::Arc> PredMap;
     990    typedef NullMap <typename Digraph::Node,typename Digraph::Arc> PredMap;
    992991    ///Instantiates a \ref PredMap.
    993992
     
    996995    ///\ref PredMap.
    997996    ///\todo The digraph alone may be insufficient to initialize
     997#ifdef DOXYGEN
    998998    static PredMap *createPredMap(const Digraph &g)
    999     {
    1000       return new PredMap(g);
     999#else
     1000    static PredMap *createPredMap(const Digraph &)
     1001#endif
     1002    {
     1003      return new PredMap();
    10011004    }
    10021005
     
    10281031    ///The type of the map that stores the distances of the nodes.
    10291032    ///It must meet the \ref concepts::WriteMap "WriteMap" concept.
    1030     typedef typename Digraph::template NodeMap<typename LM::Value> DistMap;
     1033    typedef NullMap<typename Digraph::Node,Value> DistMap;
    10311034    ///Instantiates a \ref DistMap.
    10321035
     
    10341037    ///\param g is the digraph, to which we would like to define
    10351038    ///the \ref DistMap
     1039#ifdef DOXYGEN
    10361040    static DistMap *createDistMap(const Digraph &g)
    1037     {
    1038       return new DistMap(g);
    1039     }
    1040 
    1041     ///The type of the shortest paths.
    1042 
    1043     ///The type of the shortest paths.
    1044     ///It must meet the \ref concepts::Path "Path" concept.
    1045     typedef lemon::Path<Digraph> Path;
     1041#else
     1042    static DistMap *createDistMap(const Digraph &)
     1043#endif
     1044    {
     1045      return new DistMap();
     1046    }
    10461047  };
    10471048
     
    10651066    //Pointer to the digraph the algorithm runs on.
    10661067    void *_g;
    1067     //Pointer to the length map.
     1068    //Pointer to the length map
    10681069    void *_length;
    10691070    //Pointer to the map of processed nodes.
     
    10731074    //Pointer to the map of distances.
    10741075    void *_dist;
    1075     //Pointer to the shortest path to the target node.
    1076     void *_path;
    1077     //Pointer to the distance of the target node.
    1078     void *_di;
     1076    //Pointer to the source node.
     1077    Node _source;
    10791078
    10801079  public:
     
    10821081
    10831082    /// This constructor does not require parameters, therefore it initiates
    1084     /// all of the attributes to \c 0.
     1083    /// all of the attributes to default values (0, INVALID).
    10851084    DijkstraWizardBase() : _g(0), _length(0), _processed(0), _pred(0),
    1086                            _dist(0), _path(0), _di(0) {}
     1085                           _dist(0), _source(INVALID) {}
    10871086
    10881087    /// Constructor.
    10891088
    1090     /// This constructor requires two parameters,
    1091     /// others are initiated to \c 0.
     1089    /// This constructor requires some parameters,
     1090    /// listed in the parameters list.
     1091    /// Others are initiated to 0.
    10921092    /// \param g The digraph the algorithm runs on.
    10931093    /// \param l The length map.
    1094     DijkstraWizardBase(const GR &g,const LM &l) :
     1094    /// \param s The source node.
     1095    DijkstraWizardBase(const GR &g,const LM &l, Node s=INVALID) :
    10951096      _g(reinterpret_cast<void*>(const_cast<GR*>(&g))),
    10961097      _length(reinterpret_cast<void*>(const_cast<LM*>(&l))),
    1097       _processed(0), _pred(0), _dist(0), _path(0), _di(0) {}
     1098      _processed(0), _pred(0), _dist(0), _source(s) {}
    10981099
    10991100  };
    11001101
    1101   /// Auxiliary class for the function-type interface of Dijkstra algorithm.
    1102 
    1103   /// This auxiliary class is created to implement the
    1104   /// \ref dijkstra() "function-type interface" of \ref Dijkstra algorithm.
    1105   /// It does not have own \ref run() method, it uses the functions
    1106   /// and features of the plain \ref Dijkstra.
     1102  /// Auxiliary class for the function type interface of Dijkstra algorithm.
     1103
     1104  /// This auxiliary class is created to implement the function type
     1105  /// interface of \ref Dijkstra algorithm. It uses the functions and features
     1106  /// of the plain \ref Dijkstra, but it is much simpler to use it.
     1107  /// It should only be used through the \ref dijkstra() function, which makes
     1108  /// it easier to use the algorithm.
    11071109  ///
    1108   /// This class should only be used through the \ref dijkstra() function,
    1109   /// which makes it easier to use the algorithm.
     1110  /// Simplicity means that the way to change the types defined
     1111  /// in the traits class is based on functions that returns the new class
     1112  /// and not on templatable built-in classes.
     1113  /// When using the plain \ref Dijkstra
     1114  /// the new class with the modified type comes from
     1115  /// the original class by using the ::
     1116  /// operator. In the case of \ref DijkstraWizard only
     1117  /// a function have to be called, and it will
     1118  /// return the needed class.
     1119  ///
     1120  /// It does not have own \ref run() method. When its \ref run() method
     1121  /// is called, it initiates a plain \ref Dijkstra object, and calls the
     1122  /// \ref Dijkstra::run() method of it.
    11101123  template<class TR>
    11111124  class DijkstraWizard : public TR
     
    11321145    ///The type of the map that indicates which nodes are processed.
    11331146    typedef typename TR::ProcessedMap ProcessedMap;
    1134     ///The type of the shortest paths
    1135     typedef typename TR::Path Path;
    11361147    ///The heap type used by the dijkstra algorithm.
    11371148    typedef typename TR::Heap Heap;
     
    11461157    /// Constructor that requires parameters.
    11471158    /// These parameters will be the default values for the traits class.
    1148     /// \param g The digraph the algorithm runs on.
    1149     /// \param l The length map.
    1150     DijkstraWizard(const Digraph &g, const LengthMap &l) :
    1151       TR(g,l) {}
     1159    DijkstraWizard(const Digraph &g,const LengthMap &l, Node s=INVALID) :
     1160      TR(g,l,s) {}
    11521161
    11531162    ///Copy constructor
     
    11561165    ~DijkstraWizard() {}
    11571166
    1158     ///Runs Dijkstra algorithm from the given source node.
    1159 
    1160     ///This method runs %Dijkstra algorithm from the given source node
    1161     ///in order to compute the shortest path to each node.
     1167    ///Runs Dijkstra algorithm from a source node.
     1168
     1169    ///Runs Dijkstra algorithm from a source node.
     1170    ///The node can be given with the \ref source() function.
     1171    void run()
     1172    {
     1173      if(Base::_source==INVALID) throw UninitializedParameter();
     1174      Dijkstra<Digraph,LengthMap,TR>
     1175        dij(*reinterpret_cast<const Digraph*>(Base::_g),
     1176            *reinterpret_cast<const LengthMap*>(Base::_length));
     1177      if(Base::_processed)
     1178        dij.processedMap(*reinterpret_cast<ProcessedMap*>(Base::_processed));
     1179      if(Base::_pred)
     1180        dij.predMap(*reinterpret_cast<PredMap*>(Base::_pred));
     1181      if(Base::_dist)
     1182        dij.distMap(*reinterpret_cast<DistMap*>(Base::_dist));
     1183      dij.run(Base::_source);
     1184    }
     1185
     1186    ///Runs Dijkstra algorithm from the given node.
     1187
     1188    ///Runs Dijkstra algorithm from the given node.
     1189    ///\param s is the given source.
    11621190    void run(Node s)
    11631191    {
    1164       if (s==INVALID) throw UninitializedParameter();
    1165       Dijkstra<Digraph,LengthMap,TR>
    1166         dijk(*reinterpret_cast<const Digraph*>(Base::_g),
    1167              *reinterpret_cast<const LengthMap*>(Base::_length));
    1168       if (Base::_pred)
    1169         dijk.predMap(*reinterpret_cast<PredMap*>(Base::_pred));
    1170       if (Base::_dist)
    1171         dijk.distMap(*reinterpret_cast<DistMap*>(Base::_dist));
    1172       if (Base::_processed)
    1173         dijk.processedMap(*reinterpret_cast<ProcessedMap*>(Base::_processed));
    1174       dijk.run(s);
    1175     }
    1176 
    1177     ///Finds the shortest path between \c s and \c t.
    1178 
    1179     ///This method runs the %Dijkstra algorithm from node \c s
    1180     ///in order to compute the shortest path to node \c t
    1181     ///(it stops searching when \c t is processed).
    1182     ///
    1183     ///\return \c true if \c t is reachable form \c s.
    1184     bool run(Node s, Node t)
    1185     {
    1186       if (s==INVALID || t==INVALID) throw UninitializedParameter();
    1187       Dijkstra<Digraph,LengthMap,TR>
    1188         dijk(*reinterpret_cast<const Digraph*>(Base::_g),
    1189              *reinterpret_cast<const LengthMap*>(Base::_length));
    1190       if (Base::_pred)
    1191         dijk.predMap(*reinterpret_cast<PredMap*>(Base::_pred));
    1192       if (Base::_dist)
    1193         dijk.distMap(*reinterpret_cast<DistMap*>(Base::_dist));
    1194       if (Base::_processed)
    1195         dijk.processedMap(*reinterpret_cast<ProcessedMap*>(Base::_processed));
    1196       dijk.run(s,t);
    1197       if (Base::_path)
    1198         *reinterpret_cast<Path*>(Base::_path) = dijk.path(t);
    1199       if (Base::_di)
    1200         *reinterpret_cast<Value*>(Base::_di) = dijk.dist(t);
    1201       return dijk.reached(t);
     1192      Base::_source=s;
     1193      run();
     1194    }
     1195
     1196    /// Sets the source node, from which the Dijkstra algorithm runs.
     1197
     1198    /// Sets the source node, from which the Dijkstra algorithm runs.
     1199    /// \param s is the source node.
     1200    DijkstraWizard<TR> &source(Node s)
     1201    {
     1202      Base::_source=s;
     1203      return *this;
    12021204    }
    12031205
     
    12081210      SetPredMapBase(const TR &b) : TR(b) {}
    12091211    };
    1210     ///\brief \ref named-func-param "Named parameter"
     1212    ///\brief \ref named-templ-param "Named parameter"
    12111213    ///for setting \ref PredMap object.
    12121214    ///
    1213     ///\ref named-func-param "Named parameter"
     1215    ///\ref named-templ-param "Named parameter"
    12141216    ///for setting \ref PredMap object.
    12151217    template<class T>
     
    12181220      Base::_pred=reinterpret_cast<void*>(const_cast<T*>(&t));
    12191221      return DijkstraWizard<SetPredMapBase<T> >(*this);
     1222    }
     1223
     1224    template<class T>
     1225    struct SetProcessedMapBase : public Base {
     1226      typedef T ProcessedMap;
     1227      static ProcessedMap *createProcessedMap(const Digraph &) { return 0; };
     1228      SetProcessedMapBase(const TR &b) : TR(b) {}
     1229    };
     1230    ///\brief \ref named-templ-param "Named parameter"
     1231    ///for setting \ref ProcessedMap object.
     1232    ///
     1233    /// \ref named-templ-param "Named parameter"
     1234    ///for setting \ref ProcessedMap object.
     1235    template<class T>
     1236    DijkstraWizard<SetProcessedMapBase<T> > processedMap(const T &t)
     1237    {
     1238      Base::_processed=reinterpret_cast<void*>(const_cast<T*>(&t));
     1239      return DijkstraWizard<SetProcessedMapBase<T> >(*this);
    12201240    }
    12211241
     
    12261246      SetDistMapBase(const TR &b) : TR(b) {}
    12271247    };
    1228     ///\brief \ref named-func-param "Named parameter"
     1248    ///\brief \ref named-templ-param "Named parameter"
    12291249    ///for setting \ref DistMap object.
    12301250    ///
    1231     ///\ref named-func-param "Named parameter"
     1251    ///\ref named-templ-param "Named parameter"
    12321252    ///for setting \ref DistMap object.
    12331253    template<class T>
     
    12381258    }
    12391259
    1240     template<class T>
    1241     struct SetProcessedMapBase : public Base {
    1242       typedef T ProcessedMap;
    1243       static ProcessedMap *createProcessedMap(const Digraph &) { return 0; };
    1244       SetProcessedMapBase(const TR &b) : TR(b) {}
    1245     };
    1246     ///\brief \ref named-func-param "Named parameter"
    1247     ///for setting \ref ProcessedMap object.
    1248     ///
    1249     /// \ref named-func-param "Named parameter"
    1250     ///for setting \ref ProcessedMap object.
    1251     template<class T>
    1252     DijkstraWizard<SetProcessedMapBase<T> > processedMap(const T &t)
    1253     {
    1254       Base::_processed=reinterpret_cast<void*>(const_cast<T*>(&t));
    1255       return DijkstraWizard<SetProcessedMapBase<T> >(*this);
    1256     }
    1257 
    1258     template<class T>
    1259     struct SetPathBase : public Base {
    1260       typedef T Path;
    1261       SetPathBase(const TR &b) : TR(b) {}
    1262     };
    1263     ///\brief \ref named-func-param "Named parameter"
    1264     ///for getting the shortest path to the target node.
    1265     ///
    1266     ///\ref named-func-param "Named parameter"
    1267     ///for getting the shortest path to the target node.
    1268     template<class T>
    1269     DijkstraWizard<SetPathBase<T> > path(const T &t)
    1270     {
    1271       Base::_path=reinterpret_cast<void*>(const_cast<T*>(&t));
    1272       return DijkstraWizard<SetPathBase<T> >(*this);
    1273     }
    1274 
    1275     ///\brief \ref named-func-param "Named parameter"
    1276     ///for getting the distance of the target node.
    1277     ///
    1278     ///\ref named-func-param "Named parameter"
    1279     ///for getting the distance of the target node.
    1280     DijkstraWizard dist(const Value &d)
    1281     {
    1282       Base::_di=reinterpret_cast<void*>(const_cast<Value*>(&d));
    1283       return *this;
    1284     }
    1285 
    12861260  };
    12871261
    1288   ///Function-type interface for Dijkstra algorithm.
     1262  ///Function type interface for Dijkstra algorithm.
    12891263
    12901264  /// \ingroup shortest_path
    1291   ///Function-type interface for Dijkstra algorithm.
     1265  ///Function type interface for Dijkstra algorithm.
    12921266  ///
    1293   ///This function also has several \ref named-func-param "named parameters",
     1267  ///This function also has several
     1268  ///\ref named-templ-func-param "named parameters",
    12941269  ///they are declared as the members of class \ref DijkstraWizard.
    1295   ///The following examples show how to use these parameters.
     1270  ///The following
     1271  ///example shows how to use these parameters.
    12961272  ///\code
    1297   ///  // Compute shortest path from node s to each node
    1298   ///  dijkstra(g,length).predMap(preds).distMap(dists).run(s);
    1299   ///
    1300   ///  // Compute shortest path from s to t
    1301   ///  bool reached = dijkstra(g,length).path(p).dist(d).run(s,t);
     1273  ///  dijkstra(g,length,source).predMap(preds).run();
    13021274  ///\endcode
    13031275  ///\warning Don't forget to put the \ref DijkstraWizard::run() "run()"
     
    13071279  template<class GR, class LM>
    13081280  DijkstraWizard<DijkstraWizardBase<GR,LM> >
    1309   dijkstra(const GR &digraph, const LM &length)
     1281  dijkstra(const GR &g,const LM &l,typename GR::Node s=INVALID)
    13101282  {
    1311     return DijkstraWizard<DijkstraWizardBase<GR,LM> >(digraph,length);
     1283    return DijkstraWizard<DijkstraWizardBase<GR,LM> >(g,l,s);
    13121284  }
    13131285
  • test/bfs_test.cc

    r278 r228  
    6363  BType::DistMap d(G);
    6464  BType::PredMap p(G);
     65  //  BType::PredNodeMap pn(G);
    6566
    6667  BType bfs_test(G);
     
    7273  n  = bfs_test.predNode(n);
    7374  d  = bfs_test.distMap();
     75
    7476  p  = bfs_test.predMap();
     77  //  pn = bfs_test.predNodeMap();
    7578  b  = bfs_test.reached(n);
    7679
     
    8689
    8790  Digraph g;
    88   bool b;
    89   bfs(g).run(Node());
    90   b=bfs(g).run(Node(),Node());
    91   bfs(g).run();
     91  bfs(g,Node()).run();
     92  bfs(g).source(Node()).run();
    9293  bfs(g)
    93     .predMap(concepts::ReadWriteMap<Node,Arc>())
    94     .distMap(concepts::ReadWriteMap<Node,VType>())
     94    .predMap(concepts::WriteMap<Node,Arc>())
     95    .distMap(concepts::WriteMap<Node,VType>())
    9596    .reachedMap(concepts::ReadWriteMap<Node,bool>())
    9697    .processedMap(concepts::WriteMap<Node,bool>())
    9798    .run(Node());
    98   b=bfs(g)
    99     .predMap(concepts::ReadWriteMap<Node,Arc>())
    100     .distMap(concepts::ReadWriteMap<Node,VType>())
    101     .reachedMap(concepts::ReadWriteMap<Node,bool>())
    102     .processedMap(concepts::WriteMap<Node,bool>())
    103     .path(concepts::Path<Digraph>())
    104     .dist(VType())
    105     .run(Node(),Node());
    106   bfs(g)
    107     .predMap(concepts::ReadWriteMap<Node,Arc>())
    108     .distMap(concepts::ReadWriteMap<Node,VType>())
    109     .reachedMap(concepts::ReadWriteMap<Node,bool>())
    110     .processedMap(concepts::WriteMap<Node,bool>())
    111     .run();
    11299}
    113100
     
    128115  bfs_test.run(s);
    129116
    130   check(bfs_test.dist(t)==2,"Bfs found a wrong path.");
     117  check(bfs_test.dist(t)==2,"Bfs found a wrong path." << bfs_test.dist(t));
    131118
    132119  Path<Digraph> p = bfs_test.path(t);
     
    142129    check( !bfs_test.reached(u) ||
    143130           (bfs_test.dist(v) <= bfs_test.dist(u)+1),
    144            "Wrong output. " << G.id(u) << "->" << G.id(v));
     131           "Wrong output." << G.id(v) << ' ' << G.id(u));
    145132  }
    146133
     
    154141        check(bfs_test.dist(v) - bfs_test.dist(u) == 1,
    155142              "Wrong distance. Difference: "
    156               << std::abs(bfs_test.dist(v) - bfs_test.dist(u) - 1));
     143              << std::abs(bfs_test.dist(v) - bfs_test.dist(u)
     144                          - 1));
    157145      }
    158146    }
    159   }
    160 
    161   {
    162     NullMap<Node,Arc> myPredMap;
    163     bfs(G).predMap(myPredMap).run(s);
    164147  }
    165148}
  • test/dfs_test.cc

    r278 r228  
    2121#include <lemon/list_graph.h>
    2222#include <lemon/lgf_reader.h>
     23
    2324#include <lemon/dfs.h>
    2425#include <lemon/path.h>
     
    8889
    8990  Digraph g;
    90   bool b;
    91   dfs(g).run(Node());
    92   b=dfs(g).run(Node(),Node());
    93   dfs(g).run();
     91  dfs(g,Node()).run();
     92  dfs(g).source(Node()).run();
    9493  dfs(g)
    95     .predMap(concepts::ReadWriteMap<Node,Arc>())
    96     .distMap(concepts::ReadWriteMap<Node,VType>())
     94    .predMap(concepts::WriteMap<Node,Arc>())
     95    .distMap(concepts::WriteMap<Node,VType>())
    9796    .reachedMap(concepts::ReadWriteMap<Node,bool>())
    9897    .processedMap(concepts::WriteMap<Node,bool>())
    9998    .run(Node());
    100   b=dfs(g)
    101     .predMap(concepts::ReadWriteMap<Node,Arc>())
    102     .distMap(concepts::ReadWriteMap<Node,VType>())
    103     .reachedMap(concepts::ReadWriteMap<Node,bool>())
    104     .processedMap(concepts::WriteMap<Node,bool>())
    105     .path(concepts::Path<Digraph>())
    106     .dist(VType())
    107     .run(Node(),Node());
    108   dfs(g)
    109     .predMap(concepts::ReadWriteMap<Node,Arc>())
    110     .distMap(concepts::ReadWriteMap<Node,VType>())
    111     .reachedMap(concepts::ReadWriteMap<Node,bool>())
    112     .processedMap(concepts::WriteMap<Node,bool>())
    113     .run();
    11499}
    115100
     
    145130        check(dfs_test.dist(v) - dfs_test.dist(u) == 1,
    146131              "Wrong distance. (" << dfs_test.dist(u) << "->"
    147               << dfs_test.dist(v) << ")");
     132              <<dfs_test.dist(v) << ')');
    148133      }
    149134    }
    150   }
    151 
    152   {
    153     NullMap<Node,Arc> myPredMap;
    154     dfs(G).predMap(myPredMap).run(s);
    155135  }
    156136}
  • test/dijkstra_test.cc

    r278 r228  
    2121#include <lemon/list_graph.h>
    2222#include <lemon/lgf_reader.h>
     23
    2324#include <lemon/dijkstra.h>
    2425#include <lemon/path.h>
     
    6465  DType::DistMap d(G);
    6566  DType::PredMap p(G);
     67  //  DType::PredNodeMap pn(G);
    6668  LengthMap length;
    6769
     
    7577  d  = dijkstra_test.distMap();
    7678  p  = dijkstra_test.predMap();
     79  //  pn = dijkstra_test.predNodeMap();
    7780  b  = dijkstra_test.reached(n);
    7881
     
    8992
    9093  Digraph g;
    91   bool b;
    92   dijkstra(g,LengthMap()).run(Node());
    93   b=dijkstra(g,LengthMap()).run(Node(),Node());
     94  dijkstra(g,LengthMap(),Node()).run();
     95  dijkstra(g,LengthMap()).source(Node()).run();
    9496  dijkstra(g,LengthMap())
    95     .predMap(concepts::ReadWriteMap<Node,Arc>())
    96     .distMap(concepts::ReadWriteMap<Node,VType>())
    97     .processedMap(concepts::WriteMap<Node,bool>())
     97    .predMap(concepts::WriteMap<Node,Arc>())
     98    .distMap(concepts::WriteMap<Node,VType>())
    9899    .run(Node());
    99   b=dijkstra(g,LengthMap())
    100     .predMap(concepts::ReadWriteMap<Node,Arc>())
    101     .distMap(concepts::ReadWriteMap<Node,VType>())
    102     .processedMap(concepts::WriteMap<Node,bool>())
    103     .path(concepts::Path<Digraph>())
    104     .dist(VType())
    105     .run(Node(),Node());
    106100}
    107101
     
    129123
    130124  Path<Digraph> p = dijkstra_test.path(t);
    131   check(p.length()==3,"path() found a wrong path.");
     125  check(p.length()==3,"getPath() found a wrong path.");
    132126  check(checkPath(G, p),"path() found a wrong path.");
    133127  check(pathSource(G, p) == s,"path() found a wrong path.");
     
    139133    check( !dijkstra_test.reached(u) ||
    140134           (dijkstra_test.dist(v) - dijkstra_test.dist(u) <= length[e]),
    141            "Wrong output. dist(target)-dist(source)-arc_length=" <<
     135           "dist(target)-dist(source)-arc_length= " <<
    142136           dijkstra_test.dist(v) - dijkstra_test.dist(u) - length[e]);
    143137  }
Note: See TracChangeset for help on using the changeset viewer.