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-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 void resetCachedSpeeds();
297
299 inline double getMeanSpeed() const {
300 return getMeanSpeed(true);
301 }
302
303
304 void writeVehicles(OutputDevice& of) const;
305
314
324 MSLink* getLink(const MEVehicle* veh, bool tlsPenalty = false) const;
325
333 bool isOpen(const MEVehicle* veh) const;
334
342 void send(MEVehicle* veh, MESegment* const next, const int nextQIdx, SUMOTime time, const MSMoveReminder::Notification reason);
343
351 void receive(MEVehicle* veh, const int qIdx, SUMOTime time, const bool isDepart = false, const bool isTeleport = false, const bool newEdge = false);
352
353
359 bool vaporizeAnyCar(SUMOTime currentTime, const MSDetectorFileOutput* filter);
360
364 inline const MSEdge& getEdge() const {
365 return myEdge;
366 }
367
368
373 void setSpeed(double newSpeed, SUMOTime currentTime, double jamThresh = DO_NOT_PATCH_JAM_THRESHOLD, int qIdx = -1);
374
378 SUMOTime getEventTime() const;
379
381 inline double getEventTimeSeconds() const {
382 return STEPS2TIME(getEventTime());
383 }
384
386 inline double getLastHeadwaySeconds() const {
388 }
389
391 inline double getEntryBlockTimeSeconds() const {
393 for (const Queue& q : myQueues) {
394 t = MIN2(t, q.getEntryBlockTime());
395 }
396 return STEPS2TIME(t);
397 }
398
400 double getWaitingSeconds() const;
401
404
414 void saveState(OutputDevice& out) const;
415
417 void clearState();
418
433 void loadState(const std::vector<SUMOVehicle*>& vehs, const SUMOTime blockTime, const SUMOTime entryBlockTime, const int queIdx);
435
436
439 std::vector<const MEVehicle*> getVehicles() const;
440
444 double getFlow() const;
445
447 static inline bool isInvalid(const MESegment* segment) {
448 return segment == nullptr || segment == &myVaporizationTarget;
449 }
450
452 SUMOTime getNextInsertionTime(SUMOTime earliestEntry) const;
453
455 inline int remainingVehicleCapacity(const double vehLength) const {
456 int cap = 0;
457 for (const Queue& q : myQueues) {
458 if (q.getOccupancy() == 0. && myQueueCapacity < vehLength) {
459 // even small segments can hold at least one vehicle
460 cap += 1;
461 } else {
462 cap += (int)((myQueueCapacity - q.getOccupancy()) / vehLength);
463 }
464 }
465 return cap;
466 }
467
470 return myTau_ff;
471 }
472
474 void addReminders(MEVehicle* veh) const;
475
480 SUMOTime getLinkPenalty(const MEVehicle* veh) const;
481
483 void updatePermissions();
484
485private:
486 bool overtake();
487
488 void setSpeedForQueue(double newSpeed, SUMOTime currentTime,
489 SUMOTime blockTime, const std::vector<MEVehicle*>& vehs);
490
493 SUMOTime newArrival(const MEVehicle* const v, double newSpeed, SUMOTime currentTime);
494
496 bool hasBlockedLeader() const;
497
502 void recomputeJamThreshold(double jamThresh);
503
505 double jamThresholdForSpeed(double speed, double jamThresh) const;
506
508 bool limitedControlOverride(const MSLink* link) const;
509
511 inline SUMOTime tauWithVehLength(SUMOTime tau, double lengthWithGap, double vehicleTau) const {
512 return (SUMOTime)((double)tau * vehicleTau + lengthWithGap * myTau_length);
513 }
514
515 SUMOTime getTauJJ(double nextQueueSize, double nextQueueCapacity, double nextJamThreshold) const;
516
518 bool tlsPenaltyOverride() const;
519
520private:
523
526
528 const double myLength;
529
531 const int myIndex;
532
535
538
541
543 bool myCheckMinorPenalty; // for legacy compatibility (#7802, 7804)
545
548
552
555
557 double myCapacity = 0.;
558
560 double myQueueCapacity = 0.;
561
564
566 std::vector<Queue> myQueues;
567
570
572 std::map<const MSEdge*, int> myFollowerMap;
573
576
577 /* @brief segment for signifying vaporization. This segment has invalid
578 * data and should only be used as a unique pointer */
581
583 mutable double myMeanSpeed;
584
587
588private:
591
594
596 MESegment(const std::string& id);
597};
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:80
int size() const
Definition MESegment.h:75
void setOccupancy(const double occ)
Definition MESegment.h:88
MEVehicle * remove(MEVehicle *v)
Definition MESegment.cpp:70
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:95
SUMOTime myBlockTime
The block time.
Definition MESegment.h:133
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: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:560
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:511
SUMOTime myTau_ff
The time headway parameters, see the Eissfeldt thesis.
Definition MESegment.h:537
double getEntryBlockTimeSeconds() const
get the earliest entry time in seconds
Definition MESegment.h:391
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:566
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:575
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:386
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:572
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:569
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)
void resetCachedSpeeds()
reset myLastMeanSpeedUpdate
const MSEdge & getEdge() const
Returns the edge this segment belongs to.
Definition MESegment.h:364
static MESegment myVaporizationTarget
Definition MESegment.h:580
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:563
const int myIndex
Running number of the segment in the edge.
Definition MESegment.h:531
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:544
double myMeanSpeed
the mean speed on this segment. Updated at event time or on demand
Definition MESegment.h:583
bool myCheckMinorPenalty
penalty for minor links
Definition MESegment.h:543
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:586
SUMOTime myTau_jf
Definition MESegment.h:537
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:525
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:455
double getWaitingSeconds() const
Get the waiting time for vehicles in all queues.
const double myLength
The segment's length.
Definition MESegment.h:528
SUMOTime getMinimumHeadwayTime() const
return the minimum headway-time with which vehicles may enter or leave this segment
Definition MESegment.h:469
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:522
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:381
static MSEdge myDummyParent
Definition MESegment.h:579
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:299
int getCarNumber() const
Returns the total number of cars on the segment.
Definition MESegment.h:208
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:554
SUMOTime myTau_jj
Definition MESegment.h:537
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:547
bool myTLSPenalty
Whether tls penalty is enabled.
Definition MESegment.h:540
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:447
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:557
bool myOvertaking
Whether overtaking is permitted on this segment.
Definition MESegment.h:550
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:537
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