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
226 inline SUMOTime getQueueBlockTime(int index) const {
227 assert(index < (int)myQueues.size());
228 return myQueues[index].getBlockTime();
229 }
230
235 inline int getIndex() const {
236 return myIndex;
237 }
238
243 inline MESegment* getNextSegment() const {
244 return myNextSegment;
245 }
246
251 inline double getLength() const {
252 return myLength;
253 }
254
259 inline double getCapacity() const {
260 return myCapacity;
261 }
262
267 inline double getBruttoOccupancy() const {
268 double occ = 0.;
269 for (const Queue& q : myQueues) {
270 occ += q.getOccupancy();
271 }
272 return occ;
273 }
274
278 inline double getRelativeOccupancy() const {
280 }
281
286 inline double getRelativeJamThreshold() const {
287 return myJamThreshold / myCapacity;
288 }
289
300 double getMeanSpeed(bool useCache) const;
301
303 void resetCachedSpeeds();
304
306 inline double getMeanSpeed() const {
307 return getMeanSpeed(true);
308 }
309
310
311 void writeVehicles(OutputDevice& of) const;
312
321
331 MSLink* getLink(const MEVehicle* veh, bool tlsPenalty = false) const;
332
340 bool isOpen(const MEVehicle* veh) const;
341
349 void send(MEVehicle* veh, MESegment* const next, const int nextQIdx, SUMOTime time, const MSMoveReminder::Notification reason);
350
358 void receive(MEVehicle* veh, const int qIdx, SUMOTime time, const bool isDepart = false, const bool isTeleport = false, const bool newEdge = false);
359
360
366 bool vaporizeAnyCar(SUMOTime currentTime, const MSDetectorFileOutput* filter);
367
371 inline const MSEdge& getEdge() const {
372 return myEdge;
373 }
374
375
380 void setSpeed(double newSpeed, SUMOTime currentTime, double jamThresh = DO_NOT_PATCH_JAM_THRESHOLD, int qIdx = -1);
381
385 SUMOTime getEventTime() const;
386
388 inline double getEventTimeSeconds() const {
389 return STEPS2TIME(getEventTime());
390 }
391
393 inline double getLastHeadwaySeconds() const {
395 }
396
398 inline double getEntryBlockTimeSeconds() const {
400 for (const Queue& q : myQueues) {
401 t = MIN2(t, q.getEntryBlockTime());
402 }
403 return STEPS2TIME(t);
404 }
405
407 double getWaitingSeconds() const;
408
411
421 void saveState(OutputDevice& out) const;
422
424 void clearState();
425
440 void loadState(const std::vector<SUMOVehicle*>& vehs, const SUMOTime blockTime, const SUMOTime entryBlockTime, const int queIdx);
442
443
446 std::vector<const MEVehicle*> getVehicles() const;
447
451 double getFlow() const;
452
454 static inline bool isInvalid(const MESegment* segment) {
455 return segment == nullptr || segment == &myVaporizationTarget;
456 }
457
459 SUMOTime getNextInsertionTime(SUMOTime earliestEntry) const;
460
462 inline int remainingVehicleCapacity(const double vehLength) const {
463 int cap = 0;
464 for (const Queue& q : myQueues) {
465 if (q.getOccupancy() == 0. && myQueueCapacity < vehLength) {
466 // even small segments can hold at least one vehicle
467 cap += 1;
468 } else {
469 cap += (int)((myQueueCapacity - q.getOccupancy()) / vehLength);
470 }
471 }
472 return cap;
473 }
474
477 return myTau_ff;
478 }
479
481 void addReminders(MEVehicle* veh) const;
482
487 SUMOTime getLinkPenalty(const MEVehicle* veh) const;
488
490 void updatePermissions();
491
494 myTLSPenalty = false;
495 }
496
498 inline SUMOTime getMinTauWithVehLength(double lengthWithGap, double vehicleTau) const {
499 return (SUMOTime)((double)myTau_ff * vehicleTau + lengthWithGap * myTau_length);
500 }
501
502private:
503 bool overtake();
504
505 void setSpeedForQueue(double newSpeed, SUMOTime currentTime,
506 SUMOTime blockTime, const std::vector<MEVehicle*>& vehs);
507
510 SUMOTime newArrival(const MEVehicle* const v, double newSpeed, SUMOTime currentTime);
511
513 bool hasBlockedLeader() const;
514
519 void recomputeJamThreshold(double jamThresh);
520
522 double jamThresholdForSpeed(double speed, double jamThresh) const;
523
525 bool limitedControlOverride(const MSLink* link) const;
526
528 inline SUMOTime tauWithVehLength(SUMOTime tau, double lengthWithGap, double vehicleTau) const {
529 return (SUMOTime)((double)tau * vehicleTau + lengthWithGap * myTau_length);
530 }
531
532 SUMOTime getTauJJ(double nextQueueSize, double nextQueueCapacity, double nextJamThreshold) const;
533
534private:
537
540
542 const double myLength;
543
545 const int myIndex;
546
549
552
555
557 bool myCheckMinorPenalty; // for legacy compatibility (#7802, 7804)
559
562
566
569
571 double myCapacity = 0.;
572
574 double myQueueCapacity = 0.;
575
578
580 std::vector<Queue> myQueues;
581
584
586 std::map<const MSEdge*, int> myFollowerMap;
587
590
591 /* @brief segment for signifying vaporization. This segment has invalid
592 * data and should only be used as a unique pointer */
595
597 mutable double myMeanSpeed;
598
601
602private:
605
608
610 MESegment(const std::string& id);
611};
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:574
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:528
SUMOTime myTau_ff
The time headway parameters, see the Eissfeldt thesis.
Definition MESegment.h:551
double getEntryBlockTimeSeconds() const
get the earliest entry time in seconds
Definition MESegment.h:398
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:580
double getBruttoOccupancy() const
Returns the occupany of the segment (the sum of the vehicle lengths + minGaps)
Definition MESegment.h:267
SUMOTime myLastHeadway
the last headway
Definition MESegment.h:589
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:393
double getRelativeOccupancy() const
Returns the relative occupany of the segment (percentage of road used))
Definition MESegment.h:278
void overrideTLSPenalty()
whether the traffic light should use normal junction control despite penalty options
Definition MESegment.h:493
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:586
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:583
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:251
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:371
static MESegment myVaporizationTarget
Definition MESegment.h:594
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:577
const int myIndex
Running number of the segment in the edge.
Definition MESegment.h:545
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:558
double myMeanSpeed
the mean speed on this segment. Updated at event time or on demand
Definition MESegment.h:597
bool myCheckMinorPenalty
penalty for minor links
Definition MESegment.h:557
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:600
SUMOTime myTau_jf
Definition MESegment.h:551
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:539
double getRelativeJamThreshold() const
Returns the relative occupany of the segment (percentage of road used)) at which the segment is consi...
Definition MESegment.h:286
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:462
double getWaitingSeconds() const
Get the waiting time for vehicles in all queues.
const double myLength
The segment's length.
Definition MESegment.h:542
SUMOTime getMinimumHeadwayTime() const
return the minimum headway-time with which vehicles may enter or leave this segment
Definition MESegment.h:476
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:536
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:259
double getEventTimeSeconds() const
Like getEventTime but returns seconds (for visualization)
Definition MESegment.h:388
static MSEdge myDummyParent
Definition MESegment.h:593
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:235
double getMeanSpeed() const
wrapper to satisfy the FunctionBinding signature
Definition MESegment.h:306
SUMOTime getQueueBlockTime(int index) const
Definition MESegment.h:226
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:568
SUMOTime myTau_jj
Definition MESegment.h:551
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:561
bool myTLSPenalty
Whether tls penalty is enabled.
Definition MESegment.h:554
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:498
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:454
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:571
bool myOvertaking
Whether overtaking is permitted on this segment.
Definition MESegment.h:564
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:243
bool vaporizeAnyCar(SUMOTime currentTime, const MSDetectorFileOutput *filter)
tries to remove any car from this segment
SUMOTime myTau_fj
Definition MESegment.h:551
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