gravatar
kpeter (Peter Kovacs)
kpeter@inf.elte.hu
Improve the function-type interface of bfs, dfs, and dijkstra (ticket #96) - BfsWizard and DfsWizard have run(s), run(s,t), and run() functions, DijkstraWizard has run(s) and run(s,t) functions. - Set NodeMap<T> instead of NullMap as PredMap and DistMap in the default traits classes for the function-type interface. - Modify the related test files. - Doc improvements. - Bug fix in concepts/path.h.
0 7 0
default
7 files changed with 488 insertions and 338 deletions:
↑ Collapse diff ↑
Ignore white space 6 line context
... ...
@@ -25,12 +25,13 @@
25 25

	
26 26
#include <lemon/list_graph.h>
27 27
#include <lemon/bits/path_dump.h>
28 28
#include <lemon/core.h>
29 29
#include <lemon/error.h>
30 30
#include <lemon/maps.h>
31
#include <lemon/path.h>
31 32

	
32 33
namespace lemon {
33 34

	
34 35
  ///Default traits class of Bfs class.
35 36

	
36 37
  ///Default traits class of Bfs class.
... ...
@@ -112,13 +113,13 @@
112 113

	
113 114
  ///%BFS algorithm class.
114 115

	
115 116
  ///\ingroup search
116 117
  ///This class provides an efficient implementation of the %BFS algorithm.
117 118
  ///
118
  ///There is also a \ref bfs() "function type interface" for the BFS
119
  ///There is also a \ref bfs() "function-type interface" for the BFS
119 120
  ///algorithm, which is convenient in the simplier cases and it can be
120 121
  ///used easier.
121 122
  ///
122 123
  ///\tparam GR The type of the digraph the algorithm runs on.
123 124
  ///The default value is \ref ListDigraph. The value of GR is not used
124 125
  ///directly by \ref Bfs, it is only passed to \ref BfsDefaultTraits.
... ...
@@ -838,32 +839,29 @@
838 839
    ///\brief The type of the map that stores the predecessor
839 840
    ///arcs of the shortest paths.
840 841
    ///
841 842
    ///The type of the map that stores the predecessor
842 843
    ///arcs of the shortest paths.
843 844
    ///It must meet the \ref concepts::WriteMap "WriteMap" concept.
844
    typedef NullMap<typename Digraph::Node,typename Digraph::Arc> PredMap;
845
    typedef typename Digraph::template NodeMap<typename Digraph::Arc> PredMap;
845 846
    ///Instantiates a \ref PredMap.
846 847

	
847 848
    ///This function instantiates a \ref PredMap.
848 849
    ///\param g is the digraph, to which we would like to define the
849 850
    ///\ref PredMap.
850 851
    ///\todo The digraph alone may be insufficient to initialize
851
#ifdef DOXYGEN
852 852
    static PredMap *createPredMap(const Digraph &g)
853
#else
854
    static PredMap *createPredMap(const Digraph &)
855
#endif
856 853
    {
857
      return new PredMap();
854
      return new PredMap(g);
858 855
    }
859 856

	
860 857
    ///The type of the map that indicates which nodes are processed.
861 858

	
862 859
    ///The type of the map that indicates which nodes are processed.
863 860
    ///It must meet the \ref concepts::WriteMap "WriteMap" concept.
861
    ///By default it is a NullMap.
864 862
    typedef NullMap<typename Digraph::Node,bool> ProcessedMap;
865 863
    ///Instantiates a \ref ProcessedMap.
866 864

	
867 865
    ///This function instantiates a \ref ProcessedMap.
868 866
    ///\param g is the digraph, to which
869 867
    ///we would like to define the \ref ProcessedMap.
... ...
@@ -892,27 +890,28 @@
892 890
    }
893 891

	
894 892
    ///The type of the map that stores the distances of the nodes.
895 893

	
896 894
    ///The type of the map that stores the distances of the nodes.
897 895
    ///It must meet the \ref concepts::WriteMap "WriteMap" concept.
898
    ///
899
    typedef NullMap<typename Digraph::Node,int> DistMap;
896
    typedef typename Digraph::template NodeMap<int> DistMap;
900 897
    ///Instantiates a \ref DistMap.
901 898

	
902 899
    ///This function instantiates a \ref DistMap.
903 900
    ///\param g is the digraph, to which we would like to define
904 901
    ///the \ref DistMap
905
#ifdef DOXYGEN
906 902
    static DistMap *createDistMap(const Digraph &g)
907
#else
908
    static DistMap *createDistMap(const Digraph &)
909
#endif
910 903
    {
911
      return new DistMap();
904
      return new DistMap(g);
912 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;
913 912
  };
914 913

	
915 914
  /// Default traits class used by \ref BfsWizard
916 915

	
917 916
  /// To make it easier to use Bfs algorithm
918 917
  /// we have created a wizard class.
... ...
@@ -936,57 +935,45 @@
936 935
    //Pointer to the map of processed nodes.
937 936
    void *_processed;
938 937
    //Pointer to the map of predecessors arcs.
939 938
    void *_pred;
940 939
    //Pointer to the map of distances.
941 940
    void *_dist;
942
    //Pointer to the source node.
943
    Node _source;
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;
944 945

	
945 946
    public:
946 947
    /// Constructor.
947 948

	
948 949
    /// This constructor does not require parameters, therefore it initiates
949
    /// all of the attributes to default values (0, INVALID).
950
    /// all of the attributes to \c 0.
950 951
    BfsWizardBase() : _g(0), _reached(0), _processed(0), _pred(0),
951
                      _dist(0), _source(INVALID) {}
952
                      _dist(0), _path(0), _di(0) {}
952 953

	
953 954
    /// Constructor.
954 955

	
955
    /// This constructor requires some parameters,
956
    /// listed in the parameters list.
957
    /// Others are initiated to 0.
956
    /// This constructor requires one parameter,
957
    /// others are initiated to \c 0.
958 958
    /// \param g The digraph the algorithm runs on.
959
    /// \param s The source node.
960
    BfsWizardBase(const GR &g, Node s=INVALID) :
959
    BfsWizardBase(const GR &g) :
961 960
      _g(reinterpret_cast<void*>(const_cast<GR*>(&g))),
962
      _reached(0), _processed(0), _pred(0), _dist(0), _source(s) {}
961
      _reached(0), _processed(0), _pred(0), _dist(0),  _path(0), _di(0) {}
963 962

	
964 963
  };
965 964

	
966
  /// Auxiliary class for the function type interface of BFS algorithm.
965
  /// Auxiliary class for the function-type interface of BFS algorithm.
967 966

	
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.
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.
973 971
  ///
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.
972
  /// This class should only be used through the \ref bfs() function,
973
  /// which makes it easier to use the algorithm.
987 974
  template<class TR>
988 975
  class BfsWizard : public TR
