SUMO - Simulation of Urban MObility
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
ROEdge.cpp
Go to the documentation of this file.
1 /****************************************************************************/
10 // A basic edge for routing applications
11 /****************************************************************************/
12 // SUMO, Simulation of Urban MObility; see http://sumo-sim.org/
13 // Copyright (C) 2001-2013 DLR (http://www.dlr.de/) and contributors
14 /****************************************************************************/
15 //
16 // This file is part of SUMO.
17 // SUMO is free software: you can redistribute it and/or modify
18 // it under the terms of the GNU General Public License as published by
19 // the Free Software Foundation, either version 3 of the License, or
20 // (at your option) any later version.
21 //
22 /****************************************************************************/
23 
24 
25 // ===========================================================================
26 // included modules
27 // ===========================================================================
28 #ifdef _MSC_VER
29 #include <windows_config.h>
30 #else
31 #include <config.h>
32 #endif
33 
35 #include <utils/common/ToString.h>
36 #include <algorithm>
37 #include <cassert>
38 #include <iostream>
39 #include "ROLane.h"
40 #include "ROEdge.h"
41 #include "ROVehicle.h"
45 
46 #ifdef CHECK_MEMORY_LEAKS
47 #include <foreign/nvwa/debug_new.h>
48 #endif // CHECK_MEMORY_LEAKS
49 
50 
51 // ===========================================================================
52 // static member definitions
53 // ===========================================================================
56 bool ROEdge::myInterpolate = false;
57 bool ROEdge::myHaveTTWarned = false;
58 bool ROEdge::myHaveEWarned = false;
59 std::vector<ROEdge*> ROEdge::myEdges;
60 
61 
62 // ===========================================================================
63 // method definitions
64 // ===========================================================================
65 ROEdge::ROEdge(const std::string& id, RONode* from, RONode* to, unsigned int index, const int priority)
66  : Named(id), myFromNode(from), myToNode(to), myIndex(index), myPriority(priority),
67  mySpeed(-1), myLength(-1),
68  myUsingTTTimeLine(false),
69  myUsingETimeLine(false),
70  myCombinedPermissions(0) {
71  while (myEdges.size() <= index) {
72  myEdges.push_back(0);
73  }
74  myEdges[index] = this;
75 }
76 
77 
79  for (std::vector<ROLane*>::iterator i = myLanes.begin(); i != myLanes.end(); ++i) {
80  delete(*i);
81  }
82 }
83 
84 
85 void
87  SUMOReal length = lane->getLength();
88  assert(myLength == -1 || length == myLength);
89  myLength = length;
90  SUMOReal speed = lane->getSpeed();
91  mySpeed = speed > mySpeed ? speed : mySpeed;
92  myLanes.push_back(lane);
93 
94  // integrate new allowed classes
96 }
97 
98 
99 void
100 ROEdge::addFollower(ROEdge* s, std::string) {
101  if (find(myFollowingEdges.begin(), myFollowingEdges.end(), s) == myFollowingEdges.end()) {
102  myFollowingEdges.push_back(s);
103  s->myApproachingEdges.push_back(this);
104  }
105 }
106 
107 
108 void
109 ROEdge::addEffort(SUMOReal value, SUMOReal timeBegin, SUMOReal timeEnd) {
110  myEfforts.add(timeBegin, timeEnd, value);
111  myUsingETimeLine = true;
112 }
113 
114 
115 void
116 ROEdge::addTravelTime(SUMOReal value, SUMOReal timeBegin, SUMOReal timeEnd) {
117  myTravelTimes.add(timeBegin, timeEnd, value);
118  myUsingTTTimeLine = true;
119 }
120 
121 
122 SUMOReal
123 ROEdge::getEffort(const ROVehicle* const veh, SUMOReal time) const {
124  SUMOReal ret = 0;
125  if (!getStoredEffort(time, ret)) {
126  return (SUMOReal)(myLength / MIN2(veh->getType()->maxSpeed, mySpeed));
127  }
128  return ret;
129 }
130 
131 
132 SUMOReal
133 ROEdge::getDistanceTo(const ROEdge* other) const {
134  if (getToNode() != 0 && other->getFromNode() != 0) {
135  return getToNode()->getPosition().distanceTo2D(other->getFromNode()->getPosition());
136  } else {
137  return 0; // optimism is just right for astar
138  }
139 
140 }
141 
142 
143 SUMOReal
144 ROEdge::getTravelTime(const ROVehicle* const veh, SUMOReal time) const {
145  return getTravelTime(veh->getType()->maxSpeed, time);
146 }
147 
148 
149 SUMOReal
150 ROEdge::getTravelTime(const SUMOReal maxSpeed, SUMOReal time) const {
151  return MAX2(myLength / maxSpeed, getTravelTime(time));
152 }
153 
154 
155 SUMOReal
157  if (myUsingTTTimeLine) {
158  if (!myHaveTTWarned && !myTravelTimes.describesTime(time)) {
159  WRITE_WARNING("No interval matches passed time " + toString(time) + " in edge '" + myID + "'.\n Using edge's length / edge's speed.");
160  myHaveTTWarned = true;
161  }
162  if (myInterpolate) {
163  SUMOReal inTT = myTravelTimes.getValue(time);
164  SUMOReal split = (SUMOReal)(myTravelTimes.getSplitTime(time, time + (SUMOTime)inTT) - time);
165  if (split >= 0) {
166  return myTravelTimes.getValue(time + (SUMOTime)inTT) * ((SUMOReal)1. - split / inTT) + split;
167  }
168  }
169  return myTravelTimes.getValue(time);
170  }
171  return myLength / mySpeed;
172 }
173 
174 
175 SUMOReal
176 ROEdge::getMinimumTravelTime(const ROVehicle* const veh) const {
177  return (SUMOReal)(myLength / MIN2(veh->getType()->maxSpeed, mySpeed));
178 }
179 
180 
181 SUMOReal
182 ROEdge::getCOEffort(const ROVehicle* const veh, SUMOReal time) const {
183  SUMOReal ret = 0;
184  if (!getStoredEffort(time, ret)) {
185  const SUMOReal vMax = MIN2(veh->getType()->maxSpeed, mySpeed);
187  ret = HelpersHBEFA::computeDefaultCO(veh->getType()->emissionClass, vMax, accel, getTravelTime(veh, time));
188  }
189  return ret;
190 }
191 
192 
193 SUMOReal
194 ROEdge::getCO2Effort(const ROVehicle* const veh, SUMOReal time) const {
195  SUMOReal ret = 0;
196  if (!getStoredEffort(time, ret)) {
197  const SUMOReal vMax = MIN2(veh->getType()->maxSpeed, mySpeed);
199  ret = HelpersHBEFA::computeDefaultCO2(veh->getType()->emissionClass, vMax, accel, getTravelTime(veh, time));
200  }
201  return ret;
202 }
203 
204 
205 SUMOReal
206 ROEdge::getPMxEffort(const ROVehicle* const veh, SUMOReal time) const {
207  SUMOReal ret = 0;
208  if (!getStoredEffort(time, ret)) {
209  const SUMOReal vMax = MIN2(veh->getType()->maxSpeed, mySpeed);
211  ret = HelpersHBEFA::computeDefaultPMx(veh->getType()->emissionClass, vMax, accel, getTravelTime(veh, time));
212  }
213  return ret;
214 }
215 
216 
217 SUMOReal
218 ROEdge::getHCEffort(const ROVehicle* const veh, SUMOReal time) const {
219  SUMOReal ret = 0;
220  if (!getStoredEffort(time, ret)) {
221  const SUMOReal vMax = MIN2(veh->getType()->maxSpeed, mySpeed);
223  ret = HelpersHBEFA::computeDefaultHC(veh->getType()->emissionClass, vMax, accel, getTravelTime(veh, time));
224  }
225  return ret;
226 }
227 
228 
229 SUMOReal
230 ROEdge::getNOxEffort(const ROVehicle* const veh, SUMOReal time) const {
231  SUMOReal ret = 0;
232  if (!getStoredEffort(time, ret)) {
233  const SUMOReal vMax = MIN2(veh->getType()->maxSpeed, mySpeed);
235  ret = HelpersHBEFA::computeDefaultNOx(veh->getType()->emissionClass, vMax, accel, getTravelTime(veh, time));
236  }
237  return ret;
238 }
239 
240 
241 SUMOReal
242 ROEdge::getFuelEffort(const ROVehicle* const veh, SUMOReal time) const {
243  SUMOReal ret = 0;
244  if (!getStoredEffort(time, ret)) {
245  const SUMOReal vMax = MIN2(veh->getType()->maxSpeed, mySpeed);
247  ret = HelpersHBEFA::computeDefaultFuel(veh->getType()->emissionClass, vMax, accel, getTravelTime(veh, time));
248  }
249  return ret;
250 }
251 
252 
253 SUMOReal
254 ROEdge::getNoiseEffort(const ROVehicle* const veh, SUMOReal time) const {
255  SUMOReal ret = 0;
256  if (!getStoredEffort(time, ret)) {
257  const SUMOReal v = MIN2(veh->getType()->maxSpeed, mySpeed);
259  }
260  return ret;
261 }
262 
263 
264 bool
266  if (myUsingETimeLine) {
267  if (!myEfforts.describesTime(time)) {
268  if (!myHaveEWarned) {
269  WRITE_WARNING("No interval matches passed time " + toString(time) + " in edge '" + myID + "'.\n Using edge's length / edge's speed.");
270  myHaveEWarned = true;
271  }
272  return false;
273  }
274  if (myInterpolate) {
275  SUMOReal inTT = myTravelTimes.getValue(time);
276  SUMOReal ratio = (SUMOReal)(myEfforts.getSplitTime(time, time + (SUMOTime)inTT) - time) / inTT;
277  if (ratio >= 0) {
278  ret = ratio * myEfforts.getValue(time) + (1 - ratio) * myEfforts.getValue(time + (SUMOTime)inTT);
279  return true;
280  }
281  }
282  ret = myEfforts.getValue(time);
283  return true;
284  }
285  return false;
286 }
287 
288 
289 unsigned int
291  if (getType() == ET_SINK) {
292  return 0;
293  }
294  return (unsigned int) myFollowingEdges.size();
295 }
296 
297 
298 unsigned int
300  if (getType() == ET_SOURCE) {
301  return 0;
302  }
303  return (unsigned int) myApproachingEdges.size();
304 }
305 
306 
307 void
309  myType = type;
310 }
311 
312 
313 void
314 ROEdge::buildTimeLines(const std::string& measure) {
315  if (myUsingETimeLine) {
316  SUMOReal value = (SUMOReal)(myLength / mySpeed);
317  if (measure == "CO") {
318  value = HelpersHBEFA::computeCO(SVE_UNKNOWN, mySpeed, 0) * value;
319  }
320  if (measure == "CO2") {
321  value = HelpersHBEFA::computeCO2(SVE_UNKNOWN, mySpeed, 0) * value;
322  }
323  if (measure == "HC") {
324  value = HelpersHBEFA::computeHC(SVE_UNKNOWN, mySpeed, 0) * value;
325  }
326  if (measure == "PMx") {
327  value = HelpersHBEFA::computePMx(SVE_UNKNOWN, mySpeed, 0) * value;
328  }
329  if (measure == "NOx") {
330  value = HelpersHBEFA::computeNOx(SVE_UNKNOWN, mySpeed, 0) * value;
331  }
332  if (measure == "fuel") {
333  value = HelpersHBEFA::computeFuel(SVE_UNKNOWN, mySpeed, 0) * value;
334  }
336  }
337  if (myUsingTTTimeLine) {
338  SUMOReal value = (SUMOReal)(myLength / mySpeed);
340  }
341 }
342 
343 
344 bool
345 ROEdge::allFollowersProhibit(const ROVehicle* const vehicle) const {
346  for (std::vector<ROEdge*>::const_iterator i = myFollowingEdges.begin(); i != myFollowingEdges.end(); ++i) {
347  if (!(*i)->prohibits(vehicle)) {
348  return false;
349  }
350  }
351  return true;
352 }
353 
354 
355 ROEdge*
356 ROEdge::dictionary(size_t id) {
357  assert(myEdges.size() > id);
358  return myEdges[id];
359 }
360 
361 
362 
363 /****************************************************************************/
364 
void fillGaps(T value, bool extendOverBoundaries=false)
Sets a default value for all unset intervals.
static SUMOReal computeCO(SUMOEmissionClass c, double v, double a)
Returns the amount of emitted CO given the vehicle type and state (in mg/s)
RONode * getToNode() const
Returns the node this edge ends at.
Definition: ROEdge.h:199
SUMOReal get(const SumoXMLAttr attr, const SUMOReal defaultValue) const
Returns the named value from the map, or the default if it is ot contained there. ...
EdgeType getType() const
Returns the type of the edge.
Definition: ROEdge.h:152
static bool myUseBoundariesOnOverrideTT
Whether overriding weight boundaries shall be reported.
Definition: ROEdge.h:401
static SUMOReal computeHC(SUMOEmissionClass c, double v, double a)
Returns the amount of emitted HC given the vehicle type and state (in mg/s)
A single lane the router may use.
Definition: ROLane.h:51
SUMOReal getDistanceTo(const ROEdge *other) const
optimistic distance heuristic for use in routing
Definition: ROEdge.cpp:133
static SUMOReal computeDefaultFuel(SUMOEmissionClass c, double v, double a, SUMOReal tt)
Returns the amount of fuel given the vehicle type and default values for the state (in ml) ...
static std::vector< ROEdge * > myEdges
Definition: ROEdge.h:433
SUMOReal getSplitTime(SUMOReal low, SUMOReal high) const
Returns the time point at which the value changes.
static bool myInterpolate
Information whether to interpolate at interval boundaries.
Definition: ROEdge.h:411
EdgeType
Possible types of edges.
Definition: ROEdge.h:73
static ROEdge * dictionary(size_t index)
Returns the ROEdge at the index.
Definition: ROEdge.cpp:356
ValueTimeLine< SUMOReal > myTravelTimes
Container storing passing time varying over time for the edge.
Definition: ROEdge.h:397
virtual void addLane(ROLane *lane)
Adds a lane to the edge while loading.
Definition: ROEdge.cpp:86
SUMOReal getPMxEffort(const ROVehicle *const veh, SUMOReal time) const
Definition: ROEdge.cpp:206
const SUMOVTypeParameter * getType() const
Returns the type of the vehicle.
Definition: ROVehicle.h:92
const Position & getPosition()
Returns the position of the node.
Definition: RONode.h:67
SUMOReal getCO2Effort(const ROVehicle *const veh, SUMOReal time) const
Definition: ROEdge.cpp:194
T MAX2(T a, T b)
Definition: StdDefs.h:63
std::vector< ROEdge * > myApproachingEdges
List of edges that approached this edge.
Definition: ROEdge.h:422
const SUMOReal DEFAULT_VEH_SIGMA
void add(SUMOReal begin, SUMOReal end, T value)
Adds a value for a time interval into the container.
Definition: ValueTimeLine.h:69
static bool myUseBoundariesOnOverrideE
Whether overriding weight boundaries shall be reported.
Definition: ROEdge.h:408
SVCPermissions myCombinedPermissions
The list of allowed vehicle classes combined across lanes.
Definition: ROEdge.h:431
SUMOReal getSpeed() const
Returns the maximum speed allowed on this lane.
Definition: ROLane.h:80
void addTravelTime(SUMOReal value, SUMOReal timeBegin, SUMOReal timeEnd)
Adds a travel time value.
Definition: ROEdge.cpp:116
#define WRITE_WARNING(msg)
Definition: MsgHandler.h:196
RONode * getFromNode() const
Returns the node this edge starts at.
Definition: ROEdge.h:191
static SUMOReal computeNoise(SUMOEmissionClass c, double v, double a)
Returns the noise produced by the a vehicle of the given type at the given speed. ...
An edge where vehicles are inserted at (no vehicle may come from back)
Definition: ROEdge.h:79
A vehicle as used by router.
Definition: ROVehicle.h:58
void setType(EdgeType type)
Sets the type of te edge.
Definition: ROEdge.cpp:308
bool allFollowersProhibit(const ROVehicle *const vehicle) const
Returns whether this edge succeding edges prohibit the given vehicle to pass them.
Definition: ROEdge.cpp:345
static SUMOReal computeDefaultNOx(SUMOEmissionClass c, double v, double a, SUMOReal tt)
Returns the amount of emitted NOx given the vehicle type and default values for the state (in mg) ...
bool describesTime(SUMOReal time) const
Returns whether a value for the given time is known.
ValueTimeLine< SUMOReal > myEfforts
Container storing passing time varying over time for the edge.
Definition: ROEdge.h:404
bool myUsingTTTimeLine
Information whether the time line shall be used instead of the length value.
Definition: ROEdge.h:399
static bool myHaveEWarned
Information whether the edge has reported missing weights.
Definition: ROEdge.h:414
SUMOReal myLength
The length of the edge.
Definition: ROEdge.h:393
bool myUsingETimeLine
Information whether the time line shall be used instead of the length value.
Definition: ROEdge.h:406
SUMOReal getHCEffort(const ROVehicle *const veh, SUMOReal time) const
Definition: ROEdge.cpp:218
static SUMOReal computeCO2(SUMOEmissionClass c, double v, double a)
Returns the amount of emitted CO2 given the vehicle type and state (in mg/s)
SUMOReal getNOxEffort(const ROVehicle *const veh, SUMOReal time) const
Definition: ROEdge.cpp:230
T MIN2(T a, T b)
Definition: StdDefs.h:57
static SUMOReal computeDefaultCO2(SUMOEmissionClass c, double v, double a, SUMOReal tt)
Returns the amount of emitted CO2 given the vehicle type and default values for the state (in mg) ...
std::string toString(const T &t, std::streamsize accuracy=OUTPUT_ACCURACY)
Definition: ToString.h:51
T getValue(SUMOReal time) const
Returns the value for the given time.
std::vector< ROLane * > myLanes
This edge&#39;s lanes.
Definition: ROEdge.h:428
ROEdge(const std::string &id, RONode *from, RONode *to, unsigned int index, const int priority)
Constructor.
Definition: ROEdge.cpp:65
virtual ~ROEdge()
Destructor.
Definition: ROEdge.cpp:78
A basic edge for routing applications.
Definition: ROEdge.h:67
Base class for objects which have an id.
Definition: Named.h:45
SUMOReal mySpeed
The maximum speed allowed on this edge.
Definition: ROEdge.h:390
SUMOReal maxSpeed
The vehicle type&#39;s maximum speed [m/s].
std::vector< ROEdge * > myFollowingEdges
List of edges that may be approached from this edge.
Definition: ROEdge.h:419
unsigned int getNoFollowing() const
Returns the number of edges this edge is connected to.
Definition: ROEdge.cpp:290
std::string myID
The name of the object.
Definition: Named.h:121
static SUMOReal computeDefaultPMx(SUMOEmissionClass c, double v, double a, SUMOReal tt)
Returns the amount of emitted PMx given the vehicle type and default values for the state (in mg) ...
void addEffort(SUMOReal value, SUMOReal timeBegin, SUMOReal timeEnd)
Adds a weight value.
Definition: ROEdge.cpp:109
SUMOReal getFuelEffort(const ROVehicle *const veh, SUMOReal time) const
Definition: ROEdge.cpp:242
unsigned int getNumApproaching() const
Returns the number of edges this edge is connected to.
Definition: ROEdge.cpp:299
SUMOReal getEffort(const ROVehicle *const veh, SUMOReal time) const
Returns the effort for this edge.
Definition: ROEdge.cpp:123
void buildTimeLines(const std::string &measure)
Builds the internal representation of the travel time/effort.
Definition: ROEdge.cpp:314
static SUMOReal computeNOx(SUMOEmissionClass c, double v, double a)
Returns the amount of emitted NOx given the vehicle type and state (in mg/s)
SUMOReal getLength() const
Returns the length of the lane.
Definition: ROLane.h:72
bool getStoredEffort(SUMOReal time, SUMOReal &ret) const
Retrieves the stored effort.
Definition: ROEdge.cpp:265
static SUMOReal computeDefaultCO(SUMOEmissionClass c, double v, double a, SUMOReal tt)
Returns the amount of emitted CO given the vehicle type and default values for the state (in mg) ...
static SUMOReal computeFuel(SUMOEmissionClass c, double v, double a)
Returns the amount of consumed fuel given the vehicle type and state (in ml/s)
SUMOReal getNoiseEffort(const ROVehicle *const veh, SUMOReal time) const
Definition: ROEdge.cpp:254
SUMOReal distanceTo2D(const Position &p2) const
returns the euclidean distance in the x-y-plane
Definition: Position.h:219
const SUMOReal DEFAULT_VEH_ACCEL
static SUMOReal computePMx(SUMOEmissionClass c, double v, double a)
Returns the amount of emitted PMx given the vehicle type and state (in mg/s)
#define SUMOReal
Definition: config.h:215
SUMOReal getCOEffort(const ROVehicle *const veh, SUMOReal time) const
Definition: ROEdge.cpp:182
Base class for nodes used by the router.
Definition: RONode.h:46
SUMOReal getTravelTime(const ROVehicle *const veh, SUMOReal time) const
Returns the travel time for this edge.
Definition: ROEdge.cpp:144
An edge where vehicles disappear (no vehicle may leave this edge)
Definition: ROEdge.h:81
static bool myHaveTTWarned
Information whether the edge has reported missing weights.
Definition: ROEdge.h:416
static SUMOReal computeDefaultHC(SUMOEmissionClass c, double v, double a, SUMOReal tt)
Returns the amount of emitted HC given the vehicle type and default values for the state (in mg) ...
virtual void addFollower(ROEdge *s, std::string dir="")
Adds information about a connected edge.
Definition: ROEdge.cpp:100
SUMOReal getMinimumTravelTime(const ROVehicle *const veh) const
Returns the travel time for this edge without using any stored timeLine.
Definition: ROEdge.cpp:176
EdgeType myType
The type of the edge.
Definition: ROEdge.h:425
SVCPermissions getPermissions()
Returns the list of allowed vehicle classes.
Definition: ROLane.h:88
SUMOEmissionClass emissionClass
The emission class of this vehicle.