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