989 976
  {
990 977
    typedef TR Base;
991 978

	
992 979
    ///The type of the digraph the algorithm runs on.
... ...
@@ -1003,79 +990,100 @@
1003 990
    ///\brief The type of the map that stores the distances of the nodes.
1004 991
    typedef typename TR::DistMap DistMap;
1005 992
    ///\brief The type of the map that indicates which nodes are reached.
1006 993
    typedef typename TR::ReachedMap ReachedMap;
1007 994
    ///\brief The type of the map that indicates which nodes are processed.
1008 995
    typedef typename TR::ProcessedMap ProcessedMap;
996
    ///The type of the shortest paths
997
    typedef typename TR::Path Path;
1009 998

	
1010 999
  public:
1011 1000

	
1012 1001
    /// Constructor.
1013 1002
    BfsWizard() : TR() {}
1014 1003

	
1015 1004
    /// Constructor that requires parameters.
1016 1005

	
1017 1006
    /// Constructor that requires parameters.
1018 1007
    /// These parameters will be the default values for the traits class.
1019
    BfsWizard(const Digraph &g, Node s=INVALID) :
1020
      TR(g,s) {}
1008
    /// \param g The digraph the algorithm runs on.
1009
    BfsWizard(const Digraph &g) :
1010
      TR(g) {}
1021 1011

	
1022 1012
    ///Copy constructor
1023 1013
    BfsWizard(const TR &b) : TR(b) {}
1024 1014

	
1025 1015
    ~BfsWizard() {}
1026 1016

	
1027
    ///Runs BFS algorithm from a source node.
1017
    ///Runs BFS algorithm from the given source node.
1028 1018

	
1029
    ///Runs BFS algorithm from a source node.
1030
    ///The node can be given with the \ref source() function.
1019
    ///This method runs BFS algorithm from node \c s
1020
    ///in order to compute the shortest path to each node.
1021
    void run(Node s)
1022
    {
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.
1031 1069
    void run()
1032 1070
    {
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.
1050
    void run(Node s)
1051
    {
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;
1071
      run(INVALID);
1064 1072
    }
1065 1073

	
1066 1074
    template<class T>
1067 1075
    struct SetPredMapBase : public Base {
1068 1076
      typedef T PredMap;
1069 1077
      static PredMap *createPredMap(const Digraph &) { return 0; };
1070 1078
      SetPredMapBase(const TR &b) : TR(b) {}
1071 1079
    };
1072
    ///\brief \ref named-templ-param "Named parameter"
1080
    ///\brief \ref named-func-param "Named parameter"
1073 1081
    ///for setting \ref PredMap object.
1074 1082
    ///
1075
    /// \ref named-templ-param "Named parameter"
1083
    ///\ref named-func-param "Named parameter"
1076 1084
    ///for setting \ref PredMap object.
1077 1085
    template<class T>
1078 1086
    BfsWizard<SetPredMapBase<T> > predMap(const T &t)
1079 1087
    {
1080 1088
      Base::_pred=reinterpret_cast<void*>(const_cast<T*>(&t));
1081 1089
      return BfsWizard<SetPredMapBase<T> >(*this);
... ...
@@ -1084,84 +1092,114 @@
1084 1092
    template<class T>
1085 1093
    struct SetReachedMapBase : public Base {
1086 1094
      typedef T ReachedMap;
1087 1095
      static ReachedMap *createReachedMap(const Digraph &) { return 0; };
1088 1096
      SetReachedMapBase(const TR &b) : TR(b) {}
1089 1097
    };
1090
    ///\brief \ref named-templ-param "Named parameter"
1098
    ///\brief \ref named-func-param "Named parameter"
1091 1099
    ///for setting \ref ReachedMap object.
1092 1100
    ///
1093
    /// \ref named-templ-param "Named parameter"
1101
    /// \ref named-func-param "Named parameter"
1094 1102
    ///for setting \ref ReachedMap object.
1095 1103
    template<class T>
1096 1104
    BfsWizard<SetReachedMapBase<T> > reachedMap(const T &t)
1097 1105
    {
1098 1106
      Base::_reached=reinterpret_cast<void*>(const_cast<T*>(&t));
1099 1107
      return BfsWizard<SetReachedMapBase<T> >(*this);
1100 1108
    }
1101 1109

	
1102 1110
    template<class T>
1111
    struct SetDistMapBase : public Base {
1112
      typedef T DistMap;
1113
      static DistMap *createDistMap(const Digraph &) { return 0; };
1114
      SetDistMapBase(const TR &b) : TR(b) {}
1115
    };
1116
    ///\brief \ref named-func-param "Named parameter"
1117
    ///for setting \ref DistMap object.
1118
    ///
1119
    /// \ref named-func-param "Named parameter"
1120
    ///for setting \ref DistMap object.
1121
    template<class T>
1122
    BfsWizard<SetDistMapBase<T> > distMap(const T &t)
1123
    {
1124
      Base::_dist=reinterpret_cast<void*>(const_cast<T*>(&t));
1125
      return BfsWizard<SetDistMapBase<T> >(*this);
1126
    }
1127

	
1128
    template<class T>
1103 1129
    struct SetProcessedMapBase : public Base {
1104 1130
      typedef T ProcessedMap;
1105 1131
      static ProcessedMap *createProcessedMap(const Digraph &) { return 0; };
1106 1132
      SetProcessedMapBase(const TR &b) : TR(b) {}
1107 1133
    };
1108
    ///\brief \ref named-templ-param "Named parameter"
1134
    ///\brief \ref named-func-param "Named parameter"
1109 1135
    ///for setting \ref ProcessedMap object.
1110 1136
    ///
1111
    /// \ref named-templ-param "Named parameter"
1137
    /// \ref named-func-param "Named parameter"
1112 1138
    ///for setting \ref ProcessedMap object.
1113 1139
    template<class T>
1114 1140
    BfsWizard<SetProcessedMapBase<T> > processedMap(const T &t)
1115 1141
    {
1116 1142
      Base::_processed=reinterpret_cast<void*>(const_cast<T*>(&t));
1117 1143
      return BfsWizard<SetProcessedMapBase<T> >(*this);
1118 1144
    }
1119 1145

	
1120 1146
    template<class T>
1121
    struct SetDistMapBase : public Base {
1122
      typedef T DistMap;
1123
      static DistMap *createDistMap(const Digraph &) { return 0; };
1124
      SetDistMapBase(const TR &b) : TR(b) {}
1147
    struct SetPathBase : public Base {
1148
      typedef T Path;
1149
      SetPathBase(const TR &b) : TR(b) {}
1125 1150
    };
1126
    ///\brief \ref named-templ-param "Named parameter"
1127
    ///for setting \ref DistMap object.
1151
    ///\brief \ref named-func-param "Named parameter"
1152
    ///for getting the shortest path to the target node.
1128 1153
    ///
1129
    /// \ref named-templ-param "Named parameter"
1130
    ///for setting \ref DistMap object.
1154
    ///\ref named-func-param "Named parameter"
1155
    ///for getting the shortest path to the target node.
1131 1156
    template<class T>
1132
    BfsWizard<SetDistMapBase<T> > distMap(const T &t)
1157
    BfsWizard<SetPathBase<T> > path(const T &t)
1133 1158
    {
1134
      Base::_dist=reinterpret_cast<void*>(const_cast<T*>(&t));
1135
      return BfsWizard<SetDistMapBase<T> >(*this);
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;
1136 1172
    }
1137 1173

	
1138 1174
  };
1139 1175

	
1140
  ///Function type interface for Bfs algorithm.
1176
  ///Function-type interface for BFS algorithm.
1141 1177

	
1142 1178
  /// \ingroup search
1143
  ///Function type interface for Bfs algorithm.
1179
  ///Function-type interface for BFS algorithm.
1144 1180
  ///
1145
  ///This function also has several
1146
  ///\ref named-templ-func-param "named parameters",
1181
  ///This function also has several \ref named-func-param "named parameters",
1147 1182
  ///they are declared as the members of class \ref BfsWizard.
1148
  ///The following
1149
  ///example shows how to use these parameters.
1183
  ///The following examples show how to use these parameters.
1150 1184
  ///\code
1151
  ///  bfs(g,source).predMap(preds).run();
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);
1152 1190
  ///\endcode
1153 1191
  ///\warning Don't forget to put the \ref BfsWizard::run() "run()"
1154 1192
  ///to the end of the parameter list.
1155 1193
  ///\sa BfsWizard
1156 1194
  ///\sa Bfs
1157 1195
  template<class GR>
1158 1196
  BfsWizard<BfsWizardBase<GR> >
1159
  bfs(const GR &g,typename GR::Node s=INVALID)
1197
  bfs(const GR &digraph)
1160 1198
  {
1161
    return BfsWizard<BfsWizardBase<GR> >(g,s);
1199
    return BfsWizard<BfsWizardBase<GR> >(digraph);
1162 1200
  }
1163 1201

	
1164 1202
#ifdef DOXYGEN
1165 1203
  /// \brief Visitor class for BFS.
1166 1204
  ///
1167 1205
  /// This class defines the interface of the BfsVisit events, and
Ignore white space 6 line context
... ...
@@ -63,13 +63,16 @@
63 63
      /// \brief Template constructor
64 64
      template <typename CPath>
65 65
      Path(const CPath& cpath) {}
66 66

	
67 67
      /// \brief Template assigment
68 68
      template <typename CPath>
69
      Path& operator=(const CPath& cpath) {}
69
      Path& operator=(const CPath& cpath) {
70
        ignore_unused_variable_warning(cpath);
71
        return *this;
72
      }
70 73

	
71 74
      /// Length of the path ie. the number of arcs in the path.
72 75
      int length() const { return 0;}
73 76

	
74 77
      /// Returns whether the path is empty.
75 78
      bool empty() const { return true;}
Ignore white space 6 line context
... ...
@@ -26,12 +26,13 @@
26 26
#include <lemon/list_graph.h>
27 27
#include <lemon/bits/path_dump.h>
28 28
#include <lemon/core.h>
29 29
#include <lemon/error.h>
30 30
#include <lemon/assert.h>
31 31
#include <lemon/maps.h>
32
#include <lemon/path.h>
32 33

	
33 34
namespace lemon {
34 35

	
35 36
  ///Default traits class of Dfs class.
36 37

	
37 38
  ///Default traits class of Dfs class.
... ...
@@ -113,13 +114,13 @@
113 114

	
114 115
  ///%DFS algorithm class.
115 116

	
116 117
  ///\ingroup search
117 118
  ///This class provides an efficient implementation of the %DFS algorithm.
118 119
  ///
119
  ///There is also a \ref dfs() "function type interface" for the DFS
120
  ///There is also a \ref dfs() "function-type interface" for the DFS
120 121
  ///algorithm, which is convenient in the simplier cases and it can be
121 122
  ///used easier.
122 123
  ///
123 124
  ///\tparam GR The type of the digraph the algorithm runs on.
124 125
  ///The default value is \ref ListDigraph. The value of GR is not used
125 126
  ///directly by \ref Dfs, it is only passed to \ref DfsDefaultTraits.
... ...
@@ -772,33 +773,29 @@
772 773
    ///\brief The type of the map that stores the predecessor
773 774
    ///arcs of the %DFS paths.
774 775
    ///
775 776
    ///The type of the map that stores the predecessor
776 777
    ///arcs of the %DFS paths.
777 778
    ///It must meet the \ref concepts::WriteMap "WriteMap" concept.
778
    ///
779
    typedef NullMap<typename Digraph::Node,typename Digraph::Arc> PredMap;
779
    typedef typename Digraph::template NodeMap<typename Digraph::Arc> PredMap;
780 780
    ///Instantiates a \ref PredMap.
781 781

	
782 782
    ///This function instantiates a \ref PredMap.
783 783
    ///\param g is the digraph, to which we would like to define the
784 784
    ///\ref PredMap.
785 785
    ///\todo The digraph alone may be insufficient to initialize
786
#ifdef DOXYGEN
787 786
    static PredMap *createPredMap(const Digraph &g)
788
#else
789
    static PredMap *createPredMap(const Digraph &)
790
#endif
791 787
    {
792
      return new PredMap();
788
      return new PredMap(g);
793 789
    }
794 790

	
795 791
    ///The type of the map that indicates which nodes are processed.
796 792

	
797 793
    ///The type of the map that indicates which nodes are processed.
798 794
    ///It must meet the \ref concepts::WriteMap "WriteMap" concept.
795
    ///By default it is a NullMap.
799 796
    typedef NullMap<typename Digraph::Node,bool> ProcessedMap;
800 797
    ///Instantiates a \ref ProcessedMap.
801 798

	
802 799
    ///This function instantiates a \ref ProcessedMap.
803 800
    ///\param g is the digraph, to which
804 801
    ///we would like to define the \ref ProcessedMap.
... ...
@@ -827,27 +824,28 @@
827 824
    }
828 825

	
829 826
    ///The type of the map that stores the distances of the nodes.
830 827

	
831 828
    ///The type of the map that stores the distances of the nodes.
832 829
    ///It must meet the \ref concepts::WriteMap "WriteMap" concept.
833
    ///
834
    typedef NullMap<typename Digraph::Node,int> DistMap;
830
    typedef typename Digraph::template NodeMap<int> DistMap;
835 831
    ///Instantiates a \ref DistMap.
836 832

	
837 833
    ///This function instantiates a \ref DistMap.
838 834
    ///\param g is the digraph, to which we would like to define
839 835
    ///the \ref DistMap
840
#ifdef DOXYGEN
841 836
    static DistMap *createDistMap(const Digraph &g)
842
#else
843
    static DistMap *createDistMap(const Digraph &)
844
#endif
845 837
    {
846
      return new DistMap();
838
      return new DistMap(g);
847 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;
848 846
  };
849 847

	
850 848
  /// Default traits class used by \ref DfsWizard
851 849

	
852 850
  /// To make it easier to use Dfs algorithm
853 851
  /// we have created a wizard class.
... ...
@@ -871,57 +869,45 @@
871 869
    //Pointer to the map of processed nodes.
872 870
    void *_processed;
873 871
    //Pointer to the map of predecessors arcs.
874 872
    void *_pred;
875 873
    //Pointer to the map of distances.
876 874
    void *_dist;
877
    //Pointer to the source node.
878
    Node _source;
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;
879 879

	
880 880
    public:
881 881
    /// Constructor.
882 882

	
883 883
    /// This constructor does not require parameters, therefore it initiates
884
    /// all of the attributes to default values (0, INVALID).
884
    /// all of the attributes to \c 0.
885 885
    DfsWizardBase() : _g(0), _reached(0), _processed(0), _pred(0),
886
                      _dist(0), _source(INVALID) {}
886
                      _dist(0), _path(0), _di(0) {}
887 887

	
888 888
    /// Constructor.
889 889

	
890
    /// This constructor requires some parameters,
891
    /// listed in the parameters list.
892
    /// Others are initiated to 0.
890
    /// This constructor requires one parameter,
891
    /// others are initiated to \c 0.
893 892
    /// \param g The digraph the algorithm runs on.
894
    /// \param s The source node.
895
    DfsWizardBase(const GR &g, Node s=INVALID) :
893
    DfsWizardBase(const GR &g) :
896 894
      _g(reinterpret_cast<void*>(const_cast<GR*>(&g))),
897
      _reached(0), _processed(0), _pred(0), _dist(0), _source(s) {}
895
      _reached(0), _processed(0), _pred(0), _dist(0),  _path(0), _di(0) {}
898 896

	
899 897
  };
900 898

	
901
  /// Auxiliary class for the function type interface of DFS algorithm.
899
  /// Auxiliary class for the function-type interface of DFS algorithm.
902 900

	
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.
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.
908 905
  ///
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.
906
  /// This class should only be used through the \ref dfs() function,
907
  /// which makes it easier to use the algorithm.
922 908
  template<class TR>
923 909
  class DfsWizard : public TR
924 910
  {
925 911
    typedef TR Base;
926 912

	
927 913
    ///The type of the digraph the algorithm runs on.
... ...
@@ -930,87 +916,108 @@
930 916
    typedef typename Digraph::Node Node;
931 917
    typedef typename Digraph::NodeIt NodeIt;
932 918
    typedef typename Digraph::Arc Arc;
933 919
    typedef typename Digraph::OutArcIt OutArcIt;
934 920

	
935 921
    ///\brief The type of the map that stores the predecessor
936
    ///arcs of the shortest paths.
922
    ///arcs of the DFS paths.
937 923
    typedef typename TR::PredMap PredMap;
938 924
    ///\brief The type of the map that stores the distances of the nodes.
939 925
    typedef typename TR::DistMap DistMap;
940 926
    ///\brief The type of the map that indicates which nodes are reached.
941 927
    typedef typename TR::ReachedMap ReachedMap;
942 928
    ///\brief The type of the map that indicates which nodes are processed.
943 929
    typedef typename TR::ProcessedMap ProcessedMap;
930
    ///The type of the DFS paths
931
    typedef typename TR::Path Path;
944 932

	
945 933
  public:
946 934

	
947 935
    /// Constructor.
948 936
    DfsWizard() : TR() {}
949 937

	
950 938
    /// Constructor that requires parameters.
951 939

	
952 940
    /// Constructor that requires parameters.
953 941
    /// These parameters will be the default values for the traits class.
954
    DfsWizard(const Digraph &g, Node s=INVALID) :
955
      TR(g,s) {}
942
    /// \param g The digraph the algorithm runs on.
943
    DfsWizard(const Digraph &g) :
944
      TR(g) {}
956 945

	
957 946
    ///Copy constructor
958 947
    DfsWizard(const TR &b) : TR(b) {}
959 948

	
960 949
    ~DfsWizard() {}
961 950

	
962
    ///Runs DFS algorithm from a source node.
951
    ///Runs DFS algorithm from the given source node.
963 952

	
964
    ///Runs DFS algorithm from a source node.
965
    ///The node can be given with the \ref source() function.
953
    ///This method runs DFS algorithm from node \c s
954
    ///in order to compute the DFS path to each node.
955
    void run(Node s)
956
    {
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.
966 1003
    void run()
967 1004
    {
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.
985
    void run(Node s)
986
    {
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;
1005
      run(INVALID);
999 1006
    }
1000 1007

	
1001 1008
    template<class T>
1002 1009
    struct SetPredMapBase : public Base {
1003 1010
      typedef T PredMap;
1004 1011
      static PredMap *createPredMap(const Digraph &) { return 0; };
1005 1012
      SetPredMapBase(const TR &b) : TR(b) {}
1006 1013
    };
1007
    ///\brief \ref named-templ-param "Named parameter"
1014
    ///\brief \ref named-func-param "Named parameter"
1008 1015
    ///for setting \ref PredMap object.
1009 1016
    ///
1010
    ///\ref named-templ-param "Named parameter"
1017
    ///\ref named-func-param "Named parameter"
1011 1018
    ///for setting \ref PredMap object.
1012 1019
    template<class T>
1013 1020
    DfsWizard<SetPredMapBase<T> > predMap(const T &t)
1014 1021
    {
1015 1022
      Base::_pred=reinterpret_cast<void*>(const_cast<T*>(&t));
1016 1023
      return DfsWizard<SetPredMapBase<T> >(*this);
... ...
@@ -1019,84 +1026,115 @@
1019 1026
    template<class T>
1020 1027
    struct SetReachedMapBase : public Base {
1021 1028
      typedef T ReachedMap;
1022 1029
      static ReachedMap *createReachedMap(const Digraph &) { return 0; };
1023 1030
      SetReachedMapBase(const TR &b) : TR(b) {}
1024 1031
    };
1025
    ///\brief \ref named-templ-param "Named parameter"
1032
    ///\brief \ref named-func-param "Named parameter"
1026 1033
    ///for setting \ref ReachedMap object.
1027 1034
    ///
1028
    /// \ref named-templ-param "Named parameter"
1035
    /// \ref named-func-param "Named parameter"
1029 1036
    ///for setting \ref ReachedMap object.
1030 1037
    template<class T>
1031 1038
    DfsWizard<SetReachedMapBase<T> > reachedMap(const T &t)
1032 1039
    {
1033 1040
      Base::_reached=reinterpret_cast<void*>(const_cast<T*>(&t));
1034 1041
      return DfsWizard<SetReachedMapBase<T> >(*this);
1035 1042
    }
1036 1043

	
1037 1044
    template<class T>
1045
    struct SetDistMapBase : public Base {
1046
      typedef T DistMap;
1047
      static DistMap *createDistMap(const Digraph &) { return 0; };
1048
      SetDistMapBase(const TR &b) : TR(b) {}
1049
    };
1050
    ///\brief \ref named-func-param "Named parameter"
1051
    ///for setting \ref DistMap object.
1052
    ///
1053
    /// \ref named-func-param "Named parameter"
1054
    ///for setting \ref DistMap object.
1055
    template<class T>
1056
    DfsWizard<SetDistMapBase<T> > distMap(const T &t)
1057
    {
1058
      Base::_dist=reinterpret_cast<void*>(const_cast<T*>(&t));
1059
      return DfsWizard<SetDistMapBase<T> >(*this);
1060
    }
1061

	
1062
    template<class T>
1038 1063
    struct SetProcessedMapBase : public Base {
1039 1064
      typedef T ProcessedMap;
1040 1065
      static ProcessedMap *createProcessedMap(const Digraph &) { return 0; };
1041 1066
      SetProcessedMapBase(const TR &b) : TR(b) {}
1042 1067
    };
1043
    ///\brief \ref named-templ-param "Named parameter"
1068
    ///\brief \ref named-func-param "Named parameter"
1044 1069
    ///for setting \ref ProcessedMap object.
1045 1070
    ///
1046
    /// \ref named-templ-param "Named parameter"
1071
    /// \ref named-func-param "Named parameter"
1047 1072
    ///for setting \ref ProcessedMap object.
1048 1073
    template<class T>
1049 1074
    DfsWizard<SetProcessedMapBase<T> > processedMap(const T &t)
1050 1075
    {
1051 1076
      Base::_processed=reinterpret_cast<void*>(const_cast<T*>(&t));
1052 1077
      return DfsWizard<SetProcessedMapBase<T> >(*this);
1053 1078
    }
1054 1079

	
1055 1080
    template<class T>
1056
    struct SetDistMapBase : public Base {
1057
      typedef T DistMap;
1058
      static DistMap *createDistMap(const Digraph &) { return 0; };
1059
      SetDistMapBase(const TR &b) : TR(b) {}
1081
    struct SetPathBase : public Base {
1082
      typedef T Path;
1083
      SetPathBase(const TR &b) : TR(b) {}
1060 1084
    };
1061
    ///\brief \ref named-templ-param "Named parameter"
1062
    ///for setting \ref DistMap object.
1085
    ///\brief \ref named-func-param "Named parameter"
1086
    ///for getting the DFS path to the target node.
1063 1087
    ///
1064
    ///\ref named-templ-param "Named parameter"
1065
    ///for setting \ref DistMap object.
1088
    ///\ref named-func-param "Named parameter"
1089
    ///for getting the DFS path to the target node.
1066 1090
    template<class T>
1067
    DfsWizard<SetDistMapBase<T> > distMap(const T &t)
1091
    DfsWizard<SetPathBase<T> > path(const T &t)
1068 1092
    {
1069
      Base::_dist=reinterpret_cast<void*>(const_cast<T*>(&t));
1070
      return DfsWizard<SetDistMapBase<T> >(*this);
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;
1071 1106
    }
1072 1107

	
1073 1108
  };
1074 1109

	
1075
  ///Function type interface for Dfs algorithm.
1110
  ///Function-type interface for DFS algorithm.
1076 1111

	
1077 1112
  ///\ingroup search
1078
  ///Function type interface for Dfs algorithm.
1113
  ///Function-type interface for DFS algorithm.
1079 1114
  ///
1080
  ///This function also has several
1081
  ///\ref named-templ-func-param "named parameters",
1115
  ///This function also has several \ref named-func-param "named parameters",
1082 1116
  ///they are declared as the members of class \ref DfsWizard.
1083
  ///The following
1084
  ///example shows how to use these parameters.
1117
  ///The following examples show how to use these parameters.
1085 1118
  ///\code
1086
  ///  dfs(g,source).predMap(preds).run();
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);
1087 1124
  ///\endcode
1125

	
1088 1126
  ///\warning Don't forget to put the \ref DfsWizard::run() "run()"
1089 1127
  ///to the end of the parameter list.
1090 1128
  ///\sa DfsWizard
1091 1129
  ///\sa Dfs
1092 1130
  template<class GR>
1093 1131
  DfsWizard<DfsWizardBase<GR> >
1094
  dfs(const GR &g,typename GR::Node s=INVALID)
1132
  dfs(const GR &digraph)
1095 1133
  {
1096
    return DfsWizard<DfsWizardBase<GR> >(g,s);
1134
    return DfsWizard<DfsWizardBase<GR> >(digraph);
1097 1135
  }
1098 1136

	
1099 1137
#ifdef DOXYGEN
1100 1138
  /// \brief Visitor class for DFS.
1101 1139
  ///
1102 1140
  /// This class defines the interface of the DfsVisit events, and
Ignore white space 6 line context
... ...
@@ -27,12 +27,13 @@
27 27
#include <lemon/list_graph.h>
28 28
#include <lemon/bin_heap.h>
29 29
#include <lemon/bits/path_dump.h>
30 30
#include <lemon/core.h>
31 31
#include <lemon/error.h>
32 32
#include <lemon/maps.h>
33
#include <lemon/path.h>
33 34

	
34 35
namespace lemon {
35 36

	
36 37
  /// \brief Default operation traits for the Dijkstra algorithm class.
37 38
  ///
38 39
  /// This operation traits class defines all computational operations and
... ...
@@ -196,13 +197,13 @@
196 197
  ///\ref concepts::ReadMap "ReadMap",
197 198
  ///so it is easy to change it to any kind of length.
198 199
  ///The type of the length is determined by the
199 200
  ///\ref concepts::ReadMap::Value "Value" of the length map.
200 201
  ///It is also possible to change the underlying priority heap.
201 202
  ///
202
  ///There is also a \ref dijkstra() "function type interface" for the
203
  ///There is also a \ref dijkstra() "function-type interface" for the
203 204
  ///%Dijkstra algorithm, which is convenient in the simplier cases and
204 205
  ///it can be used easier.
205 206
  ///
206 207
  ///\tparam GR The type of the digraph the algorithm runs on.
207 208
  ///The default value is \ref ListDigraph.
208 209
  ///The value of GR is not used directly by \ref Dijkstra, it is only
... ...
@@ -984,26 +985,22 @@
984 985
    ///\brief The type of the map that stores the predecessor
985 986
    ///arcs of the shortest paths.
986 987
    ///
987 988
    ///The type of the map that stores the predecessor
988 989
    ///arcs of the shortest paths.
989 990
    ///It must meet the \ref concepts::WriteMap "WriteMap" concept.
990
    typedef NullMap <typename Digraph::Node,typename Digraph::Arc> PredMap;
991
    typedef typename Digraph::template NodeMap<typename Digraph::Arc> PredMap;
991 992
    ///Instantiates a \ref PredMap.
992 993

	
993 994
    ///This function instantiates a \ref PredMap.
994 995
    ///\param g is the digraph, to which we would like to define the
995 996
    ///\ref PredMap.
996 997
    ///\todo The digraph alone may be insufficient to initialize
997
#ifdef DOXYGEN
998 998
    static PredMap *createPredMap(const Digraph &g)
999
#else
1000
    static PredMap *createPredMap(const Digraph &)
1001
#endif
1002 999
    {
1003
      return new PredMap();
1000
      return new PredMap(g);
1004 1001
    }
1005 1002

	
1006 1003
    ///The type of the map that indicates which nodes are processed.
1007 1004

	
1008 1005
    ///The type of the map that indicates which nodes are processed.
1009 1006
    ///It must meet the \ref concepts::WriteMap "WriteMap" concept.
... ...
@@ -1027,26 +1024,28 @@
1027 1024
    }
1028 1025

	
1029 1026
    ///The type of the map that stores the distances of the nodes.
1030 1027

	
1031 1028
    ///The type of the map that stores the distances of the nodes.
1032 1029
    ///It must meet the \ref concepts::WriteMap "WriteMap" concept.
1033
    typedef NullMap<typename Digraph::Node,Value> DistMap;
1030
    typedef typename Digraph::template NodeMap<typename LM::Value> DistMap;
1034 1031
    ///Instantiates a \ref DistMap.
1035 1032

	
1036 1033
    ///This function instantiates a \ref DistMap.
1037 1034
    ///\param g is the digraph, to which we would like to define
1038 1035
    ///the \ref DistMap
1039
#ifdef DOXYGEN
1040 1036
    static DistMap *createDistMap(const Digraph &g)
1041
#else
1042
    static DistMap *createDistMap(const Digraph &)
1043
#endif
1044 1037
    {
1045
      return new DistMap();
1038
      return new DistMap(g);
1046 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;
1047 1046
  };
1048 1047

	
1049 1048
  /// Default traits class used by \ref DijkstraWizard
1050 1049

	
1051 1050
  /// To make it easier to use Dijkstra algorithm
1052 1051
  /// we have created a wizard class.
... ...
@@ -1062,67 +1061,55 @@
1062 1061
  protected:
1063 1062
    //The type of the nodes in the digraph.
1064 1063
    typedef typename Base::Digraph::Node Node;
1065 1064

	
1066 1065
    //Pointer to the digraph the algorithm runs on.
1067 1066
    void *_g;
1068
    //Pointer to the length map
1067
    //Pointer to the length map.
1069 1068
    void *_length;
1070 1069
    //Pointer to the map of processed nodes.
1071 1070
    void *_processed;
1072 1071
    //Pointer to the map of predecessors arcs.
1073 1072
    void *_pred;
1074 1073
    //Pointer to the map of distances.
1075 1074
    void *_dist;
1076
    //Pointer to the source node.
1077
    Node _source;
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;
1078 1079

	
1079 1080
  public:
1080 1081
    /// Constructor.
1081 1082

	
1082 1083
    /// This constructor does not require parameters, therefore it initiates
1083
    /// all of the attributes to default values (0, INVALID).
1084
    /// all of the attributes to \c 0.
1084 1085
    DijkstraWizardBase() : _g(0), _length(0), _processed(0), _pred(0),
1085
                           _dist(0), _source(INVALID) {}
1086
                           _dist(0), _path(0), _di(0) {}
1086 1087

	
1087 1088
    /// Constructor.
1088 1089

	
1089
    /// This constructor requires some parameters,
1090
    /// listed in the parameters list.
1091
    /// Others are initiated to 0.
1090
    /// This constructor requires two parameters,
1091
    /// others are initiated to \c 0.
1092 1092
    /// \param g The digraph the algorithm runs on.
1093 1093
    /// \param l The length map.
1094
    /// \param s The source node.
1095
    DijkstraWizardBase(const GR &g,const LM &l, Node s=INVALID) :
1094
    DijkstraWizardBase(const GR &g,const LM &l) :
1096 1095
      _g(reinterpret_cast<void*>(const_cast<GR*>(&g))),
1097 1096
      _length(reinterpret_cast<void*>(const_cast<LM*>(&l))),
1098
      _processed(0), _pred(0), _dist(0), _source(s) {}
1097
      _processed(0), _pred(0), _dist(0), _path(0), _di(0) {}
1099 1098

	
1100 1099
  };
1101 1100

	
1102
  /// Auxiliary class for the function type interface of Dijkstra algorithm.
1101
  /// Auxiliary class for the function-type interface of Dijkstra algorithm.
1103 1102

	
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.
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.
1109 1107
  ///
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.
1108
  /// This class should only be used through the \ref dijkstra() function,
1109
  /// which makes it easier to use the algorithm.
1123 1110
  template<class TR>
1124 1111
  class DijkstraWizard : public TR
1125 1112
  {
1126 1113
    typedef TR Base;
1127 1114

	
1128 1115
    ///The type of the digraph the algorithm runs on.
... ...
@@ -1141,148 +1128,189 @@
1141 1128
    ///arcs of the shortest paths.
1142 1129
    typedef typename TR::PredMap PredMap;
1143 1130
    ///The type of the map that stores the distances of the nodes.
1144 1131
    typedef typename TR::DistMap DistMap;
1145 1132
    ///The type of the map that indicates which nodes are processed.
1146 1133
    typedef typename TR::ProcessedMap ProcessedMap;
1134
    ///The type of the shortest paths
1135
    typedef typename TR::Path Path;
1147 1136
    ///The heap type used by the dijkstra algorithm.
1148 1137
    typedef typename TR::Heap Heap;
1149 1138

	
1150 1139
  public:
1151 1140

	
1152 1141
    /// Constructor.
1153 1142
    DijkstraWizard() : TR() {}
1154 1143

	
1155 1144
    /// Constructor that requires parameters.
1156 1145

	
1157 1146
    /// Constructor that requires parameters.
1158 1147
    /// These parameters will be the default values for the traits class.
1159
    DijkstraWizard(const Digraph &g,const LengthMap &l, Node s=INVALID) :
1160
      TR(g,l,s) {}
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) {}
1161 1152

	
1162 1153
    ///Copy constructor
1163 1154
    DijkstraWizard(const TR &b) : TR(b) {}
1164 1155

	
1165 1156
    ~DijkstraWizard() {}
1166 1157

	
1167
    ///Runs Dijkstra algorithm from a source node.
1158
    ///Runs Dijkstra algorithm from the given source node.
1168 1159

	
1169
    ///Runs Dijkstra algorithm from a source node.
1170
    ///The node can be given with the \ref source() function.
1171
    void run()
1160
    ///This method runs %Dijkstra algorithm from the given source node
1161
    ///in order to compute the shortest path to each node.
1162
    void run(Node s)
1172 1163
    {
1173
      if(Base::_source==INVALID) throw UninitializedParameter();
1164
      if (s==INVALID) throw UninitializedParameter();
1174 1165
      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);
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);
1184 1175
    }
1185 1176

	
1186
    ///Runs Dijkstra algorithm from the given node.
1177
    ///Finds the shortest path between \c s and \c t.
1187 1178

	
1188
    ///Runs Dijkstra algorithm from the given node.
1189
    ///\param s is the given source.
1190
    void run(Node s)
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)
1191 1185
    {
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;
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);
1204 1202
    }
