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 #define DEFAULT_VEH_LENGHT_WITH_GAP 7.5f
58 // avoid division by zero when driving very slowly
59 #define MESO_MIN_SPEED ((SUMOReal)0.05)
60 
61 // ===========================================================================
62 // static member defintion
63 // ===========================================================================
64 MSEdge MESegment::myDummyParent("MESegmentDummyParent", -1, MSEdge::EDGEFUNCTION_UNKNOWN, "", "", -1);
65 MESegment MESegment::myVaporizationTarget("vaporizationTarget");
67 
68 // ===========================================================================
69 // method definitions
70 // ===========================================================================
71 MESegment::MESegment(const std::string& id,
72  const MSEdge& parent, MESegment* next,
73  SUMOReal length, SUMOReal speed,
74  int idx,
75  SUMOTime tauff, SUMOTime taufj,
76  SUMOTime taujf, SUMOTime taujj,
77  SUMOReal jamThresh, bool multiQueue, bool junctionControl,
78  SUMOReal lengthGeometryFactor) :
79  Named(id), myEdge(parent), myNextSegment(next),
80  myLength(length), myIndex(idx),
81  myTau_ff((SUMOTime)(tauff / parent.getLanes().size())),
82  myTau_fj((SUMOTime)(taufj / parent.getLanes().size())), // Eissfeldt p. 90 and 151 ff.
83  myTau_jf((SUMOTime)(taujf / parent.getLanes().size())),
84  myTau_jj((SUMOTime)(taujj / parent.getLanes().size())),
85  myTau_length(MAX2(MESO_MIN_SPEED, speed) * parent.getLanes().size() / TIME2STEPS(1)),
86  myHeadwayCapacity(length / DEFAULT_VEH_LENGHT_WITH_GAP * parent.getLanes().size())/* Eissfeldt p. 69 */,
87  myCapacity(length * parent.getLanes().size()),
88  myOccupancy(0.f),
89  myJunctionControl(junctionControl),
90  myTLSPenalty(MSGlobals::gMesoTLSPenalty > 0 && myNextSegment == 0 && (
91  parent.getToJunction()->getType() == NODETYPE_TRAFFIC_LIGHT ||
92  parent.getToJunction()->getType() == NODETYPE_TRAFFIC_LIGHT_NOJUNCTION ||
93  parent.getToJunction()->getType() == NODETYPE_TRAFFIC_LIGHT_RIGHT_ON_RED)),
94  myEntryBlockTime(SUMOTime_MIN),
95  myLengthGeometryFactor(lengthGeometryFactor),
96  myMeanSpeed(speed),
97  myLastMeanSpeedUpdate(SUMOTime_MIN) {
98  myCarQues.push_back(std::vector<MEVehicle*>());
99  myBlockTimes.push_back(-1);
100  const std::vector<MSLane*>& lanes = parent.getLanes();
101  if (multiQueue && lanes.size() > 1) {
102  int numFollower = parent.getNumSuccessors();
103  if (numFollower > 1) {
104  while (myCarQues.size() < lanes.size()) {
105  myCarQues.push_back(std::vector<MEVehicle*>());
106  myBlockTimes.push_back(-1);
107  }
108  for (int i = 0; i < numFollower; ++i) {
109  const MSEdge* const edge = parent.getSuccessors()[i];
110  const std::vector<MSLane*>* const allowed = parent.allowedLanes(*edge);
111  assert(allowed != 0);
112  assert(allowed->size() > 0);
113  for (std::vector<MSLane*>::const_iterator j = allowed->begin(); j != allowed->end(); ++j) {
114  std::vector<MSLane*>::const_iterator it = find(lanes.begin(), lanes.end(), *j);
115  myFollowerMap[edge].push_back((int)distance(lanes.begin(), it));
116  }
117  }
118  }
119  }
120  recomputeJamThreshold(jamThresh);
121 }
122 
123 
124 MESegment::MESegment(const std::string& id):
125  Named(id),
126  myEdge(myDummyParent), // arbitrary edge needed to supply the needed reference
127  myNextSegment(0), myLength(0), myIndex(0),
128  myTau_ff(0), myTau_fj(0), myTau_jf(0), myTau_jj(0), myTau_length(1),
130  myTLSPenalty(false),
132 }
133 
134 
135 void
137  if (jamThresh == DO_NOT_PATCH_JAM_THRESHOLD) {
138  return;
139  }
140  if (jamThresh < 0) {
141  // compute based on speed
143  } else {
144  // compute based on specified percentage
145  myJamThreshold = jamThresh * myCapacity;
146  }
147 
148  // update coefficients for the jam-jam headway function
149  // this function models the effect that "empty space" needs to move
150  // backwards through the downstream segment before the upstream segment may
151  // send annother vehicle
152  // the headway function f(x) depends on the number of vehicles in the
153  // downstream segment x
154  // f is a linear function that passes through the following fixed points:
155  // f(n_jam_threshold) = myTau_jf (for continuity)
156  // f(myHeadwayCapacity) = myTau_jj & myHeadwayCapacity
157 
158  if (myJamThreshold < myCapacity) {
159  // jamming is possible
160  const SUMOReal n_jam_threshold = myHeadwayCapacity * myJamThreshold / myCapacity; // number of vehicles above which the segment is jammed
161  // solving f(x) = a * x + b
164 
165  // note that the original Eissfeldt model (p. 69) used different fixed points
166  // f(n_jam_threshold) = n_jam_threshold * myTau_jj
167  // f(myHeadwayCapacity) = myTau_jf * myHeadwayCapacity
168  //
169  // However, this systematically underestimates the backpropagation speed of the jam front (see #2244)
170  } else {
171  // dummy values. Should not be used
172  myA = 0;
174  }
175 }
176 
177 
178 SUMOReal
180  // vehicles driving freely at maximum speed should not jam
181  // we compute how many vehicles could possible enter the segment until the first vehicle leaves
182  // and multiply by the space these vehicles would occupy
183  // the jamThresh parameter is scale the resulting value
184  if (speed == 0) {
185  return std::numeric_limits<double>::max(); // never jam. Irrelevant at speed 0 anyway
186  }
188  return std::ceil((myLength / (-jamThresh * speed * STEPS2TIME(myTau_ff + defaultLengthWithGap / myTau_length)))) * defaultLengthWithGap;
189 }
190 
191 
192 void
194  myDetectorData.push_back(data);
195  for (Queues::const_iterator k = myCarQues.begin(); k != myCarQues.end(); ++k) {
196  for (std::vector<MEVehicle*>::const_reverse_iterator i = k->rbegin(); i != k->rend(); ++i) {
197  (*i)->addReminder(data);
198  }
199  }
200 }
201 
202 
203 void
205  std::vector<MSMoveReminder*>::iterator it = find(
206  myDetectorData.begin(), myDetectorData.end(), data);
207  if (it != myDetectorData.end()) {
208  myDetectorData.erase(it);
209  }
210  for (Queues::const_iterator k = myCarQues.begin(); k != myCarQues.end(); ++k) {
211  for (std::vector<MEVehicle*>::const_reverse_iterator i = k->rbegin(); i != k->rend(); ++i) {
212  (*i)->removeReminder(data);
213  }
214  }
215 }
216 
217 
218 void
221  if (next == 0) {
223  } else if (next == &myVaporizationTarget) {
225  } else if (myNextSegment == 0) {
227  } else {
229  }
230  v->updateDetectors(currentTime, true, reason);
231 }
232 
233 
234 void
236  const SUMOTime currentTime = MSNet::getInstance()->getCurrentTimeStep();
237  for (Queues::const_iterator k = myCarQues.begin(); k != myCarQues.end(); ++k) {
238  SUMOTime earliestExitTime = currentTime;
239  for (std::vector<MEVehicle*>::const_reverse_iterator i = k->rbegin(); i != k->rend(); ++i) {
240  const SUMOTime exitTime = MAX2(earliestExitTime, (*i)->getEventTime());
241  (*i)->updateDetectorForWriting(&data, currentTime, exitTime);
242  earliestExitTime = exitTime + myTau_ff;
243  }
244  }
245 }
246 
247 
248 bool
249 MESegment::hasSpaceFor(const MEVehicle* veh, SUMOTime entryTime, bool init) const {
250  if (myOccupancy == 0.) {
251  // we have always space for at least one vehicle
252  return true;
253  }
254  const SUMOReal newOccupancy = myOccupancy + veh->getVehicleType().getLengthWithGap();
255  if (newOccupancy > myCapacity) {
256  // we must ensure that occupancy remains below capacity
257  return false;
258  }
259  // regular insertions and initial insertions must respect different constraints:
260  // - regular insertions must respect entryBlockTime
261  // - initial insertions should not cause additional jamming
262  if (init) {
263  // inserted vehicle should be able to continue at the current speed
264  return newOccupancy <= jamThresholdForSpeed(getMeanSpeed(false), -1);
265  }
266  // maintain propper spacing between inflow from different lanes
267  return entryTime >= myEntryBlockTime;
268 }
269 
270 
271 bool
273  if (hasSpaceFor(veh, time, true)) {
274  receive(veh, time, true);
275  // we can check only after insertion because insertion may change the route via devices
276  std::string msg;
277  if (MSGlobals::gCheckRoutes && !veh->hasValidRoute(msg)) {
278  throw ProcessError("Vehicle '" + veh->getID() + "' has no valid route. " + msg);
279  }
280  return true;
281  }
282  return false;
283 }
284 
285 
286 int
288  int total = 0;
289  for (Queues::const_iterator k = myCarQues.begin(); k != myCarQues.end(); ++k) {
290  total += (int)k->size();
291  }
292  return total;
293 }
294 
295 
296 SUMOReal
297 MESegment::getMeanSpeed(bool useCached) const {
298  const SUMOTime currentTime = MSNet::getInstance()->getCurrentTimeStep();
299  if (currentTime != myLastMeanSpeedUpdate || !useCached) {
300  myLastMeanSpeedUpdate = currentTime;
301  const SUMOTime tau = free() ? myTau_ff : myTau_jf;
302  SUMOReal v = 0;
303  int count = 0;
304  for (Queues::const_iterator k = myCarQues.begin(); k != myCarQues.end(); ++k) {
305  SUMOTime earliestExitTime = currentTime;
306  count += (int)k->size();
307  for (std::vector<MEVehicle*>::const_reverse_iterator veh = k->rbegin(); veh != k->rend(); ++veh) {
308  v += (*veh)->getConservativeSpeed(earliestExitTime); // earliestExitTime is updated!
309  earliestExitTime += tau;
310  }
311  }
312  if (count == 0) {
314  } else {
315  myMeanSpeed = v / (SUMOReal) count;
316  }
317  }
318  return myMeanSpeed;
319 }
320 
321 
322 void
324  for (Queues::const_iterator k = myCarQues.begin(); k != myCarQues.end(); ++k) {
325  for (std::vector<MEVehicle*>::const_iterator veh = k->begin(); veh != k->end(); ++veh) {
326  MSXMLRawOut::writeVehicle(of, *(*veh));
327  }
328  }
329 }
330 
331 
332 MEVehicle*
335  std::vector<MEVehicle*>& cars = myCarQues[v->getQueIndex()];
336  assert(std::find(cars.begin(), cars.end(), v) != cars.end());
337  // One could be tempted to do v->setSegment(next); here but position on lane will be invalid if next == 0
338  updateDetectorsOnLeave(v, leaveTime, next);
339  myEdge.lock();
340  if (v == cars.back()) {
341  cars.pop_back();
342  if (!cars.empty()) {
343  myEdge.unlock();
344  return cars.back();
345  }
346  } else {
347  cars.erase(std::find(cars.begin(), cars.end(), v));
348  }
349  myEdge.unlock();
350  return 0;
351 }
352 
353 
354 SUMOTime
355 MESegment::getTimeHeadway(bool predecessorIsFree, SUMOReal leaderLength) {
356  if (predecessorIsFree) {
357  return (free() ? myTau_ff : myTau_fj) + (SUMOTime)(leaderLength / myTau_length);
358  } else {
359  if (free()) {
360  return myTau_jf;
361  } else {
362  // the gap has to move from the start of the segment to its end
363  // this allows jams to clear and move upstream
364  return TIME2STEPS(myA * getCarNumber() + myB);
365  }
366  }
367 }
368 
369 
370 SUMOTime
372  // since we do not know which queue will be used we give a conservative estimate
373  SUMOTime earliestLeave = earliestEntry;
374  for (int i = 0; i < (int)myCarQues.size(); ++i) {
375  earliestLeave = MAX2(earliestLeave, myBlockTimes[i]);
376  }
377  if (myEdge.getSpeedLimit() == 0) {
378  return MAX2(earliestEntry, myEntryBlockTime); // FIXME: This line is just an adhoc-fix to avoid division by zero (Leo)
379  } else {
380  return MAX3(earliestEntry, earliestLeave - TIME2STEPS(myLength / myEdge.getSpeedLimit()), myEntryBlockTime);
381  }
382 }
383 
384 
385 MSLink*
386 MESegment::getLink(const MEVehicle* veh, bool tlsPenalty) const {
387  if (myJunctionControl || tlsPenalty) {
388  const MSEdge* const nextEdge = veh->succEdge(1);
389  if (nextEdge == 0) {
390  return 0;
391  }
392  // try to find any link leading to our next edge, start with the lane pointed to by the que index
393  const MSLane* const bestLane = myEdge.getLanes()[veh->getQueIndex()];
394  const MSLinkCont& links = bestLane->getLinkCont();
395  for (std::vector<MSLink*>::const_iterator j = links.begin(); j != links.end(); ++j) {
396  if (&(*j)->getLane()->getEdge() == nextEdge) {
397  return *j;
398  }
399  }
400  // this is for the non-multique case, maybe we should use caching here !!!
401  for (std::vector<MSLane*>::const_iterator l = myEdge.getLanes().begin(); l != myEdge.getLanes().end(); ++l) {
402  if ((*l) != bestLane) {
403  const MSLinkCont& links = (*l)->getLinkCont();
404  for (std::vector<MSLink*>::const_iterator j = links.begin(); j != links.end(); ++j) {
405  if (&(*j)->getLane()->getEdge() == nextEdge) {
406  return *j;
407  }
408  }
409  }
410  }
411  }
412  return 0;
413 }
414 
415 
416 bool
417 MESegment::isOpen(const MEVehicle* veh) const {
418  if (myTLSPenalty) {
419  // XXX should limited control take precedence over tls penalty?
420  return true;
421  }
422  const MSLink* link = getLink(veh);
423  return (link == 0
424  || link->havePriority()
425  || limitedControlOverride(link)
426  || link->opened(veh->getEventTime(), veh->getSpeed(), veh->estimateLeaveSpeed(link),
429 }
430 
431 
432 bool
434  assert(link != 0);
436  return false;
437  }
438  // if the target segment of this link is not saturated junction control is disabled
439  const MSEdge& targetEdge = link->getLane()->getEdge();
440  const MESegment* target = MSGlobals::gMesoNet->getSegmentForEdge(targetEdge);
441  return target->myOccupancy * 2 < target->myJamThreshold;
442 }
443 
444 
445 void
447  assert(isInvalid(next) || time >= myBlockTimes[veh->getQueIndex()]);
448  MSLink* link = getLink(veh);
449  if (link != 0) {
450  link->removeApproaching(veh);
451  }
452  MEVehicle* lc = removeCar(veh, time, next); // new leaderCar
453  myBlockTimes[veh->getQueIndex()] = time;
454  if (!isInvalid(next)) {
456  }
457  if (lc != 0) {
460  }
461 }
462 
463 bool
466 }
467 
468 
469 void
471  for (std::vector<MSMoveReminder*>::const_iterator i = myDetectorData.begin(); i != myDetectorData.end(); ++i) {
472  veh->addReminder(*i);
473  }
474 }
475 
476 void
477 MESegment::receive(MEVehicle* veh, SUMOTime time, bool isDepart, bool afterTeleport) {
478  const SUMOReal speed = isDepart ? -1 : MAX2(veh->getSpeed(), MESO_MIN_SPEED); // on the previous segment
479  veh->setSegment(this); // for arrival checking
480  veh->setLastEntryTime(time);
482  if (!isDepart && (
483  // arrival on entering a new edge
484  ((myIndex == 0 || afterTeleport) && veh->moveRoutePointer())
485  // arrival on entering a new segment
486  || veh->hasArrived())) {
487  // route has ended
488  veh->setEventTime(time + TIME2STEPS(myLength / speed)); // for correct arrival speed
489  addReminders(veh);
491  updateDetectorsOnLeave(veh, time, 0);
493  return;
494  }
495  // route continues
496  const SUMOReal maxSpeedOnEdge = veh->getEdge()->getVehicleMaxSpeed(veh);
497  const SUMOReal uspeed = MAX2(maxSpeedOnEdge, MESO_MIN_SPEED);
498  int nextQueIndex = 0;
499  if (myCarQues.size() > 1) {
500  const MSEdge* succ = veh->succEdge(1);
501  // succ may be invalid if called from initialise() with an invalid route
502  if (succ != 0 && myFollowerMap.count(succ) > 0) {
503  const std::vector<int>& indices = myFollowerMap[succ];
504  nextQueIndex = indices[0];
505  for (std::vector<int>::const_iterator i = indices.begin() + 1; i != indices.end(); ++i) {
506  if (myCarQues[*i].size() < myCarQues[nextQueIndex].size()) {
507  nextQueIndex = *i;
508  }
509  }
510  }
511  }
512  std::vector<MEVehicle*>& cars = myCarQues[nextQueIndex];
513  MEVehicle* newLeader = 0; // first vehicle in the current queue
514  SUMOTime tleave = MAX2(time + TIME2STEPS(myLength / uspeed) + veh->getStoptime(this) + getTLSPenalty(veh), myBlockTimes[nextQueIndex]);
515  myEdge.lock();
516  if (cars.empty()) {
517  cars.push_back(veh);
518  newLeader = veh;
519  } else {
520  SUMOTime leaderOut = cars[0]->getEventTime();
521  if (!isDepart && leaderOut > tleave && overtake()) {
522  if (cars.size() == 1) {
524  newLeader = veh;
525  }
526  cars.insert(cars.begin() + 1, veh);
527  } else {
528  tleave = MAX2(leaderOut + myTau_ff, tleave);
529  cars.insert(cars.begin(), veh);
530  }
531  }
532  myEdge.unlock();
533  if (!isDepart) {
534  // regular departs could take place anywhere on the edge so they should not block regular flow
535  // the -1 facilitates interleaving of multiple streams
536  myEntryBlockTime = time + myTau_ff - 1;
537  }
538  veh->setEventTime(tleave);
539  veh->setSegment(this, nextQueIndex);
541  addReminders(veh);
542  if (isDepart) {
543  veh->onDepart();
545  } else if (myIndex == 0 || afterTeleport) {
547  } else {
549  }
550  if (newLeader != 0) {
551  MSGlobals::gMesoNet->addLeaderCar(newLeader, getLink(newLeader));
552  }
553 }
554 
555 
556 bool
558  MEVehicle* remove = 0;
559  for (Queues::const_iterator k = myCarQues.begin(); k != myCarQues.end(); ++k) {
560  if (!k->empty()) {
561  // remove last in queue
562  remove = k->front();
563  if (k->size() == 1) {
565  }
567  return true;
568  }
569  }
570  return false;
571 }
572 
573 
574 void
575 MESegment::setSpeedForQueue(SUMOReal newSpeed, SUMOTime currentTime, SUMOTime blockTime, const std::vector<MEVehicle*>& vehs) {
576  MEVehicle* v = vehs.back();
577  v->updateDetectors(currentTime, false);
578  SUMOTime newEvent = MAX2(newArrival(v, newSpeed, currentTime), blockTime);
579  if (v->getEventTime() != newEvent) {
581  v->setEventTime(newEvent);
583  }
584  for (std::vector<MEVehicle*>::const_reverse_iterator i = vehs.rbegin() + 1; i != vehs.rend(); ++i) {
585  (*i)->updateDetectors(currentTime, false);
586  newEvent = MAX2(newArrival(*i, newSpeed, currentTime), newEvent + myTau_ff);
587  //newEvent = MAX2(newArrival(*i, newSpeed, currentTime), newEvent + myTau_ff + (SUMOTime)((*(i - 1))->getVehicleType().getLength() / myTau_length));
588  (*i)->setEventTime(newEvent);
589  }
590 }
591 
592 
593 SUMOTime
594 MESegment::newArrival(const MEVehicle* const v, SUMOReal newSpeed, SUMOTime currentTime) {
595  // since speed is only an upper bound pos may be to optimistic
596  const SUMOReal pos = MIN2(myLength, STEPS2TIME(currentTime - v->getLastEntryTime()) * v->getSpeed());
597  // traveltime may not be 0
598  return currentTime + MAX2(TIME2STEPS((myLength - pos) / newSpeed), SUMOTime(1));
599 }
600 
601 
602 void
603 MESegment::setSpeed(SUMOReal newSpeed, SUMOTime currentTime, SUMOReal jamThresh) {
604  recomputeJamThreshold(jamThresh);
605  //myTau_length = MAX2(MESO_MIN_SPEED, newSpeed) * myEdge.getLanes().size() / TIME2STEPS(1);
606  for (int i = 0; i < (int)myCarQues.size(); ++i) {
607  if (myCarQues[i].size() != 0) {
608  setSpeedForQueue(newSpeed, currentTime, myBlockTimes[i], myCarQues[i]);
609  }
610  }
611 }
612 
613 
614 SUMOTime
616  SUMOTime result = SUMOTime_MAX;
617  for (int i = 0; i < (int)myCarQues.size(); ++i) {
618  if (myCarQues[i].size() != 0 && myCarQues[i].back()->getEventTime() < result) {
619  result = myCarQues[i].back()->getEventTime();
620  }
621  }
622  if (result < SUMOTime_MAX) {
623  return result;
624  }
625  return -1;
626 }
627 
628 
629 void
632  for (int i = 0; i < (int)myCarQues.size(); ++i) {
635  out.closeTag();
636  }
637  out.closeTag();
638 }
639 
640 
641 void
642 MESegment::loadState(std::vector<std::string>& vehIds, MSVehicleControl& vc, const SUMOTime block, const int queIdx) {
643  for (std::vector<std::string>::const_iterator it = vehIds.begin(); it != vehIds.end(); ++it) {
644  MEVehicle* v = static_cast<MEVehicle*>(vc.getVehicle(*it));
645  assert(v != 0);
646  assert(v->getSegment() == this);
647  myCarQues[queIdx].push_back(v);
649  }
650  if (myCarQues[queIdx].size() != 0) {
651  // add the last vehicle of this queue
652  // !!! one question - what about the previously added vehicle? Is it stored twice?
653  MEVehicle* veh = myCarQues[queIdx].back();
655  }
656  myBlockTimes[queIdx] = block;
658 }
659 
660 
661 std::vector<const MEVehicle*>
663  std::vector<const MEVehicle*> result;
664  for (Queues::const_iterator k = myCarQues.begin(); k != myCarQues.end(); ++k) {
665  result.insert(result.end(), k->begin(), k->end());
666  }
667  return result;
668 }
669 
670 
671 SUMOReal
673  return 3600 * getCarNumber() * getMeanSpeed() / myLength;
674 }
675 
676 
677 SUMOTime
679  const MSLink* link = getLink(veh, myTLSPenalty);
680  if (link != 0 && link->isTLSControlled()) {
681  // only apply to the last segment of a tls-controlled edge
682  return link->getMesoTLSPenalty();
683  } else {
684  return 0;
685  }
686 }
687 
688 /****************************************************************************/
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:487
virtual void setSegment(MESegment *s, int idx=0)
Sets the current segment the vehicle is at together with its que.
Definition: MEVehicle.h:204
SUMOTime getTLSPenalty(const MEVehicle *veh) const
Returns the penalty time for passing a tls-controlled link (if using gMesoTLSPenalty > 0) ...
Definition: MESegment.cpp:678
MSEdge & getEdge() const
Returns the lane&#39;s edge.
Definition: MSLane.h:571
long long int SUMOTime
Definition: SUMOTime.h:43
bool isOpen(const MEVehicle *veh) const
Returns whether the vehicle may use the next link.
Definition: MESegment.cpp:417
bool hasValidRoute(std::string &msg, const MSRoute *route=0) const
Validates the current or given route.
const SUMOReal myCapacity
The number of lanes * the length.
Definition: MESegment.h:450
A vehicle from the mesoscopic point of view.
Definition: MEVehicle.h:52
int getCarNumber() const
Returns the total number of cars on the segment.
Definition: MESegment.cpp:287
MEVehicle * removeCar(MEVehicle *v, SUMOTime leaveTime, MESegment *next)
Removes the given car from the edge&#39;s que.
Definition: MESegment.cpp:333
bool overtake()
Definition: MESegment.cpp:464
bool initialise(MEVehicle *veh, SUMOTime time)
Inserts (emits) vehicle into the segment.
Definition: MESegment.cpp:272
SUMOTime getLastEntryTime() const
Returns the time the vehicle entered the current segment.
Definition: MEVehicle.h:237
MESegment(const std::string &id, const MSEdge &parent, MESegment *next, SUMOReal length, SUMOReal speed, int idx, SUMOTime tauff, SUMOTime taufj, SUMOTime taujf, SUMOTime taujj, SUMOReal jamThresh, bool multiQueue, bool junctionControl, SUMOReal lengthGeometryFactor)
constructor
Definition: MESegment.cpp:71
void setSpeedForQueue(SUMOReal newSpeed, SUMOTime currentTime, SUMOTime blockTime, const std::vector< MEVehicle *> &vehs)
Definition: MESegment.cpp:575
virtual void unlock() const
release exclusive access to the mesoscopic state
Definition: MSEdge.h:664
The vehicle arrived at a junction.
SUMOTime myEntryBlockTime
Definition: MESegment.h:479
static const SUMOReal DO_NOT_PATCH_JAM_THRESHOLD
Definition: MESegment.h:375
SUMOReal getMaxDecel() const
Get the vehicle type&#39;s maximum deceleration [m/s^2].
Definition: MSCFModel.h:201
SUMOVehicle * getVehicle(const std::string &id) const
Returns the vehicle with the given id.
SUMOReal length
The physical vehicle length.
Notification
Definition of a vehicle state.
static SUMOReal rand()
Returns a random real number in [0, 1)
Definition: RandHelper.h:62
SUMOReal getMeanSpeed() const
wrapper to satisfy the FunctionBinding signature
Definition: MESegment.h:207
std::vector< MSMoveReminder * > myDetectorData
The data collection for all kinds of detectors.
Definition: MESegment.h:465
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:300
const std::vector< MSLane * > & getLanes() const
Returns this edge&#39;s lanes.
Definition: MSEdge.h:192
SUMOTime getWaitingTime() const
Returns the duration for which the vehicle was blocked.
Definition: MEVehicle.h:260
SUMOReal myOccupancy
The occupied space (in m) on the segment.
Definition: MESegment.h:453
static MSNet * getInstance()
Returns the pointer to the unique instance of MSNet (singleton).
Definition: MSNet.cpp:159
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:195
SUMOTime newArrival(const MEVehicle *const v, SUMOReal newSpeed, SUMOTime currentTime)
compute the new arrival time when switching speed
Definition: MESegment.cpp:594
The vehicle got vaporized.
The vehicle changes the segment (meso only)
#define TIME2STEPS(x)
Definition: SUMOTime.h:66
SUMOTime getEventTime() const
Returns the (planned) time at which the next vehicle leaves this segment.
Definition: MESegment.cpp:615
static bool gMesoOvertaking
Definition: MSGlobals.h:101
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:245
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:468
int getNumSuccessors() const
Returns the number of edges that may be reached from this edge.
Definition: MSEdge.h:346
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:769
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:249
void loadState(std::vector< std::string > &vehIDs, MSVehicleControl &vc, const SUMOTime blockTime, const int queIdx)
Loads the state of this segment with the given parameters.
Definition: MESegment.cpp:642
void writeVehicles(OutputDevice &of) const
Definition: MESegment.cpp:323
void removeLeaderCar(MEVehicle *v)
Removes the given car from the leading vehicles.
Definition: MELoop.cpp:228
#define SUMOTime_MIN
Definition: SUMOTime.h:45
SUMOReal getSpeed() const
Returns the vehicle&#39;s estimated speed assuming no delays.
Definition: MEVehicle.cpp:113
A road/street connecting two junctions.
Definition: MSEdge.h:80
SUMOReal getVehicleMaxSpeed(const SUMOVehicle *const veh) const
Returns the maximum speed the vehicle may use on this edge.
Definition: MSEdge.cpp:776
const SUMOReal myHeadwayCapacity
The capacity of the segment in number of cars, used only in time headway calculation This parameter h...
Definition: MESegment.h:447
#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:477
SUMOReal jamThresholdForSpeed(SUMOReal speed, SUMOReal jamThresh) const
compute jam threshold for the given speed and jam-threshold option
Definition: MESegment.cpp:179
const MSCFModel & getCarFollowModel() const
Returns the vehicle type&#39;s car following model definition (const version)
bool free() const
return whether this segment is considered free as opposed to jammed
Definition: MESegment.h:347
static bool gCheckRoutes
Definition: MSGlobals.h:83
SUMOTime myLastMeanSpeedUpdate
the time at which myMeanSpeed was last updated
Definition: MESegment.h:493
std::map< const MSEdge *, std::vector< int > > myFollowerMap
The follower edge to que index mapping for multi queue segments.
Definition: MESegment.h:471
const SUMOTime myTau_jf
Definition: MESegment.h:438
MESegment * getSegment() const
Returns the current segment the vehicle is on.
Definition: MEVehicle.h:213
const MSEdge * getEdge() const
Returns the edge the vehicle is currently at.
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:307
static MSEdge myDummyParent
Definition: MESegment.h:486
void setLastEntryTime(SUMOTime t)
Sets the entry time for the current segment.
Definition: MEVehicle.h:229
void updateDetectorsOnLeave(MEVehicle *v, SUMOTime currentTime, MESegment *next)
Updates data of all detectors for a leaving vehicle.
Definition: MESegment.cpp:219
The vehicle arrived at its destination (is deleted)
#define STEPS2TIME(x)
Definition: SUMOTime.h:65
SUMOTime getCurrentTimeStep() const
Returns the current simulation step.
Definition: MSNet.h:254
SUMOReal myTau_length
Headway paramter for computing gross time headyway from net time heawdway, length and edge speed...
Definition: MESegment.h:440
bool hasArrived() const
Returns whether this vehicle has already arived (reached the arrivalPosition on its final edge) ...
Definition: MEVehicle.cpp:159
T MIN2(T a, T b)
Definition: StdDefs.h:69
const SUMOReal myLength
The segment&#39;s length.
Definition: MESegment.h:432
void addDetector(MSMoveReminder *data)
Adds a data collector for a detector to this segment.
Definition: MESegment.cpp:193
Something on a lane to be noticed about vehicle movement.
int getQueIndex() const
Returns the index of the que the vehicle is in.
Definition: MEVehicle.h:221
bool vaporizeAnyCar(SUMOTime currentTime)
tries to remove any car from this segment
Definition: MESegment.cpp:557
SUMOReal myJamThreshold
The space (in m) which needs to be occupied before the segment is considered jammed.
Definition: MESegment.h:462
std::vector< const MEVehicle * > getVehicles() const
returns all vehicles (for debugging)
Definition: MESegment.cpp:662
void removeDetector(MSMoveReminder *data)
Removes a data collector for a detector from this segment.
Definition: MESegment.cpp:204
Base class for objects which have an id.
Definition: Named.h:46
bool moveRoutePointer()
Update when the vehicle enters a new edge in the move step.
Definition: MEVehicle.cpp:145
const MSEdge & myEdge
The microsim edge this segment belongs to.
Definition: MESegment.h:426
SUMOReal myA
slope and axis offset for the jam-jam headway function
Definition: MESegment.h:443
SUMOTime getNextInsertionTime(SUMOTime earliestEntry) const
return a time after earliestEntry at which a vehicle may be inserted at full speed ...
Definition: MESegment.cpp:371
const SUMOTime myTau_jj
Definition: MESegment.h:438
SUMOTime getStoptime(const MESegment *const seg) const
Returns how long to stop at the given segment.
Definition: MEVehicle.cpp:243
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:603
The vehicle has departed (was inserted into the network)
void addReminders(MEVehicle *veh) const
add this lanes MoveReminders to the given vehicle
Definition: MESegment.cpp:470
void scheduleVehicleRemoval(SUMOVehicle *veh)
Removes a vehicle after it has ended.
const bool myTLSPenalty
Whether tls penalty is enabled.
Definition: MESegment.h:459
MESegment * myNextSegment
The next segment of this edge, 0 if this is the last segment of this edge.
Definition: MESegment.h:429
#define SUMOTime_MAX
Definition: SUMOTime.h:44
const MSVehicleType & getVehicleType() const
Returns the vehicle&#39;s type definition.
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:433
SUMOReal myB
Definition: MESegment.h:443
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:386
virtual void activateReminders(const MSMoveReminder::Notification reason)
"Activates" all current move reminder
A single mesoscopic segment (cell)
Definition: MESegment.h:57
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:296
MESegment * getSegmentForEdge(const MSEdge &e, SUMOReal pos=0)
Get the segment for a given edge at a given position.
Definition: MELoop.cpp:295
const MSEdgeVector & getSuccessors() const
Returns the following edges.
Definition: MSEdge.h:353
static MELoop * gMesoNet
mesoscopic simulation infrastructure
Definition: MSGlobals.h:107
const bool myJunctionControl
Whether junction control is enabled.
Definition: MESegment.h:456
void setEventTime(SUMOTime t, bool hasDelay=true)
Sets the (planned) time at which the vehicle leaves his current cell.
Definition: MEVehicle.h:183
virtual void lock() const
grant exclusive access to the mesoscopic state
Definition: MSEdge.h:661
SUMOReal estimateLeaveSpeed(const MSLink *link) const
Returns the vehicle&#39;s estimated speed after driving accross the link.
Definition: MEVehicle.cpp:129
const MSEdge * succEdge(int nSuccs) const
Returns the nSuccs&#39;th successor of edge the vehicle is currently at.
const SUMOReal myLengthGeometryFactor
Definition: MESegment.h:482
const SUMOTime myTau_fj
Definition: MESegment.h:438
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
void saveState(OutputDevice &out)
Saves the state of this segment into the given stream.
Definition: MESegment.cpp:630
std::vector< SUMOTime > myBlockTimes
The block times.
Definition: MESegment.h:474
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:235
const MSLinkCont & getLinkCont() const
returns the container with all links !!!
Definition: MSLane.cpp:1512
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:446
#define DEFAULT_VEH_LENGHT_WITH_GAP
Definition: MESegment.cpp:57
SUMOReal getImpatience() const
Returns this vehicles impatience.
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:490
#define MESO_MIN_SPEED
Definition: MESegment.cpp:59
const int myIndex
Running number of the segment in the edge.
Definition: MESegment.h:435
const std::string & getID() const
Returns the name of the vehicle.
void addReminder(MSMoveReminder *rem)
Adds a MoveReminder dynamically.
Representation of a lane in the micro simulation.
Definition: MSLane.h:79
const SUMOTime myTau_ff
The time headway parameters, see the Eissfeldt thesis.
Definition: MESegment.h:438
static bool gMesoLimitedJunctionControl
Definition: MSGlobals.h:98
void addLeaderCar(MEVehicle *veh, MSLink *link)
Adds the given car to the leading vehicles.
Definition: MELoop.cpp:208
OutputDevice & openTag(const std::string &xmlElement)
Opens an XML tag.
SUMOReal getFlow() const
returns flow based on headway
Definition: MESegment.cpp:672
SUMOReal getLengthWithGap() const
Get vehicle&#39;s length including the minimum gap [m].
void recomputeJamThreshold(SUMOReal jamThresh)
compute a value for myJamThreshold if jamThresh is negative, compute a value which allows free flow a...
Definition: MESegment.cpp:136
SUMOTime getTimeHeadway(bool predecessorIsFree, SUMOReal leaderLength)
Definition: MESegment.cpp:355
SUMOReal minGap
This class&#39; free space in front of the vehicle itself.