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
73protected:
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
199 virtual void updateEntryBlockTime(SUMOTime /*time*/) {}
200
207 bool initialise(MEVehicle* veh, SUMOTime time);
208
213 inline int getCarNumber() const {
214 return myNumVehicles;
215 }
216
218 inline int numQueues() const {
219 return (int)myQueues.size();
220 }
224 inline const std::vector<MEVehicle*>& getQueue(int index) const {
225 assert(index < (int)myQueues.size());
226 return myQueues[index].getVehicles();
227 }
228
229 inline SUMOTime getQueueBlockTime(int index) const {
230 assert(index < (int)myQueues.size());
231 return myQueues[index].getBlockTime();
232 }
233
238 inline int getIndex() const {
239 return myIndex;
240 }
241
246 inline MESegment* getNextSegment() const {
247 return myNextSegment;
248 }
249
254 inline double getLength() const {
255 return myLength;
256 }
257
262 inline double getCapacity() const {
263 return myCapacity;
264 }
265
270 inline double getBruttoOccupancy() const {
271 double occ = 0.;
272 for (const Queue& q : myQueues) {
273 occ += q.getOccupancy();
274 }
275 return occ;
276 }
277
281 inline double getRelativeOccupancy() const {
283 }
284
289 inline double getRelativeJamThreshold() const {
290 return myJamThreshold / myCapacity;
291 }
292
303 double getMeanSpeed(bool useCache) const;
304
306 void resetCachedSpeeds();
307
309 inline double getMeanSpeed() const {
310 return getMeanSpeed(true);
311 }
312
313
314 void writeVehicles(OutputDevice& of) const;
315
324
334 MSLink* getLink(const MEVehicle* veh, bool tlsPenalty = false) const;
335
343 bool isOpen(const MEVehicle* veh) const;
344
352 virtual void send(MEVehicle* veh, MESegment* const next, const int nextQIdx, SUMOTime time, const MSMoveReminder::Notification reason);
353
361 void receive(MEVehicle* veh, const int qIdx, SUMOTime time, const bool isDepart = false, const bool isTeleport = false, const bool newEdge = false);
362
363
369 bool vaporizeAnyCar(SUMOTime currentTime, const MSDetectorFileOutput* filter);
370
374 inline const MSEdge& getEdge() const {
375 return myEdge;
376 }
377
378
383 void setSpeed(double newSpeed, SUMOTime currentTime, double jamThresh = DO_NOT_PATCH_JAM_THRESHOLD, int qIdx = -1);
384
388 SUMOTime getEventTime() const;
389
391 inline double getEventTimeSeconds() const {
392 return STEPS2TIME(getEventTime());
393 }
394
396 inline double getLastHeadwaySeconds() const {
398 }
399
401 inline double getEntryBlockTimeSeconds() const {
403 for (const Queue& q : myQueues) {
404 t = MIN2(t, q.getEntryBlockTime());
405 }
406 return STEPS2TIME(t);
407 }
408
410 double getWaitingSeconds() const;
411
414
424 void saveState(OutputDevice& out) const;
425
427 void clearState();
428
443 void loadState(const std::vector<SUMOVehicle*>& vehs, const SUMOTime blockTime, const SUMOTime entryBlockTime, const int queIdx);
445
446
449 std::vector<const MEVehicle*> getVehicles() const;
450
454 double getFlow() const;
455
457 static inline bool isInvalid(const MESegment* segment) {
458 return segment == nullptr || segment == &myVaporizationTarget;
459 }
460
462 SUMOTime getNextInsertionTime(SUMOTime earliestEntry) const;
463
465 inline int remainingVehicleCapacity(const double vehLength) const {
466 int cap = 0;
467 for (const Queue& q : myQueues) {
468 if (q.getOccupancy() == 0. && myQueueCapacity < vehLength) {
469 // even small segments can hold at least one vehicle
470 cap += 1;
471 } else {
472 cap += (int)((myQueueCapacity - q.getOccupancy()) / vehLength);
473 }
474 }
475 return cap;
476 }
477
480 return myTau_ff;
481 }
482
484 void addReminders(MEVehicle* veh) const;
485
490 SUMOTime getLinkPenalty(const MEVehicle* veh) const;
491
493 void updatePermissions();
494
497 myTLSPenalty = false;
498 }
499
501 inline SUMOTime getMinTauWithVehLength(double lengthWithGap, double vehicleTau) const {
502 return (SUMOTime)((double)myTau_ff * vehicleTau + lengthWithGap * myTau_length);
503 }
504
506 inline SUMOTime getTauWithVehLength(int qIdx, double lengthWithGap, double vehicleTau) const {
507 assert(qIdx >= 0 && qIdx < (int)myQueues.size());
508 const SUMOTime tau = myQueues[qIdx].getOccupancy() < myJamThreshold ? myTau_ff : myTau_jf;
509 return tauWithVehLength(tau, lengthWithGap, vehicleTau);
510 }
511
512protected:
513 bool overtake();
514
515 void setSpeedForQueue(double newSpeed, SUMOTime currentTime,
516 SUMOTime blockTime, const std::vector<MEVehicle*>& vehs);
517
520 SUMOTime newArrival(const MEVehicle* const v, double newSpeed, SUMOTime currentTime);
521
523 bool hasBlockedLeader() const;
524
529 void recomputeJamThreshold(double jamThresh);
530
532 double jamThresholdForSpeed(double speed, double jamThresh) const;
533
535 bool limitedControlOverride(const MSLink* link) const;
536
538 inline SUMOTime tauWithVehLength(SUMOTime tau, double lengthWithGap, double vehicleTau) const {
539 return (SUMOTime)((double)tau * vehicleTau + lengthWithGap * myTau_length);
540 }
541
542 SUMOTime getTauJJ(double nextQueueSize, double nextQueueCapacity, double nextJamThreshold) const;
543
545 virtual SUMOTime computeHeadway(Queue& q, const Queue& qNext, const MESegment* const next, const MEVehicle* veh) const;
546
548 virtual bool hasSpaceForInsertion(const Queue& q, int qIdx, double newOccupancy, SUMOTime entryTime) const;
549
550protected:
553
556
558 const double myLength;
559
561 const int myIndex;
562
565
568
571
573 bool myCheckMinorPenalty; // for legacy compatibility (#7802, 7804)
575
578
582
585
587 double myCapacity = 0.;
588
590 double myQueueCapacity = 0.;
591
594
596 std::vector<Queue> myQueues;
597
600
602 std::map<const MSEdge*, int> myFollowerMap;
603
606
607 /* @brief segment for signifying vaporization. This segment has invalid
608 * data and should only be used as a unique pointer */
611
613 mutable double myMeanSpeed;
614
617
618private:
621
624
626 MESegment(const std::string& id);
627};
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:72
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:97
SUMOTime myBlockTime
The block time.
Definition MESegment.h:135
void addDetector(MSMoveReminder *data)
Definition MESegment.cpp:89
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:590
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:538
SUMOTime myTau_ff
The time headway parameters, see the Eissfeldt thesis.
Definition MESegment.h:567
double getEntryBlockTimeSeconds() const
get the earliest entry time in seconds
Definition MESegment.h:401
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:596
double getBruttoOccupancy() const
Returns the occupany of the segment (the sum of the vehicle lengths + minGaps)
Definition MESegment.h:270
SUMOTime myLastHeadway
the last headway
Definition MESegment.h:605
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:396
double getRelativeOccupancy() const
Returns the relative occupany of the segment (percentage of road used))
Definition MESegment.h:281
void overrideTLSPenalty()
whether the traffic light should use normal junction control despite penalty options
Definition MESegment.h:496
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:602
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:506
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:599
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:254
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:224
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:374
static MESegment myVaporizationTarget
Definition MESegment.h:610
int numQueues() const
return the number of queues
Definition MESegment.h:218
double myJamThreshold
The space (in m) which needs to be occupied before the segment is considered jammed.
Definition MESegment.h:593
const int myIndex
Running number of the segment in the edge.
Definition MESegment.h:561
virtual void updateEntryBlockTime(SUMOTime)
update entry blockTime for all queues
Definition MESegment.h:199
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:574
double myMeanSpeed
the mean speed on this segment. Updated at event time or on demand
Definition MESegment.h:613
bool myCheckMinorPenalty
penalty for minor links
Definition MESegment.h:573
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:616
SUMOTime myTau_jf
Definition MESegment.h:567
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:555
double getRelativeJamThreshold() const
Returns the relative occupany of the segment (percentage of road used)) at which the segment is consi...
Definition MESegment.h:289
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:465
double getWaitingSeconds() const
Get the waiting time for vehicles in all queues.
const double myLength
The segment's length.
Definition MESegment.h:558
SUMOTime getMinimumHeadwayTime() const
return the minimum headway-time with which vehicles may enter or leave this segment
Definition MESegment.h:479
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:552
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:262
double getEventTimeSeconds() const
Like getEventTime but returns seconds (for visualization)
Definition MESegment.h:391
static MSEdge myDummyParent
Definition MESegment.h:609
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:238
double getMeanSpeed() const
wrapper to satisfy the FunctionBinding signature
Definition MESegment.h:309
SUMOTime getQueueBlockTime(int index) const
Definition MESegment.h:229
int getCarNumber() const
Returns the total number of cars on the segment.
Definition MESegment.h:213
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:584
SUMOTime myTau_jj
Definition MESegment.h:567
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:577
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:570
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:501
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:457
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:587
bool myOvertaking
Whether overtaking is permitted on this segment.
Definition MESegment.h:580
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:246
bool vaporizeAnyCar(SUMOTime currentTime, const MSDetectorFileOutput *filter)
tries to remove any car from this segment
SUMOTime myTau_fj
Definition MESegment.h:567
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: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