1274 |
1274 |
1275 ///\ingroup graph_adaptors |
1275 ///\ingroup graph_adaptors |
1276 /// |
1276 /// |
1277 /// \brief An undirected graph is made from a directed graph by an adaptor |
1277 /// \brief An undirected graph is made from a directed graph by an adaptor |
1278 /// |
1278 /// |
1279 /// Undocumented, untested!!! |
1279 /// This adaptor makes an undirected graph from a directed |
1280 /// If somebody knows nice demo application, let's polulate it. |
1280 /// graph. All edge of the underlying will be showed in the adaptor |
|
1281 /// as an undirected edge. Let's see an informal example about using |
|
1282 /// this adaptor: |
|
1283 /// |
|
1284 /// There is a network of the streets of a town. Of course there are |
|
1285 /// some one-way street in the town hence the network is a directed |
|
1286 /// one. There is a crazy driver who go oppositely in the one-way |
|
1287 /// street without moral sense. Of course he can pass this streets |
|
1288 /// slower than the regular way, in fact his speed is half of the |
|
1289 /// normal speed. How long should he drive to get from a source |
|
1290 /// point to the target? Let see the example code which calculate it: |
|
1291 /// |
|
1292 ///\code |
|
1293 /// typedef UndirGraphAdaptor<Graph> UGraph; |
|
1294 /// UGraph ugraph(graph); |
|
1295 /// |
|
1296 /// typedef SimpleMap<LengthMap> FLengthMap; |
|
1297 /// FLengthMap flength(length); |
|
1298 /// |
|
1299 /// typedef ScaleMap<LengthMap> RLengthMap; |
|
1300 /// RLengthMap rlength(length, 2.0); |
|
1301 /// |
|
1302 /// typedef UGraph::CombinedEdgeMap<FLengthMap, RLengthMap > ULengthMap; |
|
1303 /// ULengthMap ulength(flength, rlength); |
1281 /// |
1304 /// |
1282 /// \author Marton Makai |
1305 /// Dijkstra<UGraph, ULengthMap> dijkstra(ugraph, ulength); |
|
1306 /// std::cout << "Driving time : " << dijkstra.run(src, trg) << std::endl; |
|
1307 ///\endcode |
|
1308 /// |
|
1309 /// The combined edge map makes the length map for the undirected |
|
1310 /// graph. It is created from a forward and reverse map. The forward |
|
1311 /// map is created from the original length map with a SimpleMap |
|
1312 /// adaptor which just makes a read-write map from the reference map |
|
1313 /// i.e. it forgets that it can be return reference to values. The |
|
1314 /// reverse map is just the scaled original map with the ScaleMap |
|
1315 /// adaptor. The combination solves that passing the reverse way |
|
1316 /// takes double time than the original. To get the driving time we |
|
1317 /// run the dijkstra algorithm on the undirected graph. |
|
1318 /// |
|
1319 /// \author Marton Makai and Balazs Dezso |
1283 template<typename _Graph> |
1320 template<typename _Graph> |
1284 class UndirGraphAdaptor : public AlterableUndirGraphAdaptor<_Graph> { |
1321 class UndirGraphAdaptor : public AlterableUndirGraphAdaptor<_Graph> { |
1285 public: |
1322 public: |
1286 typedef _Graph Graph; |
1323 typedef _Graph Graph; |
1287 typedef AlterableUndirGraphAdaptor<_Graph> Parent; |
1324 typedef AlterableUndirGraphAdaptor<_Graph> Parent; |
1288 protected: |
1325 protected: |
1289 UndirGraphAdaptor() { } |
1326 UndirGraphAdaptor() { } |
1290 public: |
1327 public: |
|
1328 |
|
1329 /// \brief Constructor |
|
1330 /// |
|
1331 /// Constructor |
1291 UndirGraphAdaptor(_Graph& _graph) { |
1332 UndirGraphAdaptor(_Graph& _graph) { |
1292 setGraph(_graph); |
1333 setGraph(_graph); |
1293 } |
1334 } |
1294 |
1335 |
|
1336 /// \brief EdgeMap combined from two original EdgeMap |
|
1337 /// |
|
1338 /// This class adapts two original graph EdgeMap to |
|
1339 /// get an edge map on the adaptor. |
1295 template <typename _ForwardMap, typename _BackwardMap> |
1340 template <typename _ForwardMap, typename _BackwardMap> |
1296 class CombinedEdgeMap { |
1341 class CombinedEdgeMap { |
1297 public: |
1342 public: |
1298 |
1343 |
1299 typedef _ForwardMap ForwardMap; |
1344 typedef _ForwardMap ForwardMap; |
1301 |
1346 |
1302 typedef typename MapTraits<ForwardMap>::ReferenceMapTag ReferenceMapTag; |
1347 typedef typename MapTraits<ForwardMap>::ReferenceMapTag ReferenceMapTag; |
1303 |
1348 |
1304 typedef typename ForwardMap::Value Value; |
1349 typedef typename ForwardMap::Value Value; |
1305 typedef typename Parent::Edge Key; |
1350 typedef typename Parent::Edge Key; |
1306 |
1351 |
|
1352 /// \brief Constructor |
|
1353 /// |
|
1354 /// Constructor |
1307 CombinedEdgeMap() : forward_map(0), backward_map(0) {} |
1355 CombinedEdgeMap() : forward_map(0), backward_map(0) {} |
1308 |
1356 |
|
1357 /// \brief Constructor |
|
1358 /// |
|
1359 /// Constructor |
1309 CombinedEdgeMap(ForwardMap& _forward_map, BackwardMap& _backward_map) |
1360 CombinedEdgeMap(ForwardMap& _forward_map, BackwardMap& _backward_map) |
1310 : forward_map(&_forward_map), backward_map(&_backward_map) {} |
1361 : forward_map(&_forward_map), backward_map(&_backward_map) {} |
1311 |
1362 |
|
1363 |
|
1364 /// \brief Sets the value associated with a key. |
|
1365 /// |
|
1366 /// Sets the value associated with a key. |
1312 void set(const Key& e, const Value& a) { |
1367 void set(const Key& e, const Value& a) { |
1313 if (Parent::direction(e)) { |
1368 if (Parent::direction(e)) { |
1314 forward_map->set(e, a); |
1369 forward_map->set(e, a); |
1315 } else { |
1370 } else { |
1316 backward_map->set(e, a); |
1371 backward_map->set(e, a); |
1317 } |
1372 } |
1318 } |
1373 } |
1319 |
1374 |
|
1375 /// \brief Returns the value associated with a key. |
|
1376 /// |
|
1377 /// Returns the value associated with a key. |
1320 typename MapTraits<ForwardMap>::ConstReturnValue |
1378 typename MapTraits<ForwardMap>::ConstReturnValue |
1321 operator[](const Key& e) const { |
1379 operator[](const Key& e) const { |
1322 if (Parent::direction(e)) { |
1380 if (Parent::direction(e)) { |
1323 return (*forward_map)[e]; |
1381 return (*forward_map)[e]; |
1324 } else { |
1382 } else { |
1325 return (*backward_map)[e]; |
1383 return (*backward_map)[e]; |
1326 } |
1384 } |
1327 } |
1385 } |
1328 |
1386 |
|
1387 /// \brief Returns the value associated with a key. |
|
1388 /// |
|
1389 /// Returns the value associated with a key. |
1329 typename MapTraits<ForwardMap>::ReturnValue |
1390 typename MapTraits<ForwardMap>::ReturnValue |
1330 operator[](const Key& e) { |
1391 operator[](const Key& e) { |
1331 if (Parent::direction(e)) { |
1392 if (Parent::direction(e)) { |
1332 return (*forward_map)[e]; |
1393 return (*forward_map)[e]; |
1333 } else { |
1394 } else { |
1334 return (*backward_map)[e]; |
1395 return (*backward_map)[e]; |
1335 } |
1396 } |
1336 } |
1397 } |
1337 |
1398 |
|
1399 /// \brief Sets the forward map |
|
1400 /// |
|
1401 /// Sets the forward map |
1338 void setForwardMap(ForwardMap& _forward_map) { |
1402 void setForwardMap(ForwardMap& _forward_map) { |
1339 forward_map = &_forward_map; |
1403 forward_map = &_forward_map; |
1340 } |
1404 } |
1341 |
1405 |
|
1406 /// \brief Sets the backward map |
|
1407 /// |
|
1408 /// Sets the backward map |
1342 void setBackwardMap(BackwardMap& _backward_map) { |
1409 void setBackwardMap(BackwardMap& _backward_map) { |
1343 backward_map = &_backward_map; |
1410 backward_map = &_backward_map; |
1344 } |
1411 } |
1345 |
1412 |
1346 protected: |
1413 protected: |