Eclipse SUMO - Simulation of Urban MObility
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-2023 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 MSEdge;
35class MSLink;
38class MEVehicle;
39class OutputDevice;
40
41
42// ===========================================================================
43// class definitions
44// ===========================================================================
49class MESegment : public Named {
50public:
51 static const double DO_NOT_PATCH_JAM_THRESHOLD;
52 static const int PARKING_QUEUE = -1;
53
55 struct MesoEdgeType {
62 double tlsPenalty;
66 };
67
68
69private:
70 class Queue {
71 public:
72 Queue(const SVCPermissions permissions) : myPermissions(permissions) {}
73 inline int size() const {
74 return (int)myVehicles.size();
75 }
76 inline const std::vector<MEVehicle*>& getVehicles() const {
77 return myVehicles;
78 }
80 inline std::vector<MEVehicle*>& getModifiableVehicles() {
81 return myVehicles;
82 }
83 inline double getOccupancy() const {
84 return myOccupancy;
85 }
86 inline void setOccupancy(const double occ) {
87 myOccupancy = occ;
88 }
89 inline bool allows(SUMOVehicleClass vclass) const {
90 return (myPermissions & vclass) == vclass;
91 }
92
94 inline SUMOTime getEntryBlockTime() const {
95 return myEntryBlockTime;
96 }
97
99 inline void setEntryBlockTime(SUMOTime entryBlockTime) {
100 myEntryBlockTime = entryBlockTime;
101 }
102
103 inline SUMOTime getBlockTime() const {
104 return myBlockTime;
105 }
106 inline void setBlockTime(SUMOTime t) {
107 myBlockTime = t;
108 }
109
111 myPermissions = p;
112 }
113
114 void addDetector(MSMoveReminder* data);
115
116 void addReminders(MEVehicle* veh) const;
117
118 private:
121
122 std::vector<MEVehicle*> myVehicles;
123
125 double myOccupancy = 0.;
126
129
132
134 std::vector<MSMoveReminder*> myDetectorData;
135
136 };
137
138public:
149 MESegment(const std::string& id,
150 const MSEdge& parent, MESegment* next,
151 const double length, const double speed,
152 const int idx,
153 const bool multiQueue,
154 const MesoEdgeType& edgeType);
155
157 void initSegment(const MesoEdgeType& edgeType, const MSEdge& parent, const double capacity);
158
161
167 void addDetector(MSMoveReminder* data, int queueIndex = -1);
168
174 // void removeDetector(MSMoveReminder* data);
175
181 void prepareDetectorForWriting(MSMoveReminder& data, int queueIndex = -1);
183
192 SUMOTime hasSpaceFor(const MEVehicle* const veh, const SUMOTime entryTime, int& qIdx, const bool init = false) const;
193
200 bool initialise(MEVehicle* veh, SUMOTime time);
201
206 inline int getCarNumber() const {
207 return myNumVehicles;
208 }
209
211 inline int numQueues() const {
212 return (int)myQueues.size();
213 }
217 inline const std::vector<MEVehicle*>& getQueue(int index) const {
218 assert(index < (int)myQueues.size());
219 return myQueues[index].getVehicles();
220 }
221
226 inline int getIndex() const {
227 return myIndex;
228 }
229
234 inline MESegment* getNextSegment() const {
235 return myNextSegment;
236 }
237
242 inline double getLength() const {
243 return myLength;
244 }
245
250 inline double getCapacity() const {
251 return myCapacity;
252 }
253
258 inline double getBruttoOccupancy() const {
259 double occ = 0.;
260 for (const Queue& q : myQueues) {
261 occ += q.getOccupancy();
262 }
263 return occ;
264 }
265
269 inline double getRelativeOccupancy() const {
271 }
272
277 inline double getRelativeJamThreshold() const {
278 return myJamThreshold / myCapacity;
279 }
280
291 double getMeanSpeed(bool useCache) const;
292
294 inline double getMeanSpeed() const {
295 return getMeanSpeed(true);
296 }
297
298
299 void writeVehicles(OutputDevice& of) const;
300
309
319 MSLink* getLink(const MEVehicle* veh, bool tlsPenalty = false) const;
320
328 bool isOpen(const MEVehicle* veh) const;
329
337 void send(MEVehicle* veh, MESegment* const next, const int nextQIdx, SUMOTime time, const MSMoveReminder::Notification reason);
338
346 void receive(MEVehicle* veh, const int qIdx, SUMOTime time, const bool isDepart = false, const bool isTeleport = false, const bool newEdge = false);
347
348
354 bool vaporizeAnyCar(SUMOTime currentTime, const MSDetectorFileOutput* filter);
355
359 inline const MSEdge& getEdge() const {
360 return myEdge;
361 }
362
363
368 void setSpeed(double newSpeed, SUMOTime currentTime, double jamThresh = DO_NOT_PATCH_JAM_THRESHOLD);
369
373 SUMOTime getEventTime() const;
374
376 inline double getEventTimeSeconds() const {
377 return STEPS2TIME(getEventTime());
378 }
379
381 inline double getLastHeadwaySeconds() const {
383 }
384
386 inline double getEntryBlockTimeSeconds() const {
388 for (const Queue& q : myQueues) {
389 t = MIN2(t, q.getEntryBlockTime());
390 }
391 return STEPS2TIME(t);
392 }
393
395 double getWaitingSeconds() const;
396
399
409 void saveState(OutputDevice& out) const;
410
412 void clearState();
413
429 void loadState(const std::vector<std::string>& vehIDs, MSVehicleControl& vc, const SUMOTime blockTime, const int queIdx);
431
432
435 std::vector<const MEVehicle*> getVehicles() const;
436
440 double getFlow() const;
441
443 static inline bool isInvalid(const MESegment* segment) {
444 return segment == nullptr || segment == &myVaporizationTarget;
445 }
446
448 SUMOTime getNextInsertionTime(SUMOTime earliestEntry) const;
449
451 inline int remainingVehicleCapacity(const double vehLength) const {
452 int cap = 0;
453 for (const Queue& q : myQueues) {
454 if (q.getOccupancy() == 0. && myQueueCapacity < vehLength) {
455 // even small segments can hold at least one vehicle
456 cap += 1;
457 } else {
458 cap += (int)((myQueueCapacity - q.getOccupancy()) / vehLength);
459 }
460 }
461 return cap;
462 }
463
466 return myTau_ff;
467 }
468
470 void addReminders(MEVehicle* veh) const;
471
476 SUMOTime getLinkPenalty(const MEVehicle* veh) const;
477
479 void updatePermissions();
480
481private:
482 bool overtake();
483
484 void setSpeedForQueue(double newSpeed, SUMOTime currentTime,
485 SUMOTime blockTime, const std::vector<MEVehicle*>& vehs);
486
489 SUMOTime newArrival(const MEVehicle* const v, double newSpeed, SUMOTime currentTime);
490
492 bool hasBlockedLeader() const;
493
498 void recomputeJamThreshold(double jamThresh);
499
501 double jamThresholdForSpeed(double speed, double jamThresh) const;
502
504 bool limitedControlOverride(const MSLink* link) const;
505
507 inline SUMOTime tauWithVehLength(SUMOTime tau, double lengthWithGap, double vehicleTau) const {
508 return (SUMOTime)((double)tau * vehicleTau + lengthWithGap * myTau_length);
509 }
510
511 SUMOTime getTauJJ(double nextQueueSize, double nextQueueCapacity, double nextJamThreshold) const;
512
513private:
516
519
521 const double myLength;
522
524 const int myIndex;
525
528
531
534
536 bool myCheckMinorPenalty; // for legacy compatibility (#7802, 7804)
538
541
545
548
550 double myCapacity = 0.;
551
553 double myQueueCapacity = 0.;
554
557
559 std::vector<Queue> myQueues;
560
563
565 std::map<const MSEdge*, int> myFollowerMap;
566
569
570 /* @brief segment for signifying vaporization. This segment has invalid
571 * data and should only be used as a unique pointer */
574
576 mutable double myMeanSpeed;
577
580
581private:
584
587
589 MESegment(const std::string& id);
590};
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
SUMOVehicleClass
Definition of vehicle classes to differ between different lane usage and authority types.
int SVCPermissions
bitset where each bit declares whether a certain SVC may use this edge/lane
T MIN2(T a, T b)
Definition: StdDefs.h:76
int size() const
Definition: MESegment.h:73
void setOccupancy(const double occ)
Definition: MESegment.h:86
MEVehicle * remove(MEVehicle *v)
Definition: MESegment.cpp:67
void setBlockTime(SUMOTime t)
Definition: MESegment.h:106
SUMOTime getBlockTime() const
Definition: MESegment.h:103
double myOccupancy
The occupied space (in m) in the queue.
Definition: MESegment.h:125
bool allows(SUMOVehicleClass vclass) const
Definition: MESegment.h:89
std::vector< MEVehicle * > & getModifiableVehicles()
Definition: MESegment.h:80
void addReminders(MEVehicle *veh) const
Definition: MESegment.cpp:92
SUMOTime myBlockTime
The block time.
Definition: MESegment.h:131
void addDetector(MSMoveReminder *data)
Definition: MESegment.cpp:84
void setEntryBlockTime(SUMOTime entryBlockTime)
set the next time at which a vehicle may enter this queue
Definition: MESegment.h:99
SUMOTime myEntryBlockTime
The block time for vehicles who wish to enter this queue.
Definition: MESegment.h:128
double getOccupancy() const
Definition: MESegment.h:83
std::vector< MSMoveReminder * > myDetectorData
The data collection for all kinds of detectors.
Definition: MESegment.h:134
std::vector< MEVehicle * > myVehicles
Definition: MESegment.h:122
const std::vector< MEVehicle * > & getVehicles() const
Definition: MESegment.h:76
Queue(const SVCPermissions permissions)
Definition: MESegment.h:72
SUMOTime getEntryBlockTime() const
return the next time at which a vehicle may enter this queue
Definition: MESegment.h:94
void setPermissions(SVCPermissions p)
Definition: MESegment.h:110
SVCPermissions myPermissions
The vClass permissions for this queue.
Definition: MESegment.h:120
A single mesoscopic segment (cell)
Definition: MESegment.h:49
void addReminders(MEVehicle *veh) const
add this lanes MoveReminders to the given vehicle
Definition: MESegment.cpp:590
double myQueueCapacity
The number of lanes represented by the queue * the length of the lane.
Definition: MESegment.h:553
bool overtake()
Definition: MESegment.cpp:584
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:507
SUMOTime myTau_ff
The time headway parameters, see the Eissfeldt thesis.
Definition: MESegment.h:530
double getEntryBlockTimeSeconds() const
get the earliest entry time in seconds
Definition: MESegment.h:386
bool initialise(MEVehicle *veh, SUMOTime time)
Inserts (emits) vehicle into the segment.
Definition: MESegment.cpp:356
std::vector< Queue > myQueues
The car queues. Vehicles are inserted in the front and removed in the back.
Definition: MESegment.h:559
double getBruttoOccupancy() const
Returns the occupany of the segment (the sum of the vehicle lengths + minGaps)
Definition: MESegment.h:258
SUMOTime myLastHeadway
the last headway
Definition: MESegment.h:568
static const int PARKING_QUEUE
Definition: MESegment.h:52
bool limitedControlOverride(const MSLink *link) const
whether the given link may be passed because the option meso-junction-control.limited is set
Definition: MESegment.cpp:507
bool isOpen(const MEVehicle *veh) const
Returns whether the vehicle may use the next link.
Definition: MESegment.cpp:467
void addDetector(MSMoveReminder *data, int queueIndex=-1)
Adds a data collector for a detector to this segment.
Definition: MESegment.cpp:250
double getLastHeadwaySeconds() const
get the last headway time in seconds
Definition: MESegment.h:381
double getRelativeOccupancy() const
Returns the relative occupany of the segment (percentage of road used))
Definition: MESegment.h:269
void clearState()
Remove all vehicles before quick-loading state.
Definition: MESegment.cpp:775
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.
Definition: MESegment.cpp:598
SUMOTime getLinkPenalty(const MEVehicle *veh) const
Returns the penalty time for passing a link (if using gMesoTLSPenalty > 0 or gMesoMinorPenalty > 0)
Definition: MESegment.cpp:833
void writeVehicles(OutputDevice &of) const
Definition: MESegment.cpp:398
std::map< const MSEdge *, int > myFollowerMap
The follower edge to allowed que index mapping for multi queue segments.
Definition: MESegment.h:565
MSLink * getLink(const MEVehicle *veh, bool tlsPenalty=false) const
Returns the link the given car will use when passing the next junction.
Definition: MESegment.cpp:438
int myNumVehicles
The cached value for the number of vehicles.
Definition: MESegment.h:562
void setSpeedForQueue(double newSpeed, SUMOTime currentTime, SUMOTime blockTime, const std::vector< MEVehicle * > &vehs)
Definition: MESegment.cpp:699
double getLength() const
Returns the length of the segment in meters.
Definition: MESegment.h:242
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.
Definition: MESegment.cpp:302
const std::vector< MEVehicle * > & getQueue(int index) const
Returns the cars in the queue with the given index for visualization.
Definition: MESegment.h:217
void updatePermissions()
called when permissions change due to Rerouter or TraCI
Definition: MESegment.cpp:204
MESegment & operator=(const MESegment &)
Invalidated assignment operator.
void saveState(OutputDevice &out) const
Saves the state of this segment into the given stream.
Definition: MESegment.cpp:754
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)
Definition: MESegment.cpp:147
const MSEdge & getEdge() const
Returns the edge this segment belongs to.
Definition: MESegment.h:359
static MESegment myVaporizationTarget
Definition: MESegment.h:573
int numQueues() const
return the number of queues
Definition: MESegment.h:211
double myJamThreshold
The space (in m) which needs to be occupied before the segment is considered jammed.
Definition: MESegment.h:556
const int myIndex
Running number of the segment in the edge.
Definition: MESegment.h:524
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.
Definition: MESegment.cpp:520
SUMOTime myMinorPenalty
Definition: MESegment.h:537
double myMeanSpeed
the mean speed on this segment. Updated at event time or on demand
Definition: MESegment.h:576
bool myCheckMinorPenalty
penalty for minor links
Definition: MESegment.h:536
double jamThresholdForSpeed(double speed, double jamThresh) const
compute jam threshold for the given speed and jam-threshold option
Definition: MESegment.cpp:231
SUMOTime myLastMeanSpeedUpdate
the time at which myMeanSpeed was last updated
Definition: MESegment.h:579
SUMOTime myTau_jf
Definition: MESegment.h:530
MESegment * myNextSegment
The next segment of this edge, 0 if this is the last segment of this edge.
Definition: MESegment.h:518
double getRelativeJamThreshold() const
Returns the relative occupany of the segment (percentage of road used)) at which the segment is consi...
Definition: MESegment.h:277
bool hasBlockedLeader() const
whether a leader in any queue is blocked
Definition: MESegment.cpp:816
int remainingVehicleCapacity(const double vehLength) const
return the remaining physical space on this segment
Definition: MESegment.h:451
double getWaitingSeconds() const
Get the waiting time for vehicles in all queues.
Definition: MESegment.cpp:856
const double myLength
The segment's length.
Definition: MESegment.h:521
SUMOTime getMinimumHeadwayTime() const
return the minimum headway-time with which vehicles may enter or leave this segment
Definition: MESegment.h:465
SUMOTime getEventTime() const
Returns the (planned) time at which the next vehicle leaves this segment.
Definition: MESegment.cpp:739
const MSEdge & myEdge
The microsim edge this segment belongs to.
Definition: MESegment.h:515
MESegment(const std::string &id, const MSEdge &parent, MESegment *next, const double length, const double speed, const int idx, const bool multiQueue, const MesoEdgeType &edgeType)
constructor
Definition: MESegment.cpp:101
MEVehicle * removeCar(MEVehicle *v, SUMOTime leaveTime, const MSMoveReminder::Notification reason)
Removes the given car from the edge's que.
Definition: MESegment.cpp:408
std::vector< const MEVehicle * > getVehicles() const
returns all vehicles (for debugging)
Definition: MESegment.cpp:806
double getCapacity() const
Returns the sum of the lengths of all usable lanes of the segment in meters.
Definition: MESegment.h:250
double getEventTimeSeconds() const
Like getEventTime but returns seconds (for visualization)
Definition: MESegment.h:376
static MSEdge myDummyParent
Definition: MESegment.h:572
void recomputeJamThreshold(double jamThresh)
compute a value for myJamThreshold if jamThresh is negative, compute a value which allows free flow a...
Definition: MESegment.cpp:216
int getIndex() const
Returns the running index of the segment in the edge (0 is the most upstream).
Definition: MESegment.h:226
double getMeanSpeed() const
wrapper to satisfy the FunctionBinding signature
Definition: MESegment.h:294
int getCarNumber() const
Returns the total number of cars on the segment.
Definition: MESegment.h:206
void setSpeed(double newSpeed, SUMOTime currentTime, double jamThresh=DO_NOT_PATCH_JAM_THRESHOLD)
reset mySpeed and patch the speed of all vehicles in it. Also set/recompute myJamThreshold
Definition: MESegment.cpp:727
void loadState(const std::vector< std::string > &vehIDs, MSVehicleControl &vc, const SUMOTime blockTime, const int queIdx)
Loads the state of this segment with the given parameters.
Definition: MESegment.cpp:782
double myTau_length
Headway parameter for computing gross time headyway from net time headway, length and edge speed.
Definition: MESegment.h:547
SUMOTime myTau_jj
Definition: MESegment.h:530
SUMOTime newArrival(const MEVehicle *const v, double newSpeed, SUMOTime currentTime)
compute the new arrival time when switching speed
Definition: MESegment.cpp:718
bool myJunctionControl
Whether junction control is enabled.
Definition: MESegment.h:540
bool myTLSPenalty
Whether tls penalty is enabled.
Definition: MESegment.h:533
static const double DO_NOT_PATCH_JAM_THRESHOLD
Definition: MESegment.h:51
double getFlow() const
returns flow based on headway
Definition: MESegment.cpp:827
static bool isInvalid(const MESegment *segment)
whether the given segment is 0 or encodes vaporization
Definition: MESegment.h:443
SUMOTime getNextInsertionTime(SUMOTime earliestEntry) const
return a time after earliestEntry at which a vehicle may be inserted at full speed
Definition: MESegment.cpp:421
double myCapacity
The number of lanes represented by the queue * the length of the lane.
Definition: MESegment.h:550
bool myOvertaking
Whether overtaking is permitted on this segment.
Definition: MESegment.h:543
void prepareDetectorForWriting(MSMoveReminder &data, int queueIndex=-1)
Removes a data collector for a detector from this segment.
Definition: MESegment.cpp:279
MESegment * getNextSegment() const
Returns the following segment on the same edge (0 if it is the last).
Definition: MESegment.h:234
bool vaporizeAnyCar(SUMOTime currentTime, const MSDetectorFileOutput *filter)
tries to remove any car from this segment
Definition: MESegment.cpp:682
SUMOTime myTau_fj
Definition: MESegment.h:530
SUMOTime getTauJJ(double nextQueueSize, double nextQueueCapacity, double nextJamThreshold) const
Definition: MESegment.cpp:555
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.
Definition: OutputDevice.h:61
edge type specific meso parameters
Definition: MESegment.h:55