SUMO - Simulation of Urban MObility
ROEdge.cpp
Go to the documentation of this file.
1 /****************************************************************************/
2 // Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.org/sumo
3 // Copyright (C) 2002-2017 German Aerospace Center (DLR) and others.
4 /****************************************************************************/
5 //
6 // This program and the accompanying materials
7 // are made available under the terms of the Eclipse Public License v2.0
8 // which accompanies this distribution, and is available at
9 // http://www.eclipse.org/legal/epl-v20.html
10 //
11 /****************************************************************************/
22 // A basic edge for routing applications
23 /****************************************************************************/
24 
25 
26 // ===========================================================================
27 // included modules
28 // ===========================================================================
29 #ifdef _MSC_VER
30 #include <windows_config.h>
31 #else
32 #include <config.h>
33 #endif
34 
36 #include <utils/common/ToString.h>
37 #include <algorithm>
38 #include <cassert>
39 #include <iostream>
43 #include "ROLane.h"
44 #include "RONet.h"
45 #include "ROVehicle.h"
46 #include "ROEdge.h"
47 
48 
49 // ===========================================================================
50 // static member definitions
51 // ===========================================================================
52 bool ROEdge::myInterpolate = false;
53 bool ROEdge::myHaveTTWarned = false;
54 bool ROEdge::myHaveEWarned = false;
56 
57 
58 // ===========================================================================
59 // method definitions
60 // ===========================================================================
61 ROEdge::ROEdge(const std::string& id, RONode* from, RONode* to, int index, const int priority) :
62  Named(id),
63  myFromJunction(from),
64  myToJunction(to),
65  myIndex(index),
66  myPriority(priority),
67  mySpeed(-1),
68  myLength(0),
69  myAmSink(false),
70  myAmSource(false),
71  myUsingTTTimeLine(false),
72  myUsingETimeLine(false),
73  myCombinedPermissions(0) {
74  while ((int)myEdges.size() <= index) {
75  myEdges.push_back(0);
76  }
77  myEdges[index] = this;
78  if (from == 0 && to == 0) {
79  // TAZ edge, no lanes
81  }
82 }
83 
84 
86  for (std::vector<ROLane*>::iterator i = myLanes.begin(); i != myLanes.end(); ++i) {
87  delete(*i);
88  }
89 }
90 
91 
92 void
94  assert(myLanes.empty() || lane->getLength() == myLength);
95  myLength = lane->getLength();
96  const double speed = lane->getSpeed();
97  mySpeed = speed > mySpeed ? speed : mySpeed;
98  myLanes.push_back(lane);
99 
100  // integrate new allowed classes
102 }
103 
104 
105 void
106 ROEdge::addSuccessor(ROEdge* s, std::string) {
107  if (s->isInternal() && !isInternal()) {
108  if (s->myApproachingEdges.size() == 0) {
109  s->myApproachingEdges.push_back(this);
110  }
111  return;
112  }
113  if (find(myFollowingEdges.begin(), myFollowingEdges.end(), s) == myFollowingEdges.end()) {
114  myFollowingEdges.push_back(s);
115  if (isTazConnector()) {
117  }
118  if (!isInternal()) {
119  s->myApproachingEdges.push_back(this);
120  if (s->isTazConnector()) {
121  s->myTazBoundary.add(getToJunction()->getPosition());
122  }
123  }
124  }
125 }
126 
127 
128 void
129 ROEdge::addEffort(double value, double timeBegin, double timeEnd) {
130  myEfforts.add(timeBegin, timeEnd, value);
131  myUsingETimeLine = true;
132 }
133 
134 
135 void
136 ROEdge::addTravelTime(double value, double timeBegin, double timeEnd) {
137  myTravelTimes.add(timeBegin, timeEnd, value);
138  myUsingTTTimeLine = true;
139 }
140 
141 
142 double
143 ROEdge::getEffort(const ROVehicle* const veh, double time) const {
144  double ret = 0;
145  if (!getStoredEffort(time, ret)) {
146  return myLength / MIN2(veh->getType()->maxSpeed, mySpeed);
147  }
148  return ret;
149 }
150 
151 
152 double
153 ROEdge::getDistanceTo(const ROEdge* other) const {
154  if (isTazConnector()) {
155  if (other->isTazConnector()) {
157  }
159  }
160  if (other->isTazConnector()) {
161  return other->myTazBoundary.distanceTo2D(getToJunction()->getPosition());
162  }
164 }
165 
166 
167 bool
168 ROEdge::hasLoadedTravelTime(double time) const {
170 }
171 
172 
173 double
174 ROEdge::getTravelTime(const ROVehicle* const veh, double time) const {
175  if (myUsingTTTimeLine) {
176  if (myTravelTimes.describesTime(time)) {
177  double lineTT = myTravelTimes.getValue(time);
178  if (myInterpolate) {
179  const double inTT = lineTT;
180  const double split = (double)(myTravelTimes.getSplitTime(time, time + inTT) - time);
181  if (split >= 0) {
182  lineTT = myTravelTimes.getValue(time + inTT) * ((double)1. - split / inTT) + split;
183  }
184  }
185  return MAX2(getMinimumTravelTime(veh), lineTT);
186  } else {
187  if (!myHaveTTWarned) {
188  WRITE_WARNING("No interval matches passed time " + toString(time) + " in edge '" + myID + "'.\n Using edge's length / max speed.");
189  myHaveTTWarned = true;
190  }
191  }
192  }
193  return myLength / MIN2(veh->getType()->maxSpeed, veh->getType()->speedFactor.getParameter()[0] * mySpeed);
194 }
195 
196 
197 double
198 ROEdge::getNoiseEffort(const ROEdge* const edge, const ROVehicle* const veh, double time) {
199  double ret = 0;
200  if (!edge->getStoredEffort(time, ret)) {
201  const double v = MIN2(veh->getType()->maxSpeed, edge->mySpeed);
203  }
204  return ret;
205 }
206 
207 
208 bool
209 ROEdge::getStoredEffort(double time, double& ret) const {
210  if (myUsingETimeLine) {
211  if (!myEfforts.describesTime(time)) {
212  if (!myHaveEWarned) {
213  WRITE_WARNING("No interval matches passed time " + toString(time) + " in edge '" + myID + "'.\n Using edge's length / edge's speed.");
214  myHaveEWarned = true;
215  }
216  return false;
217  }
218  if (myInterpolate) {
219  const double inTT = myTravelTimes.getValue(time);
220  const double ratio = (myEfforts.getSplitTime(time, time + inTT) - time) / inTT;
221  if (ratio >= 0.) {
222  ret = ratio * myEfforts.getValue(time) + (1. - ratio) * myEfforts.getValue(time + inTT);
223  return true;
224  }
225  }
226  ret = myEfforts.getValue(time);
227  return true;
228  }
229  return false;
230 }
231 
232 
233 int
235  if (myAmSink) {
236  return 0;
237  }
238  return (int) myFollowingEdges.size();
239 }
240 
241 
242 int
244  if (myAmSource) {
245  return 0;
246  }
247  return (int) myApproachingEdges.size();
248 }
249 
250 
251 const ROEdge*
253  const ROEdge* result = this;
254  while (result->isInternal()) {
255  assert(myApproachingEdges.size() == 1);
256  result = myApproachingEdges.front();
257  }
258  return result;
259 }
260 
261 
262 const ROEdge*
264  const ROEdge* result = this;
265  while (result->isInternal()) {
266  assert(myFollowingEdges.size() == 1);
267  result = myFollowingEdges.front();
268  }
269  return result;
270 }
271 
272 
273 void
274 ROEdge::buildTimeLines(const std::string& measure, const bool boundariesOverride) {
275  if (myUsingETimeLine) {
276  double value = myLength / mySpeed;
278  if (measure == "CO") {
279  value = PollutantsInterface::compute(c, PollutantsInterface::CO, mySpeed, 0, 0) * value; // @todo: give correct slope
280  }
281  if (measure == "CO2") {
282  value = PollutantsInterface::compute(c, PollutantsInterface::CO2, mySpeed, 0, 0) * value; // @todo: give correct slope
283  }
284  if (measure == "HC") {
285  value = PollutantsInterface::compute(c, PollutantsInterface::HC, mySpeed, 0, 0) * value; // @todo: give correct slope
286  }
287  if (measure == "PMx") {
288  value = PollutantsInterface::compute(c, PollutantsInterface::PM_X, mySpeed, 0, 0) * value; // @todo: give correct slope
289  }
290  if (measure == "NOx") {
291  value = PollutantsInterface::compute(c, PollutantsInterface::NO_X, mySpeed, 0, 0) * value; // @todo: give correct slope
292  }
293  if (measure == "fuel") {
294  value = PollutantsInterface::compute(c, PollutantsInterface::FUEL, mySpeed, 0, 0) * value; // @todo: give correct slope
295  }
296  if (measure == "electricity") {
297  value = PollutantsInterface::compute(c, PollutantsInterface::ELEC, mySpeed, 0, 0) * value; // @todo: give correct slope
298  }
299  myEfforts.fillGaps(value, boundariesOverride);
300  }
301  if (myUsingTTTimeLine) {
302  myTravelTimes.fillGaps(myLength / mySpeed, boundariesOverride);
303  }
304 }
305 
306 
307 bool
308 ROEdge::allFollowersProhibit(const ROVehicle* const vehicle) const {
309  for (ROEdgeVector::const_iterator i = myFollowingEdges.begin(); i != myFollowingEdges.end(); ++i) {
310  if (!(*i)->prohibits(vehicle)) {
311  return false;
312  }
313  }
314  return true;
315 }
316 
317 
318 const ROEdgeVector&
320  return myEdges;
321 }
322 
323 
324 const ROEdgeVector&
326  if (vClass == SVC_IGNORING || !RONet::getInstance()->hasPermissions() || isTazConnector()) {
327  return myFollowingEdges;
328  }
329 #ifdef HAVE_FOX
330  FXMutexLock locker(myLock);
331 #endif
332  std::map<SUMOVehicleClass, ROEdgeVector>::const_iterator i = myClassesSuccessorMap.find(vClass);
333  if (i != myClassesSuccessorMap.end()) {
334  // can use cached value
335  return i->second;
336  } else {
337  // this vClass is requested for the first time. rebuild all successors
338  std::set<ROEdge*> followers;
339  for (std::vector<ROLane*>::const_iterator it = myLanes.begin(); it != myLanes.end(); ++it) {
340  ROLane* lane = *it;
341  if ((lane->getPermissions() & vClass) != 0) {
342  const std::vector<const ROLane*>& outgoing = lane->getOutgoingLanes();
343  for (std::vector<const ROLane*>::const_iterator it2 = outgoing.begin(); it2 != outgoing.end(); ++it2) {
344  const ROLane* next = *it2;
345  if ((next->getPermissions() & vClass) != 0) {
346  followers.insert(&next->getEdge());
347  }
348  }
349  }
350  }
351  // also add district edges (they are not connected at the lane level
352  for (ROEdgeVector::const_iterator it = myFollowingEdges.begin(); it != myFollowingEdges.end(); ++it) {
353  if ((*it)->isTazConnector()) {
354  followers.insert(*it);
355  }
356  }
357  myClassesSuccessorMap[vClass].insert(myClassesSuccessorMap[vClass].begin(),
358  followers.begin(), followers.end());
359  return myClassesSuccessorMap[vClass];
360  }
361 
362 }
363 
364 
365 bool
366 ROEdge::isConnectedTo(const ROEdge* const e, const ROVehicle* const vehicle) const {
367  const SUMOVehicleClass vClass = (vehicle == 0 ? SVC_IGNORING : vehicle->getVClass());
368  const ROEdgeVector& followers = getSuccessors(vClass);
369  return std::find(followers.begin(), followers.end(), e) != followers.end();
370 }
371 
372 /****************************************************************************/
373 
void fillGaps(T value, bool extendOverBoundaries=false)
Sets a default value for all unset intervals.
double distanceTo2D(const Position &p) const
returns the euclidean distance in the x-y-plane
Definition: Boundary.cpp:223
static ROEdgeVector myEdges
Definition: ROEdge.h:548
std::map< SUMOVehicleClass, ROEdgeVector > myClassesSuccessorMap
The successors available for a given vClass.
Definition: ROEdge.h:552
SUMOVehicleClass getVClass() const
Definition: RORoutable.h:114
const Position & getPosition() const
Returns the position of the node.
Definition: RONode.h:73
double getSplitTime(double low, double high) const
Returns the time point at which the value changes.
bool isTazConnector() const
Definition: ROEdge.h:163
double myLength
The length of the edge.
Definition: ROEdge.h:505
void addTravelTime(double value, double timeBegin, double timeEnd)
Adds a travel time value.
Definition: ROEdge.cpp:136
A single lane the router may use.
Definition: ROLane.h:56
double mySpeed
The maximum speed allowed on this edge.
Definition: ROEdge.h:502
bool allFollowersProhibit(const ROVehicle *const vehicle) const
Returns whether this edge succeeding edges prohibit the given vehicle to pass them.
Definition: ROEdge.cpp:308
int getNumSuccessors() const
Returns the number of edges this edge is connected to.
Definition: ROEdge.cpp:234
SUMOVehicleClass
Definition of vehicle classes to differ between different lane usage and authority types...
double getLength() const
Returns the length of the lane.
Definition: ROLane.h:77
double distanceTo2D(const Position &p2) const
returns the euclidean distance in the x-y-plane
Definition: Position.h:249
static bool myInterpolate
Information whether to interpolate at interval boundaries.
Definition: ROEdge.h:520
Boundary myTazBoundary
The bounding rectangle of incoming or outgoing edges for taz connectors.
Definition: ROEdge.h:546
std::vector< double > & getParameter()
Returns the parameters of this distribution.
const RONode * getFromJunction() const
Definition: ROEdge.h:463
virtual void addLane(ROLane *lane)
Adds a lane to the edge while loading.
Definition: ROEdge.cpp:93
bool describesTime(double time) const
Returns whether a value for the given time is known.
T MAX2(T a, T b)
Definition: StdDefs.h:73
bool myAmSource
Definition: ROEdge.h:508
double getEffort(const ROVehicle *const veh, double time) const
Returns the effort for this edge.
Definition: ROEdge.cpp:143
static double computeNoise(SUMOEmissionClass c, double v, double a)
Returns the noise produced by the a vehicle of the given type at the given speed. ...
const std::vector< const ROLane * > & getOutgoingLanes() const
get the list of outgoing lanes
Definition: ROLane.h:105
const SVCPermissions SVCAll
all VClasses are allowed
const RONode * getToJunction() const
Definition: ROEdge.h:467
SVCPermissions myCombinedPermissions
The list of allowed vehicle classes combined across lanes.
Definition: ROEdge.h:543
ROEdge & getEdge() const
Returns the lane&#39;s edge.
Definition: ROLane.h:100
void add(double begin, double end, T value)
Adds a value for a time interval into the container.
Definition: ValueTimeLine.h:68
#define WRITE_WARNING(msg)
Definition: MsgHandler.h:199
static RONet * getInstance()
Returns the pointer to the unique instance of RONet (singleton).
Definition: RONet.cpp:61
double 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:414
ROEdgeVector myFollowingEdges
List of edges that may be approached from this edge.
Definition: ROEdge.h:528
int getNumPredecessors() const
Returns the number of edges connected to this edge.
Definition: ROEdge.cpp:243
double getDistanceTo(const ROEdge *other) const
optimistic distance heuristic for use in routing
Definition: ROEdge.cpp:153
bool hasLoadedTravelTime(double time) const
Returns whether a travel time for this edge was loaded.
Definition: ROEdge.cpp:168
A vehicle as used by router.
Definition: ROVehicle.h:59
double maxSpeed
The vehicle type&#39;s maximum speed [m/s].
std::string toString(const T &t, std::streamsize accuracy=gPrecision)
Definition: ToString.h:55
void buildTimeLines(const std::string &measure, const bool boundariesOverride)
Builds the internal representation of the travel time/effort.
Definition: ROEdge.cpp:274
bool myUsingTTTimeLine
Information whether the time line shall be used instead of the length value.
Definition: ROEdge.h:512
T getValue(double time) const
Returns the value for the given time.
const ROEdge * getNormalAfter() const
if this edge is an internal edge, return its first normal successor, otherwise the edge itself ...
Definition: ROEdge.cpp:263
static bool myHaveEWarned
Information whether the edge has reported missing weights.
Definition: ROEdge.h:523
int SUMOEmissionClass
bool myUsingETimeLine
Information whether the time line shall be used instead of the length value.
Definition: ROEdge.h:517
std::vector< ROEdge * > ROEdgeVector
Definition: RODFRouteDesc.h:42
void addEffort(double value, double timeBegin, double timeEnd)
Adds a weight value.
Definition: ROEdge.cpp:129
bool myAmSink
whether the edge is a source or a sink
Definition: ROEdge.h:508
bool getStoredEffort(double time, double &ret) const
Retrieves the stored effort.
Definition: ROEdge.cpp:209
T MIN2(T a, T b)
Definition: StdDefs.h:67
std::vector< std::string > & split(const std::string &s, char delim, std::vector< std::string > &elems)
SVCPermissions getPermissions() const
Returns the list of allowed vehicle classes.
Definition: ROLane.h:93
std::vector< ROLane * > myLanes
This edge&#39;s lanes.
Definition: ROEdge.h:540
ValueTimeLine< double > myEfforts
Container storing passing time varying over time for the edge.
Definition: ROEdge.h:515
virtual ~ROEdge()
Destructor.
Definition: ROEdge.cpp:85
A basic edge for routing applications.
Definition: ROEdge.h:77
Base class for objects which have an id.
Definition: Named.h:54
double getSpeed() const
Returns the maximum speed allowed on this lane.
Definition: ROLane.h:85
bool isInternal() const
return whether this edge is an internal edge
Definition: ROEdge.h:149
std::string myID
The name of the object.
Definition: Named.h:126
static double compute(const SUMOEmissionClass c, const EmissionType e, const double v, const double a, const double slope, const std::map< int, double > *param=0)
Returns the amount of the emitted pollutant given the vehicle type and state (in mg/s or ml/s for fue...
const SUMOVTypeParameter * getType() const
Returns the type of the routable.
Definition: RORoutable.h:91
virtual void addSuccessor(ROEdge *s, std::string dir="")
Adds information about a connected edge.
Definition: ROEdge.cpp:106
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:61
ROEdgeVector myApproachingEdges
List of edges that approached this edge.
Definition: ROEdge.h:531
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:366
const ROEdgeVector & getSuccessors() const
Returns the following edges.
Definition: ROEdge.h:321
static const ROEdgeVector & getAllEdges()
Returns all ROEdges.
Definition: ROEdge.cpp:319
double getTravelTime(const ROVehicle *const veh, double time) const
Returns the travel time for this edge.
Definition: ROEdge.cpp:174
static double getNoiseEffort(const ROEdge *const edge, const ROVehicle *const veh, double time)
Definition: ROEdge.cpp:198
ValueTimeLine< double > myTravelTimes
Container storing passing time varying over time for the edge.
Definition: ROEdge.h:510
Base class for nodes used by the router.
Definition: RONode.h:52
static bool myHaveTTWarned
Information whether the edge has reported missing weights.
Definition: ROEdge.h:525
const ROEdge * getNormalBefore() const
if this edge is an internal edge, return its first normal predecessor, otherwise the edge itself ...
Definition: ROEdge.cpp:252
void add(double x, double y, double z=0)
Makes the boundary include the given coordinate.
Definition: Boundary.cpp:85
Distribution_Parameterized speedFactor
The factor by which the maximum speed may deviate from the allowed max speed on the street...
SUMOEmissionClass emissionClass
The emission class of this vehicle.
vehicles ignoring classes