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-2014 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;
61 std::vector<ROEdge*> ROEdge::myEdges;
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 (std::vector<ROEdge*>::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 
280 /****************************************************************************/
281 
void fillGaps(T value, bool extendOverBoundaries=false)
Sets a default value for all unset intervals.
RONode * getToNode() const
Returns the node this edge ends at.
Definition: ROEdge.h:219
EdgeType getType() const
Returns the type of the edge.
Definition: ROEdge.h:172
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
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
static std::vector< ROEdge * > myEdges
Definition: ROEdge.h:499
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
static bool myInterpolate
Information whether to interpolate at interval boundaries.
Definition: ROEdge.h:477
EdgeType
Possible types of edges.
Definition: ROEdge.h:76
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:463
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:93
const Position & getPosition()
Returns the position of the node.
Definition: RONode.h:72
T MAX2(T a, T b)
Definition: StdDefs.h:74
std::vector< ROEdge * > myApproachingEdges
List of edges that approached this edge.
Definition: ROEdge.h:488
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
SVCPermissions myCombinedPermissions
The list of allowed vehicle classes combined across lanes.
Definition: ROEdge.h:497
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:211
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:82
A vehicle as used by router.
Definition: ROVehicle.h:59
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:470
bool myUsingTTTimeLine
Information whether the time line shall be used instead of the length value.
Definition: ROEdge.h:465
static bool myHaveEWarned
Information whether the edge has reported missing weights.
Definition: ROEdge.h:480
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
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:494
ROEdge(const std::string &id, RONode *from, RONode *to, unsigned int index, const int priority)
Constructor.
Definition: ROEdge.cpp:67
virtual ~ROEdge()
Destructor.
Definition: ROEdge.cpp:82
A basic edge for routing applications.
Definition: ROEdge.h:70
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].
std::vector< ROEdge * > myFollowingEdges
List of edges that may be approached from this edge.
Definition: ROEdge.h:485
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.
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
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:51
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:84
static bool myHaveTTWarned
Information whether the edge has reported missing weights.
Definition: ROEdge.h:482
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:365
EdgeType myType
The type of the edge.
Definition: ROEdge.h:491
SVCPermissions getPermissions()
Returns the list of allowed vehicle classes.
Definition: ROLane.h:89
SUMOEmissionClass emissionClass
The emission class of this vehicle.