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