Skip to content
This repository
Browse code

Reverted the bad commit c258432

  • Loading branch information...
commit 01dec404fb948258f3deb9d7d5c45cd120652c5d 1 parent 521c151
Tristram Gräbener Tristramg authored
7 ch/Makefile
... ... @@ -1,5 +1,5 @@
1   -ch: main.o bench.o test.o dijkstra.o contraction.o query.o tsaggouris.o
2   - g++ -o ch main.o bench.o test.o dijkstra.o contraction.o query.o tsaggouris.o -lpqxx -Wall -lboost_serialization
  1 +ch: main.o bench.o test.o dijkstra.o contraction.o query.o
  2 + g++ -o ch main.o bench.o test.o dijkstra.o contraction.o query.o -lpqxx -Wall -lboost_serialization
3 3
4 4 main.o: main.cc
5 5 g++ -O3 -Wall -o main.o -c main.cc
@@ -16,8 +16,5 @@ dijkstra.o: dijkstra.cc
16 16 contraction.o: contraction.cc
17 17 g++ -O3 -Wall -o contraction.o -c contraction.cc
18 18
19   -tsaggouris.o: tsaggouris.cc
20   - g++ -O3 -Wall -o tsaggouris.o -c tsaggouris.cc
21   -
22 19 query.o: query.cc
23 20 g++ -O3 -Wall -o query.o -c query.cc
34 ch/bench.cc
... ... @@ -1,6 +1,6 @@
1 1 #include "dijkstra.h"
2 2 #include "query.h"
3   -#include "tsaggouris.h"
  3 +
