28 namespace lemon { |
28 namespace lemon { |
29 |
29 |
30 /// \addtogroup flowalgs |
30 /// \addtogroup flowalgs |
31 /// @{ |
31 /// @{ |
32 |
32 |
|
33 ///Default traits class of Dijkstra class. |
|
34 |
|
35 ///Default traits class of Dijkstra class. |
|
36 ///\param GR Graph type. |
|
37 ///\param LM Type of length map. |
33 template<class GR, class LM> |
38 template<class GR, class LM> |
34 struct DijkstraDefaultTraits |
39 struct DijkstraDefaultTraits |
35 { |
40 { |
36 ///\e |
41 ///The graph type the algorithm runs on. |
37 typedef GR Graph; |
42 typedef GR Graph; |
38 ///\e |
|
39 typedef typename Graph::Node Node; |
|
40 ///\e |
|
41 typedef typename Graph::Edge Edge; |
|
42 ///The type of the map that stores the edge lengths. |
43 ///The type of the map that stores the edge lengths. |
43 |
44 |
44 ///It must meet the \ref ReadMap concept. |
45 ///It must meet the \ref ReadMap concept. |
45 /// |
46 /// |
46 typedef LM LengthMap; |
47 typedef LM LengthMap; |
47 ///The type of the length of the edges. |
48 //The type of the length of the edges. |
48 typedef typename LM::ValueType ValueType; |
49 typedef typename LM::ValueType ValueType; |
49 ///The heap type used by the dijkstra algorithm. |
50 ///The heap type used by Dijkstra algorithm. |
50 typedef BinHeap<typename Graph::Node, |
51 typedef BinHeap<typename Graph::Node, |
51 typename LM::ValueType, |
52 typename LM::ValueType, |
52 typename GR::template NodeMap<int>, |
53 typename GR::template NodeMap<int>, |
53 std::less<ValueType> > Heap; |
54 std::less<ValueType> > Heap; |
54 |
55 |
55 ///\brief The type of the map that stores the last |
56 ///\brief The type of the map that stores the last |
56 ///edges of the shortest paths. |
57 ///edges of the shortest paths. |
57 /// |
58 /// |
58 ///It must meet the \ref WriteMap concept. |
59 ///It must meet the \ref WriteMap concept. |
59 /// |
60 /// |
60 typedef typename Graph::template NodeMap<Edge> PredMap; |
61 typedef typename Graph::template NodeMap<typename GR::Edge> PredMap; |
61 /// |
62 ///Instantiates a PredMap. |
62 |
63 |
63 ///\todo Please document... |
64 ///\todo Please document... |
64 /// |
65 /// |
65 static PredMap *createPredMap(const Graph &G) |
66 static PredMap *createPredMap(const GR &G) |
66 { |
67 { |
67 return new PredMap(G); |
68 return new PredMap(G); |
68 } |
69 } |
69 ///\brief The type of the map that stores the last but one |
70 ///\brief The type of the map that stores the last but one |
70 ///nodes of the shortest paths. |
71 ///nodes of the shortest paths. |
71 /// |
72 /// |
72 ///It must meet the \ref WriteMap concept. |
73 ///It must meet the \ref WriteMap concept. |
73 /// |
74 /// |
74 typedef typename Graph::template NodeMap<Node> PredNodeMap; |
75 typedef typename Graph::template NodeMap<typename GR::Node> PredNodeMap; |
75 /// |
76 ///Instantiates a PredNodeMap. |
76 |
77 |
77 ///\todo Please document... |
78 ///\todo Please document... |
78 /// |
79 /// |
79 static PredNodeMap *createPredNodeMap(const Graph &G) |
80 static PredNodeMap *createPredNodeMap(const GR &G) |
80 { |
81 { |
81 return new PredNodeMap(G); |
82 return new PredNodeMap(G); |
82 } |
83 } |
83 ///The type of the map that stores the dists of the nodes. |
84 ///The type of the map that stores the dists of the nodes. |
84 |
85 |
85 ///It must meet the \ref WriteMap concept. |
86 ///It must meet the \ref WriteMap concept. |
86 /// |
87 /// |
87 typedef typename Graph::template NodeMap<ValueType> DistMap; |
88 typedef typename Graph::template NodeMap<typename LM::ValueType> DistMap; |
88 /// |
89 ///Instantiates a DistMap. |
89 |
90 |
90 ///\todo Please document... |
91 ///\todo Please document... |
91 /// |
92 /// |
92 static DistMap *createDistMap(const Graph &G) |
93 static DistMap *createDistMap(const GR &G) |
93 { |
94 { |
94 return new DistMap(G); |
95 return new DistMap(G); |
95 } |
96 } |
96 }; |
97 }; |
97 |
98 |
106 ///\ref skeleton::ReadMap::ValueType "ValueType" of the length map. |
107 ///\ref skeleton::ReadMap::ValueType "ValueType" of the length map. |
107 /// |
108 /// |
108 ///It is also possible to change the underlying priority heap. |
109 ///It is also possible to change the underlying priority heap. |
109 /// |
110 /// |
110 ///\param GR The graph type the algorithm runs on. The default value is |
111 ///\param GR The graph type the algorithm runs on. The default value is |
111 ///\ref ListGraph |
112 ///\ref ListGraph. The value of GR is not used directly by %Dijsktra, it |
|
113 ///is only passed to \ref DijkstraDefaultTraits. |
112 ///\param LM This read-only |
114 ///\param LM This read-only |
113 ///EdgeMap |
115 ///EdgeMap |
114 ///determines the |
116 ///determines the |
115 ///lengths of the edges. It is read once for each edge, so the map |
117 ///lengths of the edges. It is read once for each edge, so the map |
116 ///may involve in relatively time consuming process to compute the edge |
118 ///may involve in relatively time consuming process to compute the edge |
117 ///length if it is necessary. The default map type is |
119 ///length if it is necessary. The default map type is |
118 ///\ref skeleton::StaticGraph::EdgeMap "Graph::EdgeMap<int>" |
120 ///\ref skeleton::StaticGraph::EdgeMap "Graph::EdgeMap<int>". |
119 ///\param Heap The heap type used by the %Dijkstra |
121 ///The value of LM is not used directly by %Dijsktra, it |
120 ///algorithm. The default |
122 ///is only passed to \ref DijkstraDefaultTraits. |
121 ///is using \ref BinHeap "binary heap". |
123 ///\param TR Traits class to set various data types used by the algorithm. |
|
124 ///The default traits class is |
|
125 ///\ref DijkstraDefaultTraits<GR,LM> "DijkstraDefaultTraits<GR,LM>". |
|
126 ///See \ref DijkstraDefaultTraits for the documentation of |
|
127 ///a Dijkstra traits class. |
122 /// |
128 /// |
123 ///\author Jacint Szabo and Alpar Juttner |
129 ///\author Jacint Szabo and Alpar Juttner |
124 ///\todo We need a typedef-names should be standardized. (-: |
130 ///\todo We need a typedef-names should be standardized. (-: |
125 ///\todo Type of \c PredMap, \c PredNodeMap and \c DistMap |
|
126 ///should not be fixed. (Problematic to solve). |
|
127 |
131 |
128 #ifdef DOXYGEN |
132 #ifdef DOXYGEN |
129 template <typename GR, |
133 template <typename GR, |
130 typename LM, |
134 typename LM, |
131 typename TR> |
135 typename TR> |
136 #endif |
140 #endif |
137 class Dijkstra{ |
141 class Dijkstra{ |
138 public: |
142 public: |
139 typedef TR Traits; |
143 typedef TR Traits; |
140 ///The type of the underlying graph. |
144 ///The type of the underlying graph. |
141 typedef GR Graph; |
145 typedef typename TR::Graph Graph; |
142 ///\e |
146 ///\e |
143 typedef typename Graph::Node Node; |
147 typedef typename Graph::Node Node; |
144 ///\e |
148 ///\e |
145 typedef typename Graph::NodeIt NodeIt; |
149 typedef typename Graph::NodeIt NodeIt; |
146 ///\e |
150 ///\e |
147 typedef typename Graph::Edge Edge; |
151 typedef typename Graph::Edge Edge; |
148 ///\e |
152 ///\e |
149 typedef typename Graph::OutEdgeIt OutEdgeIt; |
153 typedef typename Graph::OutEdgeIt OutEdgeIt; |
150 |
154 |
151 ///The type of the length of the edges. |
155 ///The type of the length of the edges. |
152 typedef typename LM::ValueType ValueType; |
156 typedef typename TR::LengthMap::ValueType ValueType; |
153 ///The type of the map that stores the edge lengths. |
157 ///The type of the map that stores the edge lengths. |
154 typedef LM LengthMap; |
158 typedef typename TR::LengthMap LengthMap; |
155 ///\brief The type of the map that stores the last |
159 ///\brief The type of the map that stores the last |
156 ///edges of the shortest paths. |
160 ///edges of the shortest paths. |
157 typedef typename TR::PredMap PredMap; |
161 typedef typename TR::PredMap PredMap; |
158 ///\brief The type of the map that stores the last but one |
162 ///\brief The type of the map that stores the last but one |
159 ///nodes of the shortest paths. |
163 ///nodes of the shortest paths. |
160 typedef typename TR::PredNodeMap PredNodeMap; |
164 typedef typename TR::PredNodeMap PredNodeMap; |
161 ///The type of the map that stores the dists of the nodes. |
165 ///The type of the map that stores the dists of the nodes. |
162 typedef typename TR::DistMap DistMap; |
166 typedef typename TR::DistMap DistMap; |
163 |
|
164 ///The heap type used by the dijkstra algorithm. |
167 ///The heap type used by the dijkstra algorithm. |
165 typedef typename TR::Heap Heap; |
168 typedef typename TR::Heap Heap; |
166 |
169 |
167 private: |
170 private: |
168 /// Pointer to the underlying graph. |
171 /// Pointer to the underlying graph. |
169 const Graph *G; |
172 const Graph *G; |
170 /// Pointer to the length map |
173 /// Pointer to the length map |
171 const LM *length; |
174 const LengthMap *length; |
172 ///Pointer to the map of predecessors edges. |
175 ///Pointer to the map of predecessors edges. |
173 PredMap *predecessor; |
176 PredMap *predecessor; |
174 ///Indicates if \ref predecessor is locally allocated (\c true) or not. |
177 ///Indicates if \ref predecessor is locally allocated (\c true) or not. |
175 bool local_predecessor; |
178 bool local_predecessor; |
176 ///Pointer to the map of predecessors nodes. |
179 ///Pointer to the map of predecessors nodes. |
253 std::cerr << __FILE__ ":" << __LINE__ << |
262 std::cerr << __FILE__ ":" << __LINE__ << |
254 ": error: Special maps should be manually created" << std::endl; |
263 ": error: Special maps should be manually created" << std::endl; |
255 exit(1); |
264 exit(1); |
256 } |
265 } |
257 }; |
266 }; |
258 ///\ref named-templ-param "Named parameter" for setting DistMap's type |
267 ///\ref named-templ-param "Named parameter" for setting DistMap type |
|
268 |
|
269 ///\ingroup flowalgs |
|
270 ///\ref named-templ-param "Named parameter" for setting DistMap type |
259 template <class T> |
271 template <class T> |
260 class SetDistMap : public Dijkstra< Graph, |
272 class SetDistMap : public Dijkstra< Graph, |
261 LengthMap, |
273 LengthMap, |
262 SetDistMapTraits<T> > { }; |
274 SetDistMapTraits<T> > { }; |
263 |
275 |
264 ///Constructor. |
276 ///Constructor. |
265 |
277 |
266 ///\param _G the graph the algorithm will run on. |
278 ///\param _G the graph the algorithm will run on. |
267 ///\param _length the length map used by the algorithm. |
279 ///\param _length the length map used by the algorithm. |
268 Dijkstra(const Graph& _G, const LM& _length) : |
280 Dijkstra(const Graph& _G, const LengthMap& _length) : |
269 G(&_G), length(&_length), |
281 G(&_G), length(&_length), |
270 predecessor(NULL), local_predecessor(false), |
282 predecessor(NULL), local_predecessor(false), |
271 pred_node(NULL), local_pred_node(false), |
283 pred_node(NULL), local_pred_node(false), |
272 distance(NULL), local_distance(false) |
284 distance(NULL), local_distance(false) |
273 { } |
285 { } |