1205 1203

	
1206 1204
    template<class T>
1207 1205
    struct SetPredMapBase : public Base {
1208 1206
      typedef T PredMap;
1209 1207
      static PredMap *createPredMap(const Digraph &) { return 0; };
1210 1208
      SetPredMapBase(const TR &b) : TR(b) {}
1211 1209
    };
1212
    ///\brief \ref named-templ-param "Named parameter"
1210
    ///\brief \ref named-func-param "Named parameter"
1213 1211
    ///for setting \ref PredMap object.
1214 1212
    ///
1215
    ///\ref named-templ-param "Named parameter"
1213
    ///\ref named-func-param "Named parameter"
1216 1214
    ///for setting \ref PredMap object.
1217 1215
    template<class T>
1218 1216
    DijkstraWizard<SetPredMapBase<T> > predMap(const T &t)
1219 1217
    {
1220 1218
      Base::_pred=reinterpret_cast<void*>(const_cast<T*>(&t));
1221 1219
      return DijkstraWizard<SetPredMapBase<T> >(*this);
1222 1220
    }
1223 1221

	
1224 1222
    template<class T>
1223
    struct SetDistMapBase : public Base {
1224
      typedef T DistMap;
1225
      static DistMap *createDistMap(const Digraph &) { return 0; };
1226
      SetDistMapBase(const TR &b) : TR(b) {}
1227
    };
