SUMO - Simulation of Urban MObility
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules 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 "ROVehicle.h"
47 
48 #ifdef CHECK_MEMORY_LEAKS
49 #include <foreign/nvwa/debug_new.h>
50 #endif // CHECK_MEMORY_LEAKS
51 
52 
53 // ===========================================================================
54 // static member definitions
55 // ===========================================================================
58 bool ROEdge::myInterpolate = false;
59 bool ROEdge::myHaveTTWarned = false;
60 bool ROEdge::myHaveEWarned = false;
62 
63 
64 // ===========================================================================
65 // method definitions
66 // ===========================================================================
67 ROEdge::ROEdge(const std::string& id, RONode* from, RONode* to, unsigned int index, const int priority)
68  : Named(id), myFromNode(from), myToNode(to), myIndex(index), myPriority(priority),
69  mySpeed(-1), myLength(0),
70  myUsingTTTimeLine(false),
71  myUsingETimeLine(false),
72  myCombinedPermissions(0),
73  myFromJunction(0),
74  myToJunction(0) {
75  while (myEdges.size() <= index) {
76  myEdges.push_back(0);
77  }
78  myEdges[index] = this;
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 SUMOReal 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, std::string) {
104  if (find(myFollowingEdges.begin(), myFollowingEdges.end(), s) == myFollowingEdges.end()) {
105  myFollowingEdges.push_back(s);
106  s->myApproachingEdges.push_back(this);
107  }
108 }
109 
110 
111 void
112 ROEdge::addEffort(SUMOReal value, SUMOReal timeBegin, SUMOReal timeEnd) {
113  myEfforts.add(timeBegin, timeEnd, value);
114  myUsingETimeLine = true;
115 }
116 
117 
118 void
119 ROEdge::addTravelTime(SUMOReal value, SUMOReal timeBegin, SUMOReal timeEnd) {
120  myTravelTimes.add(timeBegin, timeEnd, value);
121  myUsingTTTimeLine = true;
122 }
123 
124 
125 SUMOReal
126 ROEdge::getEffort(const ROVehicle* const veh, SUMOReal time) const {
127  SUMOReal ret = 0;
128  if (!getStoredEffort(time, ret)) {
129  return myLength / MIN2(veh->getType()->maxSpeed, mySpeed);
130  }
131  return ret;
132 }
133 
134 
135 SUMOReal
136 ROEdge::getDistanceTo(const ROEdge* other) const {
137  if (getToNode() != 0 && other->getFromNode() != 0) {
138  return getToNode()->getPosition().distanceTo2D(other->getFromNode()->getPosition());
139  } else {
140  return 0; // optimism is just right for astar
141  }
142 
143 }
144 
145 
146 SUMOReal
147 ROEdge::getTravelTime(const ROVehicle* const veh, SUMOReal time) const {
148  if (myUsingTTTimeLine) {
149  if (myTravelTimes.describesTime(time)) {
150  SUMOReal lineTT = myTravelTimes.getValue(time);
151  if (myInterpolate) {
152  const SUMOReal inTT = lineTT;
153  const SUMOReal split = (SUMOReal)(myTravelTimes.getSplitTime(time, time + inTT) - time);
154  if (split >= 0) {
155  lineTT = myTravelTimes.getValue(time + inTT) * ((SUMOReal)1. - split / inTT) + split;
156  }
157  }
158  return MAX2(getMinimumTravelTime(veh), lineTT);
159  } else {
160  if (!myHaveTTWarned) {
161  WRITE_WARNING("No interval matches passed time " + toString(time) + " in edge '" + myID + "'.\n Using edge's length / max speed.");
162  myHaveTTWarned = true;
163  }
164  }
165  }
166  return myLength / MIN2(veh->getType()->maxSpeed, veh->getType()->speedFactor * mySpeed);
167 }
168 
169 
170 SUMOReal
171 ROEdge::getNoiseEffort(const ROEdge* const edge, const ROVehicle* const veh, SUMOReal time) {
172  SUMOReal ret = 0;
173  if (!edge->getStoredEffort(time, ret)) {
174  const SUMOReal v = MIN2(veh->getType()->maxSpeed, edge->mySpeed);
176  }
177  return ret;
178 }
179 
180 
181 bool
183  if (myUsingETimeLine) {
184  if (!myEfforts.describesTime(time)) {
185  if (!myHaveEWarned) {
186  WRITE_WARNING("No interval matches passed time " + toString(time) + " in edge '" + myID + "'.\n Using edge's length / edge's speed.");
187  myHaveEWarned = true;
188  }
189  return false;
190  }
191  if (myInterpolate) {
192  SUMOReal inTT = myTravelTimes.getValue(time);
193  SUMOReal ratio = (SUMOReal)(myEfforts.getSplitTime(time, time + (SUMOTime)inTT) - time) / inTT;
194  if (ratio >= 0) {
195  ret = ratio * myEfforts.getValue(time) + (1 - ratio) * myEfforts.getValue(time + (SUMOTime)inTT);
196  return true;
197  }
198  }
199  ret = myEfforts.getValue(time);
200  return true;
201  }
202  return false;
203 }
204 
205 
206 unsigned int
208  if (getType() == ET_SINK) {
209  return 0;
210  }
211  return (unsigned int) myFollowingEdges.size();
212 }
213 
214 
215 unsigned int
217  if (getType() == ET_SOURCE) {
218  return 0;
219  }
220  return (unsigned int) myApproachingEdges.size();
221 }
222 
223 
224 void
226  myType = type;
227 }
228 
229 
230 void
231 ROEdge::buildTimeLines(const std::string& measure) {
232  if (myUsingETimeLine) {
233  SUMOReal value = myLength / mySpeed;
235  if (measure == "CO") {
236  value = PollutantsInterface::compute(c, PollutantsInterface::CO, mySpeed, 0, 0) * value; // @todo: give correct slope
237  }
238  if (measure == "CO2") {
239  value = PollutantsInterface::compute(c, PollutantsInterface::CO2, mySpeed, 0, 0) * value; // @todo: give correct slope
240  }
241  if (measure == "HC") {
242  value = PollutantsInterface::compute(c, PollutantsInterface::HC, mySpeed, 0, 0) * value; // @todo: give correct slope
243  }
244  if (measure == "PMx") {
245  value = PollutantsInterface::compute(c, PollutantsInterface::PM_X, mySpeed, 0, 0) * value; // @todo: give correct slope
246  }
247  if (measure == "NOx") {
248  value = PollutantsInterface::compute(c, PollutantsInterface::NO_X, mySpeed, 0, 0) * value; // @todo: give correct slope
249  }
250  if (measure == "fuel") {
251  value = PollutantsInterface::compute(c, PollutantsInterface::FUEL, mySpeed, 0, 0) * value; // @todo: give correct slope
252  }
254  }
255  if (myUsingTTTimeLine) {
257  }
258 }
259 
260 
261 bool
262 ROEdge::allFollowersProhibit(const ROVehicle* const vehicle) const {
263  for (ROEdgeVector::const_iterator i = myFollowingEdges.begin(); i != myFollowingEdges.end(); ++i) {
264  if (!(*i)->prohibits(vehicle)) {
265  return false;
266  }
267  }
268  return true;
269 }
270 
271 
272 ROEdge*
273 ROEdge::dictionary(size_t id) {
274  assert(myEdges.size() > id);
275  return myEdges[id];
276 }
277 
278 
279 const ROEdgeVector&
281  if (vClass == SVC_IGNORING) {
282  return myFollowingEdges;
283  }
284  ClassesSuccesorMap::const_iterator i = myClassesSuccessorMap.find(vClass);
285  if (i != myClassesSuccessorMap.end()) {
286  // can use cached value
287  return i->second;
288  } else {
289  // this vClass is requested for the first time. rebuild all succesors
290  std::set<ROEdge*> followers;
291  for (std::vector<ROLane*>::const_iterator it = myLanes.begin(); it != myLanes.end(); ++it) {
292  ROLane* lane = *it;
293  if ((lane->getPermissions() & vClass) != 0) {
294  const std::vector<const ROLane*>& outgoing = lane->getOutgoingLanes();
295  for (std::vector<const ROLane*>::const_iterator it2 = outgoing.begin(); it2 != outgoing.end(); ++it2) {
296  const ROLane* next = *it2;
297  if ((next->getPermissions() & vClass) != 0) {
298  followers.insert(&next->getEdge());
299  }
300  }
301  }
302  }
303  myClassesSuccessorMap[vClass].insert(myClassesSuccessorMap[vClass].begin(),
304  followers.begin(), followers.end());
305  return myClassesSuccessorMap[vClass];
306  }
307 
308 }
309 
310 
311 bool
312 ROEdge::isConnectedTo(const ROEdge* const e, const ROVehicle* const vehicle) const {
313  const SUMOVehicleClass vClass = (vehicle == 0 ? SVC_IGNORING : vehicle->getVClass());
314  const ROEdgeVector& followers = getSuccessors(vClass);
315  return std::find(followers.begin(), followers.end(), e) != followers.end();
316 }
317 
318 /****************************************************************************/
319 
void fillGaps(T value, bool extendOverBoundaries=false)
Sets a default value for all unset intervals.
static ROEdgeVector myEdges
Definition: ROEdge.h:506
ROEdge & getEdge() const
Returns the lane's edge.
Definition: ROLane.h:96
RONode * getToNode() const
Returns the node this edge ends at.
Definition: ROEdge.h:222
EdgeType getType() const
Returns the type of the edge.
Definition: ROEdge.h:175
static bool myUseBoundariesOnOverrideTT
Whether overriding weight boundaries shall be reported.
Definition: ROEdge.h:474
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:207
SUMOReal getDistanceTo(const ROEdge *other) const
optimistic distance heuristic for use in routing
Definition: ROEdge.cpp:136
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:171
SUMOVehicleClass getVClass() const
Definition: ROVehicle.h:132
static bool myInterpolate
Information whether to interpolate at interval boundaries.
Definition: ROEdge.h:484
EdgeType
Possible types of edges.
Definition: ROEdge.h:79
static ROEdge * dictionary(size_t index)
Returns the ROEdge at the index.
Definition: ROEdge.cpp:273
ValueTimeLine< SUMOReal > myTravelTimes
Container storing passing time varying over time for the edge.
Definition: ROEdge.h:470
virtual void addLane(ROLane *lane)
Adds a lane to the edge while loading.
Definition: ROEdge.cpp:90
const SUMOVTypeParameter * getType() const
Returns the type of the vehicle.
Definition: ROVehicle.h:94
const Position & getPosition()
Returns the position of the node.
Definition: RONode.h:74
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:481
SVCPermissions myCombinedPermissions
The list of allowed vehicle classes combined across lanes.
Definition: ROEdge.h:504
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:119
#define WRITE_WARNING(msg)
Definition: MsgHandler.h:200
RONode * getFromNode() const
Returns the node this edge starts at.
Definition: ROEdge.h:214
ROEdgeVector myFollowingEdges
List of edges that may be approached from this edge.
Definition: ROEdge.h:492
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. ...
An edge where vehicles are inserted at (no vehicle may come from back)
Definition: ROEdge.h:85
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...
void setType(EdgeType type)
Sets the type of te edge.
Definition: ROEdge.cpp:225
bool allFollowersProhibit(const ROVehicle *const vehicle) const
Returns whether this edge succeeding edges prohibit the given vehicle to pass them.
Definition: ROEdge.cpp:262
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:477
bool myUsingTTTimeLine
Information whether the time line shall be used instead of the length value.
Definition: ROEdge.h:472
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:312
static bool myHaveEWarned
Information whether the edge has reported missing weights.
Definition: ROEdge.h:487
SUMOReal myLength
The length of the edge.
Definition: ROEdge.h:466
int SUMOEmissionClass
bool myUsingETimeLine
Information whether the time line shall be used instead of the length value.
Definition: ROEdge.h:479
std::vector< ROEdge * > ROEdgeVector
Definition: RODFRouteDesc.h:43
T MIN2(T a, T b)
Definition: StdDefs.h:68
ClassesSuccesorMap myClassesSuccessorMap
Definition: ROEdge.h:514
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's lanes.
Definition: ROEdge.h:501
ROEdge(const std::string &id, RONode *from, RONode *to, unsigned int index, const int priority)
Constructor.
Definition: ROEdge.cpp:67
const std::vector< const ROLane * > & getOutgoingLanes() const
get the list of outgoing lanes
Definition: ROLane.h:101
virtual ~ROEdge()
Destructor.
Definition: ROEdge.cpp:82
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:463
SUMOReal maxSpeed
The vehicle type's maximum speed [m/s].
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:112
virtual void addSuccessor(ROEdge *s, std::string dir="")
Adds information about a connected edge.
Definition: ROEdge.cpp:103
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:495
SUMOReal getEffort(const ROVehicle *const veh, SUMOReal time) const
Returns the effort for this edge.
Definition: ROEdge.cpp:126
void buildTimeLines(const std::string &measure)
Builds the internal representation of the travel time/effort.
Definition: ROEdge.cpp:231
const ROEdgeVector & getSuccessors() const
Returns the following edges.
Definition: ROEdge.h:292
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:216
int SUMOTime
Definition: SUMOTime.h:43
bool getStoredEffort(SUMOReal time, SUMOReal &ret) const
Retrieves the stored effort.
Definition: ROEdge.cpp:182
SUMOReal distanceTo2D(const Position &p2) const
returns the euclidean distance in the x-y-plane
Definition: Position.h:240
#define SUMOReal
Definition: config.h:218
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:147
An edge where vehicles disappear (no vehicle may leave this edge)
Definition: ROEdge.h:87
static bool myHaveTTWarned
Information whether the edge has reported missing weights.
Definition: ROEdge.h:489
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:372
EdgeType myType
The type of the edge.
Definition: ROEdge.h:498
SUMOEmissionClass emissionClass
The emission class of this vehicle.
vehicles ignoring classes