SUMO - Simulation of Urban MObility
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
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-2015 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  // remove loops at the route's begin
48  // (vehicle makes a turnaround to get into the right direction at an already passed node)
49  RONode* start = edges[0]->getFromNode();
50  unsigned lastStart = 0;
51  for (unsigned i = 1; i < edges.size(); i++) {
52  if (edges[i]->getFromNode() == start) {
53  lastStart = i;
54  }
55  }
56  if (lastStart > 0) {
57  edges.erase(edges.begin(), edges.begin() + lastStart - 1);
58  }
59  // remove loops at the route's end
60  // (vehicle makes a turnaround to get into the right direction at an already passed node)
61  RONode* end = edges.back()->getToNode();
62  size_t firstEnd = edges.size() - 1;
63  for (unsigned i = 0; i < firstEnd; i++) {
64  if (edges[i]->getToNode() == end) {
65  firstEnd = i;
66  }
67  }
68  if (firstEnd < edges.size() - 1) {
69  edges.erase(edges.begin() + firstEnd + 2, edges.end());
70  }
71 
72  // removal of edge loops within the route (edge occurs twice)
73  std::map<const ROEdge*, size_t> lastOccurence; // index of the last occurence of this edge
74  for (size_t ii = 0; ii < edges.size(); ++ii) {
75  std::map<const ROEdge*, size_t>::iterator it_pre = lastOccurence.find(edges[ii]);
76  if (it_pre != lastOccurence.end()) {
77  edges.erase(edges.begin() + it_pre->second, edges.begin() + ii);
78  ii = it_pre->second;
79  } else {
80  lastOccurence[edges[ii]] = ii;
81  }
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)->getFromNode());
89  }
90  nodes.push_back(edges.back()->getToNode());
91  bool changed = false;
92  do {
93  changed = false;
94  for (unsigned int b = 0; b < nodes.size() && !changed; ++b) {
95  RONode* bn = nodes[b];
96  for (unsigned 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:59
Some helping methods for router.
Definition: ROHelper.cpp:42
Base class for nodes used by the router.
Definition: RONode.h:53