Changeset 1710:f531c16dd923 in lemon-0.x
- Timestamp:
- 10/06/05 11:37:53 (19 years ago)
- Branch:
- default
- Phase:
- public
- Convert:
- svn:c9d7d8f5-90d6-0310-b91f-818b3a526b0e/lemon/trunk@2237
- Location:
- lemon
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
lemon/belmann_ford.h
r1699 r1710 168 168 /// \author Balazs Dezso 169 169 170 #ifdef DOXYGEN 171 template <typename _Graph, typename _LengthMap, typename _Traits> 172 #else 170 173 template <typename _Graph=ListGraph, 171 174 typename _LengthMap=typename _Graph::template EdgeMap<int>, 172 175 typename _Traits=BelmannFordDefaultTraits<_Graph,_LengthMap> > 176 #endif 173 177 class BelmannFord { 174 178 public: … … 234 238 public : 235 239 240 typedef BelmannFord Create; 241 236 242 /// \name Named template parameters 237 243 … … 241 247 struct DefPredMapTraits : public Traits { 242 248 typedef T PredMap; 243 static PredMap *createPredMap(const Graph& graph) {249 static PredMap *createPredMap(const Graph&) { 244 250 throw UninitializedParameter(); 245 251 } … … 251 257 /// 252 258 template <class T> 253 class DefPredMap 254 : public BelmannFord< Graph, LengthMap, DefPredMapTraits<T> > {}; 259 struct DefPredMap { 260 typedef BelmannFord< Graph, LengthMap, DefPredMapTraits<T> > Create; 261 }; 255 262 256 263 template <class T> … … 268 275 /// 269 276 template <class T> 270 class DefDistMap 271 : public BelmannFord< Graph, LengthMap, DefDistMapTraits<T> > {}; 277 struct DefDistMap 278 : public BelmannFord< Graph, LengthMap, DefDistMapTraits<T> > { 279 typedef BelmannFord< Graph, LengthMap, DefDistMapTraits<T> > Create; 280 }; 272 281 273 282 template <class T> … … 279 288 /// OperationTraits type 280 289 /// 281 /// \ref named-templ-param "Named parameter" for setting PredMap type 290 /// \ref named-templ-param "Named parameter" for setting OperationTraits 291 /// type 282 292 template <class T> 283 classDefOperationTraits293 struct DefOperationTraits 284 294 : public BelmannFord< Graph, LengthMap, DefOperationTraitsTraits<T> > { 285 public:286 295 typedef BelmannFord< Graph, LengthMap, DefOperationTraitsTraits<T> > 287 BelmannFord;296 Create; 288 297 }; 289 298 290 299 ///@} 300 301 protected: 302 303 BelmannFord() {} 291 304 292 305 public: … … 363 376 /// 364 377 /// Initializes the internal data structures. 365 void init( ) {378 void init(const Value value = OperationTraits::infinity()) { 366 379 create_maps(); 367 380 for (NodeIt it(*graph); it != INVALID; ++it) { 368 381 _pred->set(it, INVALID); 369 _dist->set(it, OperationTraits::infinity());382 _dist->set(it, value); 370 383 } 371 384 } … … 741 754 return BelmannFordWizard<DefDistMapBase<T> >(*this); 742 755 } 756 757 template<class T> 758 struct DefOperationTraitsBase : public Base { 759 typedef T OperationTraits; 760 DefOperationTraitsBase(const _Traits &b) : _Traits(b) {} 761 }; 762 763 ///\brief \ref named-templ-param "Named parameter" 764 ///function for setting OperationTraits type 765 /// 766 /// \ref named-templ-param "Named parameter" 767 ///function for setting OperationTraits type 768 /// 769 template<class T> 770 BelmannFordWizard<DefOperationTraitsBase<T> > distMap() { 771 return BelmannFordWizard<DefDistMapBase<T> >(*this); 772 } 743 773 744 774 /// \brief Sets the source node, from which the BelmannFord algorithm runs. -
lemon/bfs.h
r1709 r1710 215 215 } 216 216 } 217 218 public : 219 217 218 protected: 219 220 Bfs() {} 221 222 public: 223 224 typedef Bfs Create; 225 220 226 ///\name Named template parameters 221 227 -
lemon/dfs.h
r1709 r1710 215 215 } 216 216 } 217 218 public : 217 218 protected: 219 220 Dfs() {} 221 222 public: 219 223 220 224 typedef Dfs Create; -
lemon/dijkstra.h
r1709 r1710 237 237 238 238 public : 239 240 typedef Dijkstra Create; 239 241 240 242 ///\name Named template parameters … … 321 323 typename Graph::template NodeMap<int> _heap_map; 322 324 Heap _heap; 325 protected: 326 327 Dijkstra() {} 328 323 329 public: 324 330 -
lemon/floyd_warshall.h
r1699 r1710 171 171 /// \author Balazs Dezso 172 172 173 173 #ifdef DOXYGEN 174 template <typename _Graph, typename _LengthMap typename _Traits > 175 #else 174 176 template <typename _Graph=ListGraph, 175 177 typename _LengthMap=typename _Graph::template EdgeMap<int>, 176 178 typename _Traits=FloydWarshallDefaultTraits<_Graph,_LengthMap> > 179 #endif 177 180 class FloydWarshall { 178 181 public: … … 257 260 /// 258 261 template <class T> 259 class DefPredMap 260 : public FloydWarshall< Graph, LengthMap, DefPredMapTraits<T> > {}; 262 struct DefPredMap 263 : public FloydWarshall< Graph, LengthMap, DefPredMapTraits<T> > { 264 typedef FloydWarshall< Graph, LengthMap, DefPredMapTraits<T> > Create; 265 }; 261 266 262 267 template <class T> … … 273 278 /// 274 279 template <class T> 275 class DefDistMap 276 : public FloydWarshall< Graph, LengthMap, DefDistMapTraits<T> > {}; 280 struct DefDistMap 281 : public FloydWarshall< Graph, LengthMap, DefDistMapTraits<T> > { 282 typedef FloydWarshall< Graph, LengthMap, DefDistMapTraits<T> > Create; 283 }; 277 284 278 285 template <class T> … … 286 293 /// \ref named-templ-param "Named parameter" for setting PredMap type 287 294 template <class T> 288 classDefOperationTraits295 struct DefOperationTraits 289 296 : public FloydWarshall< Graph, LengthMap, DefOperationTraitsTraits<T> > { 297 typedef FloydWarshall< Graph, LengthMap, DefOperationTraitsTraits<T> > 298 Create; 290 299 }; 291 300 292 301 ///@} 293 302 303 protected: 304 305 FloydWarshall() {} 306 294 307 public: 308 309 typedef FloydWarshall Create; 295 310 296 311 /// \brief Constructor. -
lemon/johnson.h
r1699 r1710 25 25 #include <lemon/list_graph.h> 26 26 #include <lemon/graph_utils.h> 27 #include <lemon/dfs.h>28 27 #include <lemon/dijkstra.h> 29 28 #include <lemon/belmann_ford.h> … … 173 172 /// \author Balazs Dezso 174 173 174 #ifdef DOXYGEN 175 template <typename _Graph, typename _LengthMap, typename _Traits> 176 #else 175 177 template <typename _Graph=ListGraph, 176 178 typename _LengthMap=typename _Graph::template EdgeMap<int>, 177 179 typename _Traits=JohnsonDefaultTraits<_Graph,_LengthMap> > 180 #endif 178 181 class Johnson { 179 182 public: … … 258 261 /// 259 262 template <class T> 260 class DefPredMap 261 : public Johnson< Graph, LengthMap, DefPredMapTraits<T> > {}; 263 struct DefPredMap 264 : public Johnson< Graph, LengthMap, DefPredMapTraits<T> > { 265 typedef Johnson< Graph, LengthMap, DefPredMapTraits<T> > Create; 266 }; 262 267 263 268 template <class T> … … 274 279 /// 275 280 template <class T> 276 class DefDistMap 277 : public Johnson< Graph, LengthMap, DefDistMapTraits<T> > {}; 281 struct DefDistMap 282 : public Johnson< Graph, LengthMap, DefDistMapTraits<T> > { 283 typedef Johnson< Graph, LengthMap, DefDistMapTraits<T> > Create; 284 }; 278 285 279 286 template <class T> … … 285 292 /// OperationTraits type 286 293 /// 287 /// \ref named-templ-param "Named parameter" for setting PredMap type 294 /// \ref named-templ-param "Named parameter" for setting 295 /// OperationTraits type 288 296 template <class T> 289 class DefOperationTraits 290 : public Johnson< Graph, LengthMap, DefOperationTraitsTraits<T> > {}; 297 struct DefOperationTraits 298 : public Johnson< Graph, LengthMap, DefOperationTraitsTraits<T> > { 299 typedef Johnson< Graph, LengthMap, DefOperationTraitsTraits<T> > Create; 300 }; 291 301 292 302 ///@} 303 304 protected: 305 306 Johnson() {} 293 307 294 308 public: … … 375 389 /// - The distance between each node pairs. 376 390 void start() { 377 type name BelmannFord<Graph, LengthMap>::391 typedef typename BelmannFord<Graph, LengthMap>:: 378 392 template DefOperationTraits<OperationTraits>:: 379 BelmannFord belmannford(*graph, *length); 393 template DefPredMap<NullMap<Node, Edge> >:: 394 Create BelmannFordType; 395 396 BelmannFordType belmannford(*graph, *length); 397 398 NullMap<Node, Edge> predMap; 399 400 belmannford.predMap(predMap); 380 401 381 belmannford.init(); 382 383 typename Graph::template NodeMap<bool> initial(*graph, false); 384 385 { 386 Dfs<Graph> dfs(*graph); 387 388 dfs.init(); 389 for (NodeIt it(*graph); it != INVALID; ++it) { 390 if (!dfs.reached(it)) { 391 dfs.addSource(it); 392 while (!dfs.emptyQueue()) { 393 Edge edge = dfs.processNextEdge(); 394 initial.set(graph->target(edge), false); 395 } 396 initial.set(it, true); 397 } 398 } 399 for (NodeIt it(*graph); it != INVALID; ++it) { 400 if (initial[it]) { 401 belmannford.addSource(it); 402 } 403 } 404 } 405 402 belmannford.init(OperationTraits::zero()); 406 403 belmannford.start(); 407 404 408 405 for (NodeIt it(*graph); it != INVALID; ++it) { 409 406 typedef PotentialDifferenceMap<Graph, 410 typename BelmannFord <Graph, LengthMap>::DistMap> PotDiffMap;407 typename BelmannFordType::DistMap> PotDiffMap; 411 408 PotDiffMap potdiff(*graph, belmannford.distMap()); 412 409 typedef SubMap<LengthMap, PotDiffMap> ShiftLengthMap;
Note: See TracChangeset
for help on using the changeset viewer.