Eclipse SUMO - Simulation of Urban MObility
All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
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-2025 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;
54 static const std::string OVERRIDE_TLS_PENALTIES;
55
69
70
71private:
72 class Queue {
73 public:
74 Queue(const SVCPermissions permissions) : myPermissions(permissions) {}
75 inline int size() const {
76 return (int)myVehicles.size();
77 }
78 inline const std::vector<MEVehicle*>& getVehicles() const {
79 return myVehicles;
80 }
82 inline std::vector<MEVehicle*>& getModifiableVehicles() {
83 return myVehicles;
84 }
85 inline double getOccupancy() const {
86 return myOccupancy;
87 }
88 inline void setOccupancy(const double occ) {
89 myOccupancy = occ;
90 }
91 inline bool allows(SUMOVehicleClass vclass) const {
92 return (myPermissions & vclass) == vclass;
93 }
94
96 inline SUMOTime getEntryBlockTime() const {
97 return myEntryBlockTime;
98 }
99
101 inline void setEntryBlockTime(SUMOTime entryBlockTime) {
102 myEntryBlockTime = entryBlockTime;
103 }
104
105 inline SUMOTime getBlockTime() const {
106 return myBlockTime;
107 }
108 inline void setBlockTime(SUMOTime t) {
109 myBlockTime = t;
110 }
111
113 myPermissions = p;
114 }
115
116 void addDetector(MSMoveReminder* data);
117
118 void addReminders(MEVehicle* veh) const;
119
120 private:
123
124 std::vector<MEVehicle*> myVehicles;
125
127 double myOccupancy = 0.;
128
131
134
136 std::vector<MSMoveReminder*> myDetectorData;
137
138 };
139
140public:
151 MESegment(const std::string& id,
152 const MSEdge& parent, MESegment* next,
153 const double length, const double speed,
154 const int idx,
155 const bool multiQueue,
156 const MesoEdgeType& edgeType);
157
159 void initSegment(const MesoEdgeType& edgeType, const MSEdge& parent, const double capacity);
160
163
169 void addDetector(MSMoveReminder* data, int queueIndex = -1);
170
176 // void removeDetector(MSMoveReminder* data);
177
183 void prepareDetectorForWriting(MSMoveReminder& data, int queueIndex = -1);
185
194 SUMOTime hasSpaceFor(const MEVehicle* const veh, const SUMOTime entryTime, int& qIdx, const bool init = false) const;
195
202 bool initialise(MEVehicle* veh, SUMOTime time);
203
208 inline int getCarNumber() const {
209 return myNumVehicles;
210 }
211
213 inline int numQueues() const {
214 return (int)myQueues.size();
215 }
219 inline const std::vector<MEVehicle*>& getQueue(int index) const {
220 assert(index < (int)myQueues.size());
221 return myQueues[index].getVehicles();
222 }
223
228 inline int getIndex() const {
229 return myIndex;
230 }
231
236 inline MESegment* getNextSegment() const {
237 return myNextSegment;
238 }
239
244 inline double getLength() const {
245 return myLength;
246 }
247
252 inline double getCapacity() const {
253 return myCapacity;
254 }
255
260 inline double getBruttoOccupancy() const {
261 double occ = 0.;
262 for (const Queue& q : myQueues) {
263 occ += q.getOccupancy();
264 }
265 return occ;
266 }
267
271 inline double getRelativeOccupancy() const {
273 }
274
279 inline double getRelativeJamThreshold() const {
280 return myJamThreshold / myCapacity;
281 }
282
293 double getMeanSpeed(bool useCache) const;
294
296 inline double getMeanSpeed() const {
297 return getMeanSpeed(true);
298 }
299
300
301 void writeVehicles(OutputDevice& of) const;
302
311
321 MSLink* getLink(const MEVehicle* veh, bool tlsPenalty = false) const;
322
330 bool isOpen(const MEVehicle* veh) const;
331
339 void send(MEVehicle* veh, MESegment* const next, const int nextQIdx, SUMOTime time, const MSMoveReminder::Notification reason);
340
348 void receive(MEVehicle* veh, const int qIdx, SUMOTime time, const bool isDepart = false, const bool isTeleport = false, const bool newEdge = false);
349
350
356 bool vaporizeAnyCar(SUMOTime currentTime, const MSDetectorFileOutput* filter);
357
361 inline const MSEdge& getEdge() const {
362 return myEdge;
363 }
364
365
370 void setSpeed(double newSpeed, SUMOTime currentTime, double jamThresh = DO_NOT_PATCH_JAM_THRESHOLD, int qIdx = -1);
371
375 SUMOTime getEventTime() const;
376
378 inline double getEventTimeSeconds() const {
379 return STEPS2TIME(getEventTime());
380 }
381
383 inline double getLastHeadwaySeconds() const {
385 }
386
388 inline double getEntryBlockTimeSeconds() const {
390 for (const Queue& q : myQueues) {
391 t = MIN2(t, q.getEntryBlockTime());
392 }
393 return STEPS2TIME(t);
394 }
395
397 double getWaitingSeconds() const;
398
401
411 void saveState(OutputDevice& out) const;
412
414 void clearState();
415
430 void loadState(const std::vector<SUMOVehicle*>& vehs, const SUMOTime blockTime, const int queIdx);
432
433
436 std::vector<const MEVehicle*> getVehicles() const;
437
441 double getFlow() const;
442
444 static inline bool isInvalid(const MESegment* segment) {
445 return segment == nullptr || segment == &myVaporizationTarget;
446 }
447
449 SUMOTime getNextInsertionTime(SUMOTime earliestEntry) const;
450
452 inline int remainingVehicleCapacity(const double vehLength) const {
453 int cap = 0;
454 for (const Queue& q : myQueues) {
455 if (q.getOccupancy() == 0. && myQueueCapacity < vehLength) {
456 // even small segments can hold at least one vehicle
457 cap += 1;
458 } else {
459 cap += (int)((myQueueCapacity - q.getOccupancy()) / vehLength);
460 }
461 }
462 return cap;
463 }
464
467 return myTau_ff;
468 }
469
471 void addReminders(MEVehicle* veh) const;
472
477 SUMOTime getLinkPenalty(const MEVehicle* veh) const;
478
480 void updatePermissions();
481
482private:
483 bool overtake();
484
485 void setSpeedForQueue(double newSpeed, SUMOTime currentTime,
486 SUMOTime blockTime, const std::vector<MEVehicle*>& vehs);
487
490 SUMOTime newArrival(const MEVehicle* const v, double newSpeed, SUMOTime currentTime);
491
493 bool hasBlockedLeader() const;
494
499 void recomputeJamThreshold(double jamThresh);
500
502 double jamThresholdForSpeed(double speed, double jamThresh) const;
503
505 bool limitedControlOverride(const MSLink* link) const;
506
508 inline SUMOTime tauWithVehLength(SUMOTime tau, double lengthWithGap, double vehicleTau) const {
509 return (SUMOTime)((double)tau * vehicleTau + lengthWithGap * myTau_length);
510 }
511
512 SUMOTime getTauJJ(double nextQueueSize, double nextQueueCapacity, double nextJamThreshold) const;
513
515 bool tlsPenaltyOverride() const;
516
517private:
520
523
525 const double myLength;
526
528 const int myIndex;
529
532
535
538
540 bool myCheckMinorPenalty; // for legacy compatibility (#7802, 7804)
542
545
549
552
554 double myCapacity = 0.;
555
557 double myQueueCapacity = 0.;
558
561
563 std::vector<Queue> myQueues;
564
567
569 std::map<const MSEdge*, int> myFollowerMap;
570
573
574 /* @brief segment for signifying vaporization. This segment has invalid
575 * data and should only be used as a unique pointer */
578
580 mutable double myMeanSpeed;
581
584
585private:
588
591
593 MESegment(const std::string& id);
594};
long long int SUMOTime
Definition GUI.h:36
#define STEPS2TIME(x)
Definition SUMOTime.h:55
#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:76
int size() const
Definition MESegment.h:75
void setOccupancy(const double occ)
Definition MESegment.h:88
MEVehicle * remove(MEVehicle *v)
Definition MESegment.cpp:69
void setBlockTime(SUMOTime t)
Definition MESegment.h:108
SUMOTime getBlockTime() const
Definition MESegment.h:105
double myOccupancy
The occupied space (in m) in the queue.
Definition MESegment.h:127
bool allows(SUMOVehicleClass vclass) const
Definition MESegment.h:91
std::vector< MEVehicle * > & getModifiableVehicles()
Definition MESegment.h:82
void addReminders(MEVehicle *veh) const
Definition MESegment.cpp:94
SUMOTime myBlockTime
The block time.
Definition MESegment.h:133
void addDetector(MSMoveReminder *data)
Definition MESegment.cpp:86
void setEntryBlockTime(SUMOTime entryBlockTime)
set the next time at which a vehicle may enter this queue
Definition MESegment.h:101
SUMOTime myEntryBlockTime
The block time for vehicles who wish to enter this queue.
Definition MESegment.h:130
double getOccupancy() const
Definition MESegment.h:85
std::vector< MSMoveReminder * > myDetectorData
The data collection for all kinds of detectors.
Definition MESegment.h:136
std::vector< MEVehicle * > myVehicles
Definition MESegment.h:124
const std::vector< MEVehicle * > & getVehicles() const
Definition MESegment.h:78
Queue(const SVCPermissions permissions)
Definition MESegment.h:74
SUMOTime getEntryBlockTime() const
return the next time at which a vehicle may enter this queue
Definition MESegment.h:96
void setPermissions(SVCPermissions p)
Definition MESegment.h:112
SVCPermissions myPermissions
The vClass permissions for this queue.
Definition MESegment.h:122
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:557
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:508
SUMOTime myTau_ff
The time headway parameters, see the Eissfeldt thesis.
Definition MESegment.h:534
double getEntryBlockTimeSeconds() const
get the earliest entry time in seconds
Definition MESegment.h:388
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:563
void loadState(const std::vector< SUMOVehicle * > &vehs, const SUMOTime blockTime, const int queIdx)
Loads the state of this segment with the given parameters.
double getBruttoOccupancy() const
Returns the occupany of the segment (the sum of the vehicle lengths + minGaps)
Definition MESegment.h:260
SUMOTime myLastHeadway
the last headway
Definition MESegment.h:572
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 tlsPenaltyOverride() const
whether the traffic light should use normal junction control despite penalty options
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:383
double getRelativeOccupancy() const
Returns the relative occupany of the segment (percentage of road used))
Definition MESegment.h:271
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.
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:569
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:566
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:244
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:219
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)
const MSEdge & getEdge() const
Returns the edge this segment belongs to.
Definition MESegment.h:361
static MESegment myVaporizationTarget
Definition MESegment.h:577
int numQueues() const
return the number of queues
Definition MESegment.h:213
double myJamThreshold
The space (in m) which needs to be occupied before the segment is considered jammed.
Definition MESegment.h:560
const int myIndex
Running number of the segment in the edge.
Definition MESegment.h:528
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:541
double myMeanSpeed
the mean speed on this segment. Updated at event time or on demand
Definition MESegment.h:580
bool myCheckMinorPenalty
penalty for minor links
Definition MESegment.h:540
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:583
SUMOTime myTau_jf
Definition MESegment.h:534
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:522
double getRelativeJamThreshold() const
Returns the relative occupany of the segment (percentage of road used)) at which the segment is consi...
Definition MESegment.h:279
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:452
double getWaitingSeconds() const
Get the waiting time for vehicles in all queues.
const double myLength
The segment's length.
Definition MESegment.h:525
SUMOTime getMinimumHeadwayTime() const
return the minimum headway-time with which vehicles may enter or leave this segment
Definition MESegment.h:466
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:519
static const std::string OVERRIDE_TLS_PENALTIES
Definition MESegment.h:54
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:252
double getEventTimeSeconds() const
Like getEventTime but returns seconds (for visualization)
Definition MESegment.h:378
static MSEdge myDummyParent
Definition MESegment.h:576
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:228
double getMeanSpeed() const
wrapper to satisfy the FunctionBinding signature
Definition MESegment.h:296
int getCarNumber() const
Returns the total number of cars on the segment.
Definition MESegment.h:208
double myTau_length
Headway parameter for computing gross time headyway from net time headway, length and edge speed.
Definition MESegment.h:551
SUMOTime myTau_jj
Definition MESegment.h:534
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:544
bool myTLSPenalty
Whether tls penalty is enabled.
Definition MESegment.h:537
static const double DO_NOT_PATCH_JAM_THRESHOLD
Definition MESegment.h:52
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:444
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:554
bool myOvertaking
Whether overtaking is permitted on this segment.
Definition MESegment.h:547
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:236
bool vaporizeAnyCar(SUMOTime currentTime, const MSDetectorFileOutput *filter)
tries to remove any car from this segment
SUMOTime myTau_fj
Definition MESegment.h:534
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:77
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:54
Static storage of an output device and its base (abstract) implementation.
Representation of a vehicle.
Definition SUMOVehicle.h:62
edge type specific meso parameters
Definition MESegment.h:57