1228
    ///\brief \ref named-func-param "Named parameter"
1229
    ///for setting \ref DistMap object.
1230
    ///
1231
    ///\ref named-func-param "Named parameter"
1232
    ///for setting \ref DistMap object.
1233
    template<class T>
1234
    DijkstraWizard<SetDistMapBase<T> > distMap(const T &t)
1235
    {
1236
      Base::_dist=reinterpret_cast<void*>(const_cast<T*>(&t));
1237
      return DijkstraWizard<SetDistMapBase<T> >(*this);
1238
    }
1239

	
1240
    template<class T>
1225 1241
    struct SetProcessedMapBase : public Base {
1226 1242
      typedef T ProcessedMap;
1227 1243
      static ProcessedMap *createProcessedMap(const Digraph &) { return 0; };
1228 1244
      SetProcessedMapBase(const TR &b) : TR(b) {}
1229 1245
    };
1230
    ///\brief \ref named-templ-param "Named parameter"
1246
    ///\brief \ref named-func-param "Named parameter"
1231 1247
    ///for setting \ref ProcessedMap object.
1232 1248
    ///
1233
    /// \ref named-templ-param "Named parameter"
1249
    /// \ref named-func-param "Named parameter"
1234 1250
    ///for setting \ref ProcessedMap object.
