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
71
72
73private:
74 class Queue {
75 public:
76 Queue(const SVCPermissions permissions) : myPermissions(permissions) {}
77 inline int size() const {
78 return (int)myVehicles.size();
79 }
80 inline const std::vector<MEVehicle*>& getVehicles() const {
81 return myVehicles;
82 }
84 inline std::vector<MEVehicle*>& getModifiableVehicles() {
85 return myVehicles;
86 }
87 inline double getOccupancy() const {
88 return myOccupancy;
89 }
90 inline void setOccupancy(const double occ) {
91 myOccupancy = occ;
92 }
93 inline bool allows(SUMOVehicleClass vclass) const {
94 return (myPermissions & vclass) == vclass;
95 }
96
98 inline SUMOTime getEntryBlockTime() const {
99 return myEntryBlockTime;
100 }
101
103 inline void setEntryBlockTime(SUMOTime entryBlockTime) {
104 myEntryBlockTime = entryBlockTime;
105 }
106
107 inline SUMOTime getBlockTime() const {
108 return myBlockTime;
109 }
110 inline void setBlockTime(SUMOTime t) {
111 myBlockTime = t;
112 }
113
115 myPermissions = p;
116 }
117
118 void addDetector(MSMoveReminder* data);
119
120 void addReminders(MEVehicle* veh) const;
121
122 private:
125
126 std::vector<MEVehicle*> myVehicles;
127
129 double myOccupancy = 0.;
130
133
136
138 std::vector<MSMoveReminder*> myDetectorData;
139
140 };
141
142public:
153 MESegment(const std::string& id,
154 const MSEdge& parent, MESegment* next,
155 const double length, const double speed,
156 const int idx,
157 const bool multiQueue,
158 const MesoEdgeType& edgeType);
159
161 void initSegment(const MesoEdgeType& edgeType, const MSEdge& parent, const double capacity);
162
165
171 void addDetector(MSMoveReminder* data, int queueIndex = -1);
172
178 // void removeDetector(MSMoveReminder* data);
179
185 void prepareDetectorForWriting(MSMoveReminder& data, int queueIndex = -1);
187
196 SUMOTime hasSpaceFor(const MEVehicle* const veh, const SUMOTime entryTime, int& qIdx, const bool init = false) const;
197
204 bool initialise(MEVehicle* veh, SUMOTime time);
205
210 inline int getCarNumber() const {
211 return myNumVehicles;
212 }
213
215 inline int numQueues() const {
216 return (int)myQueues.size();
217 }
221 inline const std::vector<MEVehicle*>& getQueue(int index) const {
222 assert(index < (int)myQueues.size());
223 return myQueues[index].getVehicles();
224 }
225
230 inline int getIndex() const {
231 return myIndex;
232 }
233
238 inline MESegment* getNextSegment() const {
239 return myNextSegment;
240 }
241
246 inline double getLength() const {
247 return myLength;
248 }
249
254 inline double getCapacity() const {
255 return myCapacity;
256 }
257
262 inline double getBruttoOccupancy() const {
263 double occ = 0.;
264 for (const Queue& q : myQueues) {
265 occ += q.getOccupancy();
266 }
267 return occ;
268 }
269
273 inline double getRelativeOccupancy() const {
275 }
276
281 inline double getRelativeJamThreshold() const {
282 return myJamThreshold / myCapacity;
283 }
284
295 double getMeanSpeed(bool useCache) const;
296
298 void resetCachedSpeeds();
299
301 inline double getMeanSpeed() const {
302 return getMeanSpeed(true);
303 }
304
305
306 void writeVehicles(OutputDevice& of) const;
307
316
326 MSLink* getLink(const MEVehicle* veh, bool tlsPenalty = false) const;
327
335 bool isOpen(const MEVehicle* veh) const;
336
344 void send(MEVehicle* veh, MESegment* const next, const int nextQIdx, SUMOTime time, const MSMoveReminder::Notification reason);
345
353 void receive(MEVehicle* veh, const int qIdx, SUMOTime time, const bool isDepart = false, const bool isTeleport = false, const bool newEdge = false);
354
355
361 bool vaporizeAnyCar(SUMOTime currentTime, const MSDetectorFileOutput* filter);
362
366 inline const MSEdge& getEdge() const {
367 return myEdge;
368 }
369
370
375 void setSpeed(double newSpeed, SUMOTime currentTime, double jamThresh = DO_NOT_PATCH_JAM_THRESHOLD, int qIdx = -1);
376
380 SUMOTime getEventTime() const;
381
383 inline double getEventTimeSeconds() const {
384 return STEPS2TIME(getEventTime());
385 }
386
388 inline double getLastHeadwaySeconds() const {
390 }
391
393 inline double getEntryBlockTimeSeconds() const {
395 for (const Queue& q : myQueues) {
396 t = MIN2(t, q.getEntryBlockTime());
397 }
398 return STEPS2TIME(t);
399 }
400
402 double getWaitingSeconds() const;
403
406
416 void saveState(OutputDevice& out) const;
417
419 void clearState();
420
435 void loadState(const std::vector<SUMOVehicle*>& vehs, const SUMOTime blockTime, const SUMOTime entryBlockTime, const int queIdx);
437
438
441 std::vector<const MEVehicle*> getVehicles() const;
442
446 double getFlow() const;
447
449 static inline bool isInvalid(const MESegment* segment) {
450 return segment == nullptr || segment == &myVaporizationTarget;
451 }
452
454 SUMOTime getNextInsertionTime(SUMOTime earliestEntry) const;
455
457 inline int remainingVehicleCapacity(const double vehLength) const {
458 int cap = 0;
459 for (const Queue& q : myQueues) {
460 if (q.getOccupancy() == 0. && myQueueCapacity < vehLength) {
461 // even small segments can hold at least one vehicle
462 cap += 1;
463 } else {
464 cap += (int)((myQueueCapacity - q.getOccupancy()) / vehLength);
465 }
466 }
467 return cap;
468 }
469
472 return myTau_ff;
473 }
474
476 void addReminders(MEVehicle* veh) const;
477
482 SUMOTime getLinkPenalty(const MEVehicle* veh) const;
483
485 void updatePermissions();
486
489 myTLSPenalty = false;
490 }
491
492private:
493 bool overtake();
494
495 void setSpeedForQueue(double newSpeed, SUMOTime currentTime,
496 SUMOTime blockTime, const std::vector<MEVehicle*>& vehs);
497
500 SUMOTime newArrival(const MEVehicle* const v, double newSpeed, SUMOTime currentTime);
501
503 bool hasBlockedLeader() const;
504
509 void recomputeJamThreshold(double jamThresh);
510
512 double jamThresholdForSpeed(double speed, double jamThresh) const;
513
515 bool limitedControlOverride(const MSLink* link) const;
516
518 inline SUMOTime tauWithVehLength(SUMOTime tau, double lengthWithGap, double vehicleTau) const {
519 return (SUMOTime)((double)tau * vehicleTau + lengthWithGap * myTau_length);
520 }
521
522 SUMOTime getTauJJ(double nextQueueSize, double nextQueueCapacity, double nextJamThreshold) const;
523
524private:
527
530
532 const double myLength;
533
535 const int myIndex;
536
539
542
545
547 bool myCheckMinorPenalty; // for legacy compatibility (#7802, 7804)
549
552
556
559
561 double myCapacity = 0.;
562
564 double myQueueCapacity = 0.;
565
568
570 std::vector<Queue> myQueues;
571
574
576 std::map<const MSEdge*, int> myFollowerMap;
577
580
581 /* @brief segment for signifying vaporization. This segment has invalid
582 * data and should only be used as a unique pointer */
585
587 mutable double myMeanSpeed;
588
591
592private:
595
598
600 MESegment(const std::string& id);
601};
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:77
void setOccupancy(const double occ)
Definition MESegment.h:90
MEVehicle * remove(MEVehicle *v)
Definition MESegment.cpp:70
void setBlockTime(SUMOTime t)
Definition MESegment.h:110
SUMOTime getBlockTime() const
Definition MESegment.h:107
double myOccupancy
The occupied space (in m) in the queue.
Definition MESegment.h:129
bool allows(SUMOVehicleClass vclass) const
Definition MESegment.h:93
std::vector< MEVehicle * > & getModifiableVehicles()
Definition MESegment.h:84
void addReminders(MEVehicle *veh) const
Definition MESegment.cpp:95
SUMOTime myBlockTime
The block time.
Definition MESegment.h:135
void addDetector(MSMoveReminder *data)
Definition MESegment.cpp:87
void setEntryBlockTime(SUMOTime entryBlockTime)
set the next time at which a vehicle may enter this queue
Definition MESegment.h:103
SUMOTime myEntryBlockTime
The block time for vehicles who wish to enter this queue.
Definition MESegment.h:132
double getOccupancy() const
Definition MESegment.h:87
std::vector< MSMoveReminder * > myDetectorData
The data collection for all kinds of detectors.
Definition MESegment.h:138
std::vector< MEVehicle * > myVehicles
Definition MESegment.h:126
const std::vector< MEVehicle * > & getVehicles() const
Definition MESegment.h:80
Queue(const SVCPermissions permissions)
Definition MESegment.h:76
SUMOTime getEntryBlockTime() const
return the next time at which a vehicle may enter this queue
Definition MESegment.h:98
void setPermissions(SVCPermissions p)
Definition MESegment.h:114
SVCPermissions myPermissions
The vClass permissions for this queue.
Definition MESegment.h:124
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:564
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:518
SUMOTime myTau_ff
The time headway parameters, see the Eissfeldt thesis.
Definition MESegment.h:541
double getEntryBlockTimeSeconds() const
get the earliest entry time in seconds
Definition MESegment.h:393
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:570
double getBruttoOccupancy() const
Returns the occupany of the segment (the sum of the vehicle lengths + minGaps)
Definition MESegment.h:262
SUMOTime myLastHeadway
the last headway
Definition MESegment.h:579
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:388
double getRelativeOccupancy() const
Returns the relative occupany of the segment (percentage of road used))
Definition MESegment.h:273
void overrideTLSPenalty()
whether the traffic light should use normal junction control despite penalty options
Definition MESegment.h:488
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:576
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:573
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:246
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:221
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:366
static MESegment myVaporizationTarget
Definition MESegment.h:584
int numQueues() const
return the number of queues
Definition MESegment.h:215
double myJamThreshold
The space (in m) which needs to be occupied before the segment is considered jammed.
Definition MESegment.h:567
const int myIndex
Running number of the segment in the edge.
Definition MESegment.h:535
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:548
double myMeanSpeed
the mean speed on this segment. Updated at event time or on demand
Definition MESegment.h:587
bool myCheckMinorPenalty
penalty for minor links
Definition MESegment.h:547
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:590
SUMOTime myTau_jf
Definition MESegment.h:541
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:529
double getRelativeJamThreshold() const
Returns the relative occupany of the segment (percentage of road used)) at which the segment is consi...
Definition MESegment.h:281
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:457
double getWaitingSeconds() const
Get the waiting time for vehicles in all queues.
const double myLength
The segment's length.
Definition MESegment.h:532
SUMOTime getMinimumHeadwayTime() const
return the minimum headway-time with which vehicles may enter or leave this segment
Definition MESegment.h:471
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:526
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:254
double getEventTimeSeconds() const
Like getEventTime but returns seconds (for visualization)
Definition MESegment.h:383
static MSEdge myDummyParent
Definition MESegment.h:583
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:230
double getMeanSpeed() const
wrapper to satisfy the FunctionBinding signature
Definition MESegment.h:301
int getCarNumber() const
Returns the total number of cars on the segment.
Definition MESegment.h:210
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:558
SUMOTime myTau_jj
Definition MESegment.h:541
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:551
bool myTLSPenalty
Whether tls penalty is enabled.
Definition MESegment.h:544
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:449
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:561
bool myOvertaking
Whether overtaking is permitted on this segment.
Definition MESegment.h:554
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:238
bool vaporizeAnyCar(SUMOTime currentTime, const MSDetectorFileOutput *filter)
tries to remove any car from this segment
SUMOTime myTau_fj
Definition MESegment.h:541
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:63
edge type specific meso parameters
Definition MESegment.h:58