4 4 #include <boost/graph/dijkstra_shortest_paths.hpp>
5 5
6 6 struct found_goal{};
@@ -58,14 +58,14 @@ void bench(Graph & g, Graph & gc)
58 58 boost::progress_timer t;
59 59 for(int i=0; i < runs; i++)
60 60 {
61   - query_mono(starts[i], dests[i], gc.graph);
  61 + //query_mono(starts[i], dests[i], gc.graph);
62 62 }
63 63 }
64 64 }
65 65
66 66 void martins_bench(Graph & g, Graph & gc)
67 67 {
68   - int runs = 100;
  68 + int runs = 10;
69 69 std::vector<int> starts(runs);
70 70 std::vector<int> dests(runs);
71 71 for(int i=0; i < runs; i++)
@@ -77,7 +77,7 @@ void martins_bench(Graph & g, Graph & gc)
77 77 boost::progress_timer t;
78 78 for(int i=0; i < runs; i++)
79 79 {
80   - martins(starts[i], dests[i], g);
  80 + //martins(starts[i], dests[i], g);
81 81 }
82 82 }
83 83
@@ -90,29 +90,3 @@ void martins_bench(Graph & g, Graph & gc)
90 90 }
91 91
92 92 }
93   -
94   -void tsaggouris_bench(Graph & g)
95   -{
96   - int runs = 10;
97   - std::vector<int> starts(runs);
98   - for(int i=0; i < runs; i++)
99   - {
100   - starts[i] = rand() % boost::num_vertices(g.graph);
101   - }
102   - {
103   - boost::progress_timer t;
104   - for(int i=0; i < runs; i++)
105   - {
106   - martins_all(starts[i], g);
107   - }
108   - }
109   -
110   - {
111   - boost::progress_timer t;
112   - for(int i=0; i < runs; i++)
113   - {
114   - ssmosp(g, starts[i]);
115   - }
116   - }
117   -
118   -}
1  ch/graph.h
@@ -79,7 +79,6 @@ struct Graph
79 79 typedef boost::adjacency_list<boost::listS, boost::vecS, boost::bidirectionalS, Node, Edge > Type;
80 80 typedef boost::graph_traits<Type>::edge_descriptor edge_t;
81 81 typedef boost::graph_traits<Type>::vertex_descriptor node_t;
82   - typedef boost::graph_traits<Type>::edge_iterator edge_iterator;
83 82
84 83 struct inc_order
85 84 {
15 ch/main.cc
@@ -8,7 +8,6 @@
8 8
9 9 void bench(Graph & g, Graph & gc);
10 10 void martins_bench(Graph & g, Graph & gc);
11   -void tsaggouris_bench(Graph & g);
12 11 void test(Graph & g, Graph & gc);
13 12 float secu(int cat, int length)
14 13 {
@@ -26,7 +25,7 @@ float secu(int cat, int length)
26 25
27 26 int main(int, char** argv)
28 27 {
29   - /* Graph g;
  28 +/* Graph g;
30 29 std::map<int, int> map;
31 30 pqxx::connection Conn("dbname=mumoro");
32 31
@@ -56,12 +55,12 @@ int main(int, char** argv)
56 55 g.add_edge(map[source], map[destination], edge_prop);
57 56 // g.add_edge(map[destination], map[source], edge_prop);
58 57 ++show_progress;
59   - }
60   - g.save("paris_original");
  58 + }*/
  59 +/* g.save("paris_original");
61 60 Graph gc(g);
62 61 gc.contract();
63   - gc.save("paris_ch");*/
64   -
  62 + gc.save("paris_ch");
  63 + */
65 64 // 51937 nodes
66 65 // 619894 edges
67 66
@@ -75,7 +74,7 @@ int main(int, char** argv)
75 74 // 619894 edges
76 75
77 76 Graph g("paris_original");
78   - //Graph gc("paris_ch");
  77 + Graph gc("paris_ch");
79 78 /* gc.split();
80 79 gc.save("paris_ch");*/
81 80 // Graph gc(g);
@@ -86,7 +85,7 @@ int main(int, char** argv)
86 85
87 86 //test(g,gc);
88 87 // bench(g, gc);
89   - tsaggouris_bench(g);
  88 + martins_bench(g, gc);
90 89
91 90
92 91 }
61 ch/query.cc
@@ -157,65 +157,6 @@ bool martins(Graph::node_t start_node, Graph::node_t dest_node, const Graph & g)
157 157 return false;
158 158 }
159 159
160   -// Algo de martins sur le graphe normal, vers tous les nœuds
161   -bool martins_all(Graph::node_t start_node, const Graph & g)
162   -{
163   - my_queue::Type Q;
164   - std::vector< std::deque<Label> > P(num_vertices(g.graph));
165   -
166   - Label start;
167   - start.node = start_node;
168   - for(int i=0; i < Graph::objectives; i++)
169   - start.cost[i] = 0;
170   -
171   - Q.insert(start);
172   - const my_queue::by_cost cost_q_it = Q.get<0>();
173   - const my_queue::by_nodes node_q = Q.get<1>();
174   -
175   - int visited = 0;
176   - while( !Q.empty() )
177   - {
178   - Label l = *(cost_q_it.begin());
179   - visited++;
180   - P[l.node].push_back(l);
181   - // std::cout << "Label! node=" << l.node << " [" << l.cost[0] << "," << l.cost[1] << "]" << std::endl;
182   - Q.erase(cost_q_it.begin());
183   - BOOST_FOREACH(Graph::edge_t e, out_edges(l.node, g.graph))
184   - {
185   - Label l2;
186   - l2.node = boost::target(e, g.graph);
187   - for(int i=0; i < Graph::objectives; i++)
188   - l2.cost[i] = l.cost[i] + g[e].cost[i];
189   -
190   - if(!is_dominated_by_any(node_q.equal_range(l2.node), l2) && !is_dominated_by_any(P[l2.node],l2) )
191   - {
192   - my_queue::nodes_it it, end;
193   - tie(it, end) = node_q.equal_range(l2.node);
194   - while(it != end)
195   - {
196   - if(Graph::dominates(l2.cost, it->cost) || l2.cost == it->cost)
197   - it = Q.get<1>().erase(it);
198   - else
199   - {
200   - it++;
201   - }
202   - }
203   - Q.insert(l2);
204   - }
205   - }
206   - }
207   -
208   - size_t total = 0;
209   - for(int n = 0; n<boost::num_vertices(g.graph); n++)
210   - {
211   - total += P[n].size();
212   - }
213   -
214   - std::cout << "Number of elements found " << total << std::endl;
215   - return false;
216   -}
217   -
218   -
219 160 // Algo de martins dans un graphe CH
220 161 // On maintient une liste de couts réalisables trouvés
221 162 // À la création d'un nouveau label, on vérifie qu'il n'est pas dominé par aucun label des couts réalisables
@@ -256,7 +197,7 @@ bool ch_martins(Graph::node_t start_node, Graph::node_t dest_node, const Graph &
256 197 Q1.insert(start);
257 198 Q2.insert(dest);
258 199
259   - while(!Q1.empty() || !Q2.empty())
  200 + while(!Q1.empty() && !Q2.empty())
260 201 {
261 202 if(!Q1.empty())
262 203 {
1  ch/query.h
@@ -29,7 +29,6 @@ struct Path
29 29 std::list<Path> query(Graph::node_t source, Graph::node_t target, const Graph::Type & graph);
30 30
31 31 bool martins(Graph::node_t start_node, Graph::node_t dest_node, const Graph & g);
32   -bool martins_all(Graph::node_t start_node, const Graph & g);
33 32 bool ch_martins(Graph::node_t start_node, Graph::node_t dest_node, const Graph & g);
34 33 bool martins_witness(Graph::node_t start_node, Graph::node_t dest_node, Graph::cost_t cost, const Graph::Type & g);
35 34 #endif
8 lib/CMakeLists.txt
@@ -2,6 +2,8 @@ CMAKE_MINimum_required(VERSION 2.6)
2 2
3 3 SET( CMAKE_BUILD_TYPE DEBUG )
4 4
  5 +FIND_LIBRARY(PQXX pqxx /opt/local/lib)
  6 +
5 7 find_package(Boost COMPONENTS graph REQUIRED)
6 8 FIND_PACKAGE(PythonLibs REQUIRED)
7 9 INCLUDE_DIRECTORIES(${PYTHON_INCLUDE_PATH})
@@ -9,10 +11,10 @@ INCLUDE_DIRECTORIES(${PYTHON_INCLUDE_PATH})
9 11
10 12 include_directories(${Boost_INCLUDE_DIRS})
11 13
12   -ADD_DEFINITIONS( -O3 -Wall -fPIC -Wno-deprecated)
  14 +ADD_DEFINITIONS( -O3 -Wall -Wno-deprecated)
13 15
14   -ADD_LIBRARY(mum_lib martins.cpp graph_wrapper.cpp)
15   -TARGET_LINK_LIBRARIES(mum_lib)
  16 +ADD_LIBRARY(mum_lib martins.cpp tsaggouris.cpp graph_wrapper.cpp)
  17 +TARGET_LINK_LIBRARIES(mum_lib ${PQXX})
16 18
17 19 #ADD_EXECUTABLE(mum_test main.cpp )
18 20 #TARGET_LINK_LIBRARIES(mum_test mum_lib)
9 lib/README.CONFIG.txt
... ... @@ -0,0 +1,9 @@
  1 +Delete first line, replace values and save file as config.cfg
  2 +[DBSettings]
  3 +DBName: mumoroRE
  4 +DBUser: root
  5 +DBPassword: test
  6 +DBHost: localhost
  7 +DBTableNodes: nodes
  8 +DBTableEdges: edges
  9 +
26 lib/benchmark.py
@@ -3,9 +3,9 @@
3 3 import time
4 4 import random
5 5
6   -foot = layer.Layer('foot', mumoro.Foot, {'nodes': 'sf_nodes_ch4', 'edges': 'sf_edges_ch4'})
7   -bike = layer.Layer('bike', mumoro.Bike, {'nodes': 'sf_nodes_ch4', 'edges': 'sf_edges_ch4'})
8   -pt = layer.GTFSLayer('muni', 'pt2')
  6 +foot = layer.Layer('foot', mumoro.Foot, {'nodes': 'sf_nodes', 'edges': 'sf_edges'})
  7 +bike = layer.Layer('bike', mumoro.Bike, {'nodes': 'sf_nodes', 'edges': 'sf_edges'})
  8 +pt = layer.GTFSLayer('muni', 'pt')
9 9 g = layer.MultimodalGraph([foot, pt, bike])
10 10
11 11 e = mumoro.Edge()
@@ -17,22 +17,17 @@
17 17 g.connect_nearest_nodes(pt, foot, e, e2)
18 18
19 19 g.connect_nearest_nodes(bike, foot, e)
20   -#g.connect_nearest_nodes(bike, pt, e)
21 20
22 21 random.seed(time.clock())
23 22 found = 0
24 23 comp = []
25   -runs = 2
26   -
27   -found = 0
28 24
  25 +runs = 10
29 26 for x in range(runs):
30 27 s = random.randint(0, bike.count - 1) + bike.offset
31 28 t = random.randint(0, foot.count - 1)
32 29 comp.append((s,t))
33 30
34   -
35   -
36 31 found = 0
37 32 start = time.clock()
38 33 for (s,t) in comp:
@@ -45,11 +40,7 @@
45 40 p = mumoro.relaxed_martins(s, t, g.graph, 30000, mumoro.mode_change, 120)
46 41 efound += len(p)
47 42 eend = time.clock()
48   -fstart = time.clock()
49   -for (s,t) in comp:
50   - p = mumoro.relaxed_martins(s, -1, g.graph, 30000, mumoro.mode_change, 120)
51   -fend = time.clock()
52   -print "\"t + ms\" {0} {1} {2} {3} ".format(float(found)/runs, float(end - start) * 1000 / runs, float(efound)/runs, float(eend - estart) * 1000 / runs)
  43 +print "t + ms & {0} & {1} & {2} & {3}".format(float(found)/runs, float(end - start) * 1000 / runs, float(efound)/runs, float(eend - estart) * 1000 / runs)
53 44
54 45
55 46 found = 0
@@ -64,7 +55,7 @@
64 55 p = mumoro.relaxed_martins(s, t, g.graph, 30000, mumoro.mode_change, 120, mumoro.line_change, 60)
65 56 efound += len(p)
66 57 eend = time.clock()
67   -print "\"t + ms + ls\" {0} {1} {2} {3}".format(float(found)/runs, float(end - start) * 1000 / runs, float(efound)/runs, float(eend - estart) * 1000 / runs)
  58 +print "t + ms + ls & {0} & {1} & {2} & {3}".format(float(found)/runs, float(end - start) * 1000 / runs, float(efound)/runs, float(eend - estart) * 1000 / runs)
68 59
69 60
70 61 found = 0
@@ -79,7 +70,7 @@
79 70 p = mumoro.relaxed_martins(s, t, g.graph, 30000, mumoro.elevation, 10)
80 71 efound += len(p)
81 72 eend = time.clock()
82   -print "\"t + a\" {0} {1} {2} {3}".format(float(found)/runs, float(end - start) * 1000 / runs, float(efound)/runs, float(eend - estart) * 1000 / runs)
  73 +print "t + a & {0} & {1} & {2} & {3}".format(float(found)/runs, float(end - start) * 1000 / runs, float(efound)/runs, float(eend - estart) * 1000 / runs)
83 74
84 75
85 76 found = 0
@@ -94,6 +85,7 @@
94 85 p = mumoro.relaxed_martins(s, t, g.graph, 30000, mumoro.elevation, 10, mumoro.line_change, 60, mumoro.mode_change, 120)
95 86 efound += len(p)
96 87 eend = time.clock()
97   -print "\"t + a + ms + ls\" {0} {1} {2} {3}".format(float(found)/runs, float(end - start) * 1000 / runs, float(efound)/runs, float(eend - estart) * 1000 / runs)
  88 +print "t + a + ms + ls& {0} & {1} & {2} & {3}".format(float(found)/runs, float(end - start) * 1000 / runs, float(efound)/runs, float(eend - estart) * 1000 / runs)
  89 +
98 90
99 91
208 lib/graph_wrapper.cpp
... ... @@ -1,12 +1,8 @@
1 1 #include "graph_wrapper.h"
2 2 #include <iostream>
3 3 #include <boost/graph/dijkstra_shortest_paths.hpp>
4   -#include <boost/graph/astar_search.hpp>
5   -#include <math.h> // for sqrt
6 4
7   -using namespace boost;
8   -
9   -Edge::Edge() : distance(0), elevation(0), mode_change(0), cost(0), line_change(0), co2(0)
  5 +Edge::Edge() : distance(0), elevation(0), mode_change(0), cost(0), line_change(0)
10 6 {
11 7 }
12 8
@@ -32,11 +28,7 @@ float Duration::operator()(float start) const
32 28 if (it->first >= start)
33 29 return it->second;
34 30 }
35   - //it = timetable.lower_bound(start);
36   - //if(it->first >= start)
37   - // return it->second;
38   - //else
39   - return (start / (24*3600) + 1) * 24*3600 + timetable.begin()->second;
  31 + return (start / (24*3600) + 1) * 24*3600 + timetable.begin()->second;
40 32 }
41 33 }
42 34
@@ -45,14 +37,6 @@ Graph::Graph(int nb_nodes) : g(nb_nodes)
45 37 {
46 38 }
47 39
48   -void Graph::set_coord(int node, float x, float y)
49   -{
50   - Node n;
51   - n.x = x;
52   - n.y = y;
53   - g[node] = n;
54   -}
55   -
56 40 void Graph::add_edge(int source, int target, const Edge & e)
57 41 {
58 42 boost::add_edge(source, target, e, g);
@@ -76,47 +60,24 @@ bool Graph::public_transport_edge(int source, int target, float start, float arr
76 60 }; // exception for termination
77 61
78 62 // visitor that terminates when we find the goal
79   -int visited;
80 63
81   -class dijkstra_goal_visitor : public boost::default_dijkstra_visitor
82   -{
83   - public:
84   -
85   - dijkstra_goal_visitor(int goal) : m_goal(goal)
86   - {
87   - }
88   -
89   - template <class Graph_t>
90   - void examine_vertex(int u, Graph_t&)
91   - {
92   - visited++;
93   - if (u == m_goal)
94   - {
95   - throw found_goal();
96   - }
97   - }
98   - private:
99   - int m_goal;
100   -};
101   -
102   -
103   -// visitor that terminates when we find the goal
104   -class astar_goal_visitor : public boost::default_astar_visitor
105   -{
106   - public:
107   - astar_goal_visitor(int goal) : m_goal(goal) {}
108   - template <class Graph_t>
109   - void examine_vertex(int u, Graph_t& g) {
110   - visited++;
111   - if(u == m_goal)
112   - {
113   - throw found_goal();
  64 + class dijkstra_goal_visitor : public boost::default_dijkstra_visitor
  65 + {
  66 + public:
  67 +
  68 + dijkstra_goal_visitor(int goal) : m_goal(goal)
  69 + {
  70 + }
  71 +
  72 + template <class Graph_t>
  73 + void examine_vertex(int u, Graph_t& g)
  74 + {
  75 + if (u == m_goal)
  76 + throw found_goal();
114 77 }
115   - }
116   - private:
117   - int m_goal;
118   -};
119   -
  78 + private:
  79 + int m_goal;
  80 + };
120 81
121 82 float calc_duration(float in, Duration d)
122 83 {
@@ -129,128 +90,25 @@ struct Comp
129 90 bool operator()(const Duration &, float) const {return false;}
130 91 };
131 92
132   -int Graph::dijkstra(int source, int target)
  93 +bool Graph::dijkstra(int source, int target)
133 94 {
134   - visited = 0;
  95 + std::vector<int> p(boost::num_vertices(g));
135 96 std::vector<float> d(boost::num_vertices(g));
136   - dijkstra_goal_visitor vis(target);
137   - if(target >= 0)
138   - {
139   - try{
140   - boost::dijkstra_shortest_paths(g, source,
141   - boost::distance_map(&d[0])
142   - .weight_map(get(&Edge::duration, g))
143   - .visitor(vis)
144   - .distance_zero(30000)
145   - .distance_combine(&calc_duration)
146   - .distance_compare(Comp())
147   - );
148   - }
149   - catch(found_goal)
150   - {
151   - }
152   - }
153   - else
154   - {
155   - boost::dijkstra_shortest_paths(g, source,
156   - distance_map(&d[0])
157   - .weight_map(get(&Edge::duration, g))
158   - .visitor(vis)
159   - .distance_zero(30000)
160   - .distance_combine(&calc_duration)
161   - .distance_compare(Comp())
162   - );
163   - }
164   - return visited;
165   -}
166   -
167   -
168   -int Graph::dijkstra_dist(int source, int target)
169   -{
170   - visited = 0;
171   - dijkstra_goal_visitor vis(target);
172   - std::vector<float> d(boost::num_vertices(g));
173   - if(target >= 0)
174   - {
175   - try{
176   - boost::dijkstra_shortest_paths(g, source,
177   - distance_map(&d[0])
178   - .weight_map(get(&Edge::distance, g))
179   - .visitor(vis)
180   - );
181   - }
182   - catch(found_goal)
183   - {
184   - }
185   - }
186   - else
187   - {
188   - boost::dijkstra_shortest_paths(g, source,
189   - distance_map(&d[0])
190   - .weight_map(get(&Edge::distance, g))
191   - .visitor(vis)
192   - .distance_zero(30000)
193   - );
194   - }
195   - return visited;
196   -}
197   -
198   -
199   -class distance_heuristic : public astar_heuristic<Graph_t, float>
200   -{
201   - public:
202   - distance_heuristic(Graph & gr, int goal)
203   - : g(gr), m_goal(goal){}
204   - float operator()(int u)
205   - {
206   - return g.distance(u, m_goal) / 16; //environ 55km/h vitesse moyenne du bart
207   - }
208   - private:
209   - Graph & g;
210   - int m_goal;
211   -};
212   -
213   -
214   -int Graph::astar(int source, int target)
215   -{
216   -
217   - visited = 0;
218   - std::vector<float> d(boost::num_vertices(g));
219   - std::vector<float> r(boost::num_vertices(g));
220   - astar_goal_visitor vis(target);
221   - try
222   - {
223   - astar_search
224   - (g, source,
225   - distance_heuristic(*this, target),
226   - distance_map(&d[0])
227   - .rank_map(&r[0])
228   - .visitor(vis)
229   - .weight_map(get(&Edge::duration, g))
230   - .distance_zero(30000)
231   - .distance_combine(&calc_duration)
232   - .distance_compare(Comp())
  97 + try{
  98 + boost::dijkstra_shortest_paths(g, source,
  99 + boost::predecessor_map(&p[0])
  100 + .distance_map(&d[0])
  101 + .weight_map(get(&Edge::duration, g))
  102 +// .visitor(dijkstra_goal_visitor(target))
  103 + .distance_zero(30000)
  104 + .distance_combine(calc_duration)
  105 + .distance_compare(Comp())
233 106 );
  107 + return false;
234 108 }
235 109 catch(found_goal)
236   - {}
237   - return visited;
238   -}
239   -double rad(double deg)
240   -{
241   - return deg * 3.14159265 / 180;
242   -}
243   -
244   -
245   -float Graph::distance(int source, int target)
246   -{
247   - const double r = 6371000;
  110 + {
  111 + return true;
  112 + }
248 113
249   - float lon1 = g[source].x;
250   - float lon2 = g[target].x;
251   - float lat1 = g[source].y;
252   - float lat2 = g[target].y;
253   - return acos( sin( rad(lat1) ) * sin( rad(lat2) ) +
254   - cos( rad(lat1) ) * cos( rad(lat2) ) * cos( rad(lon2-lon1 ) )
255   - ) * r;
256 114 }
9 lib/graph_wrapper.h
@@ -18,8 +18,6 @@ class Duration
18 18
19 19 struct Node
20 20 {
21   - float x;
22   - float y;
23 21 };
24 22
25 23 struct Edge
@@ -30,7 +28,6 @@ struct Edge
30 28 float mode_change;
31 29 float cost;
32 30 float line_change;
33   - float co2;
34 31 Duration duration;
35 32 };
36 33
@@ -42,12 +39,8 @@ struct Graph
42 39 Graph_t g;
43 40 Graph(int nb_nodes);
44 41 void add_edge(int source, int target, const Edge & e);
45   - void set_coord(int node, float x, float y);
46 42 bool public_transport_edge(int source, int target, float start, float arrival);
47   - int dijkstra(int source, int target = -1);
48   - int dijkstra_dist(int source, int target = -1);
49   - int astar(int source, int target);
50   - float distance(int source, int target);
  43 + bool dijkstra(int source, int target);
51 44 };
52 45
53 46 const int invalid_node = -1;
38 lib/layer.py
@@ -36,16 +36,6 @@ def duration(length, property, mode):
36 36 else:
37 37 raise NotAccessible()
38 38
39   -def co2(length, mode):
40   - if mode == mumoro.Foot:
41   - return 0
42   - elif mode == mumoro.Bike:
43   - return 0
44   - elif mode == mumoro.Car:
45   - return length * 0.15
46   - elif mode == mumoro.PublicTransport:
47   - return length * 0.05
48   -
49 39 class BaseLayer:
50 40 def map(self, original_id):
51 41 c = self.nodes_db.cursor()
@@ -97,15 +87,18 @@ def __init__(self, name, mode, data):
97 87 self.mode = mode
98 88 self.data = data
99 89 self.name = name
100   - c = config.Config()
101   - try:
102   - self.conn = pg.connect("dbname=" + c.dbname + " user=" + c.dbuser + " password=" + c.dbpassword + " host=" + c.host);
  90 + c = config.Config()
  91 + try:
  92 + if( c.host != "" and c.dbpassword != ""):
  93 + self.conn = pg.connect("dbname=" + c.dbname + " user=" + c.dbuser + " password=" + c.dbpassword + " host=" + c.host)
  94 + else:
  95 + self.conn = pg.connect("dbname=" + c.dbname + " user=" + c.dbuser)
103 96 except:
104 97 print "I am unable to connect to the database"
105 98 self.nodes_offset = 0
106   - eld = elevation.ElevationData("North_America")
107   - self.nodes_db = sqlite3.connect(':memory:', check_same_thread = False)
108   - self.nodes_db.executescript('''
  99 + eld = elevation.ElevationData("Eurasia")
  100 + self.nodes_db = sqlite3.connect(':memory:', check_same_thread = False)
  101 + self.nodes_db.executescript('''
109 102 CREATE TABLE nodes(
110 103 original_id INTEGER PRIMARY KEY,
111 104 id INTEGER,
@@ -157,7 +150,6 @@ def edges(self):
157 150
158 151 try:
159 152 dur = duration(e.length, property, self.mode)
160   - e.co2 = co2(e.length, self.mode)
161 153 e.duration = mumoro.Duration(dur)
162 154 if self.mode == mumoro.Bike:
163 155 e.elevation = max(0, target_alt - source_alt)
@@ -239,8 +231,6 @@ def __init__(self, layers):
239 231 else:
240 232 if self.graph.public_transport_edge(e['source'], e['target'], e['departure'], e['arrival']):
241 233 count += 1
242   - for n in l.nodes():
243   - self.graph.set_coord(n['id'], n['lon'], n['lat'])
244 234 print "On layer {0}, {1} edges".format(l, count)
245 235 print "The multimodal graph has been built and has {0} nodes and {1} edges".format(nb_nodes, count)
246 236
@@ -269,6 +259,7 @@ def connect_same_nodes(self, layer1, layer2, property):
269 259 n2 = layer2.map(n1['original_id'])
270 260 if n2:
271 261 self.graph.add_edge(n1['id'], n2, property)
  262 +
272 263 def connect_same_nodes_random(self, layer1, layer2, property, freq):
273 264 count = 0
274 265 for n1 in layer1.nodes():
@@ -276,6 +267,7 @@ def connect_same_nodes_random(self, layer1, layer2, property, freq):
276 267 if n2 and count % freq == 0:
277 268 self.graph.add_edge(n1['id'], n2, property)
278 269 count += 1
  270 + self.graph.add_edge(n1, n2, property)
279 271
280 272
281 273 def connect_nodes_from_list(self, layer1, layer2, list, property, property2 = None):
@@ -292,11 +284,11 @@ def connect_nodes_from_list(self, layer1, layer2, list, property, property2 = No
292 284
293 285
294 286 def connect_nearest_nodes(self, layer1, layer2, property, property2 = None):
  287 + if property2 == None:
  288 + property2 = property
295 289 for n in layer1.nodes():
296 290 nearest = layer2.match(n['lon'], n['lat'])
297 291 if nearest:
298   - if property != None:
299   - self.graph.add_edge(n['id'], nearest, property)
300   - if property2 != None:
301   - self.graph.add_edge(nearest, n['id'], property2)
  292 + self.graph.add_edge(n['id'], nearest, property)
  293 + self.graph.add_edge(nearest, n['id'], property2)
302 294
1  lib/martins.cpp
@@ -10,7 +10,6 @@ float Edge::* get_objective(Objective o)
10 10 case mode_change: return &Edge::mode_change; break;
11 11 case cost: return &Edge::cost; break;
12 12 case line_change: return &Edge::line_change; break;
13   - case co2: return &Edge::co2; break;
14 13 default: std::cerr << "Unknown objective..." << std::endl; break;
15 14 }
16 15 }
2  lib/martins.h
@@ -3,7 +3,7 @@
3 3
4 4 #include "graph_wrapper.h"
5 5
6   -enum Objective {dist, elevation, mode_change, cost, line_change, co2};
  6 +enum Objective {dist, elevation, mode_change, cost, line_change};
7 7
8 8 struct Path
9 9 {
18 lib/martins_impl.h
@@ -7,14 +7,15 @@
7 7 #include <string>
8 8 #include <fstream>
9 9 #include <deque>
  10 +#include <boost/spirit/include/classic_core.hpp>
10 11 #include <boost/multi_index_container.hpp>
11 12 #include <boost/multi_index/ordered_index.hpp>
12 13 #include "boost/multi_index/hashed_index.hpp"
13 14 #include <boost/multi_index/member.hpp>
14 15 #include <boost/array.hpp>
15   -#include <boost/foreach.hpp>
16 16
17 17 using namespace boost::multi_index;
  18 +using namespace boost::spirit::classic;
18 19 using namespace boost;
19 20 using namespace std;
20 21
@@ -165,7 +166,7 @@ ostream & operator<<(ostream & os, Label<N> l)
165 166 os << "}";
166 167 return os;
167 168 }
168   -/*
  169 +
169 170 template<size_t N, typename Comp>
170 171 bool is_dominated_by_any(const typename my_queue<N>::Type & Q, const Label<N> & l, Comp c)
171 172 {
@@ -178,17 +179,6 @@ bool is_dominated_by_any(const typename my_queue<N>::Type & Q, const Label<N> &
178 179 }
179 180 return false;
180 181 }
181   -*/
182   -template<size_t N, typename Comp, typename Container>
183   -bool is_dominated_by_any(const Container & Q, const Label<N> & l, Comp c)
184   -{
185   - BOOST_FOREACH(Label<N> a, Q)
186   - {
187   - if( c(a, l) || a.cost == l.cost)
188   - return true;
189   - }
190   - return false;
191   -}
192 182
193 183 template<size_t N>
194 184 bool is_dominated_by_any(const typename my_queue<N>::Type & Q, const Label<N> & l)
@@ -249,7 +239,7 @@ vector<Path> martins(int start_node, int dest_node, Graph & g, int start_time, s
249 239 for(size_t i=1; i < N; i++)
250 240 l2.cost[i] = l.cost[i] + g.g[*ei].*objectives[i-1];
251 241
252   - if(!is_dominated_by_any(node_q.equal_range(l2.node), l2, std_comp) && !is_dominated_by_any(P[l2.node],l2, std_comp) && (dest_node == invalid_node || !is_dominated_by_any(P[dest_node],l2, std_comp)))
  242 + if(!is_dominated_by_any(Q, l2, std_comp) && !is_dominated_by_any(P[l2.node],l2, std_comp) && (dest_node == invalid_node || !is_dominated_by_any(P[dest_node],l2, std_comp)))
253 243 {
254 244 typename my_queue<N>::nodes_it it, end;
255 245 tie(it, end) = node_q.equal_range(l2.node);
1  lib/tsaggouris.cpp
@@ -43,6 +43,7 @@ void ssmosp(Graph & g, int start)
43 43
44 44 for(size_t i = 1; i < nodes; i++)
45 45 {
  46 + std::cout << "New round ! (" << i << "/" << nodes - 1 << ")" << std::endl;
46 47 Graph_t::edge_iterator e, e_end;
47 48 tie(e, e_end) = edges(g.g);
48 49 for(; e != e_end; e++)

0 comments on commit 01dec40

Please sign in to comment.
Something went wrong with that request. Please try again.