SUMO - Simulation of Urban MObility
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups 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-sim.org/
11 // Copyright (C) 2001-2014 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
44 recheckForLoops(std::vector<const ROEdge*>& edges) {
45  // remove loops at the route's begin
46  // (vehicle makes a turnaround to get into the right direction at an already passed node)
47  RONode* start = edges[0]->getFromNode();
48  unsigned lastStart = 0;
49  for (unsigned i = 1; i < edges.size(); i++) {
50  if (edges[i]->getFromNode() == start) {
51  lastStart = i;
52  }
53  }
54  if (lastStart > 0) {
55  edges.erase(edges.begin(), edges.begin() + lastStart - 1);
56  }
57  // remove loops at the route's end
58  // (vehicle makes a turnaround to get into the right direction at an already passed node)
59  RONode* end = edges.back()->getToNode();
60  size_t firstEnd = edges.size() - 1;
61  for (unsigned i = 0; i < firstEnd; i++) {
62  if (edges[i]->getToNode() == end) {
63  firstEnd = i;
64  }
65  }
66  if (firstEnd < edges.size() - 1) {
67  edges.erase(edges.begin() + firstEnd + 2, edges.end());
68  }
69  // remove loops within the route
70  std::vector<RONode*> nodes;
71  for (std::vector<const ROEdge*>::iterator i = edges.begin(); i != edges.end(); ++i) {
72  nodes.push_back((*i)->getFromNode());
73  }
74  nodes.push_back(edges.back()->getToNode());
75  bool changed = false;
76  do {
77  changed = false;
78  for (unsigned int b = 0; b < nodes.size() && !changed; ++b) {
79  RONode* bn = nodes[b];
80  for (unsigned int e = b + 1; e < nodes.size() && !changed; ++e) {
81  if (bn == nodes[e]) {
82  changed = true;
83  nodes.erase(nodes.begin() + b, nodes.begin() + e);
84  edges.erase(edges.begin() + b, edges.begin() + e);
85  }
86  }
87  }
88  } while (changed);
89  /*
90  */
91 }
92 
93 
94 }
95 
96 
97 /****************************************************************************/
98 
Base class for nodes used by the router.
Definition: RONode.h:51
void recheckForLoops(std::vector< const ROEdge * > &edges)
Checks whether the given edge list contains loops and removes them.
Definition: ROHelper.cpp:44