1235 1251
    template<class T>
1236 1252
    DijkstraWizard<SetProcessedMapBase<T> > processedMap(const T &t)
1237 1253
    {
1238 1254
      Base::_processed=reinterpret_cast<void*>(const_cast<T*>(&t));
1239 1255
      return DijkstraWizard<SetProcessedMapBase<T> >(*this);
1240 1256
    }
1241 1257

	
1242 1258
    template<class T>
1243
    struct SetDistMapBase : public Base {
1244
      typedef T DistMap;
1245
      static DistMap *createDistMap(const Digraph &) { return 0; };
1246
      SetDistMapBase(const TR &b) : TR(b) {}
1259
    struct SetPathBase : public Base {
1260
      typedef T Path;
1261
      SetPathBase(const TR &b) : TR(b) {}
1247 1262
    };
1248
    ///\brief \ref named-templ-param "Named parameter"
1249
    ///for setting \ref DistMap object.
1263
    ///\brief \ref named-func-param "Named parameter"
1264
    ///for getting the shortest path to the target node.
1250 1265
    ///
1251
    ///\ref named-templ-param "Named parameter"
1252
    ///for setting \ref DistMap object.
1266
    ///\ref named-func-param "Named parameter"
1267
    ///for getting the shortest path to the target node.
1253 1268
    template<class T>
1254
    DijkstraWizard<SetDistMapBase<T> > distMap(const T &t)
1269
    DijkstraWizard<SetPathBase<T> > path(const T &t)
1255 1270
    {
1256
      Base::_dist=reinterpret_cast<void*>(const_cast<T*>(&t));
1257
      return DijkstraWizard<SetDistMapBase<T> >(*this);
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;
1258 1284
    }
1259 1285

	
1260 1286
  };
