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 #ifdef HAVE_INTERNAL // catchall for internal stuff
104  s->myApproachingEdges.push_back(this);
105 #endif
106  }
107 }
108 
109 
110 void
111 ROEdge::addEffort(SUMOReal value, SUMOReal timeBegin, SUMOReal timeEnd) {
112  myEfforts.add(timeBegin, timeEnd, value);
113  myUsingETimeLine = true;
114 }
115 
116 
117 void
118 ROEdge::addTravelTime(SUMOReal value, SUMOReal timeBegin, SUMOReal timeEnd) {
119  myTravelTimes.add(timeBegin, timeEnd, value);
120  myUsingTTTimeLine = true;
121 }
122 
123 
124 SUMOReal
125 ROEdge::getEffort(const ROVehicle* const veh, SUMOReal time) const {
126  SUMOReal ret = 0;
127  if (!getStoredEffort(time, ret)) {
128  return (SUMOReal)(myLength / MIN2(veh->getType()->maxSpeed, mySpeed));
129  }
130  return ret;
131 }
132 
133 
134 SUMOReal
135 ROEdge::getDistanceTo(const ROEdge* other) const {
136  if (getToNode() != 0 && other->getFromNode() != 0) {
137  return getToNode()->getPosition().distanceTo2D(other->getFromNode()->getPosition());
138  } else {
139  return 0; // optimism is just right for astar
140  }
141 
142 }
143 
144 
145 SUMOReal
146 ROEdge::getTravelTime(const ROVehicle* const veh, SUMOReal time) const {
147  return getTravelTime(veh->getType()->maxSpeed, time);
148 }
149 
150 
151 SUMOReal
152 ROEdge::getTravelTime(const SUMOReal maxSpeed, SUMOReal time) const {
153  return MAX2(myLength / maxSpeed, getTravelTime(time));
154 }
155 
156 
157 SUMOReal
159  if (myUsingTTTimeLine) {
160  if (!myHaveTTWarned && !myTravelTimes.describesTime(time)) {
161  WRITE_WARNING("No interval matches passed time " + toString(time) + " in edge '" + myID + "'.\n Using edge's length / edge's speed.");
162  myHaveTTWarned = true;
163  }
164  if (myInterpolate) {
165  SUMOReal inTT = myTravelTimes.getValue(time);
166  SUMOReal split = (SUMOReal)(myTravelTimes.getSplitTime(time, time + (SUMOTime)inTT) - time);
167  if (split >= 0) {
168  return myTravelTimes.getValue(time + (SUMOTime)inTT) * ((SUMOReal)1. - split / inTT) + split;
169  }
170  }
171  return myTravelTimes.getValue(time);
172  }
173  return myLength / mySpeed;
174 }
175 
176 
177 SUMOReal
178 ROEdge::getMinimumTravelTime(const ROVehicle* const veh) const {
179  return (SUMOReal)(myLength / MIN2(veh->getType()->maxSpeed, mySpeed));
180 }
181 
182 
183 SUMOReal
184 ROEdge::getCOEffort(const ROVehicle* const veh, SUMOReal time) const {
185  SUMOReal ret = 0;
186  if (!getStoredEffort(time, ret)) {
187  const SUMOReal vMax = MIN2(veh->getType()->maxSpeed, mySpeed);
189  ret = HelpersHBEFA::computeDefaultCO(veh->getType()->emissionClass, vMax, accel, getTravelTime(veh, time));
190  }
191  return ret;
192 }
193 
194 
195 SUMOReal
196 ROEdge::getCO2Effort(const ROVehicle* const veh, SUMOReal time) const {
197  SUMOReal ret = 0;
198  if (!getStoredEffort(time, ret)) {
199  const SUMOReal vMax = MIN2(veh->getType()->maxSpeed, mySpeed);
201  ret = HelpersHBEFA::computeDefaultCO2(veh->getType()->emissionClass, vMax, accel, getTravelTime(veh, time));
202  }
203  return ret;
204 }
205 
206 
207 SUMOReal
208 ROEdge::getPMxEffort(const ROVehicle* const veh, SUMOReal time) const {
209  SUMOReal ret = 0;
210  if (!getStoredEffort(time, ret)) {
211  const SUMOReal vMax = MIN2(veh->getType()->maxSpeed, mySpeed);
213  ret = HelpersHBEFA::computeDefaultPMx(veh->getType()->emissionClass, vMax, accel, getTravelTime(veh, time));
214  }
215  return ret;
216 }
217 
218 
219 SUMOReal
220 ROEdge::getHCEffort(const ROVehicle* const veh, SUMOReal time) const {
221  SUMOReal ret = 0;
222  if (!getStoredEffort(time, ret)) {
223  const SUMOReal vMax = MIN2(veh->getType()->maxSpeed, mySpeed);
225  ret = HelpersHBEFA::computeDefaultHC(veh->getType()->emissionClass, vMax, accel, getTravelTime(veh, time));
226  }
227  return ret;
228 }
229 
230 
231 SUMOReal
232 ROEdge::getNOxEffort(const ROVehicle* const veh, SUMOReal time) const {
233  SUMOReal ret = 0;
234  if (!getStoredEffort(time, ret)) {
235  const SUMOReal vMax = MIN2(veh->getType()->maxSpeed, mySpeed);
237  ret = HelpersHBEFA::computeDefaultNOx(veh->getType()->emissionClass, vMax, accel, getTravelTime(veh, time));
238  }
239  return ret;
240 }
241 
242 
243 SUMOReal
244 ROEdge::getFuelEffort(const ROVehicle* const veh, SUMOReal time) const {
245  SUMOReal ret = 0;
246  if (!getStoredEffort(time, ret)) {
247  const SUMOReal vMax = MIN2(veh->getType()->maxSpeed, mySpeed);
249  ret = HelpersHBEFA::computeDefaultFuel(veh->getType()->emissionClass, vMax, accel, getTravelTime(veh, time));
250  }
251  return ret;
252 }
253 
254 
255 SUMOReal
256 ROEdge::getNoiseEffort(const ROVehicle* const veh, SUMOReal time) const {
257  SUMOReal ret = 0;
258  if (!getStoredEffort(time, ret)) {
259  const SUMOReal v = MIN2(veh->getType()->maxSpeed, mySpeed);
261  }
262  return ret;
263 }
264 
265 
266 bool
268  if (myUsingETimeLine) {
269  if (!myEfforts.describesTime(time)) {
270  if (!myHaveEWarned) {
271  WRITE_WARNING("No interval matches passed time " + toString(time) + " in edge '" + myID + "'.\n Using edge's length / edge's speed.");
272  myHaveEWarned = true;
273  }
274  return false;
275  }
276  if (myInterpolate) {
277  SUMOReal inTT = myTravelTimes.getValue(time);
278  SUMOReal ratio = (SUMOReal)(myEfforts.getSplitTime(time, time + (SUMOTime)inTT) - time) / inTT;
279  if (ratio >= 0) {
280  ret = ratio * myEfforts.getValue(time) + (1 - ratio) * myEfforts.getValue(time + (SUMOTime)inTT);
281  return true;
282  }
283  }
284  ret = myEfforts.getValue(time);
285  return true;
286  }
287  return false;
288 }
289 
290 
291 unsigned int
293  if (getType() == ET_SINK) {
294  return 0;
295  }
296  return (unsigned int) myFollowingEdges.size();
297 }
298 
299 
300 #ifdef HAVE_INTERNAL // catchall for internal stuff
301 unsigned int
302 ROEdge::getNumApproaching() const {
303  if (getType() == ET_SOURCE) {
304  return 0;
305  }
306  return (unsigned int) myApproachingEdges.size();
307 }
308 #endif
309 
310 
311 void
313  myType = type;
314 }
315 
316 
317 void
318 ROEdge::buildTimeLines(const std::string& measure) {
319  if (myUsingETimeLine) {
320  SUMOReal value = (SUMOReal)(myLength / mySpeed);
321  if (measure == "CO") {
322  value = HelpersHBEFA::computeCO(SVE_UNKNOWN, mySpeed, 0) * value;
323  }
324  if (measure == "CO2") {
325  value = HelpersHBEFA::computeCO2(SVE_UNKNOWN, mySpeed, 0) * value;
326  }
327  if (measure == "HC") {
328  value = HelpersHBEFA::computeHC(SVE_UNKNOWN, mySpeed, 0) * value;
329  }
330  if (measure == "PMx") {
331  value = HelpersHBEFA::computePMx(SVE_UNKNOWN, mySpeed, 0) * value;
332  }
333  if (measure == "NOx") {
334  value = HelpersHBEFA::computeNOx(SVE_UNKNOWN, mySpeed, 0) * value;
335  }
336  if (measure == "fuel") {
337  value = HelpersHBEFA::computeFuel(SVE_UNKNOWN, mySpeed, 0) * value;
338  }
340  }
341  if (myUsingTTTimeLine) {
342  SUMOReal value = (SUMOReal)(myLength / mySpeed);
344  }
345 }
346 
347 
348 bool
349 ROEdge::allFollowersProhibit(const ROVehicle* const vehicle) const {
350  for (std::vector<ROEdge*>::const_iterator i = myFollowingEdges.begin(); i != myFollowingEdges.end(); ++i) {
351  if (!(*i)->prohibits(vehicle)) {
352  return false;
353  }
354  }
355  return true;
356 }
357 
358 
359 ROEdge*
360 ROEdge::dictionary(size_t id) {
361  assert(myEdges.size() > id);
362  return myEdges[id];
363 }
364 
365 
366 
367 /****************************************************************************/
368 
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:197
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:150
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:135
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:435
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:360
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:208
const SUMOVTypeParameter * getType() const
Returns the type of the vehicle.
Definition: ROVehicle.h:90
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:196
T MAX2(T a, T b)
Definition: StdDefs.h:63
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:433
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:118
#define WRITE_WARNING(msg)
Definition: MsgHandler.h:196
RONode * getFromNode() const
Returns the node this edge starts at.
Definition: ROEdge.h:189
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:57
void setType(EdgeType type)
Sets the type of te edge.
Definition: ROEdge.cpp:312
bool allFollowersProhibit(const ROVehicle *const vehicle) const
Returns whether this edge succeding edges prohibit the given vehicle to pass them.
Definition: ROEdge.cpp:349
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:220
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:232
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:430
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:292
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:111
SUMOReal getFuelEffort(const ROVehicle *const veh, SUMOReal time) const
Definition: ROEdge.cpp:244
SUMOReal getEffort(const ROVehicle *const veh, SUMOReal time) const
Returns the effort for this edge.
Definition: ROEdge.cpp:125
void buildTimeLines(const std::string &measure)
Builds the internal representation of the travel time/effort.
Definition: ROEdge.cpp:318
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:267
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:256
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:221
SUMOReal getCOEffort(const ROVehicle *const veh, SUMOReal time) const
Definition: ROEdge.cpp:184
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:146
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:178
EdgeType myType
The type of the edge.
Definition: ROEdge.h:427
SVCPermissions getPermissions()
Returns the list of allowed vehicle classes.
Definition: ROLane.h:88
SUMOEmissionClass emissionClass
The emission class of this vehicle.