@@ -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};
0 commit comments