PGROUTING  3.2
GraphDefinition Class Reference

#include "GraphDefinition.h"

Collaboration diagram for GraphDefinition:

Public Member Functions

 GraphDefinition (void)
 
 ~GraphDefinition (void)
 
bool construct_graph (edge_t *edges, size_t edge_count, bool has_reverse_cost, bool directed)
 
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)
 
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)
 
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)
 

Private Member Functions

bool addEdge (edge_t edgeIn)
 
bool connectEdge (GraphEdgeInfo &firstEdge, GraphEdgeInfo &secondEdge, bool bIsStartNodeSame)
 
double construct_path (int64 ed_id, int64 v_pos)
 
void deleteall ()
 
void explore (int64 cur_node, GraphEdgeInfo &cur_edge, bool isStart, LongVector &vecIndex, std::priority_queue< PDP, std::vector< PDP >, std::greater< PDP > > &que)
 
bool get_single_cost (double total_cost, path_element_tt **path, size_t *path_count)
 
double getRestrictionCost (int64 cur_node, GraphEdgeInfo &new_edge, bool isStart)
 
void init ()
 

Private Attributes

bool isEndVirtual
 
bool isStartVirtual
 
bool m_bIsGraphConstructed
 
bool m_bIsturnRestrictOn
 
CostHolderm_dCost
 
double m_dEndPart
 
double m_dStartpart
 
int64 m_lEndEdgeId
 
int64 m_lStartEdgeId
 
Long2LongMap m_mapEdgeId2Index
 
Long2LongVectorMap m_mapNodeId2Edge
 
RuleTable m_ruleTable
 
GraphEdgeVector m_vecEdgeVector
 
std::vector< path_element_ttm_vecPath
 
int64 max_edge_id
 
int64 max_node_id
 
PARENT_PATHparent
 

Detailed Description

Definition at line 115 of file GraphDefinition.h.

Constructor & Destructor Documentation

◆ GraphDefinition()

GraphDefinition::GraphDefinition ( void  )

Definition at line 39 of file GraphDefinition.cpp.

39  {
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 }

References init(), m_bIsGraphConstructed, m_bIsturnRestrictOn, m_dCost, m_dEndPart, m_dStartpart, m_lEndEdgeId, m_lStartEdgeId, and parent.

◆ ~GraphDefinition()

GraphDefinition::~GraphDefinition ( void  )

Definition at line 52 of file GraphDefinition.cpp.

52  {
53 }

Member Function Documentation

◆ addEdge()

bool GraphDefinition::addEdge ( edge_t  edgeIn)
private

Definition at line 594 of file GraphDefinition.cpp.

594  {
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 }

References connectEdge(), edge_t::cost, edge_t::id, GraphEdgeInfo::m_dCost, GraphEdgeInfo::m_dReverseCost, GraphEdgeInfo::m_lEdgeID, GraphEdgeInfo::m_lEdgeIndex, GraphEdgeInfo::m_lEndNode, GraphEdgeInfo::m_lStartNode, m_mapEdgeId2Index, m_mapNodeId2Edge, m_vecEdgeVector, GraphEdgeInfo::m_vecEndConnedtedEdge, GraphEdgeInfo::m_vecRestrictedEdge, GraphEdgeInfo::m_vecStartConnectedEdge, max_edge_id, max_node_id, edge_t::reverse_cost, edge_t::source, and edge_t::target.

Referenced by construct_graph(), and my_dijkstra1().

◆ connectEdge()

bool GraphDefinition::connectEdge ( GraphEdgeInfo firstEdge,
GraphEdgeInfo secondEdge,
bool  bIsStartNodeSame 
)
private

Definition at line 561 of file GraphDefinition.cpp.

562  {
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 }

References GraphEdgeInfo::m_dCost, GraphEdgeInfo::m_dReverseCost, GraphEdgeInfo::m_lEdgeIndex, GraphEdgeInfo::m_lEndNode, GraphEdgeInfo::m_lStartNode, GraphEdgeInfo::m_vecEndConnedtedEdge, and GraphEdgeInfo::m_vecStartConnectedEdge.

Referenced by addEdge().

◆ construct_graph()

bool GraphDefinition::construct_graph ( edge_t edges,
size_t  edge_count,
bool  has_reverse_cost,
bool  directed 
)

Definition at line 543 of file GraphDefinition.cpp.

544  {
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 }

References addEdge(), edge_t::cost, m_bIsGraphConstructed, and edge_t::reverse_cost.

Referenced by my_dijkstra1(), and my_dijkstra3().

◆ construct_path()

double GraphDefinition::construct_path ( int64  ed_id,
int64  v_pos 
)
private

Definition at line 79 of file GraphDefinition.cpp.

79  {
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 }

References path_element::cost, path_element::edge_id, CostHolder::endCost, GraphEdgeInfo::m_dCost, m_dCost, GraphEdgeInfo::m_dReverseCost, GraphEdgeInfo::m_lEdgeID, GraphEdgeInfo::m_lEndNode, GraphEdgeInfo::m_lStartNode, m_vecEdgeVector, m_vecPath, parent, CostHolder::startCost, and path_element::vertex_id.

Referenced by my_dijkstra3().

◆ deleteall()

void GraphDefinition::deleteall ( )
private

Definition at line 66 of file GraphDefinition.cpp.

66  {
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 }

References m_dCost, m_vecEdgeVector, and parent.

Referenced by my_dijkstra3().

◆ explore()

void GraphDefinition::explore ( int64  cur_node,
GraphEdgeInfo cur_edge,
bool  isStart,
LongVector vecIndex,
std::priority_queue< PDP, std::vector< PDP >, std::greater< PDP > > &  que 
)
private

Definition at line 153 of file GraphDefinition.cpp.

159  {
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 }

References PARENT_PATH::ed_ind, CostHolder::endCost, getRestrictionCost(), m_bIsturnRestrictOn, m_dCost, GraphEdgeInfo::m_lEdgeIndex, m_vecEdgeVector, parent, CostHolder::startCost, and PARENT_PATH::v_pos.

Referenced by my_dijkstra3().

◆ get_single_cost()

bool GraphDefinition::get_single_cost ( double  total_cost,
path_element_tt **  path,
size_t *  path_count 
)
private

Definition at line 506 of file GraphDefinition.cpp.

507  {
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 }

References GraphEdgeInfo::m_dCost, m_dEndPart, GraphEdgeInfo::m_dReverseCost, m_dStartpart, m_lStartEdgeId, m_mapEdgeId2Index, m_vecEdgeVector, and path_element::vertex_id.

Referenced by my_dijkstra3().

◆ getRestrictionCost()

double GraphDefinition::getRestrictionCost ( int64  cur_node,
GraphEdgeInfo new_edge,
bool  isStart 
)
private

Definition at line 117 of file GraphDefinition.cpp.

120  {
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 }

References GraphEdgeInfo::m_lEdgeID, m_ruleTable, m_vecEdgeVector, parent, and PARENT_PATH::v_pos.

Referenced by explore().

◆ init()

void GraphDefinition::init ( )
private

Definition at line 57 of file GraphDefinition.cpp.

57  {
58  max_edge_id = 0;
59  max_node_id = 0;
60  isStartVirtual = false;
61  isEndVirtual = false;
62 }

References isEndVirtual, isStartVirtual, max_edge_id, and max_node_id.

Referenced by GraphDefinition(), my_dijkstra1(), and my_dijkstra3().

◆ my_dijkstra1()

int GraphDefinition::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 at line 210 of file GraphDefinition.cpp.

219  {
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 }

References addEdge(), construct_graph(), edge_t::cost, edge_t::id, init(), isEndVirtual, isStartVirtual, m_bIsGraphConstructed, GraphEdgeInfo::m_dCost, m_dEndPart, GraphEdgeInfo::m_dReverseCost, m_dStartpart, m_lEndEdgeId, GraphEdgeInfo::m_lEndNode, m_lStartEdgeId, GraphEdgeInfo::m_lStartNode, m_mapEdgeId2Index, m_vecEdgeVector, max_edge_id, max_node_id, my_dijkstra2(), edge_t::reverse_cost, edge_t::source, and edge_t::target.

Referenced by trsp_edge_wrapper().

◆ my_dijkstra2()

int GraphDefinition::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 at line 307 of file GraphDefinition.cpp.

314  {
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 }

References isEndVirtual, isStartVirtual, m_bIsturnRestrictOn, m_lEndEdgeId, m_lStartEdgeId, m_mapNodeId2Edge, m_ruleTable, m_vecEdgeVector, and my_dijkstra3().

Referenced by my_dijkstra1().

◆ my_dijkstra3()

int GraphDefinition::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 at line 368 of file GraphDefinition.cpp.

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 }

References construct_graph(), construct_path(), path_element::cost, deleteall(), PARENT_PATH::ed_ind, path_element::edge_id, CostHolder::endCost, explore(), get_single_cost(), init(), isEndVirtual, isStartVirtual, m_bIsGraphConstructed, GraphEdgeInfo::m_dCost, m_dCost, GraphEdgeInfo::m_dReverseCost, GraphEdgeInfo::m_lEdgeIndex, m_lEndEdgeId, GraphEdgeInfo::m_lEndNode, m_lStartEdgeId, GraphEdgeInfo::m_lStartNode, m_mapNodeId2Edge, m_vecEdgeVector, GraphEdgeInfo::m_vecEndConnedtedEdge, m_vecPath, GraphEdgeInfo::m_vecStartConnectedEdge, parent, CostHolder::startCost, PARENT_PATH::v_pos, and path_element::vertex_id.

Referenced by my_dijkstra2().

Member Data Documentation

◆ isEndVirtual

bool GraphDefinition::isEndVirtual
private

Definition at line 171 of file GraphDefinition.h.

Referenced by init(), my_dijkstra1(), my_dijkstra2(), and my_dijkstra3().

◆ isStartVirtual

bool GraphDefinition::isStartVirtual
private

Definition at line 170 of file GraphDefinition.h.

Referenced by init(), my_dijkstra1(), my_dijkstra2(), and my_dijkstra3().

◆ m_bIsGraphConstructed

bool GraphDefinition::m_bIsGraphConstructed
private

Definition at line 178 of file GraphDefinition.h.

Referenced by construct_graph(), GraphDefinition(), my_dijkstra1(), and my_dijkstra3().

◆ m_bIsturnRestrictOn

bool GraphDefinition::m_bIsturnRestrictOn
private

Definition at line 177 of file GraphDefinition.h.

Referenced by explore(), GraphDefinition(), and my_dijkstra2().

◆ m_dCost

CostHolder* GraphDefinition::m_dCost
private

Definition at line 175 of file GraphDefinition.h.

Referenced by construct_path(), deleteall(), explore(), GraphDefinition(), and my_dijkstra3().

◆ m_dEndPart

double GraphDefinition::m_dEndPart
private

Definition at line 169 of file GraphDefinition.h.

Referenced by get_single_cost(), GraphDefinition(), and my_dijkstra1().

◆ m_dStartpart

double GraphDefinition::m_dStartpart
private

Definition at line 168 of file GraphDefinition.h.

Referenced by get_single_cost(), GraphDefinition(), and my_dijkstra1().

◆ m_lEndEdgeId

int64 GraphDefinition::m_lEndEdgeId
private

Definition at line 167 of file GraphDefinition.h.

Referenced by GraphDefinition(), my_dijkstra1(), my_dijkstra2(), and my_dijkstra3().

◆ m_lStartEdgeId

int64 GraphDefinition::m_lStartEdgeId
private

◆ m_mapEdgeId2Index

Long2LongMap GraphDefinition::m_mapEdgeId2Index
private

Definition at line 162 of file GraphDefinition.h.

Referenced by addEdge(), get_single_cost(), and my_dijkstra1().

◆ m_mapNodeId2Edge

Long2LongVectorMap GraphDefinition::m_mapNodeId2Edge
private

Definition at line 163 of file GraphDefinition.h.

Referenced by addEdge(), my_dijkstra2(), and my_dijkstra3().

◆ m_ruleTable

RuleTable GraphDefinition::m_ruleTable
private

Definition at line 176 of file GraphDefinition.h.

Referenced by getRestrictionCost(), and my_dijkstra2().

◆ m_vecEdgeVector

GraphEdgeVector GraphDefinition::m_vecEdgeVector
private

◆ m_vecPath

std::vector<path_element_tt> GraphDefinition::m_vecPath
private

Definition at line 173 of file GraphDefinition.h.

Referenced by construct_path(), and my_dijkstra3().

◆ max_edge_id

int64 GraphDefinition::max_edge_id
private

Definition at line 165 of file GraphDefinition.h.

Referenced by addEdge(), init(), and my_dijkstra1().

◆ max_node_id

int64 GraphDefinition::max_node_id
private

Definition at line 164 of file GraphDefinition.h.

Referenced by addEdge(), init(), and my_dijkstra1().

◆ parent

PARENT_PATH* GraphDefinition::parent
private

The documentation for this class was generated from the following files:
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
path_element
Definition: trsp.h:56
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::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::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