Eclipse SUMO - Simulation of Urban MObility
Loading...
Searching...
No Matches
MESegment.h
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#pragma once
21#include <config.h>
22
23#include <vector>
24#include <cassert>
26#include <utils/common/Named.h>
29
30
31// ===========================================================================
32// class declarations
33// ===========================================================================
34class SUMOVehicle;
35class MSEdge;
36class MSLink;
39class MEVehicle;
40class OutputDevice;
41
42
43// ===========================================================================
44// class definitions
45// ===========================================================================
50class MESegment : public Named {
51public:
52 static const double DO_NOT_PATCH_JAM_THRESHOLD;
53 static const int PARKING_QUEUE = -1;
55 static const std::string OVERRIDE_TLS_PENALTIES;
56
72
73
74protected:
75 class Queue {
76 public:
77 Queue(const SVCPermissions permissions) : myPermissions(permissions) {}
78 inline int size() const {
79 return (int)myVehicles.size();
80 }
81 inline const std::vector<MEVehicle*>& getVehicles() const {
82 return myVehicles;
83 }
85 inline std::vector<MEVehicle*>& getModifiableVehicles() {
86 return myVehicles;
87 }
88 inline double getOccupancy() const {
89 return myOccupancy;
90 }
91 inline void setOccupancy(const double occ) {
92 myOccupancy = occ;
93 }
94 inline bool allows(SUMOVehicleClass vclass) const {
95 return (myPermissions & vclass) == vclass;
96 }
97
99 inline SUMOTime getEntryBlockTime() const {
100 return myEntryBlockTime;
101 }
102
104 inline void setEntryBlockTime(SUMOTime entryBlockTime) {
105 myEntryBlockTime = entryBlockTime;
106 }
107
108 inline SUMOTime getBlockTime() const {
109 return myBlockTime;
110 }
111 inline void setBlockTime(SUMOTime t) {
112 myBlockTime = t;
113 }
114
116 myPermissions = p;
117 }
118
119 void addDetector(MSMoveReminder* data);
120
121 void addReminders(MEVehicle* veh) const;
122
123 private:
126
127 std::vector<MEVehicle*> myVehicles;
128
130 double myOccupancy = 0.;
131
134
137
139 std::vector<MSMoveReminder*> myDetectorData;
140
141 };
142
143public:
154 MESegment(const std::string& id,
155 const MSEdge& parent, MESegment* next,
156 const double length, const double speed,
157 const int idx,
158 const bool multiQueue,
159 const MesoEdgeType& edgeType);
160
162 void initSegment(const MesoEdgeType& edgeType, const MSEdge& parent, const double capacity);
163
166
172 void addDetector(MSMoveReminder* data, int queueIndex = -1);
173
179 // void removeDetector(MSMoveReminder* data);
180
186 void prepareDetectorForWriting(MSMoveReminder& data, int queueIndex = -1);
188
197 SUMOTime hasSpaceFor(const MEVehicle* const veh, const SUMOTime entryTime, int& qIdx, const bool init = false) const;
198
200 virtual void updateEntryBlockTime(SUMOTime /*time*/) {}
201
203 virtual std::string getQueueExtraState(int /*qIdx*/) const {
204 return "";
205 }
206 virtual void loadQueueExtraState(int /*qIdx*/, const std::string& /*state*/, SUMOTime /*offset*/) {}
207
214 bool initialise(MEVehicle* veh, SUMOTime time);
215
220 inline int getCarNumber() const {
221 return myNumVehicles;
222 }
223
225 inline int numQueues() const {
226 return (int)myQueues.size();
227 }
231 inline const std::vector<MEVehicle*>& getQueue(int index) const {
232 assert(index < (int)myQueues.size());
233 return myQueues[index].getVehicles();
234 }
235
236 inline SUMOTime getQueueBlockTime(int index) const {
237 assert(index < (int)myQueues.size());
238 return myQueues[index].getBlockTime();
239 }
240
245 inline int getIndex() const {
246 return myIndex;
247 }
248
253 inline MESegment* getNextSegment() const {
254 return myNextSegment;
255 }
256
261 inline double getLength() const {
262 return myLength;
263 }
264
269 inline double getCapacity() const {
270 return myCapacity;
271 }
272
277 inline double getBruttoOccupancy() const {
278 double occ = 0.;
279 for (const Queue& q : myQueues) {
280 occ += q.getOccupancy();
281 }
282 return occ;
283 }
284
288 inline double getRelativeOccupancy() const {
290 }
291
296 inline double getRelativeJamThreshold() const {
297 return myJamThreshold / myCapacity;
298 }
299
310 double getMeanSpeed(bool useCache) const;
311
313 void resetCachedSpeeds();
314
316 inline double getMeanSpeed() const {
317 return getMeanSpeed(true);
318 }
319
320
321 void writeVehicles(OutputDevice& of) const;
322
331
341 MSLink* getLink(const MEVehicle* veh, bool tlsPenalty = false) const;
342
350 bool isOpen(const MEVehicle* veh) const;
351
359 virtual void send(MEVehicle* veh, MESegment* const next, const int nextQIdx, SUMOTime time, const MSMoveReminder::Notification reason);
360
368 void receive(MEVehicle* veh, const int qIdx, SUMOTime time, const bool isDepart = false, const bool isTeleport = false, const bool newEdge = false);
369
370
376 bool vaporizeAnyCar(SUMOTime currentTime, const MSDetectorFileOutput* filter);
377
381 inline const MSEdge& getEdge() const {
382 return myEdge;
383 }
384
385
390 void setSpeed(double newSpeed, SUMOTime currentTime, double jamThresh = DO_NOT_PATCH_JAM_THRESHOLD, int qIdx = -1);
391
395 SUMOTime getEventTime() const;
396
398 inline double getEventTimeSeconds() const {
399 return STEPS2TIME(getEventTime());
400 }
401
403 inline double getLastHeadwaySeconds() const {
405 }
406
408 inline SUMOTime getLastHeadway() const {
409 return myLastHeadway;
410 }
411
413 void setLastHeadway(SUMOTime headway) {
414 myLastHeadway = headway;
415 }
416
418 inline double getEntryBlockTimeSeconds() const {
420 for (const Queue& q : myQueues) {
421 t = MIN2(t, q.getEntryBlockTime());
422 }
423 return STEPS2TIME(t);
424 }
425
427 double getWaitingSeconds() const;
428
431
441 void saveState(OutputDevice& out) const;
442
444 void clearState();
445
460 void loadState(const std::vector<SUMOVehicle*>& vehs, const SUMOTime blockTime, const SUMOTime entryBlockTime, const int queIdx);
462
463
466 std::vector<const MEVehicle*> getVehicles() const;
467
471 double getFlow() const;
472
474 static inline bool isInvalid(const MESegment* segment) {
475 return segment == nullptr || segment == &myVaporizationTarget;
476 }
477
479 SUMOTime getNextInsertionTime(SUMOTime earliestEntry) const;
480
482 inline int remainingVehicleCapacity(const double vehLength) const {
483 int cap = 0;
484 for (const Queue& q : myQueues) {
485 if (q.getOccupancy() == 0. && myQueueCapacity < vehLength) {
486 // even small segments can hold at least one vehicle
487 cap += 1;
488 } else {
489 cap += (int)((myQueueCapacity - q.getOccupancy()) / vehLength);
490 }
491 }
492 return cap;
493 }
494
497 return myTau_ff;
498 }
499
501 void addReminders(MEVehicle* veh) const;
502
507 SUMOTime getLinkPenalty(const MEVehicle* veh) const;
508
510 void updatePermissions();
511
514 myTLSPenalty = false;
515 }
516
518 inline SUMOTime getMinTauWithVehLength(double lengthWithGap, double vehicleTau) const {
519 return (SUMOTime)((double)myTau_ff * vehicleTau + lengthWithGap * myTau_length);
520 }
521
523 inline SUMOTime getTauWithVehLength(int qIdx, double lengthWithGap, double vehicleTau) const {
524 assert(qIdx >= 0 && qIdx < (int)myQueues.size());
525 const SUMOTime tau = myQueues[qIdx].getOccupancy() < myJamThreshold ? myTau_ff : myTau_jf;
526 return tauWithVehLength(tau, lengthWithGap, vehicleTau);
527 }
528
529protected:
530 bool overtake();
531
532 void setSpeedForQueue(double newSpeed, SUMOTime currentTime,
533 SUMOTime blockTime, const std::vector<MEVehicle*>& vehs);
534
537 SUMOTime newArrival(const MEVehicle* const v, double newSpeed, SUMOTime currentTime);
538
540 bool hasBlockedLeader() const;
541
546 void recomputeJamThreshold(double jamThresh);
547
549 double jamThresholdForSpeed(double speed, double jamThresh) const;
550
552 bool limitedControlOverride(const MSLink* link) const;
553
555 inline SUMOTime tauWithVehLength(SUMOTime tau, double lengthWithGap, double vehicleTau) const {
556 return (SUMOTime)((double)tau * vehicleTau + lengthWithGap * myTau_length);
557 }
558
559 SUMOTime getTauJJ(double nextQueueSize, double nextQueueCapacity, double nextJamThreshold) const;
560
562 virtual SUMOTime computeHeadway(Queue& q, const Queue& qNext, const MESegment* const next, const MEVehicle* veh) const;
563
565 virtual bool hasSpaceForInsertion(const Queue& q, int qIdx, double newOccupancy, SUMOTime entryTime) const;
566
568 typedef std::map<std::pair<const MSEdge*, std::vector<int> >, std::vector<std::pair<double, int> > > SearchedMap;
569
578 void addDownstreamFollowers(const MSEdge& edge, const std::vector<int>& reach, const double dist, const double lookahead, const int depth, SearchedMap& searched);
579
580protected:
583
586
588 const double myLength;
589
591 const int myIndex;
592
595
598
601
603 bool myCheckMinorPenalty; // for legacy compatibility (#7802, 7804)
605
608
612
615
617 double myCapacity = 0.;
618
620 double myQueueCapacity = 0.;
621
624
626 std::vector<Queue> myQueues;
627
630
632 std::map<const MSEdge*, int> myFollowerMap;
633
635 int myLookahead = 1;
636
639
640 /* @brief segment for signifying vaporization. This segment has invalid
641 * data and should only be used as a unique pointer */
644
646
648 mutable double myMeanSpeed;
649
652
653private:
656
659
661 MESegment(const std::string& id);
662};
long long int SUMOTime
Definition GUI.h:36
#define STEPS2TIME(x)
Definition SUMOTime.h:58
#define SUMOTime_MAX
Definition SUMOTime.h:34
#define SUMOTime_MIN
Definition SUMOTime.h:35
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.
T MIN2(T a, T b)
Definition StdDefs.h:80
int size() const
Definition MESegment.h:78
void setOccupancy(const double occ)
Definition MESegment.h:91
MEVehicle * remove(MEVehicle *v)
Definition MESegment.cpp:73
void setBlockTime(SUMOTime t)
Definition MESegment.h:111
SUMOTime getBlockTime() const
Definition MESegment.h:108
double myOccupancy
The occupied space (in m) in the queue.
Definition MESegment.h:130
bool allows(SUMOVehicleClass vclass) const
Definition MESegment.h:94
std::vector< MEVehicle * > & getModifiableVehicles()
Definition MESegment.h:85
void addReminders(MEVehicle *veh) const
Definition MESegment.cpp:98
SUMOTime myBlockTime
The block time.
Definition MESegment.h:136
void addDetector(MSMoveReminder *data)
Definition MESegment.cpp:90
void setEntryBlockTime(SUMOTime entryBlockTime)
set the next time at which a vehicle may enter this queue
Definition MESegment.h:104
SUMOTime myEntryBlockTime
The block time for vehicles who wish to enter this queue.
Definition MESegment.h:133
double getOccupancy() const
Definition MESegment.h:88
std::vector< MSMoveReminder * > myDetectorData
The data collection for all kinds of detectors.
Definition MESegment.h:139
std::vector< MEVehicle * > myVehicles
Definition MESegment.h:127
const std::vector< MEVehicle * > & getVehicles() const
Definition MESegment.h:81
Queue(const SVCPermissions permissions)
Definition MESegment.h:77
SUMOTime getEntryBlockTime() const
return the next time at which a vehicle may enter this queue
Definition MESegment.h:99
void setPermissions(SVCPermissions p)
Definition MESegment.h:115
SVCPermissions myPermissions
The vClass permissions for this queue.
Definition MESegment.h:125
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:620
bool overtake()
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:555
SUMOTime myTau_ff
The time headway parameters, see the Eissfeldt thesis.
Definition MESegment.h:597
double getEntryBlockTimeSeconds() const
get the earliest entry time in seconds
Definition MESegment.h:418
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:626
double getBruttoOccupancy() const
Returns the occupany of the segment (the sum of the vehicle lengths + minGaps)
Definition MESegment.h:277
SUMOTime myLastHeadway
the last headway
Definition MESegment.h:638
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
bool isOpen(const MEVehicle *veh) const
Returns whether the vehicle may use the next link.
void addDetector(MSMoveReminder *data, int queueIndex=-1)
Adds a data collector for a detector to this segment.
double getLastHeadwaySeconds() const
get the last headway time in seconds
Definition MESegment.h:403
double getRelativeOccupancy() const
Returns the relative occupany of the segment (percentage of road used))
Definition MESegment.h:288
void overrideTLSPenalty()
whether the traffic light should use normal junction control despite penalty options
Definition MESegment.h:513
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:645
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:632
SUMOTime getTauWithVehLength(int qIdx, double lengthWithGap, double vehicleTau) const
like getMinTauWithVehLength but using the jam-state dependent net time gap of the given queue (as in ...
Definition MESegment.h:523
MSLink * getLink(const MEVehicle *veh, bool tlsPenalty=false) const
Returns the link the given car will use when passing the next junction.
int myNumVehicles
The cached value for the number of vehicles.
Definition MESegment.h:629
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:261
SUMOTime getLastHeadway() const
get the last headway time
Definition MESegment.h:408
MESegment(const MESegment &)
Invalidated copy constructor.
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:231
void updatePermissions()
called when permissions change due to Rerouter or TraCI
MESegment & operator=(const MESegment &)
Invalidated assignment operator.
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
const MSEdge & getEdge() const
Returns the edge this segment belongs to.
Definition MESegment.h:381
static MESegment myVaporizationTarget
Definition MESegment.h:643
int numQueues() const
return the number of queues
Definition MESegment.h:225
int myLookahead
The number of route edges after myEdge to look up in myFollowerMap.
Definition MESegment.h:635
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:203
double myJamThreshold
The space (in m) which needs to be occupied before the segment is considered jammed.
Definition MESegment.h:623
const int myIndex
Running number of the segment in the edge.
Definition MESegment.h:591
virtual void updateEntryBlockTime(SUMOTime)
update entry blockTime for all queues
Definition MESegment.h:200
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:604
double myMeanSpeed
the mean speed on this segment. Updated at event time or on demand
Definition MESegment.h:648
bool myCheckMinorPenalty
penalty for minor links
Definition MESegment.h:603
virtual SUMOTime computeHeadway(Queue &q, const Queue &qNext, const MESegment *const next, const MEVehicle *veh) const
compute current headway depending on traffic state
void setLastHeadway(SUMOTime headway)
restores the last headway time (when loading state)
Definition MESegment.h:413
double jamThresholdForSpeed(double speed, double jamThresh) const
compute jam threshold for the given speed and jam-threshold option
virtual void loadQueueExtraState(int, const std::string &, SUMOTime)
Definition MESegment.h:206
SUMOTime myLastMeanSpeedUpdate
the time at which myMeanSpeed was last updated
Definition MESegment.h:651
SUMOTime myTau_jf
Definition MESegment.h:597
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:585
double getRelativeJamThreshold() const
Returns the relative occupany of the segment (percentage of road used)) at which the segment is consi...
Definition MESegment.h:296
bool hasBlockedLeader() const
whether a leader in any queue is blocked
int remainingVehicleCapacity(const double vehLength) const
return the remaining physical space on this segment
Definition MESegment.h:482
double getWaitingSeconds() const
Get the waiting time for vehicles in all queues.
const double myLength
The segment's length.
Definition MESegment.h:588
SUMOTime getMinimumHeadwayTime() const
return the minimum headway-time with which vehicles may enter or leave this segment
Definition MESegment.h:496
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:582
static const std::string OVERRIDE_TLS_PENALTIES
special param value
Definition MESegment.h:55
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:269
double getEventTimeSeconds() const
Like getEventTime but returns seconds (for visualization)
Definition MESegment.h:398
static MSEdge myDummyParent
Definition MESegment.h:642
void recomputeJamThreshold(double jamThresh)
compute a value for myJamThreshold if jamThresh is negative, compute a value which allows free flow a...
int getIndex() const
Returns the running index of the segment in the edge (0 is the most upstream).
Definition MESegment.h:245
double getMeanSpeed() const
wrapper to satisfy the FunctionBinding signature
Definition MESegment.h:316
SUMOTime getQueueBlockTime(int index) const
Definition MESegment.h:236
int getCarNumber() const
Returns the total number of cars on the segment.
Definition MESegment.h:220
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:614
SUMOTime myTau_jj
Definition MESegment.h:597
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:607
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:600
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:518
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:474
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:617
bool myOvertaking
Whether overtaking is permitted on this segment.
Definition MESegment.h:610
void prepareDetectorForWriting(MSMoveReminder &data, int queueIndex=-1)
Removes a data collector for a detector from this segment.
MESegment * getNextSegment() const
Returns the following segment on the same edge (0 if it is the last).
Definition MESegment.h:253
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:568
bool vaporizeAnyCar(SUMOTime currentTime, const MSDetectorFileOutput *filter)
tries to remove any car from this segment
SUMOTime myTau_fj
Definition MESegment.h:597
SUMOTime getTauJJ(double nextQueueSize, double nextQueueCapacity, double nextJamThreshold) const
A vehicle from the mesoscopic point of view.
Definition MEVehicle.h:42
Base of value-generating classes (detectors)
A road/street connecting two junctions.
Definition MSEdge.h:78
Something on a lane to be noticed about vehicle movement.
Notification
Definition of a vehicle state.
The class responsible for building and deletion of vehicles.
Base class for objects which have an id.
Definition Named.h:53
Static storage of an output device and its base (abstract) implementation.
Representation of a vehicle.
Definition SUMOVehicle.h:63
edge type specific meso parameters
Definition MESegment.h:58