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.org/sumo
3// Copyright (C) 2001-2022 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 private:
117
118 std::vector<MEVehicle*> myVehicles;
119
121 double myOccupancy = 0.;
122
125
128 };
129
130public:
141 MESegment(const std::string& id,
142 const MSEdge& parent, MESegment* next,
143 const double length, const double speed,
144 const int idx,
145 const bool multiQueue,
146 const MesoEdgeType& edgeType);
147
149 void initSegment(const MesoEdgeType& edgeType, const MSEdge& parent, const double capacity);
150
153
158 void addDetector(MSMoveReminder* data);
159
164 void removeDetector(MSMoveReminder* data);
165
172
181 SUMOTime hasSpaceFor(const MEVehicle* const veh, const SUMOTime entryTime, int& qIdx, const bool init = false) const;
182
189 bool initialise(MEVehicle* veh, SUMOTime time);
190
195 inline int getCarNumber() const {
196 return myNumVehicles;
197 }
198
200 inline int numQueues() const {
201 return (int)myQueues.size();
202 }
206 inline const std::vector<MEVehicle*>& getQueue(int index) const {
207 assert(index < (int)myQueues.size());
208 return myQueues[index].getVehicles();
209 }
210
215 inline int getIndex() const {
216 return myIndex;
217 }
218
223 inline MESegment* getNextSegment() const {
224 return myNextSegment;
225 }
226
231 inline double getLength() const {
232 return myLength;
233 }
234
239 inline double getCapacity() const {
240 return myCapacity;
241 }
242
247 inline double getBruttoOccupancy() const {
248 double occ = 0.;
249 for (const Queue& q : myQueues) {
250 occ += q.getOccupancy();
251 }
252 return occ;
253 }
254
258 inline double getRelativeOccupancy() const {
260 }
261
266 inline double getRelativeJamThreshold() const {
267 return myJamThreshold / myCapacity;
268 }
269
280 double getMeanSpeed(bool useCache) const;
281
283 inline double getMeanSpeed() const {
284 return getMeanSpeed(true);
285 }
286
287
288 void writeVehicles(OutputDevice& of) const;
289
298
308 MSLink* getLink(const MEVehicle* veh, bool tlsPenalty = false) const;
309
317 bool isOpen(const MEVehicle* veh) const;
318
326 void send(MEVehicle* veh, MESegment* const next, const int nextQIdx, SUMOTime time, const MSMoveReminder::Notification reason);
327
335 void receive(MEVehicle* veh, const int qIdx, SUMOTime time, const bool isDepart = false, const bool isTeleport = false, const bool newEdge = false);
336
337
343 bool vaporizeAnyCar(SUMOTime currentTime, const MSDetectorFileOutput* filter);
344
348 inline const MSEdge& getEdge() const {
349 return myEdge;
350 }
351
352
357 void setSpeed(double newSpeed, SUMOTime currentTime, double jamThresh = DO_NOT_PATCH_JAM_THRESHOLD);
358
362 SUMOTime getEventTime() const;
363
365 inline double getEventTimeSeconds() const {
366 return STEPS2TIME(getEventTime());
367 }
368
370 inline double getLastHeadwaySeconds() const {
372 }
373
375 inline double getEntryBlockTimeSeconds() const {
377 for (const Queue& q : myQueues) {
378 t = MIN2(t, q.getEntryBlockTime());
379 }
380 return STEPS2TIME(t);
381 }
382
384 double getWaitingSeconds() const;
385
388
398 void saveState(OutputDevice& out) const;
399
401 void clearState();
402
418 void loadState(const std::vector<std::string>& vehIDs, MSVehicleControl& vc, const SUMOTime blockTime, const int queIdx);
420
421
424 std::vector<const MEVehicle*> getVehicles() const;
425
429 double getFlow() const;
430
432 static inline bool isInvalid(const MESegment* segment) {
433 return segment == nullptr || segment == &myVaporizationTarget;
434 }
435
437 SUMOTime getNextInsertionTime(SUMOTime earliestEntry) const;
438
440 inline int remainingVehicleCapacity(const double vehLength) const {
441 int cap = 0;
442 for (const Queue& q : myQueues) {
443 if (q.getOccupancy() == 0. && myQueueCapacity < vehLength) {
444 // even small segments can hold at least one vehicle
445 cap += 1;
446 } else {
447 cap += (int)((myQueueCapacity - q.getOccupancy()) / vehLength);
448 }
449 }
450 return cap;
451 }
452
455 return myTau_ff;
456 }
457
459 void addReminders(MEVehicle* veh) const;
460
465 SUMOTime getLinkPenalty(const MEVehicle* veh) const;
466
468 void updatePermissions();
469
470private:
471 bool overtake();
472
473 void setSpeedForQueue(double newSpeed, SUMOTime currentTime,
474 SUMOTime blockTime, const std::vector<MEVehicle*>& vehs);
475
478 SUMOTime newArrival(const MEVehicle* const v, double newSpeed, SUMOTime currentTime);
479
481 bool hasBlockedLeader() const;
482
487 void recomputeJamThreshold(double jamThresh);
488
490 double jamThresholdForSpeed(double speed, double jamThresh) const;
491
493 bool limitedControlOverride(const MSLink* link) const;
494
496 inline SUMOTime tauWithVehLength(SUMOTime tau, double lengthWithGap, double vehicleTau) const {
497 return (SUMOTime)((double)tau * vehicleTau + lengthWithGap * myTau_length);
498 }
499
500 SUMOTime getTauJJ(double nextQueueSize, double nextQueueCapacity, double nextJamThreshold) const;
501
502private:
505
508
510 const double myLength;
511
513 const int myIndex;
514
517
520
523
525 bool myCheckMinorPenalty; // for legacy compatibility (#7802, 7804)
527
530
534
537
539 double myCapacity = 0.;
540
542 double myQueueCapacity = 0.;
543
546
548 std::vector<MSMoveReminder*> myDetectorData;
549
551 std::vector<Queue> myQueues;
552
555
557 std::map<const MSEdge*, int> myFollowerMap;
558
561
562 /* @brief segment for signifying vaporization. This segment has invalid
563 * data and should only be used as a unique pointer */
566
568 mutable double myMeanSpeed;
569
572
573private:
576
579
581 MESegment(const std::string& id);
582};
long long int SUMOTime
Definition: GUI.h:36
#define STEPS2TIME(x)
Definition: SUMOTime.h:54
#define SUMOTime_MAX
Definition: SUMOTime.h:33
#define SUMOTime_MIN
Definition: SUMOTime.h:34
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:71
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:121
bool allows(SUMOVehicleClass vclass) const
Definition: MESegment.h:89
std::vector< MEVehicle * > & getModifiableVehicles()
Definition: MESegment.h:80
SUMOTime myBlockTime
The block time.
Definition: MESegment.h:127
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:124
double getOccupancy() const
Definition: MESegment.h:83
std::vector< MEVehicle * > myVehicles
Definition: MESegment.h:118
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:116
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:563
double myQueueCapacity
The number of lanes represented by the queue * the length of the lane.
Definition: MESegment.h:542
bool overtake()
Definition: MESegment.cpp:557
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:496
SUMOTime myTau_ff
The time headway parameters, see the Eissfeldt thesis.
Definition: MESegment.h:519
double getEntryBlockTimeSeconds() const
get the earliest entry time in seconds
Definition: MESegment.h:375
bool initialise(MEVehicle *veh, SUMOTime time)
Inserts (emits) vehicle into the segment.
Definition: MESegment.cpp:329
std::vector< Queue > myQueues
The car queues. Vehicles are inserted in the front and removed in the back.
Definition: MESegment.h:551
double getBruttoOccupancy() const
Returns the occupany of the segment (the sum of the vehicle lengths + minGaps)
Definition: MESegment.h:247
SUMOTime myLastHeadway
the last headway
Definition: MESegment.h:560
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:480
bool isOpen(const MEVehicle *veh) const
Returns whether the vehicle may use the next link.
Definition: MESegment.cpp:440
double getLastHeadwaySeconds() const
get the last headway time in seconds
Definition: MESegment.h:370
double getRelativeOccupancy() const
Returns the relative occupany of the segment (percentage of road used))
Definition: MESegment.h:258
void clearState()
Remove all vehicles before quick-loading state.
Definition: MESegment.cpp:748
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:571
SUMOTime getLinkPenalty(const MEVehicle *veh) const
Returns the penalty time for passing a link (if using gMesoTLSPenalty > 0 or gMesoMinorPenalty > 0)
Definition: MESegment.cpp:806
void writeVehicles(OutputDevice &of) const
Definition: MESegment.cpp:371
std::map< const MSEdge *, int > myFollowerMap
The follower edge to allowed que index mapping for multi queue segments.
Definition: MESegment.h:557
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:411
int myNumVehicles
The cached value for the number of vehicles.
Definition: MESegment.h:554
void setSpeedForQueue(double newSpeed, SUMOTime currentTime, SUMOTime blockTime, const std::vector< MEVehicle * > &vehs)
Definition: MESegment.cpp:672
double getLength() const
Returns the length of the segment in meters.
Definition: MESegment.h:231
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:275
const std::vector< MEVehicle * > & getQueue(int index) const
Returns the cars in the queue with the given index for visualization.
Definition: MESegment.h:206
void updatePermissions()
called when permissions change due to Rerouter or TraCI
Definition: MESegment.cpp:190
void removeDetector(MSMoveReminder *data)
Removes a data collector for a detector from this segment.
Definition: MESegment.cpp:247
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:727
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:133
void prepareDetectorForWriting(MSMoveReminder &data)
Updates data of a detector for all vehicle queues.
Definition: MESegment.cpp:261
const MSEdge & getEdge() const
Returns the edge this segment belongs to.
Definition: MESegment.h:348
static MESegment myVaporizationTarget
Definition: MESegment.h:565
int numQueues() const
return the number of queues
Definition: MESegment.h:200
double myJamThreshold
The space (in m) which needs to be occupied before the segment is considered jammed.
Definition: MESegment.h:545
const int myIndex
Running number of the segment in the edge.
Definition: MESegment.h:513
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:493
SUMOTime myMinorPenalty
Definition: MESegment.h:526
double myMeanSpeed
the mean speed on this segment. Updated at event time or on demand
Definition: MESegment.h:568
bool myCheckMinorPenalty
penalty for minor links
Definition: MESegment.h:525
std::vector< MSMoveReminder * > myDetectorData
The data collection for all kinds of detectors.
Definition: MESegment.h:548
double jamThresholdForSpeed(double speed, double jamThresh) const
compute jam threshold for the given speed and jam-threshold option
Definition: MESegment.cpp:217
SUMOTime myLastMeanSpeedUpdate
the time at which myMeanSpeed was last updated
Definition: MESegment.h:571
SUMOTime myTau_jf
Definition: MESegment.h:519
MESegment * myNextSegment
The next segment of this edge, 0 if this is the last segment of this edge.
Definition: MESegment.h:507
double getRelativeJamThreshold() const
Returns the relative occupany of the segment (percentage of road used)) at which the segment is consi...
Definition: MESegment.h:266
bool hasBlockedLeader() const
whether a leader in any queue is blocked
Definition: MESegment.cpp:789
int remainingVehicleCapacity(const double vehLength) const
return the remaining physical space on this segment
Definition: MESegment.h:440
double getWaitingSeconds() const
Get the waiting time for vehicles in all queues.
Definition: MESegment.cpp:829
const double myLength
The segment's length.
Definition: MESegment.h:510
SUMOTime getMinimumHeadwayTime() const
return the minimum headway-time with which vehicles may enter or leave this segment
Definition: MESegment.h:454
SUMOTime getEventTime() const
Returns the (planned) time at which the next vehicle leaves this segment.
Definition: MESegment.cpp:712
const MSEdge & myEdge
The microsim edge this segment belongs to.
Definition: MESegment.h:504
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:87
MEVehicle * removeCar(MEVehicle *v, SUMOTime leaveTime, const MSMoveReminder::Notification reason)
Removes the given car from the edge's que.
Definition: MESegment.cpp:381
std::vector< const MEVehicle * > getVehicles() const
returns all vehicles (for debugging)
Definition: MESegment.cpp:779
void addDetector(MSMoveReminder *data)
Adds a data collector for a detector to this segment.
Definition: MESegment.cpp:236
double getCapacity() const
Returns the sum of the lengths of all usable lanes of the segment in meters.
Definition: MESegment.h:239
double getEventTimeSeconds() const
Like getEventTime but returns seconds (for visualization)
Definition: MESegment.h:365
static MSEdge myDummyParent
Definition: MESegment.h:564
void recomputeJamThreshold(double jamThresh)
compute a value for myJamThreshold if jamThresh is negative, compute a value which allows free flow a...
Definition: MESegment.cpp:202
int getIndex() const
Returns the running index of the segment in the edge (0 is the most upstream).
Definition: MESegment.h:215
double getMeanSpeed() const
wrapper to satisfy the FunctionBinding signature
Definition: MESegment.h:283
int getCarNumber() const
Returns the total number of cars on the segment.
Definition: MESegment.h:195
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:700
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:755
double myTau_length
Headway parameter for computing gross time headyway from net time headway, length and edge speed.
Definition: MESegment.h:536
SUMOTime myTau_jj
Definition: MESegment.h:519
SUMOTime newArrival(const MEVehicle *const v, double newSpeed, SUMOTime currentTime)
compute the new arrival time when switching speed
Definition: MESegment.cpp:691
bool myJunctionControl
Whether junction control is enabled.
Definition: MESegment.h:529
bool myTLSPenalty
Whether tls penalty is enabled.
Definition: MESegment.h:522
static const double DO_NOT_PATCH_JAM_THRESHOLD
Definition: MESegment.h:51
double getFlow() const
returns flow based on headway
Definition: MESegment.cpp:800
static bool isInvalid(const MESegment *segment)
whether the given segment is 0 or encodes vaporization
Definition: MESegment.h:432
SUMOTime getNextInsertionTime(SUMOTime earliestEntry) const
return a time after earliestEntry at which a vehicle may be inserted at full speed
Definition: MESegment.cpp:394
double myCapacity
The number of lanes represented by the queue * the length of the lane.
Definition: MESegment.h:539
bool myOvertaking
Whether overtaking is permitted on this segment.
Definition: MESegment.h:532
MESegment * getNextSegment() const
Returns the following segment on the same edge (0 if it is the last).
Definition: MESegment.h:223
bool vaporizeAnyCar(SUMOTime currentTime, const MSDetectorFileOutput *filter)
tries to remove any car from this segment
Definition: MESegment.cpp:655
SUMOTime myTau_fj
Definition: MESegment.h:519
SUMOTime getTauJJ(double nextQueueSize, double nextQueueCapacity, double nextJamThreshold) const
Definition: MESegment.cpp:528
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