1261 1287

	
1262
  ///Function type interface for Dijkstra algorithm.
1288
  ///Function-type interface for Dijkstra algorithm.
1263 1289

	
1264 1290
  /// \ingroup shortest_path
1265
  ///Function type interface for Dijkstra algorithm.
1291
  ///Function-type interface for Dijkstra algorithm.
1266 1292
  ///
1267
  ///This function also has several
1268
  ///\ref named-templ-func-param "named parameters",
1293
  ///This function also has several \ref named-func-param "named parameters",
1269 1294
  ///they are declared as the members of class \ref DijkstraWizard.
1270
  ///The following
1271
  ///example shows how to use these parameters.
1295
  ///The following examples show how to use these parameters.
1272 1296
  ///\code
1273
  ///  dijkstra(g,length,source).predMap(preds).run();
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);
1274 1302
  ///\endcode
1275 1303
  ///\warning Don't forget to put the \ref DijkstraWizard::run() "run()"
1276 1304
  ///to the end of the parameter list.
1277 1305
  ///\sa DijkstraWizard
1278 1306
  ///\sa Dijkstra
1279 1307
  template<class GR, class LM>
1280 1308
  DijkstraWizard<DijkstraWizardBase<GR,LM> >
1281
  dijkstra(const GR &g,const LM &l,typename GR::Node s=INVALID)
