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-2019 German Aerospace Center (DLR) and others.
4 // This program and the accompanying materials
5 // are made available under the terms of the Eclipse Public License v2.0
6 // which accompanies this distribution, and is available at
7 // http://www.eclipse.org/legal/epl-v20.html
8 // SPDX-License-Identifier: EPL-2.0
9 /****************************************************************************/
14 // A single mesoscopic segment (cell)
15 /****************************************************************************/
16 #ifndef MESegment_h
17 #define MESegment_h
18 
19 
20 // ===========================================================================
21 // included modules
22 // ===========================================================================
23 #include <config.h>
24 
25 #include <vector>
26 #include <utils/common/Named.h>
27 #include <utils/common/SUMOTime.h>
28 
29 
30 // ===========================================================================
31 // class declarations
32 // ===========================================================================
33 class MSEdge;
34 class MSLink;
35 class MSMoveReminder;
36 class MSVehicleControl;
37 class MEVehicle;
38 class BinaryInputDevice;
39 class OutputDevice;
40 
41 
42 // ===========================================================================
43 // class definitions
44 // ===========================================================================
49 class MESegment : public Named {
50 public:
68  MESegment(const std::string& id,
69  const MSEdge& parent, MESegment* next,
70  double length, double speed,
71  int idx,
72  SUMOTime tauff, SUMOTime taufj,
73  SUMOTime taujf, SUMOTime taujj,
74  double jamThresh,
75  bool multiQueue, bool junctionControl);
76 
77 
78  typedef std::vector<MEVehicle*> Queue;
79  typedef std::vector<Queue> Queues;
82 
87  void addDetector(MSMoveReminder* data);
88 
93  void removeDetector(MSMoveReminder* data);
94 
101 
109  bool hasSpaceFor(const MEVehicle* veh, SUMOTime entryTime, bool init = false) const;
110 
117  bool initialise(MEVehicle* veh, SUMOTime time);
118 
123  inline int getCarNumber() const {
124  return myNumCars;
125  }
126 
128  inline int numQueues() const {
129  return (int)myCarQues.size();
130  }
134  inline const Queue& getQueue(int index) const {
135  assert(index < (int)myCarQues.size());
136  return myCarQues[index];
137  }
138 
143  inline int getIndex() const {
144  return myIndex;
145  }
146 
151  inline MESegment* getNextSegment() const {
152  return myNextSegment;
153  }
154 
159  inline double getLength() const {
160  return myLength;
161  }
162 
167  inline double getBruttoOccupancy() const {
168  return myOccupancy;
169  }
170 
171 
175  inline double getRelativeOccupancy() const {
176  return myOccupancy / myCapacity;
177  }
178 
183  inline double getRelativeJamThreshold() const {
184  return myJamThreshold / myCapacity;
185  }
186 
197  double getMeanSpeed(bool useCache) const;
198 
200  inline double getMeanSpeed() const {
201  return getMeanSpeed(true);
202  }
203 
204 
205  void writeVehicles(OutputDevice& of) const;
206 
214  MEVehicle* removeCar(MEVehicle* v, SUMOTime leaveTime, const MSMoveReminder::Notification reason);
215 
225  MSLink* getLink(const MEVehicle* veh, bool tlsPenalty = false) const;
226 
234  bool isOpen(const MEVehicle* veh) const;
235 
243  void send(MEVehicle* veh, MESegment* next, SUMOTime time, const MSMoveReminder::Notification reason);
244 
252  void receive(MEVehicle* veh, SUMOTime time, bool isDepart = false, bool afterTeleport = false);
253 
254 
260  bool vaporizeAnyCar(SUMOTime currentTime);
261 
265  inline const MSEdge& getEdge() const {
266  return myEdge;
267  }
268 
269 
274  void setSpeed(double newSpeed, SUMOTime currentTime, double jamThresh = DO_NOT_PATCH_JAM_THRESHOLD);
275 
279  SUMOTime getEventTime() const;
280 
282  inline double getEventTimeSeconds() const {
283  return STEPS2TIME(getEventTime());
284  }
285 
287  inline double getLastHeadwaySeconds() const {
288  return STEPS2TIME(myLastHeadway);
289  }
290 
292  inline double getEntryBlockTimeSeconds() const {
294  }
295 
298 
308  void saveState(OutputDevice& out);
309 
325  void loadState(const std::vector<std::string>& vehIDs, MSVehicleControl& vc, const SUMOTime blockTime, const int queIdx);
327 
328 
331  std::vector<const MEVehicle*> getVehicles() const;
332 
333 
337  double getFlow() const;
338 
339 
341  static inline bool isInvalid(const MESegment* segment) {
342  return segment == 0 || segment == &myVaporizationTarget;
343  }
344 
346  SUMOTime getNextInsertionTime(SUMOTime earliestEntry) const;
347 
350  inline bool free() const {
351  return myOccupancy <= myJamThreshold;
352  }
353 
355  inline int remainingVehicleCapacity(const double vehLength) const {
356  if (myOccupancy == 0. && myCapacity < vehLength) {
357  // even small segments can hold at least one vehicle
358  return 1;
359  }
360  return (int)((myCapacity - myOccupancy) / vehLength);
361  }
362 
364  inline SUMOTime getEntryBlockTime() const {
365  return myEntryBlockTime;
366  }
367 
369  inline void setEntryBlockTime(SUMOTime entryBlockTime) {
370  myEntryBlockTime = entryBlockTime;
371  }
372 
375  return myTau_ff;
376  }
377 
378  static const double DO_NOT_PATCH_JAM_THRESHOLD;
379 
381  void addReminders(MEVehicle* veh) const;
382 
387  SUMOTime getLinkPenalty(const MEVehicle* veh) const;
388 
393  double getTLSCapacity(const MEVehicle* veh) const;
394 
395 private:
396  bool overtake();
397 
398  SUMOTime getTimeHeadway(const MESegment* pred, const MEVehicle* veh);
399 
400  void setSpeedForQueue(double newSpeed, SUMOTime currentTime,
401  SUMOTime blockTime, const std::vector<MEVehicle*>& vehs);
402 
405  SUMOTime newArrival(const MEVehicle* const v, double newSpeed, SUMOTime currentTime);
406 
408  bool hasBlockedLeader() const;
409 
414  void recomputeJamThreshold(double jamThresh);
415 
417  double jamThresholdForSpeed(double speed, double jamThresh) const;
418 
420  bool limitedControlOverride(const MSLink* link) const;
421 
423  double getMaxPenaltySeconds() const;
424 
426  static bool useMultiQueue(bool multiQueue, const MSEdge& parent);
427 
429  inline SUMOTime tauWithVehLength(SUMOTime tau, double lengthWithGap) const {
430  return tau + (SUMOTime)(lengthWithGap / myTau_length);
431  }
432 
433 private:
435  const MSEdge& myEdge;
436 
439 
441  const double myLength;
442 
444  const int myIndex;
445 
449  double myTau_length;
450 
452  double myA, myB;
453 
456  const double myHeadwayCapacity;
457 
459  const double myCapacity;
460 
462  double myOccupancy;
463 
465  const bool myJunctionControl;
466 
468  const bool myTLSPenalty;
469 
471  const bool myMinorPenalty;
472 
475 
477  std::vector<MSMoveReminder*> myDetectorData;
478 
481 
484 
486  std::map<const MSEdge*, std::vector<int> > myFollowerMap;
487 
489  std::vector<SUMOTime> myBlockTimes;
490 
491  /* @brief The block time for vehicles who wish to enter this segment.
492  * @note since we do not know which queue will be used there is only one
493  * value for all queues */
495 
498 
499  /* @brief segment for signifying vaporization. This segment has invalid
500  * data and should only be used as a unique pointer */
503 
505  mutable double myMeanSpeed;
506 
509 
510 private:
512  MESegment(const MESegment&);
513 
515  MESegment& operator=(const MESegment&);
516 
518  MESegment(const std::string& id);
519 };
520 
521 
522 #endif
523 
524 /****************************************************************************/
MESegment::myTau_jj
const SUMOTime myTau_jj
Definition: MESegment.h:447
MEVehicle
A vehicle from the mesoscopic point of view.
Definition: MEVehicle.h:44
MESegment::myJamThreshold
double myJamThreshold
The space (in m) which needs to be occupied before the segment is considered jammed.
Definition: MESegment.h:474
MESegment::remainingVehicleCapacity
int remainingVehicleCapacity(const double vehLength) const
return the remaining physical space on this segment
Definition: MESegment.h:355
MESegment::myCarQues
Queues myCarQues
The car queues. Vehicles are inserted in the front and removed in the back.
Definition: MESegment.h:480
MESegment::newArrival
SUMOTime newArrival(const MEVehicle *const v, double newSpeed, SUMOTime currentTime)
compute the new arrival time when switching speed
Definition: MESegment.cpp:612
MESegment::myTau_fj
const SUMOTime myTau_fj
Definition: MESegment.h:447
SUMOTime.h
Named
Base class for objects which have an id.
Definition: Named.h:56
MESegment::getTLSCapacity
double getTLSCapacity(const MEVehicle *veh) const
Returns the average green time as fraction of cycle time.
Definition: MESegment.cpp:731
MESegment::limitedControlOverride
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:443
MESegment::myTau_ff
const SUMOTime myTau_ff
The time headway parameters, see the Eissfeldt thesis.
Definition: MESegment.h:447
MESegment::myMeanSpeed
double myMeanSpeed
the mean speed on this segment. Updated at event time or on demand
Definition: MESegment.h:505
MESegment
A single mesoscopic segment (cell)
Definition: MESegment.h:49
OutputDevice
Static storage of an output device and its base (abstract) implementation.
Definition: OutputDevice.h:63
MESegment::myNumCars
int myNumCars
The cached value for the number of cars.
Definition: MESegment.h:483
MESegment::loadState
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:660
MESegment::addDetector
void addDetector(MSMoveReminder *data)
Adds a data collector for a detector to this segment.
Definition: MESegment.cpp:211
MESegment::myLastHeadway
SUMOTime myLastHeadway
the last headway
Definition: MESegment.h:497
MESegment::getEdge
const MSEdge & getEdge() const
Returns the edge this segment belongs to.
Definition: MESegment.h:265
MESegment::initialise
bool initialise(MEVehicle *veh, SUMOTime time)
Inserts (emits) vehicle into the segment.
Definition: MESegment.cpp:278
MESegment::getRelativeOccupancy
double getRelativeOccupancy() const
Returns the relative occupany of the segment (percentage of road used))
Definition: MESegment.h:175
MESegment::hasSpaceFor
bool hasSpaceFor(const MEVehicle *veh, SUMOTime entryTime, bool init=false) const
Returns whether the given vehicle would still fit into the segment.
Definition: MESegment.cpp:251
MESegment::operator=
MESegment & operator=(const MESegment &)
Invalidated assignment operator.
MESegment::myEdge
const MSEdge & myEdge
The microsim edge this segment belongs to.
Definition: MESegment.h:435
SUMOTime
long long int SUMOTime
Definition: SUMOTime.h:34
MESegment::jamThresholdForSpeed
double jamThresholdForSpeed(double speed, double jamThresh) const
compute jam threshold for the given speed and jam-threshold option
Definition: MESegment.cpp:192
MESegment::getTimeHeadway
SUMOTime getTimeHeadway(const MESegment *pred, const MEVehicle *veh)
Definition: MESegment.cpp:352
MESegment::getEntryBlockTimeSeconds
double getEntryBlockTimeSeconds() const
get the last headway time in seconds
Definition: MESegment.h:292
MESegment::isOpen
bool isOpen(const MEVehicle *veh) const
Returns whether the vehicle may use the next link.
Definition: MESegment.cpp:405
MESegment::myDummyParent
static MSEdge myDummyParent
Definition: MESegment.h:501
MESegment::removeDetector
void removeDetector(MSMoveReminder *data)
Removes a data collector for a detector from this segment.
Definition: MESegment.cpp:222
MESegment::removeCar
MEVehicle * removeCar(MEVehicle *v, SUMOTime leaveTime, const MSMoveReminder::Notification reason)
Removes the given car from the edge's que.
Definition: MESegment.cpp:329
MESegment::recomputeJamThreshold
void recomputeJamThreshold(double jamThresh)
compute a value for myJamThreshold if jamThresh is negative, compute a value which allows free flow a...
Definition: MESegment.cpp:142
MESegment::getEntryBlockTime
SUMOTime getEntryBlockTime() const
return the next time at which a vehicle my enter this segment
Definition: MESegment.h:364
MSMoveReminder
Something on a lane to be noticed about vehicle movement.
Definition: MSMoveReminder.h:66
MESegment::myLastMeanSpeedUpdate
SUMOTime myLastMeanSpeedUpdate
the time at which myMeanSpeed was last updated
Definition: MESegment.h:508
MESegment::myFollowerMap
std::map< const MSEdge *, std::vector< int > > myFollowerMap
The follower edge to que index mapping for multi queue segments.
Definition: MESegment.h:486
MESegment::getMaxPenaltySeconds
double getMaxPenaltySeconds() const
return the maximum tls penalty for all links from this edge
Definition: MESegment.cpp:745
MESegment::myTau_jf
const SUMOTime myTau_jf
Definition: MESegment.h:447
MESegment::hasBlockedLeader
bool hasBlockedLeader() const
whether a leader in any queue is blocked
Definition: MESegment.cpp:693
MESegment::DO_NOT_PATCH_JAM_THRESHOLD
static const double DO_NOT_PATCH_JAM_THRESHOLD
Definition: MESegment.h:378
MESegment::prepareDetectorForWriting
void prepareDetectorForWriting(MSMoveReminder &data)
Updates data of a detector for all vehicle queues.
Definition: MESegment.cpp:237
MESegment::receive
void receive(MEVehicle *veh, SUMOTime time, bool isDepart=false, bool afterTeleport=false)
Adds the vehicle to the segment, adapting its parameters.
Definition: MESegment.cpp:491
MESegment::myNextSegment
MESegment * myNextSegment
The next segment of this edge, 0 if this is the last segment of this edge.
Definition: MESegment.h:438
MESegment::getMeanSpeed
double getMeanSpeed() const
wrapper to satisfy the FunctionBinding signature
Definition: MESegment.h:200
MESegment::getEventTimeSeconds
double getEventTimeSeconds() const
Like getEventTime but returns seconds (for visualization)
Definition: MESegment.h:282
MESegment::myHeadwayCapacity
const double myHeadwayCapacity
The capacity of the segment in number of cars, used only in time headway calculation This parameter h...
Definition: MESegment.h:456
Named.h
STEPS2TIME
#define STEPS2TIME(x)
Definition: SUMOTime.h:56
MESegment::getFlow
double getFlow() const
returns flow based on headway
Definition: MESegment.cpp:704
MESegment::getLink
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:376
MESegment::myIndex
const int myIndex
Running number of the segment in the edge.
Definition: MESegment.h:444
MESegment::getLastHeadwaySeconds
double getLastHeadwaySeconds() const
get the last headway time in seconds
Definition: MESegment.h:287
MESegment::getNextSegment
MESegment * getNextSegment() const
Returns the following segment on the same edge (0 if it is the last).
Definition: MESegment.h:151
MSEdge
A road/street connecting two junctions.
Definition: MSEdge.h:78
MESegment::getEventTime
SUMOTime getEventTime() const
Returns the (planned) time at which the next vehicle leaves this segment.
Definition: MESegment.cpp:633
MESegment::vaporizeAnyCar
bool vaporizeAnyCar(SUMOTime currentTime)
tries to remove any car from this segment
Definition: MESegment.cpp:575
MESegment::myTLSPenalty
const bool myTLSPenalty
Whether tls penalty is enabled.
Definition: MESegment.h:468
MESegment::myEntryBlockTime
SUMOTime myEntryBlockTime
Definition: MESegment.h:494
MESegment::overtake
bool overtake()
Definition: MESegment.cpp:478
MESegment::Queues
std::vector< Queue > Queues
Definition: MESegment.h:79
MESegment::isInvalid
static bool isInvalid(const MESegment *segment)
whether the given segment is 0 or encodes vaporization
Definition: MESegment.h:341
MESegment::getBruttoOccupancy
double getBruttoOccupancy() const
Returns the occupany of the segment (the sum of the vehicle lengths + minGaps)
Definition: MESegment.h:167
MESegment::getLength
double getLength() const
Returns the length of the segment in meters.
Definition: MESegment.h:159
MESegment::myBlockTimes
std::vector< SUMOTime > myBlockTimes
The block times.
Definition: MESegment.h:489
MESegment::free
bool free() const
return whether this segment is considered free as opposed to jammed
Definition: MESegment.h:350
MESegment::myJunctionControl
const bool myJunctionControl
Whether junction control is enabled.
Definition: MESegment.h:465
MESegment::myA
double myA
slope and axis offset for the jam-jam headway function
Definition: MESegment.h:452
MESegment::setEntryBlockTime
void setEntryBlockTime(SUMOTime entryBlockTime)
set the next time at which a vehicle my enter this segment
Definition: MESegment.h:369
MESegment::getNextInsertionTime
SUMOTime getNextInsertionTime(SUMOTime earliestEntry) const
return a time after earliestEntry at which a vehicle may be inserted at full speed
Definition: MESegment.cpp:361
MESegment::numQueues
int numQueues() const
return the number of queues
Definition: MESegment.h:128
MESegment::myMinorPenalty
const bool myMinorPenalty
Whether minor penalty is enabled.
Definition: MESegment.h:471
MESegment::send
void send(MEVehicle *veh, MESegment *next, SUMOTime time, const MSMoveReminder::Notification reason)
Removes the vehicle from the segment, adapting its parameters.
Definition: MESegment.cpp:456
MESegment::addReminders
void addReminders(MEVehicle *veh) const
add this lanes MoveReminders to the given vehicle
Definition: MESegment.cpp:484
MESegment::saveState
void saveState(OutputDevice &out)
Saves the state of this segment into the given stream.
Definition: MESegment.cpp:648
MESegment::getRelativeJamThreshold
double getRelativeJamThreshold() const
Returns the relative occupany of the segment (percentage of road used)) at which the segment is consi...
Definition: MESegment.h:183
MESegment::Queue
std::vector< MEVehicle * > Queue
Definition: MESegment.h:78
MESegment::myLength
const double myLength
The segment's length.
Definition: MESegment.h:441
MESegment::myCapacity
const double myCapacity
The number of lanes * the length.
Definition: MESegment.h:459
MESegment::tauWithVehLength
SUMOTime tauWithVehLength(SUMOTime tau, double lengthWithGap) const
convert net time gap (leader back to follower front) to gross time gap (leader front to follower fron...
Definition: MESegment.h:429
config.h
MESegment::myTau_length
double myTau_length
Headway parameter for computing gross time headyway from net time headway, length and edge speed.
Definition: MESegment.h:449
MSVehicleControl
The class responsible for building and deletion of vehicles.
Definition: MSVehicleControl.h:71
MESegment::getQueue
const Queue & getQueue(int index) const
Returns the cars in the queue with the given index for visualization.
Definition: MESegment.h:134
MESegment::myDetectorData
std::vector< MSMoveReminder * > myDetectorData
The data collection for all kinds of detectors.
Definition: MESegment.h:477
MESegment::MESegment
MESegment(const std::string &id, const MSEdge &parent, MESegment *next, double length, double speed, int idx, SUMOTime tauff, SUMOTime taufj, SUMOTime taujf, SUMOTime taujj, double jamThresh, bool multiQueue, bool junctionControl)
constructor
Definition: MESegment.cpp:66
MESegment::getLinkPenalty
SUMOTime getLinkPenalty(const MEVehicle *veh) const
Returns the penalty time for passing a link (if using gMesoTLSPenalty > 0 or gMesoMinorPenalty > 0)
Definition: MESegment.cpp:710
MESegment::writeVehicles
void writeVehicles(OutputDevice &of) const
Definition: MESegment.cpp:319
MESegment::setSpeed
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:621
MESegment::myVaporizationTarget
static MESegment myVaporizationTarget
Definition: MESegment.h:502
MESegment::myB
double myB
Definition: MESegment.h:452
MESegment::getIndex
int getIndex() const
Returns the running index of the segment in the edge (0 is the most upstream).
Definition: MESegment.h:143
MESegment::setSpeedForQueue
void setSpeedForQueue(double newSpeed, SUMOTime currentTime, SUMOTime blockTime, const std::vector< MEVehicle * > &vehs)
Definition: MESegment.cpp:593
MSMoveReminder::Notification
Notification
Definition of a vehicle state.
Definition: MSMoveReminder.h:91
MESegment::getVehicles
std::vector< const MEVehicle * > getVehicles() const
returns all vehicles (for debugging)
Definition: MESegment.cpp:683
MESegment::useMultiQueue
static bool useMultiQueue(bool multiQueue, const MSEdge &parent)
whether the segment requires use of multiple queues
Definition: MESegment.cpp:137
MESegment::myOccupancy
double myOccupancy
The occupied space (in m) on the segment.
Definition: MESegment.h:462
MESegment::getCarNumber
int getCarNumber() const
Returns the total number of cars on the segment.
Definition: MESegment.h:123
BinaryInputDevice
Encapsulates binary reading operations on a file.
Definition: BinaryInputDevice.h:57
MESegment::getMinimumHeadwayTime
SUMOTime getMinimumHeadwayTime() const
return the minimum headway-time with which vehicles may enter or leave this segment
Definition: MESegment.h:374