Skip to content

Commit eb506d0

Browse files
committed
prepared directory for withPoints
1 parent 50ca961 commit eb506d0

20 files changed

+857
-527
lines changed

src/common/src/baseGraph.hpp

Lines changed: 114 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -148,9 +148,78 @@ class Pgr_base_graph {
148148
//! @name Graph Modification
149149
//@{
150150
//! Used for storing the removed_edges
151-
std::deque<pgr_edge_t> removed_edges;
151+
std::deque<boost_edge_t> removed_edges;
152+
153+
//! Used for storing modified edges because of adding points
154+
// TODO
155+
#if 0
156+
std::deque<boost_edge_t> modified_edges;
157+
std::deque< Point_on_edge > points;
158+
// map to get wich boost edge was modified
159+
std::map < int64_t, int64_t >;
160+
#endif
152161
//@}
153162

163+
#if 0
164+
void add_point(Point_on_edge &point, int driving) {
165+
// we have:
166+
// point.point_id
167+
// point.edge_id
168+
// point.fraction
169+
// Look for the edge in modified edges
170+
//
171+
// Driving: 0: doesnt matter (both), 1) right, 2) left
172+
bool found = false;
173+
int64_t edge_to_modify = 0;
174+
for (const auto &edge : modified_edges) {
175+
if (point.edge_id == edge.id) {
176+
found = true;
177+
break;
178+
}
179+
++edge_to_modify;
180+
}
181+
182+
//was not there so look for it in the graph
183+
if (!found) {
184+
E_i edge_ptr, edges_end;
185+
for (boost::tie(edge_ptr, edges_end) = edges(graph);
186+
edge_ptr != edges_end; ++edge_ptr) {
187+
if (point.edge_id == edge_ptr->id) {
188+
modified_edges.push_back(*edge_ptr);
189+
boost::remove_edge(edge_ptr, graph);
190+
//delete the edge from the graph
191+
found = true;
192+
break;
193+
}
194+
}
195+
}
196+
197+
// add the point
198+
int64_t vertex_id = -(points.size() + 1);
199+
point.vertex_id = vertex_id;
200+
points.push_back(point);
201+
202+
// add the vertex
203+
LI vm_s;
204+
vm_s = vertices_map.find(vertex_id);
205+
if (vm_s == vertices_map.end()) {
206+
vertices_map[vertex_id]= m_num_vertices;
207+
gVertices_map[m_num_vertices++] = vertex_id;
208+
vm_s = vertices_map.find(vertex_id);
209+
}
210+
211+
if (!found) {
212+
// the vertex remains disconnected
213+
// because the edge was not found
214+
return;
215+
}
216+
217+
}
218+
#endif
219+
220+
221+
222+
154223

155224
//! @name The Graph
156225
//@{
@@ -190,7 +259,7 @@ class Pgr_base_graph {
190259
void disconnect_edge(int64_t p_from, int64_t p_to) {
191260
V g_from;
192261
V g_to;
193-
pgr_edge_t d_edge;
262+
boost_edge_t d_edge;
194263
// nothing to do, the vertex doesnt exist
195264
if (!get_gVertex(p_from, g_from)) return;
196265
if (!get_gVertex(p_to, g_to)) return;
@@ -203,7 +272,7 @@ class Pgr_base_graph {
203272
d_edge.source = graph[source(*out, graph)].id;
204273
d_edge.target = graph[target(*out, graph)].id;
205274
d_edge.cost = graph[*out].cost;
206-
d_edge.reverse_cost = -1;
275+
// d_edge.reverse_cost = -1;
207276
removed_edges.push_back(d_edge);
208277
}
209278
}
@@ -219,8 +288,8 @@ class Pgr_base_graph {
219288
\returns 0: The out degree of a vertex that its not in the graph
220289
221290
@param [IN] *vertex_id* original vertex id
222-
*/
223-
291+
*/
292+
224293

225294
degree_size_type out_degree(int64_t vertex_id) const{
226295
V v_from;
@@ -234,7 +303,7 @@ class Pgr_base_graph {
234303
return boost::out_degree(v, graph);
235304
}
236305
//@}
237-
306+
238307

239308
//! \brief Disconnects the outgoing edges with a particular original id from a vertex
240309
/*!
@@ -247,7 +316,7 @@ class Pgr_base_graph {
247316
*/
248317
void disconnect_out_going_edge(int64_t vertex_id, int64_t edge_id) {
249318
V v_from;
250-
pgr_edge_t d_edge;
319+
boost_edge_t d_edge;
251320

252321
// nothing to do, the vertex doesnt exist
253322
if (!get_gVertex(vertex_id, v_from)) {
@@ -266,7 +335,7 @@ class Pgr_base_graph {
266335
d_edge.source = graph[source(*out, graph)].id;
267336
d_edge.target = graph[target(*out, graph)].id;
268337
d_edge.cost = graph[*out].cost;
269-
d_edge.reverse_cost = -1;
338+
// d_edge.reverse_cost = -1;
270339
removed_edges.push_back(d_edge);
271340
boost::remove_edge((*out), graph);
272341
change = true;
@@ -294,7 +363,7 @@ class Pgr_base_graph {
294363
*/
295364
void disconnect_vertex(int64_t p_vertex) {
296365
V g_vertex;
297-
pgr_edge_t d_edge;
366+
boost_edge_t d_edge;
298367
// nothing to do, the vertex doesnt exist
299368
if (!get_gVertex(p_vertex, g_vertex)) return;
300369
EO_i out, out_end;
@@ -305,7 +374,7 @@ class Pgr_base_graph {
305374
d_edge.source = graph[source(*out, graph)].id;
306375
d_edge.target = graph[target(*out, graph)].id;
307376
d_edge.cost = graph[*out].cost;
308-
d_edge.reverse_cost = -1;
377+
// d_edge.reverse_cost = -1;
309378
removed_edges.push_back(d_edge);
310379
}
311380

@@ -318,7 +387,7 @@ class Pgr_base_graph {
318387
d_edge.source = graph[source(*in, graph)].id;
319388
d_edge.target = graph[target(*in, graph)].id;
320389
d_edge.cost = graph[*in].cost;
321-
d_edge.reverse_cost = -1;
390+
// d_edge.reverse_cost = -1;
322391
removed_edges.push_back(d_edge);
323392
}
324393
}
@@ -411,6 +480,38 @@ class Pgr_base_graph {
411480
}
412481

413482
private:
483+
484+
485+
void
486+
graph_add_edge(const boost_edge_t &edge ) {
487+
bool inserted;
488+
LI vm_s, vm_t;
489+
E e;
490+
491+
vm_s = vertices_map.find(edge.source);
492+
if (vm_s == vertices_map.end()) {
493+
vertices_map[edge.source]= m_num_vertices;
494+
gVertices_map[m_num_vertices++] = edge.source;
495+
vm_s = vertices_map.find(edge.source);
496+
}
497+
498+
vm_t = vertices_map.find(edge.target);
499+
if (vm_t == vertices_map.end()) {
500+
vertices_map[edge.target]= m_num_vertices;
501+
gVertices_map[m_num_vertices++] = edge.target;
502+
vm_t = vertices_map.find(edge.target);
503+
}
504+
505+
if (edge.cost >= 0) {
506+
boost::tie(e, inserted) =
507+
boost::add_edge(vm_s->second, vm_t->second, graph);
508+
graph[e].cost = edge.cost;
509+
graph[e].id = edge.id;
510+
graph[e].first = edge.first;
511+
}
512+
513+
}
514+
414515
void
415516
graph_add_edge(const pgr_edge_t &edge ) {
416517
bool inserted;
@@ -436,13 +537,15 @@ class Pgr_base_graph {
436537
boost::add_edge(vm_s->second, vm_t->second, graph);
437538
graph[e].cost = edge.cost;
438539
graph[e].id = edge.id;
540+
graph[e].first = true;
439541
}
440542

441543
if (edge.reverse_cost >= 0) {
442544
boost::tie(e, inserted) =
443545
boost::add_edge(vm_t->second, vm_s->second, graph);
444546
graph[e].cost = edge.reverse_cost;
445547
graph[e].id = edge.id;
548+
graph[e].first = false;
446549
}
447550
}
448551
};

src/common/src/pgr_types.h

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,13 @@ typedef struct
109109
}
110110
Restrict_t;
111111

112-
112+
typedef struct {
113+
int64_t point_id;
114+
int64_t edge_id;
115+
bool right; // true when the point is on the right of the edge
116+
float8 fraction;
117+
int64_t vertex_id; // number is negative
118+
} Point_on_edge;
113119

114120

115121
struct boost_vertex_t {
@@ -119,8 +125,9 @@ struct boost_vertex_t {
119125
struct boost_edge_t{
120126
int64_t id;
121127
float8 cost;
122-
int64_t source_id;
123-
int64_t target_id;
128+
int64_t source;
129+
int64_t target;
130+
bool first; // true (source, target) false (target, source)
124131
};
125132

126133

src/dijkstraViaVertex/src/dijkstraViaVertex.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
3737
/*
3838
Uncomment when needed
3939
*/
40-
#define DEBUG
40+
// #define DEBUG
4141

4242
#include "fmgr.h"
4343
#include "./../../common/src/debug_macro.h"

src/trsp/sql/CMakeLists.txt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
# Append in local scope
22
list(APPEND PACKAGE_SQL_FILES
3-
${CMAKE_CURRENT_SOURCE_DIR}/routing_trsp.sql
4-
${CMAKE_CURRENT_SOURCE_DIR}/routing_trsp_vias.sql
5-
#${CMAKE_CURRENT_SOURCE_DIR}/vias_trsp_V2.2.sql
6-
#${CMAKE_CURRENT_SOURCE_DIR}/trsp_V2.2.sql
3+
#${CMAKE_CURRENT_SOURCE_DIR}/routing_trsp.sql
4+
#${CMAKE_CURRENT_SOURCE_DIR}/routing_trsp_vias.sql
5+
${CMAKE_CURRENT_SOURCE_DIR}/vias_trsp_V2.2.sql
6+
${CMAKE_CURRENT_SOURCE_DIR}/trsp_V2.2.sql
77
)
88

99
# set in parent scope

src/trsp/test/from1to3.test.sql

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,6 @@ BEGIN;
8888
SELECT set_eq('q21','q22','3: Directed: without retrictions returns the same as pgr_dijkstra');
8989
SELECT set_eq('q31','q32','4: Directed: with retrictions returns expected path');
9090

91-
-- Finish the tests and clean up.
9291

9392

9493

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
1..3
2+
ok 1 - 1: No path from 1 to 1
3+
ok 2 - 2: without retrictions returns the same as pgr_dijkstra
4+
ok 3 - 3: with retrictions returns expected path
Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
/*PGR-GNU*****************************************************************
2+
3+
Copyright (c) 2015 pgRouting developers
4+
Mail: project@pgrouting.org
5+
6+
------
7+
8+
This program is free software; you can redistribute it and/or modify
9+
it under the terms of the GNU General Public License as published by
10+
the Free Software Foundation; either version 2 of the License, or
11+
(at your option) any later version.
12+
13+
This program is distributed in the hope that it will be useful,
14+
but WITHOUT ANY WARRANTY; without even the implied warranty of
15+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16+
GNU General Public License for more details.
17+
18+
You should have received a copy of the GNU General Public License
19+
along with this program; if not, write to the Free Software
20+
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
21+
22+
********************************************************************PGR-GNU*/
23+
24+
\set ECHO none
25+
\set QUIET 1
26+
-- Turn off echo and keep things quiet.
27+
28+
-- Format the output for nice TAP.
29+
\pset format unaligned
30+
\pset tuples_only true
31+
\pset pager
32+
\set VERBOSITY terse
33+
34+
-- Revert all changes on failure.
35+
\set ON_ERROR_ROLLBACK true
36+
\set ON_ERROR_STOP true
37+
\set QUIET 1
38+
39+
BEGIN;
40+
SELECT plan(3);
41+
42+
UPDATE edge_table SET cost = cost + 0.001 * id * id, reverse_cost = reverse_cost + 0.001 * id * id;
43+
44+
45+
PREPARE q1 AS
46+
SELECT * from pgr_trsp(
47+
'select id as id, source::integer, target::integer,cost, reverse_cost from edge_table',
48+
1, 1,
49+
true, true);
50+
51+
PREPARE q21 AS
52+
SELECT seq, id1, id2, cost::text from pgr_trsp(
53+
'select id as id, source::integer, target::integer,cost, reverse_cost from edge_table',
54+
3, 4,
55+
true, true);
56+
57+
PREPARE q22 AS
58+
SELECT seq-1, node::INTEGER, edge::INTEGER, cost::text from pgr_dijkstra(
59+
'select id as id, source::integer, target::integer,cost, reverse_cost from edge_table',
60+
3, 4, true);
61+
62+
PREPARE q31 AS
63+
SELECT seq, id1, id2, cost::text from pgr_trsp(
64+
'select id as id, source::integer, target::integer,cost, reverse_cost from edge_table',
65+
3, 4,
66+
true, true,
67+
'select 9::INTEGER as target_id, ''5''::TEXT as via_path, 100.2::FLOAT to_cost');
68+
69+
PREPARE q32 AS
70+
SELECT (row_number() over() -1)::INTEGER, node::INTEGER,
71+
(CASE WHEN edge = -2 THEN -1 ELSE edge END)::INTEGER, cost::text
72+
FROM pgr_dijkstraViaVertex(
73+
'select id as id, source::integer, target::integer,cost, reverse_cost from edge_table',
74+
ARRAY[3, 2, 4],
75+
true) where edge != -1;
76+
77+
78+
SELECT is_empty('q1', '1: No path from 1 to 1');
79+
SELECT set_eq('q21','q22','2: without retrictions returns the same as pgr_dijkstra');
80+
SELECT set_eq('q31','q32','3: with retrictions returns expected path');
81+
82+
-- Finish the tests and clean up.
83+
84+
SELECT * FROM finish();
85+
86+
87+
ROLLBACK
-12 KB
Binary file not shown.
File renamed without changes.

0 commit comments

Comments
 (0)