SUMO - Simulation of Urban MObility
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
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 // ===========================================================================
59 bool ROEdge::myInterpolate = false;
60 bool ROEdge::myAmParallel = false;
61 bool ROEdge::myHaveTTWarned = false;
62 bool ROEdge::myHaveEWarned = false;
64 
65 
66 // ===========================================================================
67 // method definitions
68 // ===========================================================================
69 ROEdge::ROEdge(const std::string& id, RONode* from, RONode* to, unsigned int index, const int priority) :
70  Named(id),
71  myFromJunction(from),
72  myToJunction(to),
73  myIndex(index),
74  myPriority(priority),
75  mySpeed(-1),
76  myLength(0),
77  myUsingTTTimeLine(false),
78  myUsingETimeLine(false),
79  myCombinedPermissions(0) {
80  while (myEdges.size() <= index) {
81  myEdges.push_back(0);
82  }
83  myEdges[index] = this;
84  if (from == 0 && to == 0) {
85  // TAZ edge, no lanes
87  }
88 }
89 
90 
92  for (std::vector<ROLane*>::iterator i = myLanes.begin(); i != myLanes.end(); ++i) {
93  delete(*i);
94  }
95 }
96 
97 
98 void
100  assert(myLanes.empty() || lane->getLength() == myLength);
101  myLength = lane->getLength();
102  const SUMOReal speed = lane->getSpeed();
103  mySpeed = speed > mySpeed ? speed : mySpeed;
104  myLanes.push_back(lane);
105 
106  // integrate new allowed classes
108 }
109 
110 
111 void
112 ROEdge::addSuccessor(ROEdge* s, std::string) {
113  if (find(myFollowingEdges.begin(), myFollowingEdges.end(), s) == myFollowingEdges.end()) {
114  myFollowingEdges.push_back(s);
115  s->myApproachingEdges.push_back(this);
116  }
117 }
118 
119 
120 void
121 ROEdge::addEffort(SUMOReal value, SUMOReal timeBegin, SUMOReal timeEnd) {
122  myEfforts.add(timeBegin, timeEnd, value);
123  myUsingETimeLine = true;
124 }
125 
126 
127 void
128 ROEdge::addTravelTime(SUMOReal value, SUMOReal timeBegin, SUMOReal timeEnd) {
129  myTravelTimes.add(timeBegin, timeEnd, value);
130  myUsingTTTimeLine = true;
131 }
132 
133 
134 SUMOReal
135 ROEdge::getEffort(const ROVehicle* const veh, SUMOReal time) const {
136  SUMOReal ret = 0;
137  if (!getStoredEffort(time, ret)) {
138  return myLength / MIN2(veh->getType()->maxSpeed, mySpeed);
139  }
140  return ret;
141 }
142 
143 
144 SUMOReal
145 ROEdge::getDistanceTo(const ROEdge* other) const {
146  if (getToJunction() != 0 && other->getFromJunction() != 0) {
148  } else {
149  return 0; // optimism is just right for astar
150  }
151 
152 }
153 
154 
155 SUMOReal
156 ROEdge::getTravelTime(const ROVehicle* const veh, SUMOReal time) const {
157  if (myUsingTTTimeLine) {
158  if (myTravelTimes.describesTime(time)) {
159  SUMOReal lineTT = myTravelTimes.getValue(time);
160  if (myInterpolate) {
161  const SUMOReal inTT = lineTT;
162  const SUMOReal split = (SUMOReal)(myTravelTimes.getSplitTime(time, time + inTT) - time);
163  if (split >= 0) {
164  lineTT = myTravelTimes.getValue(time + inTT) * ((SUMOReal)1. - split / inTT) + split;
165  }
166  }
167  return MAX2(getMinimumTravelTime(veh), lineTT);
168  } else {
169  if (!myHaveTTWarned) {
170  WRITE_WARNING("No interval matches passed time " + toString(time) + " in edge '" + myID + "'.\n Using edge's length / max speed.");
171  myHaveTTWarned = true;
172  }
173  }
174  }
175  return myLength / MIN2(veh->getType()->maxSpeed, veh->getType()->speedFactor * mySpeed);
176 }
177 
178 
179 SUMOReal
180 ROEdge::getNoiseEffort(const ROEdge* const edge, const ROVehicle* const veh, SUMOReal time) {
181  SUMOReal ret = 0;
182  if (!edge->getStoredEffort(time, ret)) {
183  const SUMOReal v = MIN2(veh->getType()->maxSpeed, edge->mySpeed);
185  }
186  return ret;
187 }
188 
189 
190 bool
192  if (myUsingETimeLine) {
193  if (!myEfforts.describesTime(time)) {
194  if (!myHaveEWarned) {
195  WRITE_WARNING("No interval matches passed time " + toString(time) + " in edge '" + myID + "'.\n Using edge's length / edge's speed.");
196  myHaveEWarned = true;
197  }
198  return false;
199  }
200  if (myInterpolate) {
201  SUMOReal inTT = myTravelTimes.getValue(time);
202  SUMOReal ratio = (SUMOReal)(myEfforts.getSplitTime(time, time + (SUMOTime)inTT) - time) / inTT;
203  if (ratio >= 0) {
204  ret = ratio * myEfforts.getValue(time) + (1 - ratio) * myEfforts.getValue(time + (SUMOTime)inTT);
205  return true;
206  }
207  }
208  ret = myEfforts.getValue(time);
209  return true;
210  }
211  return false;
212 }
213 
214 
215 unsigned int
217  if (getFunc() == ET_SINK) {
218  return 0;
219  }
220  return (unsigned int) myFollowingEdges.size();
221 }
222 
223 
224 unsigned int
226  if (getFunc() == ET_SOURCE) {
227  return 0;
228  }
229  return (unsigned int) myApproachingEdges.size();
230 }
231 
232 
233 void
234 ROEdge::buildTimeLines(const std::string& measure) {
235  if (myUsingETimeLine) {
236  SUMOReal value = myLength / mySpeed;
238  if (measure == "CO") {
239  value = PollutantsInterface::compute(c, PollutantsInterface::CO, mySpeed, 0, 0) * value; // @todo: give correct slope
240  }
241  if (measure == "CO2") {
242  value = PollutantsInterface::compute(c, PollutantsInterface::CO2, mySpeed, 0, 0) * value; // @todo: give correct slope
243  }
244  if (measure == "HC") {
245  value = PollutantsInterface::compute(c, PollutantsInterface::HC, mySpeed, 0, 0) * value; // @todo: give correct slope
246  }
247  if (measure == "PMx") {
248  value = PollutantsInterface::compute(c, PollutantsInterface::PM_X, mySpeed, 0, 0) * value; // @todo: give correct slope
249  }
250  if (measure == "NOx") {
251  value = PollutantsInterface::compute(c, PollutantsInterface::NO_X, mySpeed, 0, 0) * value; // @todo: give correct slope
252  }
253  if (measure == "fuel") {
254  value = PollutantsInterface::compute(c, PollutantsInterface::FUEL, mySpeed, 0, 0) * value; // @todo: give correct slope
255  }
257  }
258  if (myUsingTTTimeLine) {
260  }
261 }
262 
263 
264 bool
265 ROEdge::allFollowersProhibit(const ROVehicle* const vehicle) const {
266  for (ROEdgeVector::const_iterator i = myFollowingEdges.begin(); i != myFollowingEdges.end(); ++i) {
267  if (!(*i)->prohibits(vehicle)) {
268  return false;
269  }
270  }
271  return true;
272 }
273 
274 
275 ROEdge*
276 ROEdge::dictionary(size_t id) {
277  assert(myEdges.size() > id);
278  return myEdges[id];
279 }
280 
281 
282 const ROEdgeVector&
284  if (vClass == SVC_IGNORING || !RONet::getInstance()->hasPermissions() || myFunc == ET_DISTRICT) {
285  return myFollowingEdges;
286  }
287 #ifdef HAVE_FOX
288  if (myAmParallel) {
289  RONet::getInstance()->lock();
290  }
291 #endif
292  std::map<SUMOVehicleClass, ROEdgeVector>::const_iterator i = myClassesSuccessorMap.find(vClass);
293  if (i != myClassesSuccessorMap.end()) {
294  // can use cached value
295 #ifdef HAVE_FOX
296  if (myAmParallel) {
297  RONet::getInstance()->unlock();
298  }
299 #endif
300  return i->second;
301  } else {
302  // this vClass is requested for the first time. rebuild all successors
303  std::set<ROEdge*> followers;
304  for (std::vector<ROLane*>::const_iterator it = myLanes.begin(); it != myLanes.end(); ++it) {
305  ROLane* lane = *it;
306  if ((lane->getPermissions() & vClass) != 0) {
307  const std::vector<const ROLane*>& outgoing = lane->getOutgoingLanes();
308  for (std::vector<const ROLane*>::const_iterator it2 = outgoing.begin(); it2 != outgoing.end(); ++it2) {
309  const ROLane* next = *it2;
310  if ((next->getPermissions() & vClass) != 0) {
311  followers.insert(&next->getEdge());
312  }
313  }
314  }
315  }
316  // also add district edges (they are not connected at the lane level
317  for (ROEdgeVector::const_iterator it = myFollowingEdges.begin(); it != myFollowingEdges.end(); ++it) {
318  if ((*it)->getFunc() == ET_DISTRICT) {
319  followers.insert(*it);
320  }
321  }
322  myClassesSuccessorMap[vClass].insert(myClassesSuccessorMap[vClass].begin(),
323  followers.begin(), followers.end());
324 #ifdef HAVE_FOX
325  if (myAmParallel) {
326  RONet::getInstance()->unlock();
327  }
328 #endif
329  return myClassesSuccessorMap[vClass];
330  }
331 
332 }
333 
334 
335 bool
336 ROEdge::isConnectedTo(const ROEdge* const e, const ROVehicle* const vehicle) const {
337  const SUMOVehicleClass vClass = (vehicle == 0 ? SVC_IGNORING : vehicle->getVClass());
338  const ROEdgeVector& followers = getSuccessors(vClass);
339  return std::find(followers.begin(), followers.end(), e) != followers.end();
340 }
341 
342 /****************************************************************************/
343 
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
static bool myUseBoundariesOnOverrideTT
Whether overriding weight boundaries shall be reported.
Definition: ROEdge.h:467
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:216
SUMOReal getDistanceTo(const ROEdge *other) const
optimistic distance heuristic for use in routing
Definition: ROEdge.cpp:145
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:180
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:276
ValueTimeLine< SUMOReal > myTravelTimes
Container storing passing time varying over time for the edge.
Definition: ROEdge.h:463
virtual void addLane(ROLane *lane)
Adds a lane to the edge while loading.
Definition: ROEdge.cpp:99
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:74
void add(SUMOReal begin, SUMOReal end, T value)
Adds a value for a time interval into the container.
Definition: ValueTimeLine.h:69
static bool myUseBoundariesOnOverrideE
Whether overriding weight boundaries shall be reported.
Definition: ROEdge.h:474
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:128
#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. ...
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:421
bool allFollowersProhibit(const ROVehicle *const vehicle) const
Returns whether this edge succeeding edges prohibit the given vehicle to pass them.
Definition: ROEdge.cpp:265
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:470
An edge where vehicles disappear (no vehicle may leave this edge)
Definition: ROEdge.h:87
bool myUsingTTTimeLine
Information whether the time line shall be used instead of the length value.
Definition: ROEdge.h:465
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:336
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:459
int SUMOEmissionClass
bool myUsingETimeLine
Information whether the time line shall be used instead of the length value.
Definition: ROEdge.h:472
std::vector< ROEdge * > ROEdgeVector
Definition: RODFRouteDesc.h:43
T MIN2(T a, T b)
Definition: StdDefs.h:68
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:69
const std::vector< const ROLane * > & getOutgoingLanes() const
get the list of outgoing lanes
Definition: ROLane.h:101
virtual ~ROEdge()
Destructor.
Definition: ROEdge.cpp:91
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:456
SUMOReal maxSpeed
The vehicle type&#39;s maximum speed [m/s].
const RONode * getFromJunction() const
Definition: ROEdge.h:417
std::string myID
The name of the object.
Definition: Named.h:128
void addEffort(SUMOReal value, SUMOReal timeBegin, SUMOReal timeEnd)
Adds a weight value.
Definition: ROEdge.cpp:121
virtual void addSuccessor(ROEdge *s, std::string dir="")
Adds information about a connected edge.
Definition: ROEdge.cpp:112
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:135
void buildTimeLines(const std::string &measure)
Builds the internal representation of the travel time/effort.
Definition: ROEdge.cpp:234
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:225
bool getStoredEffort(SUMOReal time, SUMOReal &ret) const
Retrieves the stored effort.
Definition: ROEdge.cpp:191
SUMOReal distanceTo2D(const Position &p2) const
returns the euclidean distance in the x-y-plane
Definition: Position.h:240
#define SUMOReal
Definition: config.h:215
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:156
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:367
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