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-sim.org/
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::addFollower(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 (SUMOReal)(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 (SUMOReal)(myLength / MIN2(veh->getType()->maxSpeed, veh->getType()->speedFactor * mySpeed));
167 }
168 
169 
170 SUMOReal
171 ROEdge::getCOEffort(const ROVehicle* const veh, SUMOReal time) const {
172  SUMOReal ret = 0;
173  if (!getStoredEffort(time, ret)) {
174  const SUMOVTypeParameter* const type = veh->getType();
175  const SUMOReal vMax = MIN2(type->maxSpeed, mySpeed);
177  ret = PollutantsInterface::computeDefault(type->emissionClass, PollutantsInterface::CO, vMax, accel, 0, getTravelTime(veh, time)); // @todo: give correct slope
178  }
179  return ret;
180 }
181 
182 
183 SUMOReal
184 ROEdge::getCO2Effort(const ROVehicle* const veh, SUMOReal time) const {
185  SUMOReal ret = 0;
186  if (!getStoredEffort(time, ret)) {
187  const SUMOVTypeParameter* const type = veh->getType();
188  const SUMOReal vMax = MIN2(type->maxSpeed, mySpeed);
190  ret = PollutantsInterface::computeDefault(type->emissionClass, PollutantsInterface::CO2, vMax, accel, 0, getTravelTime(veh, time)); // @todo: give correct slope
191  }
192  return ret;
193 }
194 
195 
196 SUMOReal
197 ROEdge::getPMxEffort(const ROVehicle* const veh, SUMOReal time) const {
198  SUMOReal ret = 0;
199  if (!getStoredEffort(time, ret)) {
200  const SUMOVTypeParameter* const type = veh->getType();
201  const SUMOReal vMax = MIN2(type->maxSpeed, mySpeed);
203  ret = PollutantsInterface::computeDefault(type->emissionClass, PollutantsInterface::PM_X, vMax, accel, 0, getTravelTime(veh, time)); // @todo: give correct slope
204  }
205  return ret;
206 }
207 
208 
209 SUMOReal
210 ROEdge::getHCEffort(const ROVehicle* const veh, SUMOReal time) const {
211  SUMOReal ret = 0;
212  if (!getStoredEffort(time, ret)) {
213  const SUMOVTypeParameter* const type = veh->getType();
214  const SUMOReal vMax = MIN2(type->maxSpeed, mySpeed);
216  ret = PollutantsInterface::computeDefault(type->emissionClass, PollutantsInterface::HC, vMax, accel, 0, getTravelTime(veh, time)); // @todo: give correct slope
217  }
218  return ret;
219 }
220 
221 
222 SUMOReal
223 ROEdge::getNOxEffort(const ROVehicle* const veh, SUMOReal time) const {
224  SUMOReal ret = 0;
225  if (!getStoredEffort(time, ret)) {
226  const SUMOVTypeParameter* const type = veh->getType();
227  const SUMOReal vMax = MIN2(type->maxSpeed, mySpeed);
229  ret = PollutantsInterface::computeDefault(type->emissionClass, PollutantsInterface::NO_X, vMax, accel, 0, getTravelTime(veh, time)); // @todo: give correct slope
230  }
231  return ret;
232 }
233 
234 
235 SUMOReal
236 ROEdge::getFuelEffort(const ROVehicle* const veh, SUMOReal time) const {
237  SUMOReal ret = 0;
238  if (!getStoredEffort(time, ret)) {
239  const SUMOVTypeParameter* const type = veh->getType();
240  const SUMOReal vMax = MIN2(type->maxSpeed, mySpeed);
242  ret = PollutantsInterface::computeDefault(type->emissionClass, PollutantsInterface::FUEL, vMax, accel, 0, getTravelTime(veh, time)); // @todo: give correct slope
243  }
244  return ret;
245 }
246 
247 
248 SUMOReal
249 ROEdge::getNoiseEffort(const ROVehicle* const veh, SUMOReal time) const {
250  SUMOReal ret = 0;
251  if (!getStoredEffort(time, ret)) {
252  const SUMOReal v = MIN2(veh->getType()->maxSpeed, mySpeed);
254  }
255  return ret;
256 }
257 
258 
259 bool
261  if (myUsingETimeLine) {
262  if (!myEfforts.describesTime(time)) {
263  if (!myHaveEWarned) {
264  WRITE_WARNING("No interval matches passed time " + toString(time) + " in edge '" + myID + "'.\n Using edge's length / edge's speed.");
265  myHaveEWarned = true;
266  }
267  return false;
268  }
269  if (myInterpolate) {
270  SUMOReal inTT = myTravelTimes.getValue(time);
271  SUMOReal ratio = (SUMOReal)(myEfforts.getSplitTime(time, time + (SUMOTime)inTT) - time) / inTT;
272  if (ratio >= 0) {
273  ret = ratio * myEfforts.getValue(time) + (1 - ratio) * myEfforts.getValue(time + (SUMOTime)inTT);
274  return true;
275  }
276  }
277  ret = myEfforts.getValue(time);
278  return true;
279  }
280  return false;
281 }
282 
283 
284 unsigned int
286  if (getType() == ET_SINK) {
287  return 0;
288  }
289  return (unsigned int) myFollowingEdges.size();
290 }
291 
292 
293 unsigned int
295  if (getType() == ET_SOURCE) {
296  return 0;
297  }
298  return (unsigned int) myApproachingEdges.size();
299 }
300 
301 
302 void
304  myType = type;
305 }
306 
307 
308 void
309 ROEdge::buildTimeLines(const std::string& measure) {
310  if (myUsingETimeLine) {
311  SUMOReal value = myLength / mySpeed;
313  if (measure == "CO") {
314  value = PollutantsInterface::compute(c, PollutantsInterface::CO, mySpeed, 0, 0) * value; // @todo: give correct slope
315  }
316  if (measure == "CO2") {
317  value = PollutantsInterface::compute(c, PollutantsInterface::CO2, mySpeed, 0, 0) * value; // @todo: give correct slope
318  }
319  if (measure == "HC") {
320  value = PollutantsInterface::compute(c, PollutantsInterface::HC, mySpeed, 0, 0) * value; // @todo: give correct slope
321  }
322  if (measure == "PMx") {
323  value = PollutantsInterface::compute(c, PollutantsInterface::PM_X, mySpeed, 0, 0) * value; // @todo: give correct slope
324  }
325  if (measure == "NOx") {
326  value = PollutantsInterface::compute(c, PollutantsInterface::NO_X, mySpeed, 0, 0) * value; // @todo: give correct slope
327  }
328  if (measure == "fuel") {
329  value = PollutantsInterface::compute(c, PollutantsInterface::FUEL, mySpeed, 0, 0) * value; // @todo: give correct slope
330  }
332  }
333  if (myUsingTTTimeLine) {
335  }
336 }
337 
338 
339 bool
340 ROEdge::allFollowersProhibit(const ROVehicle* const vehicle) const {
341  for (std::vector<ROEdge*>::const_iterator i = myFollowingEdges.begin(); i != myFollowingEdges.end(); ++i) {
342  if (!(*i)->prohibits(vehicle)) {
343  return false;
344  }
345  }
346  return true;
347 }
348 
349 
350 ROEdge*
351 ROEdge::dictionary(size_t id) {
352  assert(myEdges.size() > id);
353  return myEdges[id];
354 }
355 
356 
357 
358 /****************************************************************************/
359