Eclipse SUMO - Simulation of Urban MObility
Loading...
Searching...
No Matches
MESegment.cpp
Go to the documentation of this file.
1/****************************************************************************/
2// Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo
3// Copyright (C) 2001-2026 German Aerospace Center (DLR) and others.
4// This program and the accompanying materials are made available under the
5// terms of the Eclipse Public License 2.0 which is available at
6// https://www.eclipse.org/legal/epl-2.0/
7// This Source Code may also be made available under the following Secondary
8// Licenses when the conditions for such availability set forth in the Eclipse
9// Public License 2.0 are satisfied: GNU General Public License, version 2
10// or later which is available at
11// https://www.gnu.org/licenses/old-licenses/gpl-2.0-standalone.html
12// SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-or-later
13/****************************************************************************/
18// A single mesoscopic segment (cell)
19/****************************************************************************/
20#include <config.h>
21
22#include <algorithm>
23#include <cmath>
24#include <limits>
26#include <microsim/MSGlobals.h>
27#include <microsim/MSEdge.h>
28#include <microsim/MSJunction.h>
29#include <microsim/MSNet.h>
30#include <microsim/MSLane.h>
31#include <microsim/MSLink.h>
44#include "MEVehicle.h"
45#include "MELoop.h"
46#include "MESegment.h"
47
48#define DEFAULT_VEH_LENGTH_WITH_GAP (SUMOVTypeParameter::getDefault().length + SUMOVTypeParameter::getDefault().minGap)
49// avoid division by zero when driving very slowly
50#define MESO_MIN_SPEED (0.05)
51
52//#define DEBUG_OPENED
53//#define DEBUG_JAMTHRESHOLD
54//#define DEBUG_COND (getID() == "blocker")
55//#define DEBUG_COND (true)
56#define DEBUG_COND (myEdge.isSelected())
57#define DEBUG_COND2(obj) ((obj != 0 && (obj)->isSelected()))
58
59
60// ===========================================================================
61// static member definition
62// ===========================================================================
63MSEdge MESegment::myDummyParent("MESegmentDummyParent", -1, SumoXMLEdgeFunc::UNKNOWN, "", "", "", -1, 0);
64MESegment MESegment::myVaporizationTarget("vaporizationTarget");
66const double MESegment::DO_NOT_PATCH_JAM_THRESHOLD(std::numeric_limits<double>::max());
67const std::string MESegment::OVERRIDE_TLS_PENALTIES("meso.tls.control");
68
69
70// ===========================================================================
71// MESegment::Queue method definitions
72// ===========================================================================
76 assert(std::find(myVehicles.begin(), myVehicles.end(), v) != myVehicles.end());
77 if (v == myVehicles.back()) {
78 myVehicles.pop_back();
79 if (myVehicles.empty()) {
80 myOccupancy = 0.;
81 } else {
82 return myVehicles.back();
83 }
84 } else {
85 myVehicles.erase(std::find(myVehicles.begin(), myVehicles.end(), v));
86 }
87 return nullptr;
88}
89
90void
92 myDetectorData.push_back(data);
93 for (MEVehicle* const v : myVehicles) {
94 v->addReminder(data);
95 }
96}
97
98void
100 for (MSMoveReminder* rem : myDetectorData) {
101 veh->addReminder(rem);
102 }
103}
104
105// ===========================================================================
106// MESegment method definitions
107// ===========================================================================
108MESegment::MESegment(const std::string& id,
109 const MSEdge& parent, MESegment* next,
110 const double length, const double speed,
111 const int idx,
112 const bool multiQueue,
113 const MesoEdgeType& edgeType):
114 Named(id), myEdge(parent), myNextSegment(next),
115 myLength(length), myIndex(idx),
116 myTau_length((double)TIME2STEPS(1) / MAX2(MESO_MIN_SPEED, speed)),
117 myNumVehicles(0),
119 myMeanSpeed(speed),
121
122 const std::vector<MSLane*>& lanes = parent.getLanes();
123 int usableLanes = 0;
124 SVCPermissions maxAllow = 0;
125 SVCPermissions minAllow = SVCAll;
126 for (MSLane* const l : lanes) {
127 const SVCPermissions allow = MSEdge::getMesoPermissions(l->getPermissions());
128 if (multiQueue) {
129 myQueues.push_back(Queue(allow));
130 }
131 if (allow != 0) {
132 usableLanes++;
133 maxAllow |= allow;
134 minAllow &= allow;
135 }
136 }
137 if (usableLanes == 0) {
138 // cars won't drive here. Give sensible tau values capacity for the ignored classes
139 usableLanes = 1;
140 }
141 if (multiQueue) {
142 // vehicles choose their queue by their next edge on the last segment and on all segments ending within the lookahead distance
143 const double distToEnd = parent.getLength() - (idx + 1) * length;
144 if (next == nullptr || distToEnd < edgeType.lookahead) {
145 SearchedMap searched;
146 for (const MSEdge* const edge : parent.getSuccessors()) {
147 if (edge->isTazConnector()) {
148 continue;
149 }
150 const std::vector<MSLane*>* const allowed = parent.allowedLanes(*edge);
151 assert(allowed != nullptr);
152 assert(allowed->size() > 0);
153 for (MSLane* const l : *allowed) {
154 std::vector<MSLane*>::const_iterator it = std::find(lanes.begin(), lanes.end(), l);
155 myFollowerMap[edge] |= (1 << distance(lanes.begin(), it));
156 }
157 if (edgeType.lookahead > 0) {
158 // follow the lanes of this edge into later edges whose turns are within the lookahead distance
159 std::vector<int> reach(lanes.size(), 0);
160 for (int i = 0; i < (int)lanes.size(); i++) {
161 for (const MSLink* const link : lanes[i]->getLinkCont()) {
162 if (&link->getLane()->getEdge() == edge) {
163 reach[i] |= 1 << link->getLane()->getIndex();
164 }
165 }
166 }
167 addDownstreamFollowers(*edge, reach, 0., edgeType.lookahead - MAX2(0., distToEnd), 1, searched);
168 }
169 }
170 }
171 myQueueCapacity = length;
172 } else {
173 myQueues.push_back(Queue(parent.getPermissions()));
174 maxAllow &= ~minAllow;
175 if ((maxAllow & ~myMultiModalWarnings) != 0) {
176 WRITE_WARNINGF("Mismodelled capacity on edge '%'. Not all lanes are usable by vClass '%'. Use option --meso-lane-queue or add unused class to option --meso-ignore-lanes-by-vclass.",
178 myMultiModalWarnings |= maxAllow;
179 }
180 }
181
182 initSegment(edgeType, parent, length * usableLanes);
183}
184
185void
186MESegment::addDownstreamFollowers(const MSEdge& edge, const std::vector<int>& reach, const double dist, const double lookahead, const int depth, SearchedMap& searched) {
187 if (dist + edge.getLength() >= lookahead) {
188 return;
189 }
190 // a search with the same reach that started no further away and at least as deep has added everything this one would
191 std::vector<std::pair<double, int> >& previous = searched[std::make_pair(&edge, reach)];
192 for (const std::pair<double, int>& p : previous) {
193 if (p.first <= dist && p.second >= depth) {
194 return;
195 }
196 }
197 previous.push_back(std::make_pair(dist, depth));
198 const std::vector<MSLane*>& lanes = edge.getLanes();
199 int usable = 0;
200 for (int i = 0; i < (int)reach.size(); i++) {
201 if (reach[i] != 0) {
202 usable |= 1 << i;
203 }
204 }
205 for (const MSEdge* const succ : edge.getSuccessors()) {
206 if (succ->isTazConnector()) {
207 continue;
208 }
209 // the queues of this segment from which succ can be reached without changing lanes
210 int queues = 0;
211 std::vector<int> succReach(reach.size(), 0);
212 for (int i = 0; i < (int)reach.size(); i++) {
213 for (int j = 0; j < (int)lanes.size(); j++) {
214 if ((reach[i] & (1 << j)) != 0) {
215 for (const MSLink* const link : lanes[j]->getLinkCont()) {
216 if (&link->getLane()->getEdge() == succ) {
217 queues |= 1 << i;
218 succReach[i] |= 1 << link->getLane()->getIndex();
219 }
220 }
221 }
222 }
223 }
224 if (queues != 0) {
225 if (queues != usable) {
226 myFollowerMap[succ] |= queues;
227 myLookahead = MAX2(myLookahead, depth + 1);
228 }
229 addDownstreamFollowers(*succ, succReach, dist + edge.getLength(), lookahead, depth + 1, searched);
230 }
231 }
232}
233
234
235void
236MESegment::initSegment(const MesoEdgeType& edgeType, const MSEdge& parent, const double capacity) {
237
238 myCapacity = capacity;
239 if (myQueues.size() == 1) {
240 const double laneScale = capacity / myLength;
241 myQueueCapacity = capacity;
242 myTau_length = (double)TIME2STEPS(1) / MAX2(MESO_MIN_SPEED, myMeanSpeed) / laneScale;
243 // Eissfeldt p. 90 and 151 ff.
244 myTau_ff = (SUMOTime)((double)edgeType.tauff / laneScale);
245 myTau_fj = (SUMOTime)((double)edgeType.taufj / laneScale);
246 myTau_jf = (SUMOTime)((double)edgeType.taujf / laneScale);
247 myTau_jj = (SUMOTime)((double)edgeType.taujj / laneScale);
248 } else {
249 myTau_ff = edgeType.tauff;
250 myTau_fj = edgeType.taufj;
251 myTau_jf = edgeType.taujf;
252 myTau_jj = edgeType.taujj;
253 }
254
256 myTLSPenalty = ((edgeType.tlsPenalty > 0 || edgeType.tlsFlowPenalty > 0) &&
257 // only apply to the last segment of a tls-controlled edge
258 myNextSegment == nullptr && (
262
263 // only apply to the last segment of an uncontrolled edge that has at least 1 minor link
264 myCheckMinorPenalty = (edgeType.minorPenalty > 0 &&
265 myNextSegment == nullptr &&
269 parent.hasMinorLink());
270 myMinorPenalty = edgeType.minorPenalty;
272 // keyed by the edge id because adding or removing edges elsewhere renumbers the numerical ids
273 myOvertakeKey = (long long int)((uint64_t)RandHelper::murmur3_32(parent.getID(), myIndex) << 32);
274
275 //std::cout << getID() << " myMinorPenalty=" << myMinorPenalty << " myTLSPenalty=" << myTLSPenalty << " myJunctionControl=" << myJunctionControl << " myOvertaking=" << myOvertaking << "\n";
276
278}
279
280MESegment::MESegment(const std::string& id):
281 Named(id),
282 myEdge(myDummyParent), // arbitrary edge needed to supply the needed reference
283 myNextSegment(nullptr), myLength(0), myIndex(0),
284 myTau_ff(0), myTau_fj(0), myTau_jf(0), myTau_jj(0),
285 myTLSPenalty(false),
286 myCheckMinorPenalty(false),
287 myMinorPenalty(0),
288 myJunctionControl(false),
289 myOvertaking(false),
290 myTau_length(1) {
291}
292
293
294void
296 if (myQueues.size() > 1) {
297 for (MSLane* lane : myEdge.getLanes()) {
298 myQueues[lane->getIndex()].setPermissions(lane->getPermissions());
299 }
300 } else {
301 myQueues.back().setPermissions(myEdge.getPermissions());
302 }
303}
304
305
306void
308 if (jamThresh == DO_NOT_PATCH_JAM_THRESHOLD) {
309 return;
310 }
311 if (jamThresh < 0) {
312 // compute based on speed
314 } else {
315 // compute based on specified percentage
316 myJamThreshold = jamThresh * myCapacity;
317 }
318}
319
320
321double
322MESegment::jamThresholdForSpeed(double speed, double jamThresh) const {
323 // vehicles driving freely at maximum speed should not jam
324 // we compute how many vehicles could possible enter the segment until the first vehicle leaves
325 // and multiply by the space these vehicles would occupy
326 // the jamThresh parameter is scale the resulting value
327 if (speed == 0) {
328 return std::numeric_limits<double>::max(); // never jam. Irrelevant at speed 0 anyway
329 }
330#ifdef DEBUG_JAMTHRESHOLD
331 if (true || DEBUG_COND) {
332 std::cout << "jamThresholdForSpeed seg=" << getID() << " speed=" << speed << " jamThresh=" << jamThresh << " ffVehs=" << std::ceil(myLength / (-jamThresh * speed * STEPS2TIME(tauWithVehLength(myTau_ff, DEFAULT_VEH_LENGTH_WITH_GAP)))) << " thresh=" << std::ceil(myLength / (-jamThresh * speed * STEPS2TIME(tauWithVehLength(myTau_ff, DEFAULT_VEH_LENGTH_WITH_GAP)))) * DEFAULT_VEH_LENGTH_WITH_GAP
333 << "\n";
334 }
335#endif
337}
338
339
340void
342 if (queueIndex == -1) {
343 for (Queue& q : myQueues) {
344 q.addDetector(data);
345 }
346 } else {
347 assert(queueIndex < (int)myQueues.size());
348 myQueues[queueIndex].addDetector(data);
349 }
350}
351
352
353/*
354void
355MESegment::removeDetector(MSMoveReminder* data) {
356 std::vector<MSMoveReminder*>::iterator it = std::find(myDetectorData.begin(), myDetectorData.end(), data);
357 if (it != myDetectorData.end()) {
358 myDetectorData.erase(it);
359 }
360 for (const Queue& q : myQueues) {
361 for (MEVehicle* const v : q.getVehicles()) {
362 v->removeReminder(data);
363 }
364 }
365}
366*/
367
368
369void
371 const SUMOTime currentTime = MSNet::getInstance()->getCurrentTimeStep();
372 if (queueIndex == -1) {
373 for (const Queue& q : myQueues) {
374 SUMOTime earliestExitTime = currentTime;
375 for (std::vector<MEVehicle*>::const_reverse_iterator i = q.getVehicles().rbegin(); i != q.getVehicles().rend(); ++i) {
376 const SUMOTime exitTime = MAX2(earliestExitTime, (*i)->getEventTime());
377 (*i)->updateDetectorForWriting(&data, currentTime, exitTime);
378 earliestExitTime = exitTime + tauWithVehLength(myTau_ff, (*i)->getVehicleType().getLengthWithGap(), (*i)->getVehicleType().getCarFollowModel().getHeadwayTime());
379 }
380 }
381 } else {
382 SUMOTime earliestExitTime = currentTime;
383 for (std::vector<MEVehicle*>::const_reverse_iterator i = myQueues[queueIndex].getVehicles().rbegin(); i != myQueues[queueIndex].getVehicles().rend(); ++i) {
384 const SUMOTime exitTime = MAX2(earliestExitTime, (*i)->getEventTime());
385 (*i)->updateDetectorForWriting(&data, currentTime, exitTime);
386 earliestExitTime = exitTime + tauWithVehLength(myTau_ff, (*i)->getVehicleType().getLengthWithGap(), (*i)->getVehicleType().getCarFollowModel().getHeadwayTime());
387 }
388 }
389}
390
391
393MESegment::hasSpaceFor(const MEVehicle* const veh, const SUMOTime entryTime, int& qIdx, const bool init) const {
394 SUMOTime earliestEntry = SUMOTime_MAX;
395 qIdx = 0;
396 if (myNumVehicles == 0 && myQueues.size() == 1 && (init || !hasTravelingGaps(0, entryTime))) {
397 // we have always space for at least one vehicle
398 if (myQueues.front().allows(veh->getVClass())) {
399 return entryTime;
400 } else {
401 return earliestEntry;
402 }
403 }
404 const SUMOVehicleClass svc = veh->getVClass();
405 int minSize = std::numeric_limits<int>::max();
406 // the queues leading to the next edges of the vehicle's route
407 int usable = -1;
408 if (!myFollowerMap.empty()) {
409 // the lane chain to a later route edge may run through lanes the vehicle may not use
410 int permitted = -1;
411 if (myLookahead > 1) {
412 permitted = 0;
413 for (int i = 0; i < (int)myQueues.size(); i++) {
414 if (myQueues[i].allows(svc)) {
415 permitted |= 1 << i;
416 }
417 }
418 }
419 const int offset = veh->getEdge() == &myEdge ? 1 : 2;
420 for (int k = 0; k < myLookahead; k++) {
421 const MSEdge* const succ = veh->succEdge(offset + k);
422 if (succ == nullptr) {
423 break;
424 }
425 const auto it = myFollowerMap.find(succ);
426 if (it != myFollowerMap.end() && (k == 0 || (usable & it->second & permitted) != 0)) {
427 usable &= it->second;
428 }
429 }
430 }
431 for (int i = 0; i < (int)myQueues.size(); i++) {
432 const Queue& q = myQueues[i];
433 const double newOccupancy = q.size() == 0 ? 0. : q.getOccupancy() + veh->getVehicleType().getLengthWithGap();
434 if (newOccupancy <= myQueueCapacity) { // we must ensure that occupancy remains below capacity
435 if ((usable & (1 << i)) != 0) {
436 if (q.allows(svc) && q.size() < minSize) {
437 if (init) {
438 // regular insertions and initial insertions must respect different constraints:
439 if (veh->getInsertionChecks() == (int)InsertionCheck::NONE || hasSpaceForInsertion(q, i, newOccupancy, entryTime)) {
440 qIdx = i;
441 minSize = q.size();
442 }
443 } else if (entryTime >= q.getEntryBlockTime()) {
444 qIdx = i;
445 minSize = q.size();
446 } else {
447 earliestEntry = MIN2(earliestEntry, q.getEntryBlockTime());
448 }
449 }
450 }
451 }
452 }
453 if (minSize == std::numeric_limits<int>::max()) {
454 return earliestEntry;
455 }
456 return entryTime;
457}
458
459
460bool
461MESegment::hasSpaceForInsertion(const Queue& q, int /*qIdx*/, double newOccupancy, SUMOTime /*entryTime*/) const {
462 // - regular insertions must respect entryBlockTime
463 // - initial insertions should not cause additional jamming
464 // - inserted vehicle should be able to continue at the current speed
466 return newOccupancy <= myJamThreshold;
467 } else {
468 return newOccupancy <= jamThresholdForSpeed(getMeanSpeed(false), -1);
469 }
470}
471
472
473bool
475 int qIdx = 0;
476 if (hasSpaceFor(veh, time, qIdx, true) == time) {
477 const bool isRail = veh->isRail();
478 // see MSLane::isInsertionSuccess
479 if (isRail && veh->getInsertionChecks() != (int)InsertionCheck::NONE
484 MSEdgeVector occupied;
485 if (dw->foeDriveWayOccupied(false, veh, occupied) || dw->sidingDeadlock(veh)) {
486 myEdge.getLanes()[0]->setParameter("insertionBlocked:" + veh->getID(), dw->getID());
487 return false;
488 }
489 }
490 receive(veh, qIdx, time, true);
491 if (isRail) {
492 myEdge.getLanes()[0]->unsetParameter("insertionConstraint:" + veh->getID());
493 //unsetParameter("insertionOrder:" + veh->getID());
494 //unsetParameter("insertionBlocked:" + veh->getID());
497 //if (firstRailSignal != nullptr && firstRailSignal->getJunction()->getType() == SumoXMLNodeType::RAIL_SIGNAL) {
498 // veh->registerInsertionApproach(firstRailSignal, firstRailSignalDist);
499 //}
500 }
501 return true;
502 }
503 return false;
504}
505
506
507double
508MESegment::getMeanSpeed(bool useCached) const {
509 const SUMOTime currentTime = MSNet::getInstance()->getCurrentTimeStep();
510 if (currentTime != myLastMeanSpeedUpdate || !useCached) {
511 myLastMeanSpeedUpdate = currentTime;
512 double v = 0;
513 int count = 0;
514 for (const Queue& q : myQueues) {
515 const SUMOTime tau = q.getOccupancy() < myJamThreshold ? myTau_ff : myTau_jf;
516 SUMOTime earliestExitTime = currentTime;
517 count += q.size();
518 for (std::vector<MEVehicle*>::const_reverse_iterator veh = q.getVehicles().rbegin(); veh != q.getVehicles().rend(); ++veh) {
519 v += (*veh)->getConservativeSpeed(earliestExitTime); // earliestExitTime is updated!
520 earliestExitTime += tauWithVehLength(tau, (*veh)->getVehicleType().getLengthWithGap(), (*veh)->getVehicleType().getCarFollowModel().getHeadwayTime());
521 }
522 }
523 if (count == 0) {
525 } else {
526 myMeanSpeed = v / (double) count;
527 }
528 }
529 return myMeanSpeed;
530}
531
532
533void
537
538
539void
542 return;
543 }
544 const double segmentOffset = myStartOffset;
545 const double segLength = getLength();
546 const double lanesCovered = numQueues() == 1
547 ? std::round(getCapacity() / segLength) : 1.;
548 const double now = SIMTIME;
549 for (int qIdx = 0; qIdx < numQueues(); ++qIdx) {
550 const std::vector<MEVehicle*> queue = getQueue(qIdx);
551 const int queueSize = (int)queue.size();
552 SUMOTime earliestExitTime = getQueueBlockTime(qIdx);
553 int overlap = 0;
554 double prevPos = std::numeric_limits<double>::max();
555 for (int i = 0; i < queueSize; ++i) {
556 MEVehicle* const veh = queue[queueSize - i - 1];
557 earliestExitTime = MAX2(earliestExitTime, veh->getEventTime());
558 const double vehLength = veh->getVehicleType().getLengthWithGap();
559 double maxPos = segmentOffset + segLength;
560 const double oldPos = MAX2(0., veh->getMesoPosition());
561 if (i > 0) {
562 earliestExitTime += getMinTauWithVehLength(vehLength, veh->getVehicleType().getCarFollowModel().getHeadwayTime());
563 maxPos = MIN2(maxPos, prevPos - vehLength / lanesCovered);
564 }
565 const double entry = veh->getLastEntryTimeSeconds();
566 assert(STEPS2TIME(earliestExitTime) > entry);
567 const double pos = MAX2(MIN2(segmentOffset + segLength * (now - entry) / (STEPS2TIME(earliestExitTime) - entry), maxPos), oldPos);
568 if (overlap == 0 && prevPos - pos < vehLength) {
569 overlap = lanesCovered > 1. ? -3 : -1;
570 } else {
571 overlap = 0;
572 }
573 veh->setMesoPosition(pos, overlap);
574 prevPos = pos;
575 }
576 }
578}
579
580
581void
583 for (const Queue& q : myQueues) {
584 for (const MEVehicle* const veh : q.getVehicles()) {
586 }
587 }
588}
589
590
593 // One could be tempted to do v->setSegment(next); here but position on lane will be invalid if next == 0
594 v->updateDetectors(leaveTime, v->getEventTime(), true, reason);
595 if (v->getQueIndex() == PARKING_QUEUE) {
596 return nullptr;
597 }
598 Queue& q = myQueues[v->getQueIndex()];
600 myEdge.lock();
601 MEVehicle* nextLeader = q.remove(v);
604 myEdge.unlock();
605 return nextLeader;
606}
607
608
611 // since we do not know which queue will be used we give a conservative estimate
612 SUMOTime earliestLeave = earliestEntry;
613 SUMOTime latestEntry = -1;
614 for (const Queue& q : myQueues) {
615 earliestLeave = MAX2(earliestLeave, q.getBlockTime());
616 latestEntry = MAX2(latestEntry, q.getEntryBlockTime());
617 }
618 if (myEdge.getSpeedLimit() == 0) {
619 return MAX2(earliestEntry, latestEntry); // FIXME: This line is just an adhoc-fix to avoid division by zero (Leo)
620 } else {
621 return MAX3(earliestEntry, earliestLeave - TIME2STEPS(myLength / myEdge.getSpeedLimit()), latestEntry);
622 }
623}
624
625
626MSLink*
627MESegment::getLink(const MEVehicle* veh, bool penalty) const {
628 if (myJunctionControl || penalty) {
629 const MSEdge* const nextEdge = veh->succEdge(1);
630 if (nextEdge == nullptr || veh->getQueIndex() == PARKING_QUEUE) {
631 return nullptr;
632 }
633 // try to find any link leading to our next edge, start with the lane pointed to by the que index
634 const MSLane* const bestLane = myEdge.getLanes()[veh->getQueIndex()];
635 for (MSLink* const link : bestLane->getLinkCont()) {
636 if (&link->getLane()->getEdge() == nextEdge) {
637 return link;
638 }
639 }
640 // this is for the non-multique case, maybe we should use caching here !!!
641 for (const MSLane* const lane : myEdge.getLanes()) {
642 if (lane != bestLane) {
643 for (MSLink* const link : lane->getLinkCont()) {
644 if (&link->getLane()->getEdge() == nextEdge) {
645 return link;
646 }
647 }
648 }
649 }
650 }
651 return nullptr;
652}
653
654
655int
656MESegment::isOpen(const MEVehicle* veh) const {
657#ifdef DEBUG_OPENED
658 if (DEBUG_COND || DEBUG_COND2(veh)) {
659 gDebugFlag1 = true;
660 std::cout << SIMTIME << " opened seg=" << getID() << " veh=" << Named::getIDSecure(veh)
661 << " tlsPenalty=" << myTLSPenalty;
662 const MSLink* link = getLink(veh);
663 if (link == 0) {
664 std::cout << " link=0";
665 } else {
666 std::cout << " prio=" << link->havePriority()
667 << " override=" << limitedControlOverride(link)
668 << " isOpen=" << link->opened(veh->getEventTime(), veh->getSpeed(), veh->estimateLeaveSpeed(link),
671 0, nullptr, false, veh)
672 << " et=" << veh->getEventTime()
673 << " v=" << veh->getSpeed()
674 << " vLeave=" << veh->estimateLeaveSpeed(link)
675 << " impatience=" << veh->getImpatience()
676 << " tWait=" << veh->getWaitingTime();
677 }
678 std::cout << "\n";
679 gDebugFlag1 = false;
680 }
681#endif
682 if (myTLSPenalty) {
683 // XXX should limited control take precedence over tls penalty?
684 return PROCEED_YES;
685 }
686 const MSLink* link = getLink(veh);
687 const bool open = (link == nullptr
688 || link->havePriority()
690 || link->opened(veh->getEventTime(), veh->getSpeed(), veh->estimateLeaveSpeed(link),
693 0, nullptr, false, veh));
694 if (open) {
695 return PROCEED_YES;
696 } else {
697 int status = PROCEED_NO;
698 if (link != nullptr && link->isTLSControlled()) {
699 status |= PROCEED_NO_TLS;
700 }
701 return status;
702 }
703}
704
705
706bool
708 assert(link != nullptr);
710 return false;
711 }
712 // if the target segment of this link is not saturated junction control is disabled
713 const MSEdge& targetEdge = link->getLane()->getEdge();
714 const MESegment* target = MSGlobals::gMesoNet->getSegmentForEdge(targetEdge);
715 return (target->getBruttoOccupancy() * 2 < target->myJamThreshold) && !targetEdge.isRoundabout();
716}
717
718
720MESegment::computeHeadway(Queue& /*q*/, const Queue& qNext, const MESegment* const next, const MEVehicle* veh) const {
721 const bool nextFree = qNext.getOccupancy() <= next->myJamThreshold;
722 const SUMOTime tau = (!veh->wasJammed()
723 ? (nextFree ? myTau_ff : myTau_fj)
724 : (nextFree ? myTau_jf : getTauJJ((double)qNext.size(), next->myQueueCapacity, next->myJamThreshold)));
725 assert(tau >= 0);
727 if (myTLSPenalty) {
728 const MSLink* const tllink = getLink(veh, true);
729 if (tllink != nullptr && tllink->isTLSControlled()) {
730 assert(tllink->getGreenFraction() > 0);
731 headway = (SUMOTime)((double)headway / tllink->getGreenFraction());
732 }
733 }
734 return headway;
735}
736
737
738void
739MESegment::send(MEVehicle* veh, MESegment* const next, const int nextQIdx, SUMOTime time, const MSMoveReminder::Notification reason) {
740 Queue& q = myQueues[veh->getQueIndex()];
741 assert(isInvalid(next) || time >= q.getBlockTime());
742 MSLink* const link = getLink(veh);
743 if (link != nullptr) {
744 link->removeApproaching(veh);
745 }
746 if (veh->isStopped()) {
747 veh->processStop();
748 }
749 MEVehicle* lc = removeCar(veh, time, reason); // new leaderCar
750 q.setBlockTime(time);
751 if (myEdge.isNormal() && myCapacity >= 22.5) {
753 }
754 if (!isInvalid(next)) {
755 myLastHeadway = computeHeadway(q, next->myQueues[nextQIdx], next, veh);
756 q.setBlockTime(time + myLastHeadway);
757 }
758 if (lc != nullptr) {
761 }
762}
763
764
766MESegment::getTauJJ(double nextQueueSize, double nextQueueCapacity, double nextJamThreshold) const {
767 // compute coefficients for the jam-jam headway function
768 // this function models the effect that "empty space" needs to move
769 // backwards through the downstream segment before the upstream segment may
770 // send annother vehicle.
771 // this allows jams to clear and move upstream.
772 // the headway function f(x) depends on the number of vehicles in the
773 // downstream segment x
774 // f is a linear function that passes through the following fixed points:
775 // f(n_jam_threshold) = tau_jf_withLength (for continuity)
776 // f(headwayCapacity) = myTau_jj * headwayCapacity
777
778 const SUMOTime tau_jf_withLength = tauWithVehLength(myTau_jf, DEFAULT_VEH_LENGTH_WITH_GAP, 1.);
779 // number of vehicles that fit into the NEXT queue (could be larger than expected with DEFAULT_VEH_LENGTH_WITH_GAP!)
780 const double headwayCapacity = MAX2(nextQueueSize, nextQueueCapacity / DEFAULT_VEH_LENGTH_WITH_GAP);
781 // number of vehicles above which the NEXT queue is jammed
782 const double n_jam_threshold = headwayCapacity * nextJamThreshold / nextQueueCapacity;
783
784 // slope a and axis offset b for the jam-jam headway function
785 // solving f(x) = a * x + b
786 const double a = (STEPS2TIME(myTau_jj) * headwayCapacity - STEPS2TIME(tau_jf_withLength)) / (headwayCapacity - n_jam_threshold);
787 const double b = headwayCapacity * (STEPS2TIME(myTau_jj) - a);
788
789 // it is only well defined for nextQueueSize >= n_jam_threshold (which may not be the case for longer vehicles), so we take the MAX
790 return TIME2STEPS(a * MAX2(nextQueueSize, n_jam_threshold) + b);
791}
792
793
794bool
796 // the global RNG would let the number of draws elsewhere decide this vehicle's outcome
797 const long long int key = veh->getRandomSeed() ^ myOvertakeKey;
799}
800
801
802void
804 if (veh->getQueIndex() != PARKING_QUEUE) {
805 myQueues[veh->getQueIndex()].addReminders(veh);
806 }
807}
808
809
810double
811MESegment::getVehicleMaxSpeed(const MEVehicle& veh, int queueIndex) const {
812 const auto& routeLanes = veh.getEdge()->getLanes();
813 // The route edge is still the incoming edge until the vehicle leaves the junction.
814 const MSLane* const lane = queueIndex < (int)routeLanes.size()
815 ? routeLanes[queueIndex] : myEdge.getLanes()[queueIndex];
816 return lane->getVehicleMaxSpeed(&veh);
817}
818
819
820void
821MESegment::receive(MEVehicle* veh, const int qIdx, SUMOTime time, const bool isDepart, const bool isTeleport, const bool newEdge) {
822 const double speed = isDepart ? -1 : MAX2(veh->getSpeed(), MESO_MIN_SPEED); // on the previous segment
823 veh->setSegment(this); // for arrival checking
824 veh->setLastEntryTime(time);
826 if (!isDepart && (
827 // arrival on entering a new edge
828 (newEdge && myEdge.isNormal() && veh->moveRoutePointer())
829 // arrival on entering a new segment
830 || veh->hasArrived())) {
831 // route has ended
832 veh->setEventTime(time + TIME2STEPS(myLength / speed)); // for correct arrival speed
833 addReminders(veh);
835 veh->updateDetectors(time, veh->getEventTime(), true,
838 return;
839 }
840 assert(veh->getEdge() == &getEdge() || getEdge().isInternal());
841 // route continues
842 Queue& q = myQueues[qIdx];
843 const double maxSpeedOnEdge = getVehicleMaxSpeed(*veh, qIdx);
844 const double uspeed = MAX2(maxSpeedOnEdge, MESO_MIN_SPEED);
845 std::vector<MEVehicle*>& cars = q.getModifiableVehicles();
846 MEVehicle* newLeader = nullptr; // first vehicle in the current queue
847 const SUMOTime stopTime = veh->checkStop(time);
848 SUMOTime tleave = MAX2(stopTime + TIME2STEPS(myLength / uspeed) + getLinkPenalty(veh), q.getBlockTime());
849 if (veh->isStopped()) {
850 myEdge.addWaiting(veh);
851 }
852 if (veh->isParking()) {
853 // parking stops should take at least 1ms
854 veh->setEventTime(MAX2(stopTime, veh->getEventTime() + 1));
855 veh->setSegment(this, PARKING_QUEUE);
856 myEdge.getLanes()[0]->addParking(veh); // TODO for GUI only
857 } else {
858 myEdge.lock();
859 if (cars.empty()) {
860 cars.push_back(veh);
861 newLeader = veh;
862 } else {
863 SUMOTime leaderOut = cars[0]->getEventTime();
864 if (!isDepart && leaderOut > tleave && overtake(veh)) {
865 if (cars.size() == 1) {
866 // the overtaken car is no longer the leader and must not block foes
867 MSLink* const link = getLink(cars[0]);
868 if (link != nullptr) {
869 link->removeApproaching(cars[0]);
870 }
872 newLeader = veh;
873 }
874 cars.insert(cars.begin() + 1, veh);
875 } else {
876 tleave = MAX2(leaderOut + tauWithVehLength(myTau_ff, cars[0]->getVehicleType().getLengthWithGap(), cars[0]->getVehicleType().getCarFollowModel().getHeadwayTime()), tleave);
877 cars.insert(cars.begin(), veh);
878 }
879 }
881 myEdge.unlock();
883 if (!isDepart && !isTeleport) {
884 // departs and teleports could take place anywhere on the edge so they should not block regular flow
885 // the -1 facilitates interleaving of multiple streams
887 }
889 veh->setEventTime(tleave);
890 veh->setUnqueuedEventTime(tleave);
891 veh->setSegment(this, qIdx);
892 }
893 addReminders(veh);
894 if (isDepart) {
895 veh->onDepart();
897 } else if (newEdge) {
899 } else {
901 }
902 if (veh->isParking()) {
903 MSGlobals::gMesoNet->addLeaderCar(veh, nullptr);
904 } else {
905 if (newLeader != nullptr) {
906 MSGlobals::gMesoNet->addLeaderCar(newLeader, getLink(newLeader));
907 }
908 }
909}
910
911
912bool
914 for (const Queue& q : myQueues) {
915 if (q.size() > 0) {
916 for (MEVehicle* const veh : q.getVehicles()) {
917 if (filter->vehicleApplies(*veh)) {
920 return true;
921 }
922 }
923 }
924 }
925 return false;
926}
927
928
929void
930MESegment::setSpeedForQueue(double newSpeed, SUMOTime currentTime, SUMOTime blockTime, const std::vector<MEVehicle*>& vehs) {
931 MEVehicle* v = vehs.back();
932 SUMOTime oldEarliestExitTime = currentTime;
933 const SUMOTime oldExit = MAX2(oldEarliestExitTime, v->getEventTime());
934 v->updateDetectors(currentTime, oldExit, false);
936 SUMOTime newEvent = MAX2(newArrival(v, newSpeed, currentTime), blockTime);
937 if (v->getEventTime() != newEvent) {
939 v->setEventTime(newEvent);
941 }
942 for (std::vector<MEVehicle*>::const_reverse_iterator i = vehs.rbegin() + 1; i != vehs.rend(); ++i) {
943 const SUMOTime oldExitTime = MAX2(oldEarliestExitTime, (*i)->getEventTime());
944 (*i)->updateDetectors(currentTime, oldExitTime, false);
945 const SUMOTime minTau = tauWithVehLength(myTau_ff, (*i)->getVehicleType().getLengthWithGap(), (*i)->getVehicleType().getCarFollowModel().getHeadwayTime());
946 oldEarliestExitTime = oldExitTime + minTau;
947 newEvent = MAX2(newArrival(*i, newSpeed, currentTime), newEvent + minTau);
948 (*i)->setEventTime(newEvent);
949 }
950}
951
952
954MESegment::newArrival(const MEVehicle* const v, double newSpeed, SUMOTime currentTime) {
955 // since speed is only an upper bound, pos may be too optimistic
956 const double pos = MIN2(myLength, STEPS2TIME(currentTime - v->getLastEntryTime()) * v->getSpeed());
957 // traveltime may not be 0
958 double tt = (myLength - pos) / MAX2(newSpeed, MESO_MIN_SPEED);
959 return currentTime + MAX2(TIME2STEPS(tt), SUMOTime(1));
960}
961
962
963void
964MESegment::setSpeed(double newSpeed, SUMOTime currentTime, double jamThresh, int qIdx) {
965 recomputeJamThreshold(jamThresh);
966 //myTau_length = MAX2(MESO_MIN_SPEED, newSpeed) * myEdge.getLanes().size() / TIME2STEPS(1);
967 int i = 0;
968 for (const Queue& q : myQueues) {
969 if (q.size() != 0) {
970 if (qIdx == -1 || qIdx == i) {
971 setSpeedForQueue(newSpeed, currentTime, q.getBlockTime(), q.getVehicles());
972 }
973 }
974 i++;
975 }
976}
977
978
981 SUMOTime result = SUMOTime_MAX;
982 for (const Queue& q : myQueues) {
983 if (q.size() != 0 && q.getVehicles().back()->getEventTime() < result) {
984 result = q.getVehicles().back()->getEventTime();
985 }
986 }
987 if (result < SUMOTime_MAX) {
988 return result;
989 }
990 return -1;
991}
992
993
994void
996 bool write = false;
997 for (int i = 0; i < (int)myQueues.size(); i++) {
998 if (myQueues[i].getBlockTime() != -1 || !myQueues[i].getVehicles().empty() || getQueueExtraState(i) != "") {
999 write = true;
1000 break;
1001 }
1002 }
1003 if (write) {
1005 for (int i = 0; i < (int)myQueues.size(); i++) {
1006 const Queue& q = myQueues[i];
1008 out.writeAttr(SUMO_ATTR_TIME, toString<SUMOTime>(q.getBlockTime()));
1009 out.writeAttr(SUMO_ATTR_BLOCKTIME, toString<SUMOTime>(q.getEntryBlockTime()));
1011 const std::string extra = getQueueExtraState(i);
1012 if (extra != "") {
1013 out.writeAttr(SUMO_ATTR_STATE, extra);
1014 }
1015 out.closeTag();
1016 }
1017 out.closeTag();
1018 }
1019}
1020
1021
1022void
1025 for (Queue& q : myQueues) {
1026 for (MEVehicle* veh : q.getModifiableVehicles()) {
1027 veh->invalidateMesoPosition();
1028 }
1029 q.getModifiableVehicles().clear();
1030 }
1031}
1032
1033void
1034MESegment::loadState(const std::vector<SUMOVehicle*>& vehs, const SUMOTime blockTime, const SUMOTime entryBlockTime, const int queIdx) {
1036 Queue& q = myQueues[queIdx];
1037 for (SUMOVehicle* veh : vehs) {
1038 MEVehicle* v = static_cast<MEVehicle*>(veh);
1039 assert(v->getSegment() == this || myEdge.isInternal());
1040 if (myEdge.isInternal()) {
1041 v->setSegment(this, v->getQueIndex());
1042 }
1043 q.getModifiableVehicles().push_back(v);
1044 myNumVehicles++;
1046 addReminders(v);
1047 }
1048 if (q.size() != 0) {
1049 // add the last vehicle of this queue
1050 // !!! one question - what about the previously added vehicle? Is it stored twice?
1051 MEVehicle* veh = q.getVehicles().back();
1052 MSGlobals::gMesoNet->addLeaderCar(veh, getLink(veh), true);
1053 }
1054 q.setBlockTime(blockTime);
1055 q.setEntryBlockTime(entryBlockTime);
1057}
1058
1059
1060std::vector<const MEVehicle*>
1062 std::vector<const MEVehicle*> result;
1063 for (const Queue& q : myQueues) {
1064 result.insert(result.end(), q.getVehicles().begin(), q.getVehicles().end());
1065 }
1066 return result;
1067}
1068
1069
1070bool
1072 for (const Queue& q : myQueues) {
1073 if (q.size() > 0 && q.getVehicles().back()->getWaitingTime() > 0) {
1074 return true;
1075 }
1076 }
1077 return false;
1078}
1079
1080
1081double
1083 return 3600 * getCarNumber() * getMeanSpeed() / myLength;
1084}
1085
1086
1089 const MSLink* link = getLink(veh, myTLSPenalty || myCheckMinorPenalty);
1090 if (link != nullptr) {
1091 SUMOTime result = 0;
1092 if (link->isTLSControlled() && myTLSPenalty) {
1093 result += link->getMesoTLSPenalty();
1094 }
1095 // minor tls links may get an additional penalty
1096 if (!link->havePriority() &&
1097 // do not apply penalty on top of tLSPenalty
1098 !myTLSPenalty &&
1099 // do not apply penalty if limited control is active
1101 result += myMinorPenalty;
1102 }
1103 return result;
1104 } else {
1105 return 0;
1106 }
1107}
1108
1109
1110double
1112 double result = 0;
1113 for (const Queue& q : myQueues) {
1114 // @note: only the leader currently accumulates waitingTime but this might change in the future
1115 for (const MEVehicle* veh : q.getVehicles()) {
1116 result += veh->getWaitingSeconds();
1117 }
1118 }
1119 return result;
1120}
1121
1122
1123/****************************************************************************/
long long int SUMOTime
Definition GUI.h:36
#define DEFAULT_VEH_LENGTH_WITH_GAP
#define DEBUG_COND2(obj)
#define MESO_MIN_SPEED
Definition MESegment.cpp:50
std::vector< MSEdge * > MSEdgeVector
Definition MSEdge.h:74
#define WRITE_WARNINGF(...)
Definition MsgHandler.h:299
#define STEPS2TIME(x)
Definition SUMOTime.h:58
#define SIMSTEP
Definition SUMOTime.h:69
constexpr SUMOTime TIME2STEPS(double x)
Definition SUMOTime.h:60
#define SUMOTime_MAX
Definition SUMOTime.h:34
#define SUMOTime_MIN
Definition SUMOTime.h:35
#define SIMTIME
Definition SUMOTime.h:70
const SVCPermissions SVCAll
all VClasses are allowed
const std::string & getVehicleClassNames(SVCPermissions permissions, bool expand)
Returns the ids of the given classes, divided using a ' '.
bool isRailwayOrShared(SVCPermissions permissions)
Returns whether an edge with the given permissions is a railway edge or a shared road/rail edge.
long long int SVCPermissions
bitset where each bit declares whether a certain SVC may use this edge/lane
SUMOVehicleClass
Definition of vehicle classes to differ between different lane usage and authority types.
@ SPLIT
The departure is triggered by a train split.
@ SUMO_TAG_VIEWSETTINGS_VEHICLES
@ SUMO_TAG_SEGMENT
segment of a lane
@ SUMO_ATTR_VALUE
@ SUMO_ATTR_BLOCKTIME
@ SUMO_ATTR_ID
@ SUMO_ATTR_STATE
The state of a link.
@ SUMO_ATTR_TIME
trigger: the time of the step
bool gDebugFlag1
global utility flags for debugging
Definition StdDefs.cpp:44
T MIN2(T a, T b)
Definition StdDefs.h:80
T MAX2(T a, T b)
Definition StdDefs.h:86
T MAX3(T a, T b, T c)
Definition StdDefs.h:100
static bool isEnteringRoundabout(const MSEdge &e)
whether the given edge is entering a roundabout
Definition MELoop.cpp:452
void addLeaderCar(MEVehicle *veh, MSLink *link, const bool fromState=false)
Adds the given car to the leading vehicles.
Definition MELoop.cpp:331
SUMOTime changeSegment(MEVehicle *veh, SUMOTime leaveTime, MESegment *const toSegment, MSMoveReminder::Notification reason, const bool ignoreLink=false) const
change to the next segment this handles combinations of the following cases: (ending / continuing rou...
Definition MELoop.cpp:130
MESegment * getSegmentForEdge(const MSEdge &e, double pos=0)
Get the segment for a given edge at a given position.
Definition MELoop.cpp:435
void removeLeaderCar(MEVehicle *v)
Removes the given car from the leading vehicles.
Definition MELoop.cpp:348
int size() const
Definition MESegment.h:91
void setOccupancy(const double occ)
Definition MESegment.h:104
MEVehicle * remove(MEVehicle *v)
Definition MESegment.cpp:74
void setBlockTime(SUMOTime t)
Definition MESegment.h:124
SUMOTime getBlockTime() const
Definition MESegment.h:121
double myOccupancy
The occupied space (in m) in the queue.
Definition MESegment.h:143
bool allows(SUMOVehicleClass vclass) const
Definition MESegment.h:107
std::vector< MEVehicle * > & getModifiableVehicles()
Definition MESegment.h:98
void addReminders(MEVehicle *veh) const
Definition MESegment.cpp:99
void addDetector(MSMoveReminder *data)
Definition MESegment.cpp:91
void setEntryBlockTime(SUMOTime entryBlockTime)
set the next time at which a vehicle may enter this queue
Definition MESegment.h:117
double getOccupancy() const
Definition MESegment.h:101
std::vector< MEVehicle * > myVehicles
Definition MESegment.h:140
const std::vector< MEVehicle * > & getVehicles() const
Definition MESegment.h:94
SUMOTime getEntryBlockTime() const
return the next time at which a vehicle may enter this queue
Definition MESegment.h:112
A single mesoscopic segment (cell)
Definition MESegment.h:50
void addReminders(MEVehicle *veh) const
add this lanes MoveReminders to the given vehicle
double myQueueCapacity
The number of lanes represented by the queue * the length of the lane.
Definition MESegment.h:657
double getVehicleMaxSpeed(const MEVehicle &veh, int queueIndex) const
Maximum vehicle speed for the given queue, accounting for internal junction segments.
SUMOTime tauWithVehLength(SUMOTime tau, double lengthWithGap, double vehicleTau) const
convert net time gap (leader back to follower front) to gross time gap (leader front to follower fron...
Definition MESegment.h:584
SUMOTime myTau_ff
The time headway parameters, see the Eissfeldt thesis.
Definition MESegment.h:631
int isOpen(const MEVehicle *veh) const
Returns whether the vehicle may use the next link.
bool initialise(MEVehicle *veh, SUMOTime time)
Inserts (emits) vehicle into the segment.
std::vector< Queue > myQueues
The car queues. Vehicles are inserted in the front and removed in the back.
Definition MESegment.h:663
double getBruttoOccupancy() const
Returns the occupany of the segment (the sum of the vehicle lengths + minGaps)
Definition MESegment.h:298
SUMOTime myLastHeadway
the last headway
Definition MESegment.h:675
static const int PARKING_QUEUE
Definition MESegment.h:53
bool limitedControlOverride(const MSLink *link) const
whether the given link may be passed because the option meso-junction-control.limited is set
void addDetector(MSMoveReminder *data, int queueIndex=-1)
Adds a data collector for a detector to this segment.
void clearState()
Remove all vehicles before quick-loading state.
void receive(MEVehicle *veh, const int qIdx, SUMOTime time, const bool isDepart=false, const bool isTeleport=false, const bool newEdge=false)
Adds the vehicle to the segment, adapting its parameters.
static SVCPermissions myMultiModalWarnings
Definition MESegment.h:682
SUMOTime getLinkPenalty(const MEVehicle *veh) const
Returns the penalty time for passing a link (if using gMesoTLSPenalty > 0 or gMesoMinorPenalty > 0)
void writeVehicles(OutputDevice &of) const
std::map< const MSEdge *, int > myFollowerMap
The follower edge to allowed que index mapping for multi queue segments.
Definition MESegment.h:669
MSLink * getLink(const MEVehicle *veh, bool tlsPenalty=false) const
Returns the link the given car will use when passing the next junction.
SUMOTime myMesoPositionUpdateTime
The time step of the last interpolated position update.
Definition MESegment.h:691
int myNumVehicles
The cached value for the number of vehicles.
Definition MESegment.h:666
void setSpeedForQueue(double newSpeed, SUMOTime currentTime, SUMOTime blockTime, const std::vector< MEVehicle * > &vehs)
double getLength() const
Returns the length of the segment in meters.
Definition MESegment.h:282
SUMOTime hasSpaceFor(const MEVehicle *const veh, const SUMOTime entryTime, int &qIdx, const bool init=false) const
Returns whether the given vehicle would still fit into the segment.
const std::vector< MEVehicle * > & getQueue(int index) const
Returns the cars in the queue with the given index for visualization.
Definition MESegment.h:244
void updatePermissions()
called when permissions change due to Rerouter or TraCI
void invalidateMesoPositions() const
Invalidate the cached interpolated positions.
Definition MESegment.h:253
long long int myOvertakeKey
this segment's part of the overtaking draws (hash of edge id and segment index in the upper 32 bits)
Definition MESegment.h:647
void saveState(OutputDevice &out) const
Saves the state of this segment into the given stream.
void initSegment(const MesoEdgeType &edgeType, const MSEdge &parent, const double capacity)
set model parameters (may be updated from additional file after network loading is complete)
void resetCachedSpeeds()
reset myLastMeanSpeedUpdate
virtual bool hasTravelingGaps(int, SUMOTime) const
whether space vacated by vehicles that left the given queue has not yet reached the upstream end
Definition MESegment.h:597
const MSEdge & getEdge() const
Returns the edge this segment belongs to.
Definition MESegment.h:405
static MESegment myVaporizationTarget
Definition MESegment.h:680
int numQueues() const
return the number of queues
Definition MESegment.h:238
void updateMesoPositions() const
Update interpolated positions for all vehicles on this segment.
int myLookahead
The number of route edges after myEdge to look up in myFollowerMap.
Definition MESegment.h:672
double myStartOffset
Distance from the start of the edge for position interpolation.
Definition MESegment.h:695
void addDownstreamFollowers(const MSEdge &edge, const std::vector< int > &reach, const double dist, const double lookahead, const int depth, SearchedMap &searched)
add the queues leading to the successors of the given downstream edge to myFollowerMap
virtual std::string getQueueExtraState(int) const
model specific queue state (e.g. the gap times of meso-ltm) for saving / loading
Definition MESegment.h:216
double myJamThreshold
The space (in m) which needs to be occupied before the segment is considered jammed.
Definition MESegment.h:660
const int myIndex
Running number of the segment in the edge.
Definition MESegment.h:625
virtual void send(MEVehicle *veh, MESegment *const next, const int nextQIdx, SUMOTime time, const MSMoveReminder::Notification reason)
Removes the vehicle from the segment, adapting its parameters.
SUMOTime myMinorPenalty
Definition MESegment.h:638
double myMeanSpeed
the mean speed on this segment. Updated at event time or on demand
Definition MESegment.h:685
bool myCheckMinorPenalty
penalty for minor links
Definition MESegment.h:637
virtual SUMOTime computeHeadway(Queue &q, const Queue &qNext, const MESegment *const next, const MEVehicle *veh) const
compute current headway depending on traffic state
double jamThresholdForSpeed(double speed, double jamThresh) const
compute jam threshold for the given speed and jam-threshold option
SUMOTime myLastMeanSpeedUpdate
the time at which myMeanSpeed was last updated
Definition MESegment.h:688
SUMOTime myTau_jf
Definition MESegment.h:631
void setSpeed(double newSpeed, SUMOTime currentTime, double jamThresh=DO_NOT_PATCH_JAM_THRESHOLD, int qIdx=-1)
reset mySpeed and patch the speed of all vehicles in it. Also set/recompute myJamThreshold
MESegment * myNextSegment
The next segment of this edge, 0 if this is the last segment of this edge.
Definition MESegment.h:619
bool hasBlockedLeader() const
whether a leader in any queue is blocked
double getWaitingSeconds() const
Get the waiting time for vehicles in all queues.
const double myLength
The segment's length.
Definition MESegment.h:622
SUMOTime getEventTime() const
Returns the (planned) time at which the next vehicle leaves this segment.
const MSEdge & myEdge
The microsim edge this segment belongs to.
Definition MESegment.h:616
static const std::string OVERRIDE_TLS_PENALTIES
special param value
Definition MESegment.h:55
MESegment(const std::string &id, const MSEdge &parent, MESegment *next, const double length, const double speed, const int idx, const bool multiQueue, const MesoEdgeType &edgeType)
constructor
MEVehicle * removeCar(MEVehicle *v, SUMOTime leaveTime, const MSMoveReminder::Notification reason)
Removes the given car from the edge's que.
std::vector< const MEVehicle * > getVehicles() const
returns all vehicles (for debugging)
double getCapacity() const
Returns the sum of the lengths of all usable lanes of the segment in meters.
Definition MESegment.h:290
static MSEdge myDummyParent
Definition MESegment.h:679
@ PROCEED_NO
the vehicle must stay on the current segment
Definition MESegment.h:79
@ PROCEED_NO_TLS
vehicle want's to change to right lane
Definition MESegment.h:81
@ PROCEED_YES
the vehicle may proceed to the next segment
Definition MESegment.h:77
void recomputeJamThreshold(double jamThresh)
compute a value for myJamThreshold if jamThresh is negative, compute a value which allows free flow a...
double getMeanSpeed() const
wrapper to satisfy the FunctionBinding signature
Definition MESegment.h:340
SUMOTime getQueueBlockTime(int index) const
Definition MESegment.h:257
int getCarNumber() const
Returns the total number of cars on the segment.
Definition MESegment.h:233
bool overtake(const MEVehicle *veh) const
whether veh overtakes the queue's last vehicle, drawn from a number specific to vehicle and segment
void loadState(const std::vector< SUMOVehicle * > &vehs, const SUMOTime blockTime, const SUMOTime entryBlockTime, const int queIdx)
Loads the state of this segment with the given parameters.
double myTau_length
Headway parameter for computing gross time headyway from net time headway, length and edge speed.
Definition MESegment.h:651
SUMOTime myTau_jj
Definition MESegment.h:631
SUMOTime newArrival(const MEVehicle *const v, double newSpeed, SUMOTime currentTime)
compute the new arrival time when switching speed
bool myJunctionControl
Whether junction control is enabled.
Definition MESegment.h:641
virtual bool hasSpaceForInsertion(const Queue &q, int qIdx, double newOccupancy, SUMOTime entryTime) const
check jam-avoidance constraints during insertion
bool myTLSPenalty
Whether tls penalty is enabled.
Definition MESegment.h:634
static const double DO_NOT_PATCH_JAM_THRESHOLD
Definition MESegment.h:52
SUMOTime getMinTauWithVehLength(double lengthWithGap, double vehicleTau) const
convert net time gap (leader back to follower front) to gross time gap (leader front to follower fron...
Definition MESegment.h:546
double getFlow() const
returns flow based on headway
static bool isInvalid(const MESegment *segment)
whether the given segment is 0 or encodes vaporization
Definition MESegment.h:498
SUMOTime getNextInsertionTime(SUMOTime earliestEntry) const
return a time after earliestEntry at which a vehicle may be inserted at full speed
double myCapacity
The number of lanes represented by the queue * the length of the lane.
Definition MESegment.h:654
bool myOvertaking
Whether overtaking is permitted on this segment.
Definition MESegment.h:644
void prepareDetectorForWriting(MSMoveReminder &data, int queueIndex=-1)
Removes a data collector for a detector from this segment.
std::map< std::pair< const MSEdge *, std::vector< int > >, std::vector< std::pair< double, int > > > SearchedMap
the (distance, depth) pairs at which a downstream edge was searched with a given lane reach
Definition MESegment.h:602
bool vaporizeAnyCar(SUMOTime currentTime, const MSDetectorFileOutput *filter)
tries to remove any car from this segment
SUMOTime myTau_fj
Definition MESegment.h:631
SUMOTime getTauJJ(double nextQueueSize, double nextQueueCapacity, double nextJamThreshold) const
A vehicle from the mesoscopic point of view.
Definition MEVehicle.h:42
double getLastEntryTimeSeconds() const
Returns the entry time for the current segment.
Definition MEVehicle.h:368
void markJammed(bool jammed)
Definition MEVehicle.h:413
double estimateLeaveSpeed(const MSLink *link) const
Returns the vehicle's estimated speed after driving across the link.
void processStop()
ends the current stop and performs loading/unloading
SUMOTime getWaitingTime(const bool accumulated=false) const
Returns the duration for which the vehicle was blocked.
Definition MEVehicle.h:347
bool hasArrived() const
Returns whether this vehicle has already arrived (reached the arrivalPosition on its final edge)
bool moveRoutePointer()
Update when the vehicle enters a new edge in the move step.
double getMesoPosition() const
Returns the cached interpolated mesoscopic position.
Definition MEVehicle.h:280
void updateDetectors(const SUMOTime currentTime, const SUMOTime exitTime, const bool isLeave, const MSMoveReminder::Notification reason=MSMoveReminder::NOTIFICATION_JUNCTION)
Updates all vehicle detectors.
SUMOTime checkStop(SUMOTime time)
Returns until when to stop at the current segment and sets the information that the stop has been rea...
void setUnqueuedEventTime(SUMOTime t)
Sets the minimum time at which the vehicle leaves its current segment (this includes planned stops)
Definition MEVehicle.h:235
SUMOTime getLastEntryTime() const
Returns the time the vehicle entered the current segment.
Definition MEVehicle.h:318
void setEventTime(SUMOTime t, bool hasDelay=true)
Sets the (planned) time at which the vehicle leaves its current segment.
Definition MEVehicle.h:206
void setMesoPosition(double pos, int overlap)
Sets the interpolated position and lateral overlap offset.
Definition MEVehicle.h:285
MESegment * getSegment() const
Returns the current segment the vehicle is on.
Definition MEVehicle.h:266
bool wasJammed() const
Definition MEVehicle.h:417
void setLastEntryTime(SUMOTime t)
Sets the entry time for the current segment.
Definition MEVehicle.h:310
int getQueIndex() const
Returns the index of the que the vehicle is in.
Definition MEVehicle.h:275
virtual void setSegment(MESegment *s, int idx=0)
Sets the current segment the vehicle is at together with its que.
Definition MEVehicle.h:250
SUMOTime getEventTime() const
Returns the (planned) time at which the vehicle leaves its current segment.
Definition MEVehicle.h:218
void invalidateMesoPosition()
Invalidates the cached interpolated position.
Definition MEVehicle.h:296
void setBlockTime(const SUMOTime t)
Sets the time at which the vehicle was blocked.
Definition MEVehicle.h:332
double getSpeed() const
Returns the vehicle's estimated speed assuming no delays.
double getImpatience() const
Returns this vehicles impatience.
const MSEdge * succEdge(int nSuccs) const
Returns the nSuccs'th successor of edge the vehicle is currently at.
int getInsertionChecks() const
const SUMOVehicleParameter & getParameter() const
Returns the vehicle's parameter (including departure definition)
bool isRail() const
bool isParking() const
Returns whether the vehicle is parking.
const MSEdge * getEdge() const
Returns the edge the vehicle is currently at.
void addReminder(MSMoveReminder *rem, double pos=0)
Adds a MoveReminder dynamically.
virtual void activateReminders(const MSMoveReminder::Notification reason, const MSLane *enteredLane=0)
"Activates" all current move reminder
SUMOVehicleClass getVClass() const
Returns the vehicle's access class.
void onDepart()
Called when the vehicle is inserted into the network.
long long int getRandomSeed() const
return vehicle-specific random number
const MSVehicleType & getVehicleType() const
Returns the vehicle's type definition.
bool isStopped() const
Returns whether the vehicle is at a stop.
double getMaxDecel() const
Get the vehicle type's maximal comfortable deceleration [m/s^2].
Definition MSCFModel.h:285
virtual double getHeadwayTime() const
Get the driver's desired headway [s].
Definition MSCFModel.h:355
Base of value-generating classes (detectors)
bool vehicleApplies(const SUMOTrafficObject &veh) const
Checks whether the detector measures vehicles of the given type.
bool sidingDeadlock(const SUMOVehicle *veh) const
whether insertion on this driveway would cause deadlock in an approached siding
static const MSDriveWay * getDepartureDriveway(const SUMOVehicle *veh, bool init=false)
bool foeDriveWayOccupied(bool store, const SUMOVehicle *ego, MSEdgeVector &occupied) const
whether any of myFoes is occupied (vehicles that are the target of a join must be ignored)
A road/street connecting two junctions.
Definition MSEdge.h:78
virtual void unlock() const
release exclusive access to the mesoscopic state
Definition MSEdge.h:802
SVCPermissions getPermissions() const
Returns the combined permissions of all lanes of this edge.
Definition MSEdge.h:659
const std::vector< MSLane * > & getLanes() const
Returns this edge's lanes.
Definition MSEdge.h:169
const std::vector< MSLane * > * allowedLanes(const MSEdge &destination, SUMOVehicleClass vclass=SVC_IGNORING, bool ignoreTransientPermissions=false) const
Get the allowed lanes to reach the destination-edge.
Definition MSEdge.cpp:516
bool isNormal() const
return whether this edge is an internal edge
Definition MSEdge.h:265
double getSpeedLimit() const
Returns the speed limit of the edge @caution The speed limit of the first lane is returned; should pr...
Definition MSEdge.cpp:1235
const MSJunction * getToJunction() const
Definition MSEdge.h:428
double getLength() const
return the length of the edge
Definition MSEdge.h:695
static SVCPermissions getMesoPermissions(SVCPermissions p, SVCPermissions ignoreIgnored=0)
Definition MSEdge.cpp:317
bool isRoundabout() const
Definition MSEdge.h:743
bool isInternal() const
return whether this edge is an internal edge
Definition MSEdge.h:270
bool isVaporizing() const
Returns whether vehicles on this edge shall be vaporized.
Definition MSEdge.h:444
void addWaiting(SUMOVehicle *vehicle) const
Adds a vehicle to the list of waiting vehicles.
Definition MSEdge.cpp:1534
bool hasMinorLink() const
whether any lane has a minor link
Definition MSEdge.cpp:1433
virtual void lock() const
grant exclusive access to the mesoscopic state
Definition MSEdge.h:799
const MSEdgeVector & getSuccessors(SUMOVehicleClass vClass=SVC_IGNORING) const
Returns the following edges, restricted by vClass.
Definition MSEdge.cpp:1342
static MELoop * gMesoNet
mesoscopic simulation infrastructure
Definition MSGlobals.h:115
static bool gMesoLimitedJunctionControl
Definition MSGlobals.h:109
SumoXMLNodeType getType() const
return the type of this Junction
Definition MSJunction.h:133
Representation of a lane in the micro simulation.
Definition MSLane.h:84
double getVehicleMaxSpeed(const SUMOTrafficObject *const veh) const
Returns the lane's maximum speed, given a vehicle's speed limit adaptation.
Definition MSLane.h:575
MSEdge & getEdge() const
Returns the lane's edge.
Definition MSLane.h:790
const std::vector< MSLink * > & getLinkCont() const
returns the container with all links !!!
Definition MSLane.h:750
Something on a lane to be noticed about vehicle movement.
Notification
Definition of a vehicle state.
@ NOTIFICATION_ARRIVED
The vehicle arrived at its destination (is deleted)
@ NOTIFICATION_VAPORIZED_CALIBRATOR
The vehicle got removed by a calibrator.
@ NOTIFICATION_DEPARTED
The vehicle has departed (was inserted into the network)
@ NOTIFICATION_SEGMENT
The vehicle changes the segment (meso only)
@ NOTIFICATION_VAPORIZED_VAPORIZER
The vehicle got vaporized with a vaporizer.
@ NOTIFICATION_JUNCTION
The vehicle arrived at a junction.
static MSNet * getInstance()
Returns the pointer to the unique instance of MSNet (singleton).
Definition MSNet.cpp:201
SUMOTime getCurrentTimeStep() const
Returns the current simulation step.
Definition MSNet.h:335
MSVehicleControl & getVehicleControl()
Returns the vehicle control.
Definition MSNet.h:403
static bool isSignalized(SUMOVehicleClass svc)
void scheduleVehicleRemoval(SUMOVehicle *veh, bool checkDuplicate=false)
Removes a vehicle after it has ended.
double getLengthWithGap() const
Get vehicle's length including the minimum gap [m].
const MSCFModel & getCarFollowModel() const
Returns the vehicle type's car following model definition (const version)
static void writeVehicle(OutputDevice &of, const MSBaseVehicle &veh)
Writes the dump of the given vehicle into the given device.
Base class for objects which have an id.
Definition Named.h:53
static std::string getIDSecure(const T *obj, const std::string &fallBack="NULL")
get an identifier for Named-like object which may be Null
Definition Named.h:66
const std::string & getID() const
Returns the id.
Definition Named.h:73
Static storage of an output device and its base (abstract) implementation.
OutputDevice & openTag(const std::string &xmlElement)
Opens an XML tag.
OutputDevice & writeAttr(const ATTR_TYPE &attr, const T &val, const bool isNull=false, const bool escape=false)
writes a named attribute
bool closeTag(const std::string &comment="")
Closes the most recently opened tag and optionally adds a comment.
static double randHash(long long int x)
return a value scrambled value from [0, 1]
Definition RandHelper.h:257
static uint32_t murmur3_32(const std::string &key2, int seed)
string hashing adapted from https://en.wikipedia.org/wiki/MurmurHash
Definition RandHelper.h:266
Representation of a vehicle.
Definition SUMOVehicle.h:63
DepartDefinition departProcedure
Information how the vehicle shall choose the depart time.
#define DEBUG_COND
edge type specific meso parameters
Definition MESegment.h:58