There is a network of the streets of a town. Of course there are some one-way street in the town hence the network is a directed one. There is a crazy driver who go oppositely in the one-way street without moral sense. Of course he can pass this streets slower than the regular way, in fact his speed is half of the normal speed. How long should he drive to get from a source point to the target? Let see the example code which calculate it:
typedef UndirGraphAdaptor<Graph> UGraph; UGraph ugraph(graph); typedef SimpleMap<LengthMap> FLengthMap; FLengthMap flength(length); typedef ScaleMap<LengthMap> RLengthMap; RLengthMap rlength(length, 2.0); typedef UGraph::CombinedEdgeMap<FLengthMap, RLengthMap > ULengthMap; ULengthMap ulength(flength, rlength); Dijkstra<UGraph, ULengthMap> dijkstra(ugraph, ulength); std::cout << "Driving time : " << dijkstra.run(src, trg) << std::endl;
The combined edge map makes the length map for the undirected graph. It is created from a forward and reverse map. The forward map is created from the original length map with a SimpleMap adaptor which just makes a read-write map from the reference map i.e. it forgets that it can be return reference to values. The reverse map is just the scaled original map with the ScaleMap adaptor. The combination solves that passing the reverse way takes double time than the original. To get the driving time we run the dijkstra algorithm on the undirected graph.
#include <lemon/graph_adaptor.h>
Inherits lemon::AlterableUndirGraphAdaptor<_Graph>.
Classes | |
class | CombinedEdgeMap |
EdgeMap combined from two original EdgeMap. More... | |
Public Member Functions | |
UndirGraphAdaptor (_Graph &_graph) | |
Constructor. |
UndirGraphAdaptor | ( | _Graph & | _graph | ) | [inline] |
Constructor