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-2017 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 
50 // ===========================================================================
51 // static member definitions
52 // ===========================================================================
53 bool ROEdge::myInterpolate = false;
54 bool ROEdge::myHaveTTWarned = false;
55 bool ROEdge::myHaveEWarned = false;
57 
58 
59 // ===========================================================================
60 // method definitions
61 // ===========================================================================
62 ROEdge::ROEdge(const std::string& id, RONode* from, RONode* to, int index, const int priority) :
63  Named(id),
64  myFromJunction(from),
65  myToJunction(to),
66  myIndex(index),
67  myPriority(priority),
68  mySpeed(-1),
69  myLength(0),
70  myAmSink(false),
71  myAmSource(false),
72  myUsingTTTimeLine(false),
73  myUsingETimeLine(false),
74  myCombinedPermissions(0) {
75  while ((int)myEdges.size() <= index) {
76  myEdges.push_back(0);
77  }
78  myEdges[index] = this;
79  if (from == 0 && to == 0) {
80  // TAZ edge, no lanes
82  }
83 }
84 
85 
87  for (std::vector<ROLane*>::iterator i = myLanes.begin(); i != myLanes.end(); ++i) {
88  delete(*i);
89  }
90 }
91 
92 
93 void
95  assert(myLanes.empty() || lane->getLength() == myLength);
96  myLength = lane->getLength();
97  const double speed = lane->getSpeed();
98  mySpeed = speed > mySpeed ? speed : mySpeed;
99  myLanes.push_back(lane);
100 
101  // integrate new allowed classes
103 }
104 
105 
106 void
107 ROEdge::addSuccessor(ROEdge* s, std::string) {
108  if (s->isInternal() && !isInternal()) {
109  if (s->myApproachingEdges.size() == 0) {
110  s->myApproachingEdges.push_back(this);
111  }
112  return;
113  }
114  if (find(myFollowingEdges.begin(), myFollowingEdges.end(), s) == myFollowingEdges.end()) {
115  myFollowingEdges.push_back(s);
116  if (isTazConnector()) {
118  }
119  if (!isInternal()) {
120  s->myApproachingEdges.push_back(this);
121  if (s->isTazConnector()) {
122  s->myTazBoundary.add(getToJunction()->getPosition());
123  }
124  }
125  }
126 }
127 
128 
129 void
130 ROEdge::addEffort(double value, double timeBegin, double timeEnd) {
131  myEfforts.add(timeBegin, timeEnd, value);
132  myUsingETimeLine = true;
133 }
134 
135 
136 void
137 ROEdge::addTravelTime(double value, double timeBegin, double timeEnd) {
138  myTravelTimes.add(timeBegin, timeEnd, value);
139  myUsingTTTimeLine = true;
140 }
141 
142 
143 double
144 ROEdge::getEffort(const ROVehicle* const veh, double time) const {
145  double ret = 0;
146  if (!getStoredEffort(time, ret)) {
147  return myLength / MIN2(veh->getType()->maxSpeed, mySpeed);
148  }
149  return ret;
150 }
151 
152 
153 double
154 ROEdge::getDistanceTo(const ROEdge* other) const {
155  if (isTazConnector()) {
156  if (other->isTazConnector()) {
158  }
160  }
161  if (other->isTazConnector()) {
162  return other->myTazBoundary.distanceTo2D(getToJunction()->getPosition());
163  }
165 }
166 
167 
168 bool
169 ROEdge::hasLoadedTravelTime(double time) const {
171 }
172 
173 
174 double
175 ROEdge::getTravelTime(const ROVehicle* const veh, double time) const {
176  if (myUsingTTTimeLine) {
177  if (myTravelTimes.describesTime(time)) {
178  double lineTT = myTravelTimes.getValue(time);
179  if (myInterpolate) {
180  const double inTT = lineTT;
181  const double split = (double)(myTravelTimes.getSplitTime(time, time + inTT) - time);
182  if (split >= 0) {
183  lineTT = myTravelTimes.getValue(time + inTT) * ((double)1. - split / inTT) + split;
184  }
185  }
186  return MAX2(getMinimumTravelTime(veh), lineTT);
187  } else {
188  if (!myHaveTTWarned) {
189  WRITE_WARNING("No interval matches passed time " + toString(time) + " in edge '" + myID + "'.\n Using edge's length / max speed.");
190  myHaveTTWarned = true;
191  }
192  }
193  }
194  return myLength / MIN2(veh->getType()->maxSpeed, veh->getType()->speedFactor.getParameter()[0] * mySpeed);
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  double inTT = myTravelTimes.getValue(time);
221  double ratio = (double)(myEfforts.getSplitTime(time, time + (SUMOTime)inTT) - time) / inTT;
222  if (ratio >= 0) {
223  ret = ratio * myEfforts.getValue(time) + (1 - ratio) * myEfforts.getValue(time + (SUMOTime)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 ROEdgeVector&
327  if (vClass == SVC_IGNORING || !RONet::getInstance()->hasPermissions() || isTazConnector()) {
328  return myFollowingEdges;
329  }
330 #ifdef HAVE_FOX
331  FXMutexLock locker(myLock);
332 #endif
333  std::map<SUMOVehicleClass, ROEdgeVector>::const_iterator i = myClassesSuccessorMap.find(vClass);
334  if (i != myClassesSuccessorMap.end()) {
335  // can use cached value
336  return i->second;
337  } else {
338  // this vClass is requested for the first time. rebuild all successors
339  std::set<ROEdge*> followers;
340  for (std::vector<ROLane*>::const_iterator it = myLanes.begin(); it != myLanes.end(); ++it) {
341  ROLane* lane = *it;
342  if ((lane->getPermissions() & vClass) != 0) {
343  const std::vector<const ROLane*>& outgoing = lane->getOutgoingLanes();
344  for (std::vector<const ROLane*>::const_iterator it2 = outgoing.begin(); it2 != outgoing.end(); ++it2) {
345  const ROLane* next = *it2;
346  if ((next->getPermissions() & vClass) != 0) {
347  followers.insert(&next->getEdge());
348  }
349  }
350  }
351  }
352  // also add district edges (they are not connected at the lane level
353  for (ROEdgeVector::const_iterator it = myFollowingEdges.begin(); it != myFollowingEdges.end(); ++it) {
354  if ((*it)->isTazConnector()) {
355  followers.insert(*it);
356  }
357  }
358  myClassesSuccessorMap[vClass].insert(myClassesSuccessorMap[vClass].begin(),
359  followers.begin(), followers.end());
360  return myClassesSuccessorMap[vClass];
361  }
362 
363 }
364 
365 
366 bool
367 ROEdge::isConnectedTo(const ROEdge* const e, const ROVehicle* const vehicle) const {
368  const SUMOVehicleClass vClass = (vehicle == 0 ? SVC_IGNORING : vehicle->getVClass());
369  const ROEdgeVector& followers = getSuccessors(vClass);
370  return std::find(followers.begin(), followers.end(), e) != followers.end();
371 }
372 
373 /****************************************************************************/
374 
void fillGaps(T value, bool extendOverBoundaries=false)
Sets a default value for all unset intervals.
static ROEdgeVector myEdges
Definition: ROEdge.h:549
std::map< SUMOVehicleClass, ROEdgeVector > myClassesSuccessorMap
The successors available for a given vClass.
Definition: ROEdge.h:553
ROEdge & getEdge() const
Returns the lane&#39;s edge.
Definition: ROLane.h:101
double myLength
The length of the edge.
Definition: ROEdge.h:506
void addTravelTime(double value, double timeBegin, double timeEnd)
Adds a travel time value.
Definition: ROEdge.cpp:137
double distanceTo2D(const Position &p2) const
returns the euclidean distance in the x-y-plane
Definition: Position.h:250
A single lane the router may use.
Definition: ROLane.h:57
double mySpeed
The maximum speed allowed on this edge.
Definition: ROEdge.h:503
SUMOVehicleClass
Definition of vehicle classes to differ between different lane usage and authority types...
SVCPermissions getPermissions() const
Returns the list of allowed vehicle classes.
Definition: ROLane.h:94
double getLength() const
Returns the length of the lane.
Definition: ROLane.h:78
static bool myInterpolate
Information whether to interpolate at interval boundaries.
Definition: ROEdge.h:521
Boundary myTazBoundary
The bounding rectangle of incoming or outgoing edges for taz connectors.
Definition: ROEdge.h:547
std::vector< double > & getParameter()
Returns the parameters of this distribution.
virtual void addLane(ROLane *lane)
Adds a lane to the edge while loading.
Definition: ROEdge.cpp:94
double getSpeed() const
Returns the maximum speed allowed on this lane.
Definition: ROLane.h:86
T MAX2(T a, T b)
Definition: StdDefs.h:74
int getNumSuccessors() const
Returns the number of edges this edge is connected to.
Definition: ROEdge.cpp:235
bool isTazConnector() const
Definition: ROEdge.h:164
double getTravelTime(const ROVehicle *const veh, double time) const
Returns the travel time for this edge.
Definition: ROEdge.cpp:175
bool myAmSource
Definition: ROEdge.h:509
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
SVCPermissions myCombinedPermissions
The list of allowed vehicle classes combined across lanes.
Definition: ROEdge.h:544
double getEffort(const ROVehicle *const veh, double time) const
Returns the effort for this edge.
Definition: ROEdge.cpp:144
void add(double begin, double end, T value)
Adds a value for a time interval into the container.
Definition: ValueTimeLine.h:69
#define WRITE_WARNING(msg)
Definition: MsgHandler.h:200
T getValue(double time) const
Returns the value for the given time.
static RONet * getInstance()
Returns the pointer to the unique instance of RONet (singleton).
Definition: RONet.cpp:62
ROEdgeVector myFollowingEdges
List of edges that may be approached from this edge.
Definition: ROEdge.h:529
A vehicle as used by router.
Definition: ROVehicle.h:60
const RONode * getToJunction() const
Definition: ROEdge.h:468
bool allFollowersProhibit(const ROVehicle *const vehicle) const
Returns whether this edge succeeding edges prohibit the given vehicle to pass them.
Definition: ROEdge.cpp:309
bool getStoredEffort(double time, double &ret) const
Retrieves the stored effort.
Definition: ROEdge.cpp:210
bool isInternal() const
return whether this edge is an internal edge
Definition: ROEdge.h: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:56
const SUMOVTypeParameter * getType() const
Returns the type of the vehicle.
Definition: RORoutable.h:83
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:513
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:367
static bool myHaveEWarned
Information whether the edge has reported missing weights.
Definition: ROEdge.h:524
int SUMOEmissionClass
bool myUsingETimeLine
Information whether the time line shall be used instead of the length value.
Definition: ROEdge.h:518
double getSplitTime(double low, double high) const
Returns the time point at which the value changes.
std::vector< ROEdge * > ROEdgeVector
Definition: RODFRouteDesc.h:43
void addEffort(double value, double timeBegin, double timeEnd)
Adds a weight value.
Definition: ROEdge.cpp:130
bool myAmSink
whether the edge is a source or a sink
Definition: ROEdge.h:509
T MIN2(T a, T b)
Definition: StdDefs.h:68
std::vector< std::string > & split(const std::string &s, char delim, std::vector< std::string > &elems)
std::vector< ROLane * > myLanes
This edge&#39;s lanes.
Definition: ROEdge.h:541
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:415
const std::vector< const ROLane * > & getOutgoingLanes() const
get the list of outgoing lanes
Definition: ROLane.h:106
ValueTimeLine< double > myEfforts
Container storing passing time varying over time for the edge.
Definition: ROEdge.h:516
virtual ~ROEdge()
Destructor.
Definition: ROEdge.cpp:86
A basic edge for routing applications.
Definition: ROEdge.h:78
Base class for objects which have an id.
Definition: Named.h:46
bool hasLoadedTravelTime(double time) const
Returns whether a travel time for this edge was loaded.
Definition: ROEdge.cpp:169
double getDistanceTo(const ROEdge *other) const
optimistic distance heuristic for use in routing
Definition: ROEdge.cpp:154
const RONode * getFromJunction() const
Definition: ROEdge.h:464
std::string myID
The name of the object.
Definition: Named.h:136
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...
virtual void addSuccessor(ROEdge *s, std::string dir="")
Adds information about a connected edge.
Definition: ROEdge.cpp:107
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:62
ROEdgeVector myApproachingEdges
List of edges that approached this edge.
Definition: ROEdge.h:532
double distanceTo2D(const Position &p) const
returns the euclidean distance in the x-y-plane
Definition: Boundary.cpp:224
int getNumPredecessors() const
Returns the number of edges connected to this edge.
Definition: ROEdge.cpp:244
static const ROEdgeVector & getAllEdges()
Returns all ROEdges.
Definition: ROEdge.cpp:320
const ROEdgeVector & getSuccessors() const
Returns the following edges.
Definition: ROEdge.h:322
bool describesTime(double time) const
Returns whether a value for the given time is known.
static double getNoiseEffort(const ROEdge *const edge, const ROVehicle *const veh, double time)
Definition: ROEdge.cpp:199
const ROEdge * getNormalAfter() const
if this edge is an internal edge, return its first normal successor, otherwise the edge itself ...
Definition: ROEdge.cpp:264
ValueTimeLine< double > myTravelTimes
Container storing passing time varying over time for the edge.
Definition: ROEdge.h:511
const ROEdge * getNormalBefore() const
if this edge is an internal edge, return its first normal predecessor, otherwise the edge itself ...
Definition: ROEdge.cpp:253
long long int SUMOTime
Definition: TraCIDefs.h:52
Base class for nodes used by the router.
Definition: RONode.h:53
static bool myHaveTTWarned
Information whether the edge has reported missing weights.
Definition: ROEdge.h:526
void add(double x, double y, double z=0)
Makes the boundary include the given coordinate.
Definition: Boundary.cpp:86
SUMOVehicleClass getVClass() const
Definition: RORoutable.h:106
const Position & getPosition() const
Returns the position of the node.
Definition: RONode.h:74
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