SUMO - Simulation of Urban MObility
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.dlr.de/
15 // Copyright (C) 2002-2015 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 "RONet.h"
44 #include "ROVehicle.h"
48 
49 #ifdef CHECK_MEMORY_LEAKS
50 #include <foreign/nvwa/debug_new.h>
51 #endif // CHECK_MEMORY_LEAKS
52 
53 
54 // ===========================================================================
55 // static member definitions
56 // ===========================================================================
57 bool ROEdge::myInterpolate = false;
58 bool ROEdge::myAmParallel = false;
59 bool ROEdge::myHaveTTWarned = false;
60 bool ROEdge::myHaveEWarned = false;
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),
69  myFromJunction(from),
70  myToJunction(to),
71  myIndex(index),
72  myPriority(priority),
73  mySpeed(-1),
74  myLength(0),
75  myUsingTTTimeLine(false),
76  myUsingETimeLine(false),
77  myCombinedPermissions(0) {
78  while (myEdges.size() <= index) {
79  myEdges.push_back(0);
80  }
81  myEdges[index] = this;
82  if (from == 0 && to == 0) {
83  // TAZ edge, no lanes
85  }
86 }
87 
88 
90  for (std::vector<ROLane*>::iterator i = myLanes.begin(); i != myLanes.end(); ++i) {
91  delete(*i);
92  }
93 }
94 
95 
96 void
98  assert(myLanes.empty() || lane->getLength() == myLength);
99  myLength = lane->getLength();
100  const SUMOReal speed = lane->getSpeed();
101  mySpeed = speed > mySpeed ? speed : mySpeed;
102  myLanes.push_back(lane);
103 
104  // integrate new allowed classes
106 }
107 
108 
109 void
110 ROEdge::addSuccessor(ROEdge* s, std::string) {
111  if (find(myFollowingEdges.begin(), myFollowingEdges.end(), s) == myFollowingEdges.end()) {
112  myFollowingEdges.push_back(s);
113  s->myApproachingEdges.push_back(this);
114  }
115 }
116 
117 
118 void
119 ROEdge::addEffort(SUMOReal value, SUMOReal timeBegin, SUMOReal timeEnd) {
120  myEfforts.add(timeBegin, timeEnd, value);
121  myUsingETimeLine = true;
122 }
123 
124 
125 void
126 ROEdge::addTravelTime(SUMOReal value, SUMOReal timeBegin, SUMOReal timeEnd) {
127  myTravelTimes.add(timeBegin, timeEnd, value);
128  myUsingTTTimeLine = true;
129 }
130 
131 
132 SUMOReal
133 ROEdge::getEffort(const ROVehicle* const veh, SUMOReal time) const {
134  SUMOReal ret = 0;
135  if (!getStoredEffort(time, ret)) {
136  return myLength / MIN2(veh->getType()->maxSpeed, mySpeed);
137  }
138  return ret;
139 }
140 
141 
142 SUMOReal
143 ROEdge::getDistanceTo(const ROEdge* other) const {
144  if (getToJunction() != 0 && other->getFromJunction() != 0) {
146  } else {
147  return 0; // optimism is just right for astar
148  }
149 
150 }
151 
152 
153 bool
156 }
157 
158 
159 SUMOReal
160 ROEdge::getTravelTime(const ROVehicle* const veh, SUMOReal time) const {
161  if (myUsingTTTimeLine) {
162  if (myTravelTimes.describesTime(time)) {
163  SUMOReal lineTT = myTravelTimes.getValue(time);
164  if (myInterpolate) {
165  const SUMOReal inTT = lineTT;
166  const SUMOReal split = (SUMOReal)(myTravelTimes.getSplitTime(time, time + inTT) - time);
167  if (split >= 0) {
168  lineTT = myTravelTimes.getValue(time + inTT) * ((SUMOReal)1. - split / inTT) + split;
169  }
170  }
171  return MAX2(getMinimumTravelTime(veh), lineTT);
172  } else {
173  if (!myHaveTTWarned) {
174  WRITE_WARNING("No interval matches passed time " + toString(time) + " in edge '" + myID + "'.\n Using edge's length / max speed.");
175  myHaveTTWarned = true;
176  }
177  }
178  }
179  return myLength / MIN2(veh->getType()->maxSpeed, veh->getType()->speedFactor * mySpeed);
180 }
181 
182 
183 SUMOReal
184 ROEdge::getNoiseEffort(const ROEdge* const edge, const ROVehicle* const veh, SUMOReal time) {
185  SUMOReal ret = 0;
186  if (!edge->getStoredEffort(time, ret)) {
187  const SUMOReal v = MIN2(veh->getType()->maxSpeed, edge->mySpeed);
189  }
190  return ret;
191 }
192 
193 
194 bool
196  if (myUsingETimeLine) {
197  if (!myEfforts.describesTime(time)) {
198  if (!myHaveEWarned) {
199  WRITE_WARNING("No interval matches passed time " + toString(time) + " in edge '" + myID + "'.\n Using edge's length / edge's speed.");
200  myHaveEWarned = true;
201  }
202  return false;
203  }
204  if (myInterpolate) {
205  SUMOReal inTT = myTravelTimes.getValue(time);
206  SUMOReal ratio = (SUMOReal)(myEfforts.getSplitTime(time, time + (SUMOTime)inTT) - time) / inTT;
207  if (ratio >= 0) {
208  ret = ratio * myEfforts.getValue(time) + (1 - ratio) * myEfforts.getValue(time + (SUMOTime)inTT);
209  return true;
210  }
211  }
212  ret = myEfforts.getValue(time);
213  return true;
214  }
215  return false;
216 }
217 
218 
219 unsigned int
221  if (getFunc() == ET_SINK) {
222  return 0;
223  }
224  return (unsigned int) myFollowingEdges.size();
225 }
226 
227 
228 unsigned int
230  if (getFunc() == ET_SOURCE) {
231  return 0;
232  }
233  return (unsigned int) myApproachingEdges.size();
234 }
235 
236 
237 void
238 ROEdge::buildTimeLines(const std::string& measure, const bool boundariesOverride) {
239  if (myUsingETimeLine) {
240  SUMOReal value = myLength / mySpeed;
242  if (measure == "CO") {
243  value = PollutantsInterface::compute(c, PollutantsInterface::CO, mySpeed, 0, 0) * value; // @todo: give correct slope
244  }
245  if (measure == "CO2") {
246  value = PollutantsInterface::compute(c, PollutantsInterface::CO2, mySpeed, 0, 0) * value; // @todo: give correct slope
247  }
248  if (measure == "HC") {
249  value = PollutantsInterface::compute(c, PollutantsInterface::HC, mySpeed, 0, 0) * value; // @todo: give correct slope
250  }
251  if (measure == "PMx") {
252  value = PollutantsInterface::compute(c, PollutantsInterface::PM_X, mySpeed, 0, 0) * value; // @todo: give correct slope
253  }
254  if (measure == "NOx") {
255  value = PollutantsInterface::compute(c, PollutantsInterface::NO_X, mySpeed, 0, 0) * value; // @todo: give correct slope
256  }
257  if (measure == "fuel") {
258  value = PollutantsInterface::compute(c, PollutantsInterface::FUEL, mySpeed, 0, 0) * value; // @todo: give correct slope
259  }
260  myEfforts.fillGaps(value, boundariesOverride);
261  }
262  if (myUsingTTTimeLine) {
263  myTravelTimes.fillGaps(myLength / mySpeed, boundariesOverride);
264  }
265 }
266 
267 
268 bool
269 ROEdge::allFollowersProhibit(const ROVehicle* const vehicle) const {
270  for (ROEdgeVector::const_iterator i = myFollowingEdges.begin(); i != myFollowingEdges.end(); ++i) {
271  if (!(*i)->prohibits(vehicle)) {
272  return false;
273  }
274  }
275  return true;
276 }
277 
278 
279 ROEdge*
280 ROEdge::dictionary(size_t id) {
281  assert(myEdges.size() > id);
282  return myEdges[id];
283 }
284 
285 
286 const ROEdgeVector&
288  if (vClass == SVC_IGNORING || !RONet::getInstance()->hasPermissions() || myFunc == ET_DISTRICT) {
289  return myFollowingEdges;
290  }
291 #ifdef HAVE_FOX
292  if (myAmParallel) {
293  RONet::getInstance()->lock();
294  }
295 #endif
296  std::map<SUMOVehicleClass, ROEdgeVector>::const_iterator i = myClassesSuccessorMap.find(vClass);
297  if (i != myClassesSuccessorMap.end()) {
298  // can use cached value
299 #ifdef HAVE_FOX
300  if (myAmParallel) {
301  RONet::getInstance()->unlock();
302  }
303 #endif
304  return i->second;
305  } else {
306  // this vClass is requested for the first time. rebuild all successors
307  std::set<ROEdge*> followers;
308  for (std::vector<ROLane*>::const_iterator it = myLanes.begin(); it != myLanes.end(); ++it) {
309  ROLane* lane = *it;
310  if ((lane->getPermissions() & vClass) != 0) {
311  const std::vector<const ROLane*>& outgoing = lane->getOutgoingLanes();
312  for (std::vector<const ROLane*>::const_iterator it2 = outgoing.begin(); it2 != outgoing.end(); ++it2) {
313  const ROLane* next = *it2;
314  if ((next->getPermissions() & vClass) != 0) {
315  followers.insert(&next->getEdge());
316  }
317  }
318  }
319  }
320  // also add district edges (they are not connected at the lane level
321  for (ROEdgeVector::const_iterator it = myFollowingEdges.begin(); it != myFollowingEdges.end(); ++it) {
322  if ((*it)->getFunc() == ET_DISTRICT) {
323  followers.insert(*it);
324  }
325  }
326  myClassesSuccessorMap[vClass].insert(myClassesSuccessorMap[vClass].begin(),
327  followers.begin(), followers.end());
328 #ifdef HAVE_FOX
329  if (myAmParallel) {
330  RONet::getInstance()->unlock();
331  }
332 #endif
333  return myClassesSuccessorMap[vClass];
334  }
335 
336 }
337 
338 
339 bool
340 ROEdge::isConnectedTo(const ROEdge* const e, const ROVehicle* const vehicle) const {
341  const SUMOVehicleClass vClass = (vehicle == 0 ? SVC_IGNORING : vehicle->getVClass());
342  const ROEdgeVector& followers = getSuccessors(vClass);
343  return std::find(followers.begin(), followers.end(), e) != followers.end();
344 }
345 
346 /****************************************************************************/
347 
void fillGaps(T value, bool extendOverBoundaries=false)
Sets a default value for all unset intervals.
static ROEdgeVector myEdges
Definition: ROEdge.h:505
std::map< SUMOVehicleClass, ROEdgeVector > myClassesSuccessorMap
The successors available for a given vClass.
Definition: ROEdge.h:509
ROEdge & getEdge() const
Returns the lane&#39;s edge.
Definition: ROLane.h:96
long long int SUMOTime
Definition: SUMOTime.h:43
A single lane the router may use.
Definition: ROLane.h:52
SUMOVehicleClass
Definition of vehicle classes to differ between different lane usage and authority types...
unsigned int getNumSuccessors() const
Returns the number of edges this edge is connected to.
Definition: ROEdge.cpp:220
SUMOReal getDistanceTo(const ROEdge *other) const
optimistic distance heuristic for use in routing
Definition: ROEdge.cpp:143
SVCPermissions getPermissions() const
Returns the list of allowed vehicle classes.
Definition: ROLane.h:89
SUMOReal getSplitTime(SUMOReal low, SUMOReal high) const
Returns the time point at which the value changes.
static SUMOReal getNoiseEffort(const ROEdge *const edge, const ROVehicle *const veh, SUMOReal time)
Definition: ROEdge.cpp:184
SUMOVehicleClass getVClass() const
Definition: ROVehicle.h:132
static bool myInterpolate
Information whether to interpolate at interval boundaries.
Definition: ROEdge.h:477
static ROEdge * dictionary(size_t index)
Returns the ROEdge at the index.
Definition: ROEdge.cpp:280
ValueTimeLine< SUMOReal > myTravelTimes
Container storing passing time varying over time for the edge.
Definition: ROEdge.h:467
virtual void addLane(ROLane *lane)
Adds a lane to the edge while loading.
Definition: ROEdge.cpp:97
static bool myAmParallel
Information whether we are routing multi-threaded.
Definition: ROEdge.h:480
EdgeFunc getFunc() const
Returns the function of the edge.
Definition: ROEdge.h:186
const SUMOVTypeParameter * getType() const
Returns the type of the vehicle.
Definition: ROVehicle.h:94
T MAX2(T a, T b)
Definition: StdDefs.h:79
void add(SUMOReal begin, SUMOReal end, T value)
Adds a value for a time interval into the container.
Definition: ValueTimeLine.h:69
const SVCPermissions SVCAll
SVCPermissions myCombinedPermissions
The list of allowed vehicle classes combined across lanes.
Definition: ROEdge.h:503
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:126
#define WRITE_WARNING(msg)
Definition: MsgHandler.h:200
static RONet * getInstance()
Returns the pointer to the unique instance of RONet (singleton).
Definition: RONet.cpp:65
ROEdgeVector myFollowingEdges
List of edges that may be approached from this edge.
Definition: ROEdge.h:488
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. ...
bool hasLoadedTravelTime(SUMOReal time) const
Returns whether a travel time for this edge was loaded.
Definition: ROEdge.cpp:154
A vehicle as used by router.
Definition: ROVehicle.h:60
SUMOReal speedFactor
The factor by which the maximum speed may deviate from the allowed max speed on the street...
const RONode * getToJunction() const
Definition: ROEdge.h:425
bool allFollowersProhibit(const ROVehicle *const vehicle) const
Returns whether this edge succeeding edges prohibit the given vehicle to pass them.
Definition: ROEdge.cpp:269
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:472
An edge where vehicles disappear (no vehicle may leave this edge)
Definition: ROEdge.h:87
void buildTimeLines(const std::string &measure, const bool boundariesOverride)
Builds the internal representation of the travel time/effort.
Definition: ROEdge.cpp:238
bool myUsingTTTimeLine
Information whether the time line shall be used instead of the length value.
Definition: ROEdge.h:469
bool isConnectedTo(const ROEdge *const e, const ROVehicle *const vehicle) const
returns the information whether this edge is directly connected to the given
Definition: ROEdge.cpp:340
An edge where vehicles are inserted at (no vehicle may come from back)
Definition: ROEdge.h:85
static bool myHaveEWarned
Information whether the edge has reported missing weights.
Definition: ROEdge.h:483
SUMOReal myLength
The length of the edge.
Definition: ROEdge.h:463
int SUMOEmissionClass
bool myUsingETimeLine
Information whether the time line shall be used instead of the length value.
Definition: ROEdge.h:474
std::vector< ROEdge * > ROEdgeVector
Definition: RODFRouteDesc.h:43
T MIN2(T a, T b)
Definition: StdDefs.h:73
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&#39;s lanes.
Definition: ROEdge.h:500
ROEdge(const std::string &id, RONode *from, RONode *to, unsigned int index, const int priority)
Constructor.
Definition: ROEdge.cpp:67
const std::vector< const ROLane * > & getOutgoingLanes() const
get the list of outgoing lanes
Definition: ROLane.h:101
virtual ~ROEdge()
Destructor.
Definition: ROEdge.cpp:89
A basic edge for routing applications.
Definition: ROEdge.h:73
Base class for objects which have an id.
Definition: Named.h:45
SUMOReal mySpeed
The maximum speed allowed on this edge.
Definition: ROEdge.h:460
SUMOReal maxSpeed
The vehicle type&#39;s maximum speed [m/s].
const RONode * getFromJunction() const
Definition: ROEdge.h:421
std::string myID
The name of the object.
Definition: Named.h:133
void addEffort(SUMOReal value, SUMOReal timeBegin, SUMOReal timeEnd)
Adds a weight value.
Definition: ROEdge.cpp:119
virtual void addSuccessor(ROEdge *s, std::string dir="")
Adds information about a connected edge.
Definition: ROEdge.cpp:110
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.
ROEdgeVector myApproachingEdges
List of edges that approached this edge.
Definition: ROEdge.h:491
SUMOReal getEffort(const ROVehicle *const veh, SUMOReal time) const
Returns the effort for this edge.
Definition: ROEdge.cpp:133
const ROEdgeVector & getSuccessors() const
Returns the following edges.
Definition: ROEdge.h:287
SUMOReal getLength() const
Returns the length of the lane.
Definition: ROLane.h:73
unsigned int getNumPredecessors() const
Returns the number of edges connected to this edge.
Definition: ROEdge.cpp:229
bool getStoredEffort(SUMOReal time, SUMOReal &ret) const
Retrieves the stored effort.
Definition: ROEdge.cpp:195
SUMOReal distanceTo2D(const Position &p2) const
returns the euclidean distance in the x-y-plane
Definition: Position.h:232
#define SUMOReal
Definition: config.h:214
Base class for nodes used by the router.
Definition: RONode.h:53
SUMOReal getTravelTime(const ROVehicle *const veh, SUMOReal time) const
Returns the travel time for this edge.
Definition: ROEdge.cpp:160
static bool myHaveTTWarned
Information whether the edge has reported missing weights.
Definition: ROEdge.h:485
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:375
An edge representing a whole district.
Definition: ROEdge.h:83
const Position & getPosition() const
Returns the position of the node.
Definition: RONode.h:74
EdgeFunc myFunc
The function of the edge.
Definition: ROEdge.h:494
SUMOEmissionClass emissionClass
The emission class of this vehicle.
vehicles ignoring classes