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