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.sourceforge.net/
11 // Copyright (C) 2001-2012 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 /*
44 SUMOReal
45 recomputeCosts(SUMOAbstractRouter<ROEdge,ROVehicle> &router,
46  const std::vector<const ROEdge*> &edges,
47  const ROVehicle * const v, SUMOTime time) {
48  SUMOReal costs = 0;
49  for (std::vector<const ROEdge*>::const_iterator i=edges.begin(); i!=edges.end(); i++) {
50  costs += router.getEffort(v, time + costs, *i);
51  if ((*i)->prohibits(v)) {
52  return -1;
53  }
54  }
55  return costs;
56 }
57 */
58 
59 void
60 recheckForLoops(std::vector<const ROEdge*>& edges) {
61  // remove loops at the route's begin
62  // (vehicle makes a turnaround to get into the right direction at an already passed node)
63  RONode* start = edges[0]->getFromNode();
64  unsigned lastStart = 0;
65  for (unsigned i = 1; i < edges.size(); i++) {
66  if (edges[i]->getFromNode() == start) {
67  lastStart = i;
68  }
69  }
70  if (lastStart > 0) {
71  edges.erase(edges.begin(), edges.begin() + lastStart - 1);
72  }
73  // remove loops at the route's end
74  // (vehicle makes a turnaround to get into the right direction at an already passed node)
75  RONode* end = edges.back()->getToNode();
76  size_t firstEnd = edges.size() - 1;
77  for (unsigned i = 0; i < firstEnd; i++) {
78  if (edges[i]->getToNode() == end) {
79  firstEnd = i;
80  }
81  }
82  if (firstEnd < edges.size() - 1) {
83  edges.erase(edges.begin() + firstEnd + 2, edges.end());
84  }
85  // remove loops within the route
86  std::vector<RONode*> nodes;
87  for (std::vector<const ROEdge*>::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 std::ostream& operator<<(std::ostream& os, const std::vector<const ROEdge*>& ev) {
113  bool hadFirst = false;
114  for (std::vector<const ROEdge*>::const_iterator j = ev.begin(); j != ev.end(); j++) {
115  if ((*j)->getType() != ROEdge::ET_DISTRICT) {
116  if (hadFirst) {
117  os << ' ';
118  }
119  os << (*j)->getID();
120  hadFirst = true;
121  }
122  }
123  return os;
124 }
125 
126 
127 /****************************************************************************/
128