1309
  dijkstra(const GR &digraph, const LM &length)
1282 1310
  {
1283
    return DijkstraWizard<DijkstraWizardBase<GR,LM> >(g,l,s);
1311
    return DijkstraWizard<DijkstraWizardBase<GR,LM> >(digraph,length);
1284 1312
  }
1285 1313

	
1286 1314
} //END OF NAMESPACE LEMON
1287 1315

	
1288 1316
#endif
Ignore white space 6 line context
... ...
@@ -59,25 +59,22 @@
59 59
  Digraph::Node n;
60 60
  Digraph::Arc e;
61 61
  int l;
62 62
  bool b;
63 63
  BType::DistMap d(G);
64 64
  BType::PredMap p(G);
65
  //  BType::PredNodeMap pn(G);
66 65

	
67 66
  BType bfs_test(G);
68 67

	
69 68
  bfs_test.run(n);
70 69

	
71 70
  l  = bfs_test.dist(n);
72 71
  e  = bfs_test.predArc(n);
73 72
  n  = bfs_test.predNode(n);
74 73
  d  = bfs_test.distMap();
75

	
76 74
  p  = bfs_test.predMap();
77
  //  pn = bfs_test.predNodeMap();
78 75
  b  = bfs_test.reached(n);
79 76

	
80 77
  Path<Digraph> pp = bfs_test.path(n);
81 78
}
82 79

	
83 80
void checkBfsFunctionCompile()
... ...
@@ -85,20 +82,36 @@
85 82
  typedef int VType;
86 83
  typedef concepts::Digraph Digraph;
87 84
  typedef Digraph::Arc Arc;
88 85
  typedef Digraph::Node Node;
89 86

	
90 87
  Digraph g;
91
  bfs(g,Node()).run();
92
  bfs(g).source(Node()).run();
88
  bool b;
89
  bfs(g).run(Node());
90
  b=bfs(g).run(Node(),Node());
91
  bfs(g).run();
93 92
  bfs(g)
94
    .predMap(concepts::WriteMap<Node,Arc>())
95
    .distMap(concepts::WriteMap<Node,VType>())
93
    .predMap(concepts::ReadWriteMap<Node,Arc>())
94
    .distMap(concepts::ReadWriteMap<Node,VType>())
96 95
    .reachedMap(concepts::ReadWriteMap<Node,bool>())
97 96
    .processedMap(concepts::WriteMap<Node,bool>())
98 97
    .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();
99 112
}
100 113

	
101 114
template <class Digraph>
102 115
void checkBfs() {
103 116
  TEMPLATE_DIGRAPH_TYPEDEFS(Digraph);
104 117

	
... ...
@@ -111,13 +124,13 @@
111 124
    node("target", t).
112 125
    run();
113 126

	
114 127
  Bfs<Digraph> bfs_test(G);
115 128
  bfs_test.run(s);
116 129

	
117
  check(bfs_test.dist(t)==2,"Bfs found a wrong path." << bfs_test.dist(t));
130
  check(bfs_test.dist(t)==2,"Bfs found a wrong path.");
118 131

	
119 132
  Path<Digraph> p = bfs_test.path(t);
120 133
  check(p.length()==2,"path() found a wrong path.");
121 134
  check(checkPath(G, p),"path() found a wrong path.");
122 135
  check(pathSource(G, p) == s,"path() found a wrong path.");
123 136
  check(pathTarget(G, p) == t,"path() found a wrong path.");
... ...
@@ -125,29 +138,33 @@
125 138

	
126 139
  for(ArcIt a(G); a!=INVALID; ++a) {
127 140
    Node u=G.source(a);
128 141
    Node v=G.target(a);
129 142
    check( !bfs_test.reached(u) ||
130 143
           (bfs_test.dist(v) <= bfs_test.dist(u)+1),
131
           "Wrong output." << G.id(v) << ' ' << G.id(u));
144
           "Wrong output. " << G.id(u) << "->" << G.id(v));
132 145
  }
133 146

	
134 147
  for(NodeIt v(G); v!=INVALID; ++v) {
135 148
    if (bfs_test.reached(v)) {
136 149
      check(v==s || bfs_test.predArc(v)!=INVALID, "Wrong tree.");
137 150
      if (bfs_test.predArc(v)!=INVALID ) {
138 151
        Arc a=bfs_test.predArc(v);
139 152
        Node u=G.source(a);
140 153
        check(u==bfs_test.predNode(v),"Wrong tree.");
141 154
        check(bfs_test.dist(v) - bfs_test.dist(u) == 1,
142 155
              "Wrong distance. Difference: "
143
              << std::abs(bfs_test.dist(v) - bfs_test.dist(u)
144
                          - 1));
156
              << std::abs(bfs_test.dist(v) - bfs_test.dist(u) - 1));
145 157
      }
146 158
    }
