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-2018 German Aerospace Center (DLR) and others.
4 // This program and the accompanying materials
5 // are made available under the terms of the Eclipse Public License v2.0
6 // which accompanies this distribution, and is available at
7 // http://www.eclipse.org/legal/epl-v20.html
8 // SPDX-License-Identifier: EPL-2.0
9 /****************************************************************************/
20 // A basic edge for routing applications
21 /****************************************************************************/
22 
23 
24 // ===========================================================================
25 // included modules
26 // ===========================================================================
27 #include <config.h>
28 
30 #include <utils/common/ToString.h>
31 #include <algorithm>
32 #include <cassert>
33 #include <iostream>
37 #include "ROLane.h"
38 #include "RONet.h"
39 #include "ROVehicle.h"
40 #include "ROEdge.h"
41 
42 
43 // ===========================================================================
44 // static member definitions
45 // ===========================================================================
46 bool ROEdge::myInterpolate = false;
47 bool ROEdge::myHaveTTWarned = false;
48 bool ROEdge::myHaveEWarned = false;
50 
51 
52 // ===========================================================================
53 // method definitions
54 // ===========================================================================
55 ROEdge::ROEdge(const std::string& id, RONode* from, RONode* to, int index, const int priority) :
56  Named(id),
57  myFromJunction(from),
58  myToJunction(to),
59  myIndex(index),
60  myPriority(priority),
61  mySpeed(-1),
62  myLength(0),
63  myAmSink(false),
64  myAmSource(false),
65  myUsingTTTimeLine(false),
66  myUsingETimeLine(false),
67  myCombinedPermissions(0) {
68  while ((int)myEdges.size() <= index) {
69  myEdges.push_back(0);
70  }
71  myEdges[index] = this;
72  if (from == nullptr && to == nullptr) {
73  // TAZ edge, no lanes
75  } else {
76  myBoundary.add(from->getPosition());
77  myBoundary.add(to->getPosition());
78  }
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 double 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::addSuccessor(ROEdge* s, ROEdge* via, std::string) {
104  if (find(myFollowingEdges.begin(), myFollowingEdges.end(), s) == myFollowingEdges.end()) {
105  myFollowingEdges.push_back(s);
106  myFollowingViaEdges.push_back(std::make_pair(s, via));
107  if (isTazConnector()) {
109  }
110  if (!isInternal()) {
111  s->myApproachingEdges.push_back(this);
112  if (s->isTazConnector()) {
113  s->myBoundary.add(getToJunction()->getPosition());
114  }
115  if (via != nullptr) {
116  if (via->myApproachingEdges.size() == 0) {
117  via->myApproachingEdges.push_back(this);
118  }
119  }
120  }
121  }
122 }
123 
124 
125 void
126 ROEdge::addEffort(double value, double timeBegin, double timeEnd) {
127  myEfforts.add(timeBegin, timeEnd, value);
128  myUsingETimeLine = true;
129 }
130 
131 
132 void
133 ROEdge::addTravelTime(double value, double timeBegin, double timeEnd) {
134  myTravelTimes.add(timeBegin, timeEnd, value);
135  myUsingTTTimeLine = true;
136 }
137 
138 
139 double
140 ROEdge::getEffort(const ROVehicle* const veh, double time) const {
141  double ret = 0;
142  if (!getStoredEffort(time, ret)) {
143  return myLength / MIN2(veh->getType()->maxSpeed, mySpeed);
144  }
145  return ret;
146 }
147 
148 
149 double
150 ROEdge::getDistanceTo(const ROEdge* other, const bool doBoundaryEstimate) const {
151  if (doBoundaryEstimate) {
152  return myBoundary.distanceTo2D(other->myBoundary);
153  }
154  if (isTazConnector()) {
155  if (other->isTazConnector()) {
156  return myBoundary.distanceTo2D(other->myBoundary);
157  }
159  }
160  if (other->isTazConnector()) {
161  return other->myBoundary.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  const double speed = veh != nullptr ? MIN2(veh->getType()->maxSpeed, veh->getType()->speedFactor.getParameter()[0] * mySpeed) : mySpeed;
194  return myLength / speed;
195 }
196 
197 
198 double
199 ROEdge::getNoiseEffort(const ROEdge* const edge, const ROVehicle* const veh, double time) {
200  double ret = 0;
201  if (!edge->getStoredEffort(time, ret)) {
202  const double v = MIN2(veh->getType()->maxSpeed, edge->mySpeed);
204  }
205  return ret;
206 }
207 
208 
209 bool
210 ROEdge::getStoredEffort(double time, double& ret) const {
211  if (myUsingETimeLine) {
212  if (!myEfforts.describesTime(time)) {
213  if (!myHaveEWarned) {
214  WRITE_WARNING("No interval matches passed time " + toString(time) + " in edge '" + myID + "'.\n Using edge's length / edge's speed.");
215  myHaveEWarned = true;
216  }
217  return false;
218  }
219  if (myInterpolate) {
220  const double inTT = myTravelTimes.getValue(time);
221  const double ratio = (myEfforts.getSplitTime(time, time + inTT) - time) / inTT;
222  if (ratio >= 0.) {
223  ret = ratio * myEfforts.getValue(time) + (1. - ratio) * myEfforts.getValue(time + inTT);
224  return true;
225  }
226  }
227  ret = myEfforts.getValue(time);
228  return true;
229  }
230  return false;
231 }
232 
233 
234 int
236  if (myAmSink) {
237  return 0;
238  }
239  return (int) myFollowingEdges.size();
240 }
241 
242 
243 int
245  if (myAmSource) {
246  return 0;
247  }
248  return (int) myApproachingEdges.size();
249 }
250 
251 
252 const ROEdge*
254  const ROEdge* result = this;
255  while (result->isInternal()) {
256  assert(myApproachingEdges.size() == 1);
257  result = myApproachingEdges.front();
258  }
259  return result;
260 }
261 
262 
263 const ROEdge*
265  const ROEdge* result = this;
266  while (result->isInternal()) {
267  assert(myFollowingEdges.size() == 1);
268  result = myFollowingEdges.front();
269  }
270  return result;
271 }
272 
273 
274 void
275 ROEdge::buildTimeLines(const std::string& measure, const bool boundariesOverride) {
276  if (myUsingETimeLine) {
277  double value = myLength / mySpeed;
279  if (measure == "CO") {
280  value = PollutantsInterface::compute(c, PollutantsInterface::CO, mySpeed, 0, 0) * value; // @todo: give correct slope
281  }
282  if (measure == "CO2") {
283  value = PollutantsInterface::compute(c, PollutantsInterface::CO2, mySpeed, 0, 0) * value; // @todo: give correct slope
284  }
285  if (measure == "HC") {
286  value = PollutantsInterface::compute(c, PollutantsInterface::HC, mySpeed, 0, 0) * value; // @todo: give correct slope
287  }
288  if (measure == "PMx") {
289  value = PollutantsInterface::compute(c, PollutantsInterface::PM_X, mySpeed, 0, 0) * value; // @todo: give correct slope
290  }
291  if (measure == "NOx") {
292  value = PollutantsInterface::compute(c, PollutantsInterface::NO_X, mySpeed, 0, 0) * value; // @todo: give correct slope
293  }
294  if (measure == "fuel") {
295  value = PollutantsInterface::compute(c, PollutantsInterface::FUEL, mySpeed, 0, 0) * value; // @todo: give correct slope
296  }
297  if (measure == "electricity") {
298  value = PollutantsInterface::compute(c, PollutantsInterface::ELEC, mySpeed, 0, 0) * value; // @todo: give correct slope
299  }
300  myEfforts.fillGaps(value, boundariesOverride);
301  }
302  if (myUsingTTTimeLine) {
303  myTravelTimes.fillGaps(myLength / mySpeed, boundariesOverride);
304  }
305 }
306 
307 
308 bool
309 ROEdge::allFollowersProhibit(const ROVehicle* const vehicle) const {
310  for (ROEdgeVector::const_iterator i = myFollowingEdges.begin(); i != myFollowingEdges.end(); ++i) {
311  if (!(*i)->prohibits(vehicle)) {
312  return false;
313  }
314  }
315  return true;
316 }
317 
318 
319 const ROEdgeVector&
321  return myEdges;
322 }
323 
324 
325 const Position
327  const double middle = (stop.endPos + stop.startPos) / 2.;
329  return (edge->getFromJunction()->getPosition() + edge->getToJunction()->getPosition()) * (middle / edge->getLength());
330 }
331 
332 
333 const ROEdgeVector&
335  if (vClass == SVC_IGNORING || !RONet::getInstance()->hasPermissions() || isTazConnector()) {
336  return myFollowingEdges;
337  }
338 #ifdef HAVE_FOX
339  FXMutexLock locker(myLock);
340 #endif
341  std::map<SUMOVehicleClass, ROEdgeVector>::const_iterator i = myClassesSuccessorMap.find(vClass);
342  if (i != myClassesSuccessorMap.end()) {
343  // can use cached value
344  return i->second;
345  }
346  // this vClass is requested for the first time. rebuild all successors
347  std::set<ROEdge*> followers;
348  for (const ROLane* const lane : myLanes) {
349  if ((lane->getPermissions() & vClass) != 0) {
350  for (const auto& next : lane->getOutgoingViaLanes()) {
351  if ((next.first->getPermissions() & vClass) != 0) {
352  followers.insert(&next.first->getEdge());
353  }
354  }
355  }
356  }
357  // also add district edges (they are not connected at the lane level
358  for (ROEdgeVector::const_iterator it = myFollowingEdges.begin(); it != myFollowingEdges.end(); ++it) {
359  if ((*it)->isTazConnector()) {
360  followers.insert(*it);
361  }
362  }
363  myClassesSuccessorMap[vClass].insert(myClassesSuccessorMap[vClass].begin(),
364  followers.begin(), followers.end());
365  return myClassesSuccessorMap[vClass];
366 }
367 
368 
371  if (vClass == SVC_IGNORING || !RONet::getInstance()->hasPermissions() || isTazConnector()) {
372  return myFollowingViaEdges;
373  }
374 #ifdef HAVE_FOX
375  FXMutexLock locker(myLock);
376 #endif
377  std::map<SUMOVehicleClass, ROConstEdgePairVector>::const_iterator i = myClassesViaSuccessorMap.find(vClass);
378  if (i != myClassesViaSuccessorMap.end()) {
379  // can use cached value
380  return i->second;
381  }
382  // this vClass is requested for the first time. rebuild all successors
383  std::set<std::pair<const ROEdge*, const ROEdge*> > followers;
384  for (const ROLane* const lane : myLanes) {
385  if ((lane->getPermissions() & vClass) != 0) {
386  for (const auto& next : lane->getOutgoingViaLanes()) {
387  if ((next.first->getPermissions() & vClass) != 0) {
388  followers.insert(std::make_pair(&next.first->getEdge(), next.second));
389  }
390  }
391  }
392  }
393  // also add district edges (they are not connected at the lane level
394  for (const ROEdge* e : myFollowingEdges) {
395  if (e->isTazConnector()) {
396  followers.insert(std::make_pair(e, e));
397  }
398  }
399  myClassesViaSuccessorMap[vClass].insert(myClassesViaSuccessorMap[vClass].begin(),
400  followers.begin(), followers.end());
401  return myClassesViaSuccessorMap[vClass];
402 }
403 
404 
405 bool
406 ROEdge::isConnectedTo(const ROEdge* const e, const ROVehicle* const vehicle) const {
407  const SUMOVehicleClass vClass = (vehicle == nullptr ? SVC_IGNORING : vehicle->getVClass());
408  const ROEdgeVector& followers = getSuccessors(vClass);
409  return std::find(followers.begin(), followers.end(), e) != followers.end();
410 }
411 
412 
413 /****************************************************************************/
414 
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:547
std::map< SUMOVehicleClass, ROEdgeVector > myClassesSuccessorMap
The successors available for a given vClass.
Definition: ROEdge.h:551
SUMOVehicleClass getVClass() const
Definition: RORoutable.h:108
const Position & getPosition() const
Returns the position of the node.
Definition: RONode.h:67
double getSplitTime(double low, double high) const
Returns the time point at which the value changes.
bool isTazConnector() const
Definition: ROEdge.h:158
double myLength
The length of the edge.
Definition: ROEdge.h:502
void addTravelTime(double value, double timeBegin, double timeEnd)
Adds a travel time value.
Definition: ROEdge.cpp:133
A single lane the router may use.
Definition: ROLane.h:50
double mySpeed
The maximum speed allowed on this edge.
Definition: ROEdge.h:499
bool allFollowersProhibit(const ROVehicle *const vehicle) const
Returns whether this edge succeeding edges prohibit the given vehicle to pass them.
Definition: ROEdge.cpp:309
int getNumSuccessors() const
Returns the number of edges this edge is connected to.
Definition: ROEdge.cpp:235
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:71
double distanceTo2D(const Position &p2) const
returns the euclidean distance in the x-y-plane
Definition: Position.h:244
static bool myInterpolate
Information whether to interpolate at interval boundaries.
Definition: ROEdge.h:517
std::vector< double > & getParameter()
Returns the parameters of this distribution.
const RONode * getFromJunction() const
Definition: ROEdge.h:460
virtual void addLane(ROLane *lane)
Adds a lane to the edge while loading.
Definition: ROEdge.cpp:90
bool describesTime(double time) const
Returns whether a value for the given time is known.
T MAX2(T a, T b)
Definition: StdDefs.h:76
ROConstEdgePairVector myFollowingViaEdges
Definition: ROEdge.h:527
bool myAmSource
Definition: ROEdge.h:505
double getEffort(const ROVehicle *const veh, double time) const
Returns the effort for this edge.
Definition: ROEdge.cpp:140
double getLength() const
Returns the length of the edge.
Definition: ROEdge.h:199
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 SVCPermissions SVCAll
all VClasses are allowed
const RONode * getToJunction() const
Definition: ROEdge.h:464
SVCPermissions myCombinedPermissions
The list of allowed vehicle classes combined across lanes.
Definition: ROEdge.h:542
void add(double begin, double end, T value)
Adds a value for a time interval into the container.
Definition: ValueTimeLine.h:62
#define WRITE_WARNING(msg)
Definition: MsgHandler.h:241
static RONet * getInstance()
Returns the pointer to the unique instance of RONet (singleton).
Definition: RONet.cpp:55
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:408
ROEdgeVector myFollowingEdges
List of edges that may be approached from this edge.
Definition: ROEdge.h:525
int getNumPredecessors() const
Returns the number of edges connected to this edge.
Definition: ROEdge.cpp:244
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:53
double getDistanceTo(const ROEdge *other, const bool doBoundaryEstimate=false) const
optimistic distance heuristic for use in routing
Definition: ROEdge.cpp:150
double maxSpeed
The vehicle type&#39;s maximum speed [m/s].
std::string toString(const T &t, std::streamsize accuracy=gPrecision)
Definition: ToString.h:49
void buildTimeLines(const std::string &measure, const bool boundariesOverride)
Builds the internal representation of the travel time/effort.
Definition: ROEdge.cpp:275
bool myUsingTTTimeLine
Information whether the time line shall be used instead of the length value.
Definition: ROEdge.h:509
T getValue(double time) const
Returns the value for the given time.
Definition: ValueTimeLine.h:96
double startPos
The stopping position start.
const ROEdge * getNormalAfter() const
if this edge is an internal edge, return its first normal successor, otherwise the edge itself ...
Definition: ROEdge.cpp:264
A point in 2D or 3D with translation and scaling methods.
Definition: Position.h:39
static bool myHaveEWarned
Information whether the edge has reported missing weights.
Definition: ROEdge.h:520
int SUMOEmissionClass
bool myUsingETimeLine
Information whether the time line shall be used instead of the length value.
Definition: ROEdge.h:514
std::vector< ROEdge * > ROEdgeVector
Definition: RODFRouteDesc.h:36
void addEffort(double value, double timeBegin, double timeEnd)
Adds a weight value.
Definition: ROEdge.cpp:126
bool myAmSink
whether the edge is a source or a sink
Definition: ROEdge.h:505
Boundary myBoundary
The bounding rectangle of end nodes incoming or outgoing edges for taz connectors or of my own start ...
Definition: ROEdge.h:545
bool getStoredEffort(double time, double &ret) const
Retrieves the stored effort.
Definition: ROEdge.cpp:210
T MIN2(T a, T b)
Definition: StdDefs.h:70
std::vector< std::string > & split(const std::string &s, char delim, std::vector< std::string > &elems)
static const Position getStopPosition(const SUMOVehicleParameter::Stop &stop)
return the coordinates of the center of the given stop
Definition: ROEdge.cpp:326
std::vector< std::pair< const ROEdge *, const ROEdge * > > ROConstEdgePairVector
Definition: ROEdge.h:57
double endPos
The stopping position end.
SVCPermissions getPermissions() const
Returns the list of allowed vehicle classes.
Definition: ROLane.h:87
std::vector< ROLane * > myLanes
This edge&#39;s lanes.
Definition: ROEdge.h:539
ValueTimeLine< double > myEfforts
Container storing passing time varying over time for the edge.
Definition: ROEdge.h:512
virtual ~ROEdge()
Destructor.
Definition: ROEdge.cpp:82
A basic edge for routing applications.
Definition: ROEdge.h:72
Base class for objects which have an id.
Definition: Named.h:58
std::string lane
The lane to stop at.
double getSpeed() const
Returns the maximum speed allowed on this lane.
Definition: ROLane.h:79
bool isInternal() const
return whether this edge is an internal edge
Definition: ROEdge.h:144
std::string myID
The name of the object.
Definition: Named.h:130
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:85
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:55
ROEdgeVector myApproachingEdges
List of edges that approached this edge.
Definition: ROEdge.h:530
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:406
virtual void addSuccessor(ROEdge *s, ROEdge *via=nullptr, std::string dir="")
Adds information about a connected edge.
Definition: ROEdge.cpp:103
std::map< SUMOVehicleClass, ROConstEdgePairVector > myClassesViaSuccessorMap
The successors with vias available for a given vClass.
Definition: ROEdge.h:554
Definition of vehicle stop (position and duration)
static const ROEdgeVector & getAllEdges()
Returns all ROEdges.
Definition: ROEdge.cpp:320
double getTravelTime(const ROVehicle *const veh, double time) const
Returns the travel time for this edge.
Definition: ROEdge.cpp:174
const ROEdgeVector & getSuccessors(SUMOVehicleClass vClass=SVC_IGNORING) const
Returns the following edges, restricted by vClass.
Definition: ROEdge.cpp:334
static double getNoiseEffort(const ROEdge *const edge, const ROVehicle *const veh, double time)
Definition: ROEdge.cpp:199
ValueTimeLine< double > myTravelTimes
Container storing passing time varying over time for the edge.
Definition: ROEdge.h:507
const ROConstEdgePairVector & getViaSuccessors(SUMOVehicleClass vClass=SVC_IGNORING) const
Returns the following edges including vias, restricted by vClass.
Definition: ROEdge.cpp:370
Base class for nodes used by the router.
Definition: RONode.h:46
static bool myHaveTTWarned
Information whether the edge has reported missing weights.
Definition: ROEdge.h:522
const ROEdge * getNormalBefore() const
if this edge is an internal edge, return its first normal predecessor, otherwise the edge itself ...
Definition: ROEdge.cpp:253
ROEdge * getEdge(const std::string &name) const
Retrieves an edge from the network.
Definition: RONet.h:157
void add(double x, double y, double z=0)
Makes the boundary include the given coordinate.
Definition: Boundary.cpp:79
static std::string getEdgeIDFromLane(const std::string laneID)
return edge id when given the lane ID
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