PGROUTING  3.2
GraphDefinition.cpp
Go to the documentation of this file.
1 /*PGR-GNU*****************************************************************
2 
3 File: GraphDefinition.cpp
4 
5 Copyright (c) 2015 pgRouting developers
7 
8 ------
9 
10 This program is free software; you can redistribute it and/or modify
11 it under the terms of the GNU General Public License as published by
12 the Free Software Foundation; either version 2 of the License, or
13 (at your option) any later version.
14 
15 This program is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 GNU General Public License for more details.
19 
20 You should have received a copy of the GNU General Public License
21 along with this program; if not, write to the Free Software
22 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
23 
24  ********************************************************************PGR-GNU*/
25 
26 #ifdef __MINGW32__
27 #include <winsock2.h>
28 #include <windows.h>
29 #endif
30 
31 
32 #include <utility>
33 #include <queue>
34 #include <vector>
35 #include <functional>
36 #include "trsp/GraphDefinition.h"
37 
38 // -------------------------------------------------------------------------
40  m_lStartEdgeId = -1;
41  m_lEndEdgeId = 0;
42  m_dStartpart = 0.0;
43  m_dEndPart = 0.0;
44  m_dCost = NULL;
45  m_bIsturnRestrictOn = false;
46  m_bIsGraphConstructed = false;
47  parent = NULL;
48  init();
49 }
50 
51 // -------------------------------------------------------------------------
53 }
54 
55 
56 // -------------------------------------------------------------------------
58  max_edge_id = 0;
59  max_node_id = 0;
60  isStartVirtual = false;
61  isEndVirtual = false;
62 }
63 
64 
65 // -------------------------------------------------------------------------
67  std::vector<GraphEdgeInfo*>::iterator it;
68  for (it = m_vecEdgeVector.begin(); it != m_vecEdgeVector.end(); ++it) {
69  delete *it;
70  }
71  m_vecEdgeVector.clear();
72 
73  delete [] parent;
74  delete [] m_dCost;
75 }
76 
77 
78 // -------------------------------------------------------------------------
79 double GraphDefinition::construct_path(int64 ed_id, int64 v_pos) {
80  if (parent[ed_id].ed_ind[v_pos] == -1) {
81  path_element_tt pelement;
82  GraphEdgeInfo* cur_edge = m_vecEdgeVector[static_cast<size_t>(ed_id)];
83  if (v_pos == 0) {
84  pelement.vertex_id = cur_edge->m_lStartNode;
85  pelement.cost = cur_edge->m_dCost;
86  } else {
87  pelement.vertex_id = cur_edge->m_lEndNode;
88  pelement.cost = cur_edge->m_dReverseCost;
89  }
90  pelement.edge_id = cur_edge->m_lEdgeID;
91 
92  m_vecPath.push_back(pelement);
93  return pelement.cost;
94  }
95  double ret = construct_path(parent[ed_id].ed_ind[v_pos],
96  parent[ed_id].v_pos[v_pos]);
97  path_element_tt pelement;
98  GraphEdgeInfo* cur_edge = m_vecEdgeVector[static_cast<size_t>(ed_id)];
99  if (v_pos == 0) {
100  pelement.vertex_id = cur_edge->m_lStartNode;
101  pelement.cost = m_dCost[ed_id].endCost - ret; // cur_edge.m_dCost;
102  ret = m_dCost[ed_id].endCost;
103  } else {
104  pelement.vertex_id = cur_edge->m_lEndNode;
105  pelement.cost = m_dCost[ed_id].startCost - ret;
106  ret = m_dCost[ed_id].startCost;
107  }
108  pelement.edge_id = cur_edge->m_lEdgeID;
109 
110  m_vecPath.push_back(pelement);
111 
112  return ret;
113 }
114 
115 
116 // -------------------------------------------------------------------------
118  int64 edge_ind,
119  GraphEdgeInfo& new_edge,
120  bool isStart) {
121  double cost = 0.0;
122  int64 edge_id = new_edge.m_lEdgeID;
123  if (m_ruleTable.find(edge_id) == m_ruleTable.end()) {
124  return(0.0);
125  }
126  std::vector<Rule> vecRules = m_ruleTable[edge_id];
127  int64 st_edge_ind = edge_ind;
128  for (const auto &rule : vecRules) {
129  bool flag = true;
130  int64 v_pos = (isStart?0:1);
131  edge_ind = st_edge_ind;
132  for (auto const &precedence : rule.precedencelist) {
133  if (edge_ind == -1) {
134  flag = false;
135  break;
136  }
137  if (precedence != m_vecEdgeVector[static_cast<size_t>(edge_ind)]->m_lEdgeID) {
138  flag = false;
139  break;
140  }
141  auto parent_ind = parent[static_cast<size_t>(edge_ind)].ed_ind[static_cast<size_t>(v_pos)];
142  v_pos = parent[edge_ind].v_pos[v_pos];
143  edge_ind = parent_ind;
144  }
145  if (flag)
146  cost += rule.cost;
147  }
148  return cost;
149 }
150 
151 
152 // -------------------------------------------------------------------------
154  int64 cur_node,
155  GraphEdgeInfo& cur_edge,
156  bool isStart,
157  LongVector &vecIndex,
158  std::priority_queue<PDP, std::vector<PDP>,
159  std::greater<PDP> > &que) {
160  double totalCost;
161  for (const auto &index : vecIndex) {
162  auto new_edge = m_vecEdgeVector[static_cast<size_t>(index)];
163  double extCost = 0.0;
164  if (m_bIsturnRestrictOn) {
165  extCost = getRestrictionCost(cur_edge.m_lEdgeIndex,
166  *new_edge, isStart);
167  }
168  if (new_edge->m_lStartNode == cur_node) {
169  if (new_edge->m_dCost >= 0.0) {
170  if (isStart)
171  totalCost = m_dCost[cur_edge.m_lEdgeIndex].endCost +
172  new_edge->m_dCost + extCost;
173  else
174  totalCost = m_dCost[cur_edge.m_lEdgeIndex].startCost +
175  new_edge->m_dCost + extCost;
176  if (totalCost < m_dCost[index].endCost) {
177  m_dCost[index].endCost = totalCost;
178  parent[new_edge->m_lEdgeIndex].v_pos[0] = (isStart?0:1);
179  parent[new_edge->m_lEdgeIndex].ed_ind[0] =
180  cur_edge.m_lEdgeIndex;
181  que.push(std::make_pair(totalCost,
182  std::make_pair(new_edge->m_lEdgeIndex, true)));
183  }
184  }
185  } else {
186  if (new_edge->m_dReverseCost >= 0.0) {
187  if (isStart)
188  totalCost = m_dCost[cur_edge.m_lEdgeIndex].endCost +
189  new_edge->m_dReverseCost + extCost;
190  else
191  totalCost = m_dCost[cur_edge.m_lEdgeIndex].startCost +
192  new_edge->m_dReverseCost + extCost;
193  if (totalCost < m_dCost[index].startCost) {
194  m_dCost[index].startCost = totalCost;
195  parent[new_edge->m_lEdgeIndex].v_pos[1] = (isStart?0:1);
196  parent[new_edge->m_lEdgeIndex].ed_ind[1] =
197  cur_edge.m_lEdgeIndex;
198  que.push(std::make_pair(totalCost,
199  std::make_pair(new_edge->m_lEdgeIndex, false)));
200  }
201  }
202  }
203  }
204 }
205 
206 
207 
208 
209 // -------------------------------------------------------------------------
211  edge_t *edges, size_t edge_count,
212  int64 start_edge_id, double start_part,
213  int64 end_edge_id, double end_part,
214  bool directed, bool has_reverse_cost,
215 
216  path_element_tt **path,
217  size_t *path_count,
218  char **err_msg,
219  std::vector<PDVI> &ruleList) {
220  if (!m_bIsGraphConstructed) {
221  init();
222  construct_graph(edges, edge_count, has_reverse_cost, directed);
223  m_bIsGraphConstructed = true;
224  }
225  GraphEdgeInfo* start_edge_info =
226  m_vecEdgeVector[static_cast<size_t>(m_mapEdgeId2Index[static_cast<int64>(start_edge_id)])];
227  edge_t start_edge;
228  int64 start_vertex, end_vertex;
229  m_dStartpart = start_part;
230  m_dEndPart = end_part;
231  m_lStartEdgeId = start_edge_id;
232  m_lEndEdgeId = end_edge_id;
233 
234  if (start_part == 0.0) {
235  start_vertex = start_edge_info->m_lStartNode;
236  } else if (start_part == 1.0) {
237  start_vertex = start_edge_info->m_lEndNode;
238  } else {
239  isStartVirtual = true;
240  m_lStartEdgeId = start_edge_id;
241  start_vertex = max_node_id + 1;
242  max_node_id++;
243  start_edge.id = max_edge_id + 1;
244  max_edge_id++;
245  start_edge.source = start_vertex;
246  start_edge.reverse_cost = -1.0;
247  if (start_edge_info->m_dCost >= 0.0) {
248  start_edge.target = start_edge_info->m_lEndNode;
249  start_edge.cost = (1.0 - start_part) * start_edge_info->m_dCost;
250  addEdge(start_edge);
251  edge_count++;
252  }
253  if (start_edge_info->m_dReverseCost >= 0.0) {
254  start_edge.id = max_edge_id + 1;
255  max_edge_id++;
256  start_edge.target = start_edge_info->m_lStartNode;
257  start_edge.cost = start_part * start_edge_info->m_dReverseCost;
258  addEdge(start_edge);
259  edge_count++;
260  }
261  }
262 
263  GraphEdgeInfo* end_edge_info =
264  m_vecEdgeVector[static_cast<size_t>(m_mapEdgeId2Index[static_cast<int64>(end_edge_id)])];
265  edge_t end_edge;
266 
267  if (end_part == 0.0) {
268  end_vertex = end_edge_info->m_lStartNode;
269  } else if (end_part == 1.0) {
270  end_vertex = end_edge_info->m_lEndNode;
271  } else {
272  isEndVirtual = true;
273  m_lEndEdgeId = end_edge_id;
274  end_vertex = max_node_id + 1;
275  max_node_id++;
276  end_edge.id = max_edge_id + 1;
277  max_edge_id++;
278  end_edge.target = end_vertex;
279  end_edge.reverse_cost = -1.0;
280  if (end_edge_info->m_dCost >= 0.0) {
281  end_edge.source = end_edge_info->m_lStartNode;
282  end_edge.cost = end_part * end_edge_info->m_dCost;
283  addEdge(end_edge);
284  edge_count++;
285  }
286  if (end_edge_info->m_dReverseCost >= 0.0) {
287  end_edge.source = end_edge_info->m_lEndNode;
288  end_edge.id = max_edge_id + 1;
289  end_edge.cost = (1.0 - end_part) * end_edge_info->m_dReverseCost;
290  addEdge(end_edge);
291  edge_count++;
292  }
293  }
294 
295  return(my_dijkstra2(
296  edges, edge_count,
297  start_vertex, end_vertex,
298  directed, has_reverse_cost,
299 
300  path, path_count, err_msg,
301 
302  ruleList));
303 }
304 
305 
306 // -------------------------------------------------------------------------
308  edge_t *edges, size_t edge_count,
309  int64 start_vertex, int64 end_vertex,
310  bool directed, bool has_reverse_cost,
311 
312  path_element_tt **path, size_t *path_count,
313  char **err_msg,
314  std::vector<PDVI> &ruleList) {
315  m_ruleTable.clear();
316  LongVector vecsource;
317  for (const auto &rule : ruleList) {
318  size_t j;
319  size_t seq_cnt = rule.second.size();
320  std::vector<int64> temp_precedencelist;
321  temp_precedencelist.clear();
322  for (j = 1; j < seq_cnt; j++) {
323  temp_precedencelist.push_back(rule.second[j]);
324  }
325  int64 dest_edge_id = rule.second[0];
326  if (m_ruleTable.find(dest_edge_id) != m_ruleTable.end()) {
327  m_ruleTable[dest_edge_id].push_back(Rule(rule.first,
328  temp_precedencelist));
329  } else {
330  std::vector<Rule> temprules;
331  temprules.clear();
332  temprules.push_back(Rule(rule.first, temp_precedencelist));
333  m_ruleTable.insert(std::make_pair(dest_edge_id, temprules));
334  }
335 
336  if (isStartVirtual) {
337  if (seq_cnt == 2 && rule.second[1] == m_lStartEdgeId) {
338  vecsource = m_mapNodeId2Edge[start_vertex];
339  for (const auto &source : vecsource) {
340  temp_precedencelist.clear();
341  temp_precedencelist.push_back(
342  m_vecEdgeVector[static_cast<size_t>(source)]->m_lEdgeID);
343  m_ruleTable[dest_edge_id].push_back(Rule(rule.first,
344  temp_precedencelist));
345  }
346  }
347  }
348  }
349  if (isEndVirtual) {
350  if (m_ruleTable.find(m_lEndEdgeId) != m_ruleTable.end()) {
351  std::vector<Rule> tmpRules = m_ruleTable[m_lEndEdgeId];
352  vecsource = m_mapNodeId2Edge[end_vertex];
353  for (const auto &source : vecsource) {
354  m_ruleTable.insert(std::make_pair(
355  m_vecEdgeVector[static_cast<size_t>(source)]->m_lEdgeID, tmpRules));
356  }
357  }
358  }
359  m_bIsturnRestrictOn = true;
360  return(my_dijkstra3(
361  edges, edge_count,
362  start_vertex, end_vertex,
363  directed, has_reverse_cost,
364  path, path_count, err_msg));
365 }
366 
367 // -------------------------------------------------------------------------
369  edge_t *edges, size_t edge_count,
370  int64 start_vertex, int64 end_vertex,
371  bool directed, bool has_reverse_cost,
372  path_element_tt **path, size_t *path_count, char **err_msg
373  ) {
374  if (!m_bIsGraphConstructed) {
375  init();
376  construct_graph(edges, edge_count, has_reverse_cost, directed);
377  m_bIsGraphConstructed = true;
378  }
379 
380  std::priority_queue<PDP, std::vector<PDP>, std::greater<PDP> > que;
381  parent = new PARENT_PATH[edge_count + 1];
382  m_dCost = new CostHolder[edge_count + 1];
383  m_vecPath.clear();
384 
385  unsigned int i;
386  for (i = 0; i <= edge_count; i++) {
387  m_dCost[i].startCost = 1e15;
388  m_dCost[i].endCost = 1e15;
389  }
390 
391  if (m_mapNodeId2Edge.find(start_vertex) == m_mapNodeId2Edge.end()) {
392  *err_msg = const_cast<char *>("Source Not Found");
393  deleteall();
394  return -1;
395  }
396 
397  if (m_mapNodeId2Edge.find(end_vertex) == m_mapNodeId2Edge.end()) {
398  *err_msg = const_cast<char *>("Destination Not Found");
399  deleteall();
400  return -1;
401  }
402 
403  LongVector vecsource = m_mapNodeId2Edge[start_vertex];
404  GraphEdgeInfo* cur_edge = NULL;
405 
406  for (const auto &source : vecsource) {
407  cur_edge = m_vecEdgeVector[static_cast<size_t>(source)];
408  if (cur_edge->m_lStartNode == start_vertex) {
409  if (cur_edge->m_dCost >= 0.0) {
410  m_dCost[cur_edge->m_lEdgeIndex].endCost = cur_edge->m_dCost;
411  parent[cur_edge->m_lEdgeIndex].v_pos[0] = -1;
412  parent[cur_edge->m_lEdgeIndex].ed_ind[0] = -1;
413  que.push(std::make_pair(cur_edge->m_dCost,
414  std::make_pair(cur_edge->m_lEdgeIndex, true)));
415  }
416  } else {
417  if (cur_edge->m_dReverseCost >= 0.0) {
418  m_dCost[cur_edge->m_lEdgeIndex].startCost =
419  cur_edge->m_dReverseCost;
420  parent[cur_edge->m_lEdgeIndex].v_pos[1] = -1;
421  parent[cur_edge->m_lEdgeIndex].ed_ind[1] = -1;
422  que.push(std::make_pair(cur_edge->m_dReverseCost,
423  std::make_pair(cur_edge->m_lEdgeIndex, false)));
424  }
425  }
426  }
427  int64 cur_node = -1;
428 
429  while (!que.empty()) {
430  PDP cur_pos = que.top();
431  que.pop();
432  int64 cured_index = cur_pos.second.first;
433  cur_edge = m_vecEdgeVector[static_cast<size_t>(cured_index)];
434 
435  if (cur_pos.second.second) { // explore edges connected to end node
436  cur_node = cur_edge->m_lEndNode;
437  if (cur_edge->m_dCost < 0.0)
438  continue;
439  if (cur_node == end_vertex)
440  break;
441  explore(cur_node, *cur_edge, true, cur_edge->m_vecEndConnedtedEdge,
442  que);
443  } else { // explore edges connected to start node
444  cur_node = cur_edge->m_lStartNode;
445  if (cur_edge->m_dReverseCost < 0.0)
446  continue;
447  if (cur_node == end_vertex)
448  break;
449  explore(cur_node, *cur_edge, false,
450  cur_edge->m_vecStartConnectedEdge, que);
451  }
452  }
453  if (cur_node != end_vertex) {
454  if (m_lStartEdgeId == m_lEndEdgeId) {
455  if (get_single_cost(1000.0, path, path_count)) {
456  return 0;
457  }
458  }
459  *err_msg = const_cast<char *>("Path Not Found");
460  deleteall();
461  return -1;
462  } else {
463  double total_cost;
464  if (cur_node == cur_edge->m_lStartNode) {
465  total_cost = m_dCost[cur_edge->m_lEdgeIndex].startCost;
466  construct_path(cur_edge->m_lEdgeIndex, 1);
467  } else {
468  total_cost = m_dCost[cur_edge->m_lEdgeIndex].endCost;
469  construct_path(cur_edge->m_lEdgeIndex, 0);
470  }
471  path_element_tt pelement;
472  pelement.vertex_id = end_vertex;
473  pelement.edge_id = -1;
474  pelement.cost = 0.0;
475  m_vecPath.push_back(pelement);
476 
477  if (m_lStartEdgeId == m_lEndEdgeId) {
478  if (get_single_cost(total_cost, path, path_count)) {
479  return 0;
480  }
481  }
482 
483  *path = reinterpret_cast<path_element_tt *>(
484  malloc(sizeof(path_element_tt) * (m_vecPath.size() + 1)));
485  *path_count = m_vecPath.size();
486 
487  for (size_t i = 0; i < *path_count; i++) {
488  (*path)[i].vertex_id = m_vecPath[i].vertex_id;
489  (*path)[i].edge_id = m_vecPath[i].edge_id;
490  (*path)[i].cost = m_vecPath[i].cost;
491  }
492  if (isStartVirtual) {
493  (*path)[0].vertex_id = -1;
494  (*path)[0].edge_id = m_lStartEdgeId;
495  }
496  if (isEndVirtual) {
497  *path_count = *path_count - 1;
498  (*path)[*path_count - 1].edge_id = m_lEndEdgeId;
499  }
500  }
501  deleteall();
502  return 0;
503 }
504 
505 // -------------------------------------------------------------------------
506 bool GraphDefinition::get_single_cost(double total_cost, path_element_tt **path,
507  size_t *path_count) {
508  GraphEdgeInfo* start_edge_info =
509  m_vecEdgeVector[static_cast<size_t>(m_mapEdgeId2Index[m_lStartEdgeId])];
510  if (m_dEndPart >= m_dStartpart) {
511  if (start_edge_info->m_dCost >= 0.0 && start_edge_info->m_dCost *
512  (m_dEndPart - m_dStartpart) <= total_cost) {
513  *path = reinterpret_cast<path_element_tt *>(malloc(
514  sizeof(path_element_tt) * (1)));
515  *path_count = 1;
516  (*path)[0].vertex_id = -1;
517  (*path)[0].edge_id = m_lStartEdgeId;
518  (*path)[0].cost = start_edge_info->m_dCost *
520 
521  return true;
522  }
523  } else {
524  if (start_edge_info->m_dReverseCost >= 0.0 &&
525  start_edge_info->m_dReverseCost * (m_dStartpart - m_dEndPart) <=
526  total_cost) {
527  *path = reinterpret_cast<path_element_tt *>(malloc(
528  sizeof(path_element_tt) * (1)));
529  *path_count = 1;
530  (*path)[0].vertex_id = -1;
531  (*path)[0].edge_id = m_lStartEdgeId;
532  (*path)[0].cost = start_edge_info->m_dReverseCost *
534 
535  return true;
536  }
537  }
538  return false;
539 }
540 
541 
542 // -------------------------------------------------------------------------
543 bool GraphDefinition::construct_graph(edge_t* edges, size_t edge_count,
544  bool has_reverse_cost, bool directed) {
545  for (size_t i = 0; i < edge_count; i++) {
546  if (!has_reverse_cost) {
547  if (directed) {
548  edges[i].reverse_cost = -1.0;
549  } else {
550  edges[i].reverse_cost = edges[i].cost;
551  }
552  }
553  addEdge(edges[i]);
554  }
555  m_bIsGraphConstructed = true;
556  return true;
557 }
558 
559 
560 // -------------------------------------------------------------------------
562  GraphEdgeInfo& secondEdge, bool bIsStartNodeSame) {
563  if (bIsStartNodeSame) {
564  if (firstEdge.m_dReverseCost >= 0.0)
565  firstEdge.m_vecStartConnectedEdge.push_back(
566  secondEdge.m_lEdgeIndex);
567  if (firstEdge.m_lStartNode == secondEdge.m_lStartNode) {
568  if (secondEdge.m_dReverseCost >= 0.0)
569  secondEdge.m_vecStartConnectedEdge.push_back(
570  firstEdge.m_lEdgeIndex);
571  } else {
572  if (secondEdge.m_dCost >= 0.0)
573  secondEdge.m_vecEndConnedtedEdge.push_back(
574  firstEdge.m_lEdgeIndex);
575  }
576  } else {
577  if (firstEdge.m_dCost >= 0.0)
578  firstEdge.m_vecEndConnedtedEdge.push_back(secondEdge.m_lEdgeIndex);
579  if (firstEdge.m_lEndNode == secondEdge.m_lStartNode) {
580  if (secondEdge.m_dReverseCost >= 0.0)
581  secondEdge.m_vecStartConnectedEdge.push_back(
582  firstEdge.m_lEdgeIndex);
583  } else {
584  if (secondEdge.m_dCost >= 0.0)
585  secondEdge.m_vecEndConnedtedEdge.push_back(
586  firstEdge.m_lEdgeIndex);
587  }
588  }
589  return true;
590 }
591 
592 
593 // -------------------------------------------------------------------------
595  // int64 lTest;
596  Long2LongMap::iterator itMap = m_mapEdgeId2Index.find(edgeIn.id);
597  if (itMap != m_mapEdgeId2Index.end())
598  return false;
599 
600 
601  GraphEdgeInfo* newEdge = new GraphEdgeInfo();
602  newEdge->m_vecStartConnectedEdge.clear();
603  newEdge->m_vecEndConnedtedEdge.clear();
604  newEdge->m_vecRestrictedEdge.clear();
605  newEdge->m_lEdgeID = edgeIn.id;
606  newEdge->m_lEdgeIndex = static_cast<int64>(m_vecEdgeVector.size());
607  newEdge->m_lStartNode = edgeIn.source;
608  newEdge->m_lEndNode = edgeIn.target;
609  newEdge->m_dCost = edgeIn.cost;
610  newEdge->m_dReverseCost = edgeIn.reverse_cost;
611 
612  if (edgeIn.id > max_edge_id) {
613  max_edge_id = edgeIn.id;
614  }
615 
616  if (newEdge->m_lStartNode > max_node_id) {
617  max_node_id = newEdge->m_lStartNode;
618  }
619  if (newEdge->m_lEndNode > max_node_id) {
620  max_node_id = newEdge->m_lEndNode;
621  }
622 
623  // Searching the start node for connectivity
624  Long2LongVectorMap::iterator itNodeMap = m_mapNodeId2Edge.find(
625  edgeIn.source);
626  if (itNodeMap != m_mapNodeId2Edge.end()) {
627  // Connect current edge with existing edge with start node
628  // connectEdge(
629  int64 lEdgeCount = static_cast<int64>(itNodeMap->second.size());
630  int64 lEdgeIndex;
631  for (lEdgeIndex = 0; lEdgeIndex < lEdgeCount; lEdgeIndex++) {
632  int64 lEdge = itNodeMap->second.at(static_cast<size_t>(lEdgeIndex));
633  connectEdge(*newEdge, *m_vecEdgeVector[static_cast<size_t>(lEdge)], true);
634  }
635  }
636 
637 
638  // Searching the end node for connectivity
639  itNodeMap = m_mapNodeId2Edge.find(edgeIn.target);
640  if (itNodeMap != m_mapNodeId2Edge.end()) {
641  // Connect current edge with existing edge with end node
642  // connectEdge(
643  int64 lEdgeCount = static_cast<int64>(itNodeMap->second.size());
644  int64 lEdgeIndex;
645  for (lEdgeIndex = 0; lEdgeIndex < lEdgeCount; lEdgeIndex++) {
646  int64 lEdge = itNodeMap->second.at(static_cast<size_t>(lEdgeIndex));
647  connectEdge(*newEdge, *m_vecEdgeVector[static_cast<size_t>(lEdge)], false);
648  }
649  }
650 
651 
652 
653  // Add this node and edge into the data structure
654  m_mapNodeId2Edge[edgeIn.source].push_back(newEdge->m_lEdgeIndex);
655  m_mapNodeId2Edge[edgeIn.target].push_back(newEdge->m_lEdgeIndex);
656 
657 
658  // Adding edge to the list
659  m_mapEdgeId2Index.insert(std::make_pair(newEdge->m_lEdgeID,
660  m_vecEdgeVector.size()));
661  m_vecEdgeVector.push_back(newEdge);
662 
663  //
664 
665 
666  return true;
667 }
GraphDefinition::m_mapNodeId2Edge
Long2LongVectorMap m_mapNodeId2Edge
Definition: GraphDefinition.h:163
GraphDefinition::m_vecPath
std::vector< path_element_tt > m_vecPath
Definition: GraphDefinition.h:173
Rule
struct Rule Rule
GraphEdgeInfo::m_dCost
double m_dCost
Definition: GraphDefinition.h:94
CostHolder::endCost
double endCost
Definition: GraphDefinition.h:82
GraphDefinition::m_vecEdgeVector
GraphEdgeVector m_vecEdgeVector
Definition: GraphDefinition.h:161
PARENT_PATH::ed_ind
int64 ed_ind[2]
Definition: GraphDefinition.h:71
GraphDefinition::addEdge
bool addEdge(edge_t edgeIn)
Definition: GraphDefinition.cpp:594
edge_t::source
int64_t source
Definition: trsp_types.h:39
path_element::edge_id
int64 edge_id
Definition: trsp.h:58
GraphEdgeInfo::m_lEdgeID
int64 m_lEdgeID
Definition: GraphDefinition.h:91
GraphEdgeInfo::m_lEdgeIndex
int64 m_lEdgeIndex
Definition: GraphDefinition.h:92
GraphEdgeInfo::m_vecEndConnedtedEdge
LongVector m_vecEndConnedtedEdge
Definition: GraphDefinition.h:97
edge_t
Definition: trsp_types.h:37
edge_t::target
int64_t target
Definition: trsp_types.h:40
edge_t::reverse_cost
double reverse_cost
Definition: trsp_types.h:42
GraphDefinition::m_dStartpart
double m_dStartpart
Definition: GraphDefinition.h:168
GraphDefinition::GraphDefinition
GraphDefinition(void)
Definition: GraphDefinition.cpp:39
path_element
Definition: trsp.h:56
GraphDefinition::~GraphDefinition
~GraphDefinition(void)
Definition: GraphDefinition.cpp:52
GraphEdgeInfo::m_vecStartConnectedEdge
LongVector m_vecStartConnectedEdge
Definition: GraphDefinition.h:96
GraphDefinition::m_dEndPart
double m_dEndPart
Definition: GraphDefinition.h:169
GraphDefinition::m_bIsturnRestrictOn
bool m_bIsturnRestrictOn
Definition: GraphDefinition.h:177
GraphDefinition::explore
void explore(int64 cur_node, GraphEdgeInfo &cur_edge, bool isStart, LongVector &vecIndex, std::priority_queue< PDP, std::vector< PDP >, std::greater< PDP > > &que)
Definition: GraphDefinition.cpp:153
GraphEdgeInfo::m_lEndNode
int64 m_lEndNode
Definition: GraphDefinition.h:102
GraphDefinition::connectEdge
bool connectEdge(GraphEdgeInfo &firstEdge, GraphEdgeInfo &secondEdge, bool bIsStartNodeSame)
Definition: GraphDefinition.cpp:561
GraphDefinition::max_node_id
int64 max_node_id
Definition: GraphDefinition.h:164
PARENT_PATH::v_pos
int64 v_pos[2]
Definition: GraphDefinition.h:72
GraphDefinition::parent
PARENT_PATH * parent
Definition: GraphDefinition.h:174
PDP
std::pair< double, PIB > PDP
Definition: GraphDefinition.h:49
GraphDefinition::m_dCost
CostHolder * m_dCost
Definition: GraphDefinition.h:175
GraphDefinition.h
GraphDefinition::m_mapEdgeId2Index
Long2LongMap m_mapEdgeId2Index
Definition: GraphDefinition.h:162
CostHolder
Definition: GraphDefinition.h:81
GraphDefinition::m_lEndEdgeId
int64 m_lEndEdgeId
Definition: GraphDefinition.h:167
GraphDefinition::isStartVirtual
bool isStartVirtual
Definition: GraphDefinition.h:170
GraphDefinition::construct_graph
bool construct_graph(edge_t *edges, size_t edge_count, bool has_reverse_cost, bool directed)
Definition: GraphDefinition.cpp:543
GraphDefinition::construct_path
double construct_path(int64 ed_id, int64 v_pos)
Definition: GraphDefinition.cpp:79
edge_t::id
int64_t id
Definition: trsp_types.h:38
path_element::cost
float8 cost
Definition: trsp.h:59
GraphEdgeInfo::m_vecRestrictedEdge
VectorOfLongVector m_vecRestrictedEdge
Definition: GraphDefinition.h:99
GraphDefinition::deleteall
void deleteall()
Definition: GraphDefinition.cpp:66
GraphEdgeInfo::m_lStartNode
int64 m_lStartNode
Definition: GraphDefinition.h:101
GraphDefinition::m_lStartEdgeId
int64 m_lStartEdgeId
Definition: GraphDefinition.h:166
GraphDefinition::get_single_cost
bool get_single_cost(double total_cost, path_element_tt **path, size_t *path_count)
Definition: GraphDefinition.cpp:506
GraphEdgeInfo
Definition: GraphDefinition.h:89
GraphDefinition::m_bIsGraphConstructed
bool m_bIsGraphConstructed
Definition: GraphDefinition.h:178
GraphDefinition::my_dijkstra3
int my_dijkstra3(edge_t *edges, size_t edge_count, int64 start_vertex, int64 end_vertex, bool directed, bool has_reverse_cost, path_element_tt **path, size_t *path_count, char **err_msg)
Definition: GraphDefinition.cpp:368
path_element::vertex_id
int64 vertex_id
Definition: trsp.h:57
LongVector
std::vector< int64 > LongVector
Definition: GraphDefinition.h:46
GraphDefinition::my_dijkstra1
int my_dijkstra1(edge_t *edges, size_t edge_count, int64 start_edge, double start_part, int64 end_edge, double end_part, bool directed, bool has_reverse_cost, path_element_tt **path, size_t *path_count, char **err_msg, std::vector< PDVI > &ruleList)
Definition: GraphDefinition.cpp:210
GraphDefinition::max_edge_id
int64 max_edge_id
Definition: GraphDefinition.h:165
GraphEdgeInfo::m_dReverseCost
double m_dReverseCost
Definition: GraphDefinition.h:95
GraphDefinition::isEndVirtual
bool isEndVirtual
Definition: GraphDefinition.h:171
CostHolder::startCost
double startCost
Definition: GraphDefinition.h:82
GraphDefinition::getRestrictionCost
double getRestrictionCost(int64 cur_node, GraphEdgeInfo &new_edge, bool isStart)
Definition: GraphDefinition.cpp:117
PARENT_PATH
Definition: GraphDefinition.h:70
GraphDefinition::init
void init()
Definition: GraphDefinition.cpp:57
GraphDefinition::my_dijkstra2
int my_dijkstra2(edge_t *edges, size_t edge_count, int64 start_vertex, int64 end_vertex, bool directed, bool has_reverse_cost, path_element_tt **path, size_t *path_count, char **err_msg, std::vector< PDVI > &ruleList)
Definition: GraphDefinition.cpp:307
GraphDefinition::m_ruleTable
RuleTable m_ruleTable
Definition: GraphDefinition.h:176
edge_t::cost
double cost
Definition: trsp_types.h:41