147 159
  }
160

	
161
  {
162
    NullMap<Node,Arc> myPredMap;
163
    bfs(G).predMap(myPredMap).run(s);
164
  }
148 165
}
149 166

	
150 167
int main()
151 168
{
152 169
  checkBfs<ListDigraph>();
153 170
  checkBfs<SmartDigraph>();
Ignore white space 6 line context
... ...
@@ -17,13 +17,12 @@
17 17
 */
18 18

	
19 19
#include <lemon/concepts/digraph.h>
20 20
#include <lemon/smart_graph.h>
21 21
#include <lemon/list_graph.h>
22 22
#include <lemon/lgf_reader.h>
23

	
24 23
#include <lemon/dfs.h>
25 24
#include <lemon/path.h>
26 25

	
27 26
#include "graph_test.h"
28 27
#include "test_tools.h"
29 28

	
... ...
@@ -85,20 +84,36 @@
85 84
  typedef int VType;
86 85
  typedef concepts::Digraph Digraph;
87 86
  typedef Digraph::Arc Arc;
88 87
  typedef Digraph::Node Node;
89 88

	
90 89
  Digraph g;
91
  dfs(g,Node()).run();
92
  dfs(g).source(Node()).run();
90
  bool b;
91
  dfs(g).run(Node());
92
  b=dfs(g).run(Node(),Node());
93
  dfs(g).run();
93 94
  dfs(g)
94
    .predMap(concepts::WriteMap<Node,Arc>())
95
    .distMap(concepts::WriteMap<Node,VType>())
95
    .predMap(concepts::ReadWriteMap<Node,Arc>())
96
    .distMap(concepts::ReadWriteMap<Node,VType>())
96 97
    .reachedMap(concepts::ReadWriteMap<Node,bool>())
97 98
    .processedMap(concepts::WriteMap<Node,bool>())
98 99
    .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();
99 114
}
100 115

	
101 116
template <class Digraph>
102 117
void checkDfs() {
103 118
  TEMPLATE_DIGRAPH_TYPEDEFS(Digraph);
104 119

	
... ...
@@ -126,16 +141,21 @@
126 141
      if (dfs_test.predArc(v)!=INVALID ) {
127 142
        Arc e=dfs_test.predArc(v);
128 143
        Node u=G.source(e);
129 144
        check(u==dfs_test.predNode(v),"Wrong tree.");
130 145
        check(dfs_test.dist(v) - dfs_test.dist(u) == 1,
131 146
              "Wrong distance. (" << dfs_test.dist(u) << "->"
132
              <<dfs_test.dist(v) << ')');
147
              << dfs_test.dist(v) << ")");
133 148
      }
134 149
    }
135 150
  }
151

	
152
  {
153
    NullMap<Node,Arc> myPredMap;
154
    dfs(G).predMap(myPredMap).run(s);
155
  }
136 156
}
137 157

	
138 158
int main()
139 159
{
140 160
  checkDfs<ListDigraph>();
141 161
  checkDfs<SmartDigraph>();
Ignore white space 12 line context
... ...
@@ -17,13 +17,12 @@
17 17
 */
18 18

	
19 19
#include <lemon/concepts/digraph.h>
20 20
#include <lemon/smart_graph.h>
21 21
#include <lemon/list_graph.h>
22 22
#include <lemon/lgf_reader.h>
23

	
24 23
#include <lemon/dijkstra.h>
25 24
#include <lemon/path.h>
26 25

	
27 26
#include "graph_test.h"
28 27
#include "test_tools.h"
29 28

	
... ...
@@ -61,25 +60,23 @@
61 60
  Digraph::Node n;
62 61
  Digraph::Arc e;
63 62
  VType l;
64 63
  bool b;
65 64
  DType::DistMap d(G);
66 65
  DType::PredMap p(G);
67
  //  DType::PredNodeMap pn(G);
68 66
  LengthMap length;
69 67

	
70 68
  DType dijkstra_test(G,length);
71 69

	
72 70
  dijkstra_test.run(n);
73 71

	
74 72
  l  = dijkstra_test.dist(n);
75 73
  e  = dijkstra_test.predArc(n);
76 74
  n  = dijkstra_test.predNode(n);
77 75
  d  = dijkstra_test.distMap();
78 76
  p  = dijkstra_test.predMap();
79
  //  pn = dijkstra_test.predNodeMap();
80 77
  b  = dijkstra_test.reached(n);
81 78

	
82 79
  Path<Digraph> pp = dijkstra_test.path(n);
83 80
}
84 81

	
85 82
void checkDijkstraFunctionCompile()
... ...
@@ -88,18 +85,27 @@
88 85
  typedef concepts::Digraph Digraph;
89 86
  typedef Digraph::Arc Arc;
90 87
  typedef Digraph::Node Node;
91 88
  typedef concepts::ReadMap<Digraph::Arc,VType> LengthMap;
92 89

	
93 90
  Digraph g;
94
  dijkstra(g,LengthMap(),Node()).run();
95
  dijkstra(g,LengthMap()).source(Node()).run();
91
  bool b;
92
  dijkstra(g,LengthMap()).run(Node());
93
  b=dijkstra(g,LengthMap()).run(Node(),Node());
96 94
  dijkstra(g,LengthMap())
97
    .predMap(concepts::WriteMap<Node,Arc>())
98
    .distMap(concepts::WriteMap<Node,VType>())
95
    .predMap(concepts::ReadWriteMap<Node,Arc>())
96
    .distMap(concepts::ReadWriteMap<Node,VType>())
97
    .processedMap(concepts::WriteMap<Node,bool>())
99 98
    .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());
100 106
}
101 107

	
102 108
template <class Digraph>
103 109
void checkDijkstra() {
104 110
  TEMPLATE_DIGRAPH_TYPEDEFS(Digraph);
105 111
  typedef typename Digraph::template ArcMap<int> LengthMap;
... ...
@@ -119,23 +125,23 @@
119 125
        dijkstra_test(G, length);
120 126
  dijkstra_test.run(s);
121 127

	
122 128
  check(dijkstra_test.dist(t)==3,"Dijkstra found a wrong path.");
123 129

	
124 130
  Path<Digraph> p = dijkstra_test.path(t);
125
  check(p.length()==3,"getPath() found a wrong path.");
131
  check(p.length()==3,"path() found a wrong path.");
126 132
  check(checkPath(G, p),"path() found a wrong path.");
127 133
  check(pathSource(G, p) == s,"path() found a wrong path.");
128 134
  check(pathTarget(G, p) == t,"path() found a wrong path.");
129 135

	
130 136
  for(ArcIt e(G); e!=INVALID; ++e) {
131 137
    Node u=G.source(e);
132 138
    Node v=G.target(e);
133 139
    check( !dijkstra_test.reached(u) ||
134 140
           (dijkstra_test.dist(v) - dijkstra_test.dist(u) <= length[e]),
135
           "dist(target)-dist(source)-arc_length= " <<
141
           "Wrong output. dist(target)-dist(source)-arc_length=" <<
136 142
           dijkstra_test.dist(v) - dijkstra_test.dist(u) - length[e]);
137 143
  }
138 144

	
139 145
  for(NodeIt v(G); v!=INVALID; ++v) {
140 146
    if (dijkstra_test.reached(v)) {
141 147
      check(v==s || dijkstra_test.predArc(v)!=INVALID, "Wrong tree.");
0 comments (0 inline)