src/demo/min_route.cc
changeset 1374 bcfa3980b432
parent 1342 e335eebdae5b
child 1394 f0c48d7fa73d
equal deleted inserted replaced
0:9f3f30de0868 1:66167fae9bb0
       
     1 #include <iostream>
       
     2 #include <fstream>
       
     3 
     1 #include <lemon/smart_graph.h>
     4 #include <lemon/smart_graph.h>
     2 #include <lemon/dijkstra.h>
     5 #include <lemon/dijkstra.h>
     3 #include <lemon/maps.h>
     6 #include <lemon/maps.h>
     4 #include <lemon/xy.h>
     7 #include <lemon/xy.h>
     5 #include <lemon/graph_reader.h>
     8 #include <lemon/graph_reader.h>
     6 
     9 
     7 #include <lemon/time_measure.h>
    10 #include <lemon/time_measure.h>
     8 
    11 
     9 #include <cmath>
    12 #include <cmath>
       
    13 
    10 
    14 
    11 using namespace lemon;
    15 using namespace lemon;
    12 
    16 
    13 template <typename CoordMap>
    17 template <typename CoordMap>
    14 class PotentialMap {
    18 class PotentialMap {
    22   double operator[](const Key& node) const {
    26   double operator[](const Key& node) const {
    23     return std::sqrt((coord[node].x - target.x) * (coord[node].x - target.x) + 
    27     return std::sqrt((coord[node].x - target.x) * (coord[node].x - target.x) + 
    24 		     (coord[node].y - target.y) * (coord[node].y - target.y));
    28 		     (coord[node].y - target.y) * (coord[node].y - target.y));
    25   }
    29   }
    26 private:
    30 private:
       
    31   const CoordMap& coord;
    27   xy<double> target;
    32   xy<double> target;
    28   const CoordMap& coord;
       
    29 };
    33 };
    30 
    34 
    31 template <typename Graph, typename LengthMap, typename PotentialMap>
    35 template <typename Graph, typename LengthMap, typename PotentialMap>
    32 class ReducedLengthMap {
    36 class ReducedLengthMap {
    33 public:
    37 public:
    58   typedef Graph::EdgeMap<double> LengthMap;
    62   typedef Graph::EdgeMap<double> LengthMap;
    59   typedef Graph::NodeMap<xy<double> > CoordMap;
    63   typedef Graph::NodeMap<xy<double> > CoordMap;
    60 
    64 
    61   SmartGraph graph;
    65   SmartGraph graph;
    62 
    66 
    63   GraphReader<Graph> reader(std::cin, graph);
    67   std::ifstream is("route.lgf");
       
    68   GraphReader<Graph> reader(is, graph);
    64   
    69   
    65   CoordMap coord(graph);
    70   CoordMap coord(graph);
    66   XMap<CoordMap> xcoord = xMap(coord);
    71   XMap<CoordMap> xcoord = xMap(coord);
    67   reader.addNodeMap("coordinates_x", xcoord);
    72   reader.addNodeMap("coordinates_x", xcoord);
    68   YMap<CoordMap> ycoord = yMap(coord);
    73   YMap<CoordMap> ycoord = yMap(coord);