SUMO - Simulation of Urban MObility
ROHelper.cpp
Go to the documentation of this file.
1 /****************************************************************************/
2 // Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.org/sumo
3 // Copyright (C) 2001-2017 German Aerospace Center (DLR) and others.
4 /****************************************************************************/
5 //
6 // This program and the accompanying materials
7 // are made available under the terms of the Eclipse Public License v2.0
8 // which accompanies this distribution, and is available at
9 // http://www.eclipse.org/legal/epl-v20.html
10 //
11 /****************************************************************************/
18 // Some helping methods for router
19 /****************************************************************************/
20 
21 // ===========================================================================
22 // included modules
23 // ===========================================================================
24 #ifdef _MSC_VER
25 #include <windows_config.h>
26 #else
27 #include <config.h>
28 #endif
29 
30 #include <functional>
31 #include <vector>
32 #include "ROEdge.h"
33 #include "ROVehicle.h"
34 
35 
36 // ===========================================================================
37 // class definitions
38 // ===========================================================================
39 
40 
41 namespace ROHelper {
42 void
44  // XXX check for stops, departLane, departPos, departSpeed, ....
45 
46  // removal of edge loops within the route (edge occurs twice)
47  std::map<const ROEdge*, int> lastOccurence; // index of the last occurence of this edge
48  for (int ii = 0; ii < (int)edges.size(); ++ii) {
49  std::map<const ROEdge*, int>::iterator it_pre = lastOccurence.find(edges[ii]);
50  if (it_pre != lastOccurence.end()) {
51  edges.erase(edges.begin() + it_pre->second, edges.begin() + ii);
52  ii = it_pre->second;
53  } else {
54  lastOccurence[edges[ii]] = ii;
55  }
56  }
57 
58  // remove loops at the route's begin
59  // (vehicle makes a turnaround to get into the right direction at an already passed node)
60  const RONode* start = edges[0]->getFromJunction();
61  int lastStart = 0;
62  for (int i = 1; i < (int)edges.size(); i++) {
63  if (edges[i]->getFromJunction() == start) {
64  lastStart = i;
65  }
66  }
67  if (lastStart > 0) {
68  edges.erase(edges.begin(), edges.begin() + lastStart - 1);
69  }
70  // remove loops at the route's end
71  // (vehicle makes a turnaround to get into the right direction at an already passed node)
72  const RONode* end = edges.back()->getToJunction();
73  int firstEnd = (int)edges.size() - 1;
74  for (int i = 0; i < firstEnd; i++) {
75  if (edges[i]->getToJunction() == end) {
76  firstEnd = i;
77  }
78  }
79  if (firstEnd < (int)edges.size() - 1) {
80  edges.erase(edges.begin() + firstEnd + 2, edges.end());
81  }
82 
83  // removal of node loops (node occurs twice) is not done because these may occur legitimately
84  /*
85  std::vector<RONode*> nodes;
86  for (ConstROEdgeVector::iterator i = edges.begin(); i != edges.end(); ++i) {
87  nodes.push_back((*i)->getFromJunction());
88  }
89  nodes.push_back(edges.back()->getToJunction());
90  bool changed = false;
91  do {
92  changed = false;
93  for (int b = 0; b < nodes.size() && !changed; ++b) {
94  RONode* bn = nodes[b];
95  for (int e = b + 1; e < nodes.size() && !changed; ++e) {
96  if (bn == nodes[e]) {
97  changed = true;
98  nodes.erase(nodes.begin() + b, nodes.begin() + e);
99  edges.erase(edges.begin() + b, edges.begin() + e);
100  }
101  }
102  }
103  } while (changed);
104  */
105 }
106 
107 
108 }
109 
110 
111 /****************************************************************************/
112 
void recheckForLoops(ConstROEdgeVector &edges)
Checks whether the given edge list contains loops and removes them.
Definition: ROHelper.cpp:43
std::vector< const ROEdge * > ConstROEdgeVector
Definition: ROEdge.h:62
Some helping methods for router.
Definition: ROHelper.cpp:41
Base class for nodes used by the router.
Definition: RONode.h:52