1.1 --- a/src/demo/min_route.cc Sat May 21 21:04:57 2005 +0000
1.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000
1.3 @@ -1,114 +0,0 @@
1.4 -#include <iostream>
1.5 -#include <fstream>
1.6 -
1.7 -#include <lemon/smart_graph.h>
1.8 -#include <lemon/dijkstra.h>
1.9 -#include <lemon/maps.h>
1.10 -#include <lemon/xy.h>
1.11 -#include <lemon/graph_reader.h>
1.12 -
1.13 -#include <lemon/time_measure.h>
1.14 -
1.15 -#include <cmath>
1.16 -
1.17 -
1.18 -using namespace lemon;
1.19 -
1.20 -template <typename CoordMap>
1.21 -class PotentialMap {
1.22 -public:
1.23 - typedef double Value;
1.24 - typedef typename CoordMap::Key Key;
1.25 -
1.26 - PotentialMap(const CoordMap& _coord, const xy<double>& _target)
1.27 - : coord(_coord), target(_target) {}
1.28 -
1.29 - double operator[](const Key& node) const {
1.30 - return std::sqrt((coord[node].x - target.x) * (coord[node].x - target.x) +
1.31 - (coord[node].y - target.y) * (coord[node].y - target.y));
1.32 - }
1.33 -private:
1.34 - const CoordMap& coord;
1.35 - xy<double> target;
1.36 -};
1.37 -
1.38 -template <typename Graph, typename LengthMap, typename PotentialMap>
1.39 -class ReducedLengthMap {
1.40 -public:
1.41 - typedef double Value;
1.42 - typedef typename LengthMap::Key Key;
1.43 -
1.44 - ReducedLengthMap(const Graph& _graph, const LengthMap& _length,
1.45 - const PotentialMap& _pot)
1.46 - : graph(_graph), length(_length), pot(_pot) {}
1.47 -
1.48 - Value operator[](const Key& edge) const {
1.49 - return length[edge] - (pot[graph.source(edge)] - pot[graph.target(edge)]);
1.50 - }
1.51 -
1.52 -private:
1.53 - const Graph& graph;
1.54 - const LengthMap& length;
1.55 - const PotentialMap& pot;
1.56 -};
1.57 -
1.58 -int main() {
1.59 - typedef SmartGraph Graph;
1.60 -
1.61 - typedef Graph::Edge Edge;
1.62 - typedef Graph::Node Node;
1.63 - typedef Graph::EdgeIt EdgeIt;
1.64 - typedef Graph::NodeIt NodeIt;
1.65 - typedef Graph::EdgeMap<double> LengthMap;
1.66 - typedef Graph::NodeMap<xy<double> > CoordMap;
1.67 -
1.68 - SmartGraph graph;
1.69 -
1.70 - std::ifstream is("route.lgf");
1.71 - GraphReader<Graph> reader(is, graph);
1.72 -
1.73 - CoordMap coord(graph);
1.74 - XMap<CoordMap> xcoord = xMap(coord);
1.75 - reader.readNodeMap("coordinates_x", xcoord);
1.76 - YMap<CoordMap> ycoord = yMap(coord);
1.77 - reader.readNodeMap("coordinates_y", ycoord);
1.78 -
1.79 - LengthMap length(graph);
1.80 - reader.readEdgeMap("length", length);
1.81 -
1.82 - Node source, target;
1.83 - reader.readNode("source", source);
1.84 - reader.readNode("target", target);
1.85 -
1.86 - reader.run();
1.87 -
1.88 - {
1.89 - Timer timer;
1.90 - Dijkstra<Graph, LengthMap> dijkstra(graph, length);
1.91 - dijkstra.init();
1.92 - dijkstra.addSource(source);
1.93 - dijkstra.start(target);
1.94 -
1.95 - std::cout << dijkstra.dist(target) << std::endl;
1.96 - std::cout << timer << std::endl;
1.97 - }
1.98 - {
1.99 - Timer timer;
1.100 - typedef PotentialMap<CoordMap> Potential;
1.101 - Potential potential(coord, coord[target]);
1.102 -
1.103 - typedef ReducedLengthMap<Graph, LengthMap, Potential> ReducedLength;
1.104 - ReducedLength reduced(graph, length, potential);
1.105 -
1.106 - Dijkstra<Graph, ReducedLength> dijkstra(graph, reduced);
1.107 -
1.108 - dijkstra.init();
1.109 - dijkstra.addSource(source);
1.110 - dijkstra.start(target);
1.111 -
1.112 - std::cout << dijkstra.dist(target) + potential[source] << std::endl;
1.113 - std::cout << timer << std::endl;
1.114 - }
1.115 -
1.116 - return 0;
1.117 -}