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