SUMO - Simulation of Urban MObility
MESegment.cpp
Go to the documentation of this file.
1 /****************************************************************************/
7 // A single mesoscopic segment (cell)
8 /****************************************************************************/
9 // SUMO, Simulation of Urban MObility; see http://sumo.dlr.de/
10 // Copyright (C) 2001-2016 DLR (http://www.dlr.de/) and contributors
11 /****************************************************************************/
12 //
13 // This file is part of SUMO.
14 // SUMO is free software: you can redistribute it and/or modify
15 // it under the terms of the GNU General Public License as published by
16 // the Free Software Foundation, either version 3 of the License, or
17 // (at your option) any later version.
18 //
19 /****************************************************************************/
20 
21 
22 // ===========================================================================
23 // included modules
24 // ===========================================================================
25 #ifdef _MSC_VER
26 #include <windows_config.h>
27 #else
28 #include <config.h>
29 #endif
30 
31 #include <algorithm>
32 #include <limits>
33 #include <utils/common/StdDefs.h>
34 #include <microsim/MSGlobals.h>
35 #include <microsim/MSEdge.h>
36 #include <microsim/MSJunction.h>
37 #include <microsim/MSNet.h>
38 #include <microsim/MSLane.h>
39 #include <microsim/MSLinkCont.h>
40 #include <microsim/MSVehicle.h>
49 #include "MEVehicle.h"
50 #include "MELoop.h"
51 #include "MESegment.h"
52 
53 #ifdef CHECK_MEMORY_LEAKS
54 #include <foreign/nvwa/debug_new.h>
55 #endif // CHECK_MEMORY_LEAKS
56 
57 // ===========================================================================
58 // static member defintion
59 // ===========================================================================
60 MSEdge MESegment::myDummyParent("MESegmentDummyParent", -1, MSEdge::EDGEFUNCTION_UNKNOWN, "", "", -1);
61 MESegment MESegment::myVaporizationTarget("vaporizationTarget");
63 
64 // ===========================================================================
65 // method definitions
66 // ===========================================================================
67 MESegment::MESegment(const std::string& id,
68  const MSEdge& parent, MESegment* next,
69  SUMOReal length, SUMOReal speed,
70  unsigned int idx,
71  SUMOTime tauff, SUMOTime taufj,
72  SUMOTime taujf, SUMOTime taujj,
73  SUMOReal jamThresh, bool multiQueue, bool junctionControl,
74  SUMOReal lengthGeometryFactor) :
75  Named(id), myEdge(parent), myNextSegment(next),
76  myLength(length), myIndex(idx),
77  myTau_ff((SUMOTime)(tauff / parent.getLanes().size())),
78  myTau_fj((SUMOTime)(taufj / parent.getLanes().size())), // Eissfeldt p. 90 and 151 ff.
79  myTau_jf((SUMOTime)(taujf / parent.getLanes().size())),
80  myTau_jj((SUMOTime)(taujj / parent.getLanes().size())),
81  myHeadwayCapacity(length / 7.5f * parent.getLanes().size())/* Eissfeldt p. 69 */,
82  myCapacity(length * parent.getLanes().size()),
83  myOccupancy(0.f),
84  myJunctionControl(junctionControl),
85  myTLSPenalty(MSGlobals::gMesoTLSPenalty > 0 && myNextSegment == 0 && (
86  parent.getToJunction()->getType() == NODETYPE_TRAFFIC_LIGHT ||
87  parent.getToJunction()->getType() == NODETYPE_TRAFFIC_LIGHT_NOJUNCTION ||
88  parent.getToJunction()->getType() == NODETYPE_TRAFFIC_LIGHT_RIGHT_ON_RED)),
89  myEntryBlockTime(SUMOTime_MIN),
90  myLengthGeometryFactor(lengthGeometryFactor),
91  myMeanSpeed(speed),
92  myLastMeanSpeedUpdate(SUMOTime_MIN) {
93  myCarQues.push_back(std::vector<MEVehicle*>());
94  myBlockTimes.push_back(-1);
95  const std::vector<MSLane*>& lanes = parent.getLanes();
96  if (multiQueue && lanes.size() > 1) {
97  unsigned int numFollower = parent.getNumSuccessors();
98  if (numFollower > 1) {
99  while (myCarQues.size() < lanes.size()) {
100  myCarQues.push_back(std::vector<MEVehicle*>());
101  myBlockTimes.push_back(-1);
102  }
103  for (unsigned int i = 0; i < numFollower; ++i) {
104  const MSEdge* edge = parent.getSuccessors()[i];
105  myFollowerMap[edge] = std::vector<size_t>();
106  const std::vector<MSLane*>* allowed = parent.allowedLanes(*edge);
107  assert(allowed != 0);
108  assert(allowed->size() > 0);
109  for (std::vector<MSLane*>::const_iterator j = allowed->begin(); j != allowed->end(); ++j) {
110  std::vector<MSLane*>::const_iterator it = find(lanes.begin(), lanes.end(), *j);
111  myFollowerMap[edge].push_back(distance(lanes.begin(), it));
112  }
113  }
114  }
115  }
116  recomputeJamThreshold(jamThresh);
117 }
118 
119 
120 MESegment::MESegment(const std::string& id):
121  Named(id),
122  myEdge(myDummyParent), // arbitrary edge needed to supply the needed reference
123  myNextSegment(0), myLength(0), myIndex(0),
124  myTau_ff(0), myTau_fj(0), myTau_jf(0), myTau_jj(0),
126  myTLSPenalty(false),
128 }
129 
130 
131 void
133  if (jamThresh == DO_NOT_PATCH_JAM_THRESHOLD) {
134  return;
135  }
136  if (jamThresh < 0) {
137  // compute based on speed
139  } else {
140  // compute based on specified percentage
141  myJamThreshold = jamThresh * myCapacity;
142  }
143 }
144 
145 
146 SUMOReal
148  // vehicles driving freely at maximum speed should not jam
149  // we compute how many vehicles could possible enter the segment until the first vehicle leaves
150  // and multiply by the space these vehicles would occupy
151  if (speed == 0) {
152  return std::numeric_limits<double>::max(); // FIXME: This line is just an adhoc-fix to avoid division by zero (Leo)
153  }
155 }
156 
157 
158 void
160  myDetectorData.push_back(data);
161  for (Queues::const_iterator k = myCarQues.begin(); k != myCarQues.end(); ++k) {
162  for (std::vector<MEVehicle*>::const_reverse_iterator i = k->rbegin(); i != k->rend(); ++i) {
163  (*i)->addReminder(data);
164  }
165  }
166 }
167 
168 
169 void
171  std::vector<MSMoveReminder*>::iterator it = find(
172  myDetectorData.begin(), myDetectorData.end(), data);
173  if (it != myDetectorData.end()) {
174  myDetectorData.erase(it);
175  }
176  for (Queues::const_iterator k = myCarQues.begin(); k != myCarQues.end(); ++k) {
177  for (std::vector<MEVehicle*>::const_reverse_iterator i = k->rbegin(); i != k->rend(); ++i) {
178  (*i)->removeReminder(data);
179  }
180  }
181 }
182 
183 
184 void
187  if (next == 0) {
189  } else if (next == &myVaporizationTarget) {
191  } else if (myNextSegment == 0) {
193  } else {
195  }
196  v->updateDetectors(currentTime, true, reason);
197 }
198 
199 
200 void
202  const SUMOTime currentTime = MSNet::getInstance()->getCurrentTimeStep();
203  for (Queues::const_iterator k = myCarQues.begin(); k != myCarQues.end(); ++k) {
204  SUMOTime earliestExitTime = currentTime;
205  for (std::vector<MEVehicle*>::const_reverse_iterator i = k->rbegin(); i != k->rend(); ++i) {
206  const SUMOTime exitTime = MAX2(earliestExitTime, (*i)->getEventTime());
207  (*i)->updateDetectorForWriting(&data, currentTime, exitTime);
208  earliestExitTime = exitTime + myTau_ff;
209  }
210  }
211 }
212 
213 
214 bool
215 MESegment::hasSpaceFor(const MEVehicle* veh, SUMOTime entryTime, bool init) const {
216  if (myOccupancy == 0.) {
217  // we have always space for at least one vehicle
218  return true;
219  }
220  const SUMOReal newOccupancy = myOccupancy + veh->getVehicleType().getLengthWithGap();
221  if (newOccupancy > myCapacity) {
222  // we must ensure that occupancy remains below capacity
223  return false;
224  }
225  // regular insertions and initial insertions must respect different constraints:
226  // - regular insertions must respect entryBlockTime
227  // - initial insertions should not cause additional jamming
228  if (init) {
229  // inserted vehicle should be able to continue at the current speed
230  return newOccupancy <= jamThresholdForSpeed(getMeanSpeed(false));
231  }
232  // maintain propper spacing between inflow from different lanes
233  return entryTime >= myEntryBlockTime;
234 }
235 
236 
237 bool
239  if (hasSpaceFor(veh, time, true)) {
240  receive(veh, time, true);
241  // we can check only after insertion because insertion may change the route via devices
242  std::string msg;
243  if (MSGlobals::gCheckRoutes && !veh->hasValidRoute(msg)) {
244  throw ProcessError("Vehicle '" + veh->getID() + "' has no valid route. " + msg);
245  }
246  return true;
247  }
248  return false;
249 }
250 
251 
252 size_t
254  size_t total = 0;
255  for (Queues::const_iterator k = myCarQues.begin(); k != myCarQues.end(); ++k) {
256  total += k->size();
257  }
258  return total;
259 }
260 
261 
262 SUMOReal
263 MESegment::getMeanSpeed(bool useCached) const {
264  const SUMOTime currentTime = MSNet::getInstance()->getCurrentTimeStep();
265  if (currentTime != myLastMeanSpeedUpdate || !useCached) {
266  myLastMeanSpeedUpdate = currentTime;
267  const SUMOTime tau = free() ? myTau_ff : myTau_jf;
268  SUMOReal v = 0;
269  size_t count = 0;
270  for (Queues::const_iterator k = myCarQues.begin(); k != myCarQues.end(); ++k) {
271  SUMOTime earliestExitTime = currentTime;
272  count += k->size();
273  for (std::vector<MEVehicle*>::const_reverse_iterator veh = k->rbegin(); veh != k->rend(); ++veh) {
274  v += (*veh)->getConservativeSpeed(earliestExitTime); // earliestExitTime is updated!
275  earliestExitTime += tau;
276  }
277  }
278  if (count == 0) {
280  } else {
281  myMeanSpeed = v / (SUMOReal) count;
282  }
283  }
284  return myMeanSpeed;
285 }
286 
287 
288 void
290  for (Queues::const_iterator k = myCarQues.begin(); k != myCarQues.end(); ++k) {
291  for (std::vector<MEVehicle*>::const_iterator veh = k->begin(); veh != k->end(); ++veh) {
292  MSXMLRawOut::writeVehicle(of, *(*veh));
293  }
294  }
295 }
296 
297 
298 MEVehicle*
301  std::vector<MEVehicle*>& cars = myCarQues[v->getQueIndex()];
302  assert(std::find(cars.begin(), cars.end(), v) != cars.end());
303  // One could be tempted to do v->setSegment(next); here but position on lane will be invalid if next == 0
304  updateDetectorsOnLeave(v, leaveTime, next);
305  myEdge.lock();
306  if (v == cars.back()) {
307  cars.pop_back();
308  if (!cars.empty()) {
309  myEdge.unlock();
310  return cars.back();
311  }
312  } else {
313  cars.erase(std::find(cars.begin(), cars.end(), v));
314  }
315  myEdge.unlock();
316  return 0;
317 }
318 
319 
320 SUMOTime
321 MESegment::getTimeHeadway(bool predecessorIsFree) {
322  if (predecessorIsFree) {
323  return free() ? myTau_ff : myTau_fj;
324  } else {
325  if (free() || myTLSPenalty) {
326  return myTau_jf;
327  } else {
328  // the gap has to move from the start of the segment to its end
329  // this allows jams to clear and move upstream
330  const SUMOTime b = (SUMOTime)(myHeadwayCapacity * (myTau_jf - myTau_jj)); // FIXME: unsigned integer overflow (in meso/tau/tau_jj)
331  return (SUMOTime)(myTau_jj * getCarNumber() + b);
332  }
333  }
334 }
335 
336 
337 SUMOTime
339  // since we do not know which queue will be used we give a conservative estimate
340  SUMOTime earliestLeave = earliestEntry;
341  for (size_t i = 0; i < myCarQues.size(); ++i) {
342  earliestLeave = MAX2(earliestLeave, myBlockTimes[i]);
343  }
344  if (myEdge.getSpeedLimit() == 0) {
345  return MAX2(earliestEntry, myEntryBlockTime); // FIXME: This line is just an adhoc-fix to avoid division by zero (Leo)
346  } else {
347  return MAX3(earliestEntry, earliestLeave - TIME2STEPS(myLength / myEdge.getSpeedLimit()), myEntryBlockTime);
348  }
349 }
350 
351 
352 MSLink*
353 MESegment::getLink(const MEVehicle* veh, bool tlsPenalty) const {
354  if (myJunctionControl || tlsPenalty) {
355  const MSEdge* const nextEdge = veh->succEdge(1);
356  if (nextEdge == 0) {
357  return 0;
358  }
359  // try to find any link leading to our next edge, start with the lane pointed to by the que index
360  const MSLane* const bestLane = myEdge.getLanes()[veh->getQueIndex()];
361  const MSLinkCont& links = bestLane->getLinkCont();
362  for (std::vector<MSLink*>::const_iterator j = links.begin(); j != links.end(); ++j) {
363  if (&(*j)->getLane()->getEdge() == nextEdge) {
364  return *j;
365  }
366  }
367  // this is for the non-multique case, maybe we should use caching here !!!
368  for (std::vector<MSLane*>::const_iterator l = myEdge.getLanes().begin(); l != myEdge.getLanes().end(); ++l) {
369  if ((*l) != bestLane) {
370  const MSLinkCont& links = (*l)->getLinkCont();
371  for (std::vector<MSLink*>::const_iterator j = links.begin(); j != links.end(); ++j) {
372  if (&(*j)->getLane()->getEdge() == nextEdge) {
373  return *j;
374  }
375  }
376  }
377  }
378  }
379  return 0;
380 }
381 
382 
383 bool
384 MESegment::isOpen(const MEVehicle* veh) const {
385  if (myTLSPenalty) {
386  // XXX should limited control take precedence over tls penalty?
387  return true;
388  }
389  const MSLink* link = getLink(veh);
390  return (link == 0
391  || link->havePriority()
392  || limitedControlOverride(link)
393  || link->opened(veh->getEventTime(), veh->getSpeed(), veh->estimateLeaveSpeed(link),
396 }
397 
398 
399 bool
401  assert(link != 0);
403  return false;
404  }
405  // if the target segment of this link is not saturated junction control is disabled
406  const MSEdge& targetEdge = link->getLane()->getEdge();
407  const MESegment* target = MSGlobals::gMesoNet->getSegmentForEdge(targetEdge);
408  return target->myOccupancy * 2 < target->myJamThreshold;
409 }
410 
411 
412 void
414  assert(isInvalid(next) || time >= myBlockTimes[veh->getQueIndex()]);
415  MSLink* link = getLink(veh);
416  if (link != 0) {
417  link->removeApproaching(veh);
418  }
419  MEVehicle* lc = removeCar(veh, time, next); // new leaderCar
420  myBlockTimes[veh->getQueIndex()] = time;
421  if (!isInvalid(next)) {
422  myBlockTimes[veh->getQueIndex()] += next->getTimeHeadway(free());
423  }
424  if (lc != 0) {
427  }
428 }
429 
430 bool
433 }
434 
435 
436 void
438  for (std::vector<MSMoveReminder*>::const_iterator i = myDetectorData.begin(); i != myDetectorData.end(); ++i) {
439  veh->addReminder(*i);
440  }
441 }
442 
443 void
444 MESegment::receive(MEVehicle* veh, SUMOTime time, bool isDepart, bool afterTeleport) {
445  const SUMOReal speed = isDepart ? -1 : veh->getSpeed(); // on the previous segment
446  veh->setSegment(this); // for arrival checking
447  veh->setLastEntryTime(time);
449  if (!isDepart && (
450  // arrival on entering a new edge
451  ((myIndex == 0 || afterTeleport) && veh->moveRoutePointer())
452  // arrival on entering a new segment
453  || veh->hasArrived())) {
454  // route has ended
455  veh->setEventTime(time + TIME2STEPS(myLength / speed)); // for correct arrival speed
456  addReminders(veh);
458  updateDetectorsOnLeave(veh, time, 0);
460  return;
461  }
462  // route continues
463  const SUMOReal maxSpeedOnEdge = veh->getEdge()->getVehicleMaxSpeed(veh);
464  const SUMOReal uspeed = MAX2(maxSpeedOnEdge, (SUMOReal).05);
465  size_t nextQueIndex = 0;
466  if (myCarQues.size() > 1) {
467  const MSEdge* succ = veh->succEdge(1);
468  // succ may be invalid if called from initialise() with an invalid route
469  if (succ != 0 && myFollowerMap.count(succ) > 0) {
470  const std::vector<size_t>& indices = myFollowerMap[succ];
471  nextQueIndex = indices[0];
472  for (std::vector<size_t>::const_iterator i = indices.begin() + 1; i != indices.end(); ++i) {
473  if (myCarQues[*i].size() < myCarQues[nextQueIndex].size()) {
474  nextQueIndex = *i;
475  }
476  }
477  }
478  }
479  std::vector<MEVehicle*>& cars = myCarQues[nextQueIndex];
480  MEVehicle* newLeader = 0; // first vehicle in the current queue
481  SUMOTime tleave = MAX2(time + TIME2STEPS(myLength / uspeed) + veh->getStoptime(this) + getTLSPenalty(veh), myBlockTimes[nextQueIndex]);
482  myEdge.lock();
483  if (cars.empty()) {
484  cars.push_back(veh);
485  newLeader = veh;
486  } else {
487  SUMOTime leaderOut = cars[0]->getEventTime();
488  if (!isDepart && leaderOut > tleave && overtake()) {
489  if (cars.size() == 1) {
491  newLeader = veh;
492  }
493  cars.insert(cars.begin() + 1, veh);
494  } else {
495  tleave = MAX2(leaderOut + myTau_ff, tleave);
496  cars.insert(cars.begin(), veh);
497  }
498  }
499  myEdge.unlock();
500  if (!isDepart) {
501  // regular departs could take place anywhere on the edge so they should not block regular flow
502  // the -1 facilitates interleaving of multiple streams
503  myEntryBlockTime = time + myTau_ff - 1;
504  }
505  veh->setEventTime(tleave);
506  veh->setSegment(this, nextQueIndex);
508  addReminders(veh);
509  if (isDepart) {
510  veh->onDepart();
512  } else if (myIndex == 0 || afterTeleport) {
514  } else {
516  }
517  if (newLeader != 0) {
518  MSGlobals::gMesoNet->addLeaderCar(newLeader, getLink(newLeader));
519  }
520 }
521 
522 
523 bool
525  MEVehicle* remove = 0;
526  for (Queues::const_iterator k = myCarQues.begin(); k != myCarQues.end(); ++k) {
527  if (!k->empty()) {
528  // remove last in queue
529  remove = k->front();
530  if (k->size() == 1) {
532  }
534  return true;
535  }
536  }
537  return false;
538 }
539 
540 
541 void
542 MESegment::setSpeedForQueue(SUMOReal newSpeed, SUMOTime currentTime, SUMOTime blockTime, const std::vector<MEVehicle*>& vehs) {
543  MEVehicle* v = vehs.back();
544  v->updateDetectors(currentTime, false);
545  SUMOTime newEvent = MAX2(newArrival(v, newSpeed, currentTime), blockTime);
546  if (v->getEventTime() != newEvent) {
548  v->setEventTime(newEvent);
550  }
551  for (std::vector<MEVehicle*>::const_reverse_iterator i = vehs.rbegin() + 1; i != vehs.rend(); ++i) {
552  (*i)->updateDetectors(currentTime, false);
553  newEvent = MAX2(newArrival(*i, newSpeed, currentTime), newEvent + myTau_ff);
554  (*i)->setEventTime(newEvent);
555  }
556 }
557 
558 
559 SUMOTime
560 MESegment::newArrival(const MEVehicle* const v, SUMOReal newSpeed, SUMOTime currentTime) {
561  // since speed is only an upper bound pos may be to optimistic
562  const SUMOReal pos = MIN2(myLength, STEPS2TIME(currentTime - v->getLastEntryTime()) * v->getSpeed());
563  // traveltime may not be 0
564  return currentTime + MAX2(TIME2STEPS((myLength - pos) / newSpeed), SUMOTime(1));
565 }
566 
567 
568 void
569 MESegment::setSpeed(SUMOReal newSpeed, SUMOTime currentTime, SUMOReal jamThresh) {
570  recomputeJamThreshold(jamThresh);
571  for (size_t i = 0; i < myCarQues.size(); ++i) {
572  if (myCarQues[i].size() != 0) {
573  setSpeedForQueue(newSpeed, currentTime, myBlockTimes[i], myCarQues[i]);
574  }
575  }
576 }
577 
578 
579 SUMOTime
581  SUMOTime result = SUMOTime_MAX;
582  for (size_t i = 0; i < myCarQues.size(); ++i) {
583  if (myCarQues[i].size() != 0 && myCarQues[i].back()->getEventTime() < result) {
584  result = myCarQues[i].back()->getEventTime();
585  }
586  }
587  if (result < SUMOTime_MAX) {
588  return result;
589  }
590  return -1;
591 }
592 
593 
594 void
597  for (size_t i = 0; i < myCarQues.size(); ++i) {
600  out.closeTag();
601  }
602  out.closeTag();
603 }
604 
605 
606 void
607 MESegment::loadState(std::vector<std::string>& vehIds, MSVehicleControl& vc, const SUMOTime block, const unsigned int queIdx) {
608  for (std::vector<std::string>::const_iterator it = vehIds.begin(); it != vehIds.end(); ++it) {
609  MEVehicle* v = static_cast<MEVehicle*>(vc.getVehicle(*it));
610  assert(v != 0);
611  assert(v->getSegment() == this);
612  myCarQues[queIdx].push_back(v);
614  }
615  if (myCarQues[queIdx].size() != 0) {
616  // add the last vehicle of this queue
617  // !!! one question - what about the previously added vehicle? Is it stored twice?
618  MEVehicle* veh = myCarQues[queIdx].back();
620  }
621  myBlockTimes[queIdx] = block;
623 }
624 
625 
626 std::vector<const MEVehicle*>
628  std::vector<const MEVehicle*> result;
629  for (Queues::const_iterator k = myCarQues.begin(); k != myCarQues.end(); ++k) {
630  result.insert(result.end(), k->begin(), k->end());
631  }
632  return result;
633 }
634 
635 
636 SUMOReal
638  return 3600 * getCarNumber() * getMeanSpeed() / myLength;
639 }
640 
641 
642 SUMOTime
644  const MSLink* link = getLink(veh, myTLSPenalty);
645  if (link != 0 && link->isTLSControlled()) {
646  // only apply to the last segment of a tls-controlled edge
647  return link->getMesoTLSPenalty();
648  } else {
649  return 0;
650  }
651 }
652 
653 /****************************************************************************/
OutputDevice & writeAttr(const SumoXMLAttr attr, const T &val)
writes a named attribute
Definition: OutputDevice.h:257
bool changeSegment(MEVehicle *veh, SUMOTime leaveTime, MESegment *const toSegment, const bool ignoreLink=false)
change to the next segment this handles combinations of the following cases: (ending / continuing rou...
Definition: MELoop.cpp:91
static MESegment myVaporizationTarget
Definition: MESegment.h:483
MSEdge & getEdge() const
Returns the lane&#39;s edge.
Definition: MSLane.h:467
const unsigned int myIndex
Running number of the segment in the edge.
Definition: MESegment.h:436
long long int SUMOTime
Definition: SUMOTime.h:43
SUMOReal getFlow() const
returns flow based on headway
Definition: MESegment.cpp:637
const SUMOReal myCapacity
The number of lanes * the length.
Definition: MESegment.h:446
bool hasArrived() const
Returns whether this vehicle has already arived (reached the arrivalPosition on its final edge) ...
Definition: MEVehicle.cpp:153
std::vector< const MEVehicle * > getVehicles() const
returns all vehicles (for debugging)
Definition: MESegment.cpp:627
A vehicle from the mesoscopic point of view.
Definition: MEVehicle.h:52
MESegment(const std::string &id, const MSEdge &parent, MESegment *next, SUMOReal length, SUMOReal speed, unsigned int idx, SUMOTime tauff, SUMOTime taufj, SUMOTime taujf, SUMOTime taujj, SUMOReal jamThresh, bool multiQueue, bool junctionControl, SUMOReal lengthGeometryFactor)
constructor
Definition: MESegment.cpp:67
MEVehicle * removeCar(MEVehicle *v, SUMOTime leaveTime, MESegment *next)
Removes the given car from the edge&#39;s que.
Definition: MESegment.cpp:299
bool overtake()
Definition: MESegment.cpp:431
bool initialise(MEVehicle *veh, SUMOTime time)
Inserts (emits) vehicle into the segment.
Definition: MESegment.cpp:238
bool limitedControlOverride(const MSLink *link) const
whether the given link may be passed because the option meso-junction-control.limited is set ...
Definition: MESegment.cpp:400
const std::vector< MSLane * > & getLanes() const
Returns this edge&#39;s lanes.
Definition: MSEdge.h:185
SUMOReal getLengthWithGap() const
Get vehicle&#39;s length including the minimum gap [m].
SUMOReal getImpatience() const
Returns this vehicles impatience.
The vehicle arrived at a junction.
virtual void lock() const
grant exclusive access to the mesoscopic state
Definition: MSEdge.h:625
SUMOTime getStoptime(const MESegment *const seg) const
Returns how long to stop at the given segment.
Definition: MEVehicle.cpp:236
SUMOTime myEntryBlockTime
Definition: MESegment.h:475
static const SUMOReal DO_NOT_PATCH_JAM_THRESHOLD
Definition: MESegment.h:375
SUMOTime getWaitingTime() const
Returns the duration for which the vehicle was blocked.
Definition: MEVehicle.h:254
SUMOReal length
The physical vehicle length.
SUMOReal getSpeed() const
Returns the vehicle&#39;s estimated speed assuming no delays.
Definition: MEVehicle.cpp:107
Notification
Definition of a vehicle state.
static SUMOReal rand()
Returns a random real number in [0, 1)
Definition: RandHelper.h:62
std::vector< MSMoveReminder * > myDetectorData
The data collection for all kinds of detectors.
Definition: MESegment.h:461
SUMOReal myOccupancy
The occupied space (in m) on the segment.
Definition: MESegment.h:449
static MSNet * getInstance()
Returns the pointer to the unique instance of MSNet (singleton).
Definition: MSNet.cpp:160
T MAX2(T a, T b)
Definition: StdDefs.h:75
SUMOTime getEventTime() const
Returns the (planned) time at which the vehicle leaves his current cell.
Definition: MEVehicle.h:189
SUMOReal getMeanSpeed() const
wrapper to satisfy the FunctionBinding signature
Definition: MESegment.h:207
SUMOTime newArrival(const MEVehicle *const v, SUMOReal newSpeed, SUMOTime currentTime)
compute the new arrival time when switching speed
Definition: MESegment.cpp:560
The vehicle got vaporized.
The vehicle changes the segment (meso only)
void setSpeedForQueue(SUMOReal newSpeed, SUMOTime currentTime, SUMOTime blockTime, const std::vector< MEVehicle * > &vehs)
Definition: MESegment.cpp:542
#define TIME2STEPS(x)
Definition: SUMOTime.h:66
SUMOTime getCurrentTimeStep() const
Returns the current simulation step.
Definition: MSNet.h:255
SUMOTime getLastEntryTime() const
Returns the time the vehicle entered the current segment.
Definition: MEVehicle.h:231
static bool gMesoOvertaking
Definition: MSGlobals.h:93
T MAX3(T a, T b, T c)
Definition: StdDefs.h:89
void setBlockTime(const SUMOTime t)
Sets the time at which the vehicle was blocked.
Definition: MEVehicle.h:239
The purpose of the edge is not known.
Definition: MSEdge.h:91
Queues myCarQues
The car queues. Vehicles are inserted in the front and removed in the back.
Definition: MESegment.h:464
const MSCFModel & getCarFollowModel() const
Returns the vehicle type&#39;s car following model definition (const version)
void removeLeaderCar(MEVehicle *v)
Removes the given car from the leading vehicles.
Definition: MELoop.cpp:228
MSLink * getLink(const MEVehicle *veh, bool tlsPenalty=false) const
Returns the link the given car will use when passing the next junction.
Definition: MESegment.cpp:353
#define SUMOTime_MIN
Definition: SUMOTime.h:45
A road/street connecting two junctions.
Definition: MSEdge.h:80
const SUMOReal myHeadwayCapacity
The capacity of the segment in number of cars, used only in time headway calculation This parameter h...
Definition: MESegment.h:443
#define max(a, b)
Definition: polyfonts.c:65
void receive(MEVehicle *veh, SUMOTime time, bool isDepart=false, bool afterTeleport=false)
Adds the vehicle to the segment, adapting its parameters.
Definition: MESegment.cpp:444
void writeVehicles(OutputDevice &of) const
Definition: MESegment.cpp:289
static bool gCheckRoutes
Definition: MSGlobals.h:78
SUMOTime myLastMeanSpeedUpdate
the time at which myMeanSpeed was last updated
Definition: MESegment.h:489
bool free() const
return whether this segment is considered free as opposed to jammed
Definition: MESegment.h:347
const SUMOTime myTau_jf
Definition: MESegment.h:439
static bool isInvalid(const MESegment *segment)
whether the given segment is 0 or encodes vaporization
Definition: MESegment.h:338
MSVehicleControl & getVehicleControl()
Returns the vehicle control.
Definition: MSNet.h:308
void loadState(std::vector< std::string > &vehIDs, MSVehicleControl &vc, const SUMOTime blockTime, const unsigned int queIdx)
Loads the state of this segment with the given parameters.
Definition: MESegment.cpp:607
static MSEdge myDummyParent
Definition: MESegment.h:482
size_t getCarNumber() const
Returns the total number of cars on the segment.
Definition: MESegment.cpp:253
const MSEdge * succEdge(unsigned int nSuccs) const
Returns the nSuccs&#39;th successor of edge the vehicle is currently at.
void setLastEntryTime(SUMOTime t)
Sets the entry time for the current segment.
Definition: MEVehicle.h:223
void updateDetectorsOnLeave(MEVehicle *v, SUMOTime currentTime, MESegment *next)
Updates data of all detectors for a leaving vehicle.
Definition: MESegment.cpp:185
The vehicle arrived at its destination (is deleted)
#define STEPS2TIME(x)
Definition: SUMOTime.h:65
SUMOTime getTimeHeadway(bool predecessorIsFree)
Definition: MESegment.cpp:321
T MIN2(T a, T b)
Definition: StdDefs.h:69
const SUMOReal myLength
The segment&#39;s length.
Definition: MESegment.h:433
void addDetector(MSMoveReminder *data)
Adds a data collector for a detector to this segment.
Definition: MESegment.cpp:159
Something on a lane to be noticed about vehicle movement.
SUMOReal getMaxDecel() const
Get the vehicle type&#39;s maximum deceleration [m/s^2].
Definition: MSCFModel.h:186
bool vaporizeAnyCar(SUMOTime currentTime)
tries to remove any car from this segment
Definition: MESegment.cpp:524
SUMOReal myJamThreshold
The space (in m) which needs to be occupied before the segment is considered jammed.
Definition: MESegment.h:458
SUMOReal getSpeedLimit() const
Returns the speed limit of the edge The speed limit of the first lane is retured; should probably be...
Definition: MSEdge.cpp:674
SUMOReal jamThresholdForSpeed(SUMOReal speed) const
compute jam threshold for the given speed
Definition: MESegment.cpp:147
void removeDetector(MSMoveReminder *data)
Removes a data collector for a detector from this segment.
Definition: MESegment.cpp:170
Base class for objects which have an id.
Definition: Named.h:45
bool isOpen(const MEVehicle *veh) const
Returns whether the vehicle may use the next link.
Definition: MESegment.cpp:384
SUMOTime getTLSPenalty(const MEVehicle *veh) const
Returns the penalty time for passing a tls-controlled link (if using gMesoTLSPenalty > 0) ...
Definition: MESegment.cpp:643
bool moveRoutePointer()
Update when the vehicle enters a new edge in the move step.
Definition: MEVehicle.cpp:139
const MSEdge & myEdge
The microsim edge this segment belongs to.
Definition: MESegment.h:427
const SUMOTime myTau_jj
Definition: MESegment.h:439
void setSpeed(SUMOReal newSpeed, SUMOTime currentTime, SUMOReal jamThresh=DO_NOT_PATCH_JAM_THRESHOLD)
reset mySpeed and patch the speed of all vehicles in it. Also set/recompute myJamThreshold ...
Definition: MESegment.cpp:569
The vehicle has departed (was inserted into the network)
void scheduleVehicleRemoval(SUMOVehicle *veh)
Removes a vehicle after it has ended.
const bool myTLSPenalty
Whether tls penalty is enabled.
Definition: MESegment.h:455
MESegment * myNextSegment
The next segment of this edge, 0 if this is the last segment of this edge.
Definition: MESegment.h:430
#define SUMOTime_MAX
Definition: SUMOTime.h:44
virtual void unlock() const
release exclusive access to the mesoscopic state
Definition: MSEdge.h:628
size_t getQueIndex() const
Returns the index of the que the vehicle is in.
Definition: MEVehicle.h:215
SUMOTime getEventTime() const
Returns the (planned) time at which the next vehicle leaves this segment.
Definition: MESegment.cpp:580
virtual void activateReminders(const MSMoveReminder::Notification reason)
"Activates" all current move reminder
A single mesoscopic segment (cell)
Definition: MESegment.h:57
const std::vector< MSLane * > * allowedLanes(const MSEdge &destination, SUMOVehicleClass vclass=SVC_IGNORING) const
Get the allowed lanes to reach the destination-edge.
Definition: MSEdge.cpp:221
bool hasSpaceFor(const MEVehicle *veh, SUMOTime entryTime, bool init=false) const
Returns whether the given vehicle would still fit into the segment.
Definition: MESegment.cpp:215
void onDepart()
Called when the vehicle is inserted into the network.
void updateDetectors(SUMOTime currentTime, const bool isLeave, const MSMoveReminder::Notification reason=MSMoveReminder::NOTIFICATION_JUNCTION)
Updates all vehicle detectors.
Definition: MEVehicle.cpp:279
const MSVehicleType & getVehicleType() const
Returns the vehicle&#39;s type definition.
Definition: MSBaseVehicle.h:93
MESegment * getSegmentForEdge(const MSEdge &e, SUMOReal pos=0)
Get the segment for a given edge at a given position.
Definition: MELoop.cpp:288
static MELoop * gMesoNet
mesoscopic simulation infrastructure
Definition: MSGlobals.h:99
const bool myJunctionControl
Whether junction control is enabled.
Definition: MESegment.h:452
SUMOVehicle * getVehicle(const std::string &id) const
Returns the vehicle with the given id.
void setEventTime(SUMOTime t, bool hasDelay=true)
Sets the (planned) time at which the vehicle leaves his current cell.
Definition: MEVehicle.h:177
const SUMOReal myLengthGeometryFactor
Definition: MESegment.h:478
const SUMOTime myTau_fj
Definition: MESegment.h:439
std::map< const MSEdge *, std::vector< size_t > > myFollowerMap
The follower edge to que index mapping for multi queue segments.
Definition: MESegment.h:467
bool hasValidRoute(std::string &msg) const
Validates the current route.
Static storage of an output device and its base (abstract) implementation.
Definition: OutputDevice.h:71
bool closeTag()
Closes the most recently opened tag.
#define SUMOReal
Definition: config.h:213
unsigned int getNumSuccessors() const
Returns the number of edges that may be reached from this edge.
Definition: MSEdge.h:335
void saveState(OutputDevice &out)
Saves the state of this segment into the given stream.
Definition: MESegment.cpp:595
const MSEdgeVector & getSuccessors() const
Returns the following edges.
Definition: MSEdge.h:342
SUMOTime getNextInsertionTime(SUMOTime earliestEntry) const
return a time after earliestEntry at which a vehicle may be inserted at full speed ...
Definition: MESegment.cpp:338
SUMOReal getVehicleMaxSpeed(const SUMOVehicle *const veh) const
Returns the maximum speed the vehicle may use on this edge.
Definition: MSEdge.cpp:681
virtual void setSegment(MESegment *s, size_t idx=0)
Sets the current segment the vehicle is at together with its que.
Definition: MEVehicle.h:198
const MSEdge * getEdge() const
Returns the edge the vehicle is currently at.
std::vector< SUMOTime > myBlockTimes
The block times.
Definition: MESegment.h:470
const MSLinkCont & getLinkCont() const
returns the container with all links !!!
Definition: MSLane.cpp:947
The class responsible for building and deletion of vehicles.
void prepareDetectorForWriting(MSMoveReminder &data)
Updates data of a detector for all vehicle queues.
Definition: MESegment.cpp:201
static void writeVehicle(OutputDevice &of, const MSBaseVehicle &veh)
Writes the dump of the given vehicle into the given device.
void send(MEVehicle *veh, MESegment *next, SUMOTime time)
Removes the vehicle from the segment, adapting its parameters.
Definition: MESegment.cpp:413
static const SUMOVTypeParameter & getDefault()
return the default parameters, this is a function due to the http://www.parashift.com/c++-faq/static-init-order.html
SUMOReal myMeanSpeed
the mean speed on this segment. Updated at event time or on demand
Definition: MESegment.h:486
void addReminder(MSMoveReminder *rem)
Adds a MoveReminder dynamically.
Representation of a lane in the micro simulation.
Definition: MSLane.h:77
const SUMOTime myTau_ff
The time headway parameters, see the Eissfeldt thesis.
Definition: MESegment.h:439
static bool gMesoLimitedJunctionControl
Definition: MSGlobals.h:90
void addLeaderCar(MEVehicle *veh, MSLink *link)
Adds the given car to the leading vehicles.
Definition: MELoop.cpp:208
void addReminders(MEVehicle *veh) const
add this lanes MoveReminders to the given vehicle
Definition: MESegment.cpp:437
MESegment * getSegment() const
Returns the current segment the vehicle is on.
Definition: MEVehicle.h:207
SUMOReal estimateLeaveSpeed(const MSLink *link) const
Returns the vehicle&#39;s estimated speed after driving accross the link.
Definition: MEVehicle.cpp:123
OutputDevice & openTag(const std::string &xmlElement)
Opens an XML tag.
void recomputeJamThreshold(SUMOReal jamThresh)
compute a value for myJamThreshold if jamThresh is negative, compute a value which allows free flow a...
Definition: MESegment.cpp:132
const std::string & getID() const
Returns the name of the vehicle.
SUMOReal minGap
This class&#39; free space in front of the vehicle itself.