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 /****************************************************************************/
15 // A single mesoscopic segment (cell)
16 /****************************************************************************/
17 #ifndef MESegment_h
18 #define MESegment_h
19 
20 
21 // ===========================================================================
22 // included modules
23 // ===========================================================================
24 #include <config.h>
25 
26 #include <vector>
27 #include <utils/common/Named.h>
28 #include <utils/common/SUMOTime.h>
29 
30 
31 // ===========================================================================
32 // class declarations
33 // ===========================================================================
34 class MSEdge;
35 class MSLink;
36 class MSMoveReminder;
37 class MSVehicleControl;
38 class MEVehicle;
39 class BinaryInputDevice;
40 class OutputDevice;
41 
42 
43 // ===========================================================================
44 // class definitions
45 // ===========================================================================
50 class MESegment : public Named {
51 public:
69  MESegment(const std::string& id,
70  const MSEdge& parent, MESegment* next,
71  double length, double speed,
72  int idx,
73  SUMOTime tauff, SUMOTime taufj,
74  SUMOTime taujf, SUMOTime taujj,
75  double jamThresh,
76  bool multiQueue, bool junctionControl);
77 
78 
79  typedef std::vector<MEVehicle*> Queue;
80  typedef std::vector<Queue> Queues;
83 
88  void addDetector(MSMoveReminder* data);
89 
94  void removeDetector(MSMoveReminder* data);
95 
102 
110  bool hasSpaceFor(const MEVehicle* veh, SUMOTime entryTime, bool init = false) const;
111 
118  bool initialise(MEVehicle* veh, SUMOTime time);
119 
124  inline int getCarNumber() const {
125  return myNumCars;
126  }
127 
129  inline int numQueues() const {
130  return (int)myCarQues.size();
131  }
135  inline const Queue& getQueue(int index) const {
136  assert(index < (int)myCarQues.size());
137  return myCarQues[index];
138  }
139 
144  inline int getIndex() const {
145  return myIndex;
146  }
147 
152  inline MESegment* getNextSegment() const {
153  return myNextSegment;
154  }
155 
160  inline double getLength() const {
161  return myLength;
162  }
163 
168  inline double getBruttoOccupancy() const {
169  return myOccupancy;
170  }
171 
172 
176  inline double getRelativeOccupancy() const {
177  return myOccupancy / myCapacity;
178  }
179 
184  inline double getRelativeJamThreshold() const {
185  return myJamThreshold / myCapacity;
186  }
187 
198  double getMeanSpeed(bool useCache) const;
199 
201  inline double getMeanSpeed() const {
202  return getMeanSpeed(true);
203  }
204 
205 
206  void writeVehicles(OutputDevice& of) const;
207 
215  MEVehicle* removeCar(MEVehicle* v, SUMOTime leaveTime, const MSMoveReminder::Notification reason);
216 
226  MSLink* getLink(const MEVehicle* veh, bool tlsPenalty = false) const;
227 
235  bool isOpen(const MEVehicle* veh) const;
236 
244  void send(MEVehicle* veh, MESegment* next, SUMOTime time, const MSMoveReminder::Notification reason);
245 
253  void receive(MEVehicle* veh, SUMOTime time, bool isDepart = false, bool afterTeleport = false);
254 
255 
261  bool vaporizeAnyCar(SUMOTime currentTime);
262 
266  inline const MSEdge& getEdge() const {
267  return myEdge;
268  }
269 
270 
275  void setSpeed(double newSpeed, SUMOTime currentTime, double jamThresh = DO_NOT_PATCH_JAM_THRESHOLD);
276 
280  SUMOTime getEventTime() const;
281 
283  inline double getEventTimeSeconds() const {
284  return STEPS2TIME(getEventTime());
285  }
286 
288  inline double getLastHeadwaySeconds() const {
289  return STEPS2TIME(myLastHeadway);
290  }
291 
293  inline double getEntryBlockTimeSeconds() const {
295  }
296 
299 
309  void saveState(OutputDevice& out);
310 
326  void loadState(const std::vector<std::string>& vehIDs, MSVehicleControl& vc, const SUMOTime blockTime, const int queIdx);
328 
329 
332  std::vector<const MEVehicle*> getVehicles() const;
333 
334 
338  double getFlow() const;
339 
340 
342  static inline bool isInvalid(const MESegment* segment) {
343  return segment == 0 || segment == &myVaporizationTarget;
344  }
345 
347  SUMOTime getNextInsertionTime(SUMOTime earliestEntry) const;
348 
351  inline bool free() const {
352  return myOccupancy <= myJamThreshold;
353  }
354 
356  inline int remainingVehicleCapacity(const double vehLength) const {
357  if (myOccupancy == 0. && myCapacity < vehLength) {
358  // even small segments can hold at least one vehicle
359  return 1;
360  }
361  return (int)((myCapacity - myOccupancy) / vehLength);
362  }
363 
365  inline SUMOTime getEntryBlockTime() const {
366  return myEntryBlockTime;
367  }
368 
370  inline void setEntryBlockTime(SUMOTime entryBlockTime) {
371  myEntryBlockTime = entryBlockTime;
372  }
373 
376  return myTau_ff;
377  }
378 
379  static const double DO_NOT_PATCH_JAM_THRESHOLD;
380 
382  void addReminders(MEVehicle* veh) const;
383 
388  SUMOTime getLinkPenalty(const MEVehicle* veh) const;
389 
394  double getTLSCapacity(const MEVehicle* veh) const;
395 
396 private:
397  bool overtake();
398 
399  SUMOTime getTimeHeadway(const MESegment* pred, const MEVehicle* veh);
400 
401  void setSpeedForQueue(double newSpeed, SUMOTime currentTime,
402  SUMOTime blockTime, const std::vector<MEVehicle*>& vehs);
403 
406  SUMOTime newArrival(const MEVehicle* const v, double newSpeed, SUMOTime currentTime);
407 
409  bool hasBlockedLeader() const;
410 
415  void recomputeJamThreshold(double jamThresh);
416 
418  double jamThresholdForSpeed(double speed, double jamThresh) const;
419 
421  bool limitedControlOverride(const MSLink* link) const;
422 
424  double getMaxPenaltySeconds() const;
425 
427  static bool useMultiQueue(bool multiQueue, const MSEdge& parent);
428 
430  inline SUMOTime tauWithVehLength(SUMOTime tau, double lengthWithGap) const {
431  return tau + (SUMOTime)(lengthWithGap / myTau_length);
432  }
433 
434 private:
436  const MSEdge& myEdge;
437 
440 
442  const double myLength;
443 
445  const int myIndex;
446 
450  double myTau_length;
451 
453  double myA, myB;
454 
457  const double myHeadwayCapacity;
458 
460  const double myCapacity;
461 
463  double myOccupancy;
464 
466  const bool myJunctionControl;
467 
469  const bool myTLSPenalty;
470 
472  const bool myMinorPenalty;
473 
476 
478  std::vector<MSMoveReminder*> myDetectorData;
479 
481  Queues myCarQues;
482 
485 
487  std::map<const MSEdge*, std::vector<int> > myFollowerMap;
488 
490  std::vector<SUMOTime> myBlockTimes;
491 
492  /* @brief The block time for vehicles who wish to enter this segment.
493  * @note since we do not know which queue will be used there is only one
494  * value for all queues */
496 
499 
500  /* @brief segment for signifying vaporization. This segment has invalid
501  * data and should only be used as a unique pointer */
504 
506  mutable double myMeanSpeed;
507 
510 
511 private:
513  MESegment(const MESegment&);
514 
516  MESegment& operator=(const MESegment&);
517 
519  MESegment(const std::string& id);
520 };
521 
522 
523 #endif
524 
525 /****************************************************************************/
MESegment * getNextSegment() const
Returns the following segment on the same edge (0 if it is the last).
Definition: MESegment.h:152
double myMeanSpeed
the mean speed on this segment. Updated at event time or on demand
Definition: MESegment.h:506
static MESegment myVaporizationTarget
Definition: MESegment.h:503
double getRelativeOccupancy() const
Returns the relative occupany of the segment (percentage of road used))
Definition: MESegment.h:176
long long int SUMOTime
Definition: SUMOTime.h:35
bool isOpen(const MEVehicle *veh) const
Returns whether the vehicle may use the next link.
Definition: MESegment.cpp:408
std::vector< MEVehicle * > Queue
Definition: MESegment.h:79
double getMeanSpeed() const
wrapper to satisfy the FunctionBinding signature
Definition: MESegment.h:201
A vehicle from the mesoscopic point of view.
Definition: MEVehicle.h:45
double getLength() const
Returns the length of the segment in meters.
Definition: MESegment.h:160
const bool myMinorPenalty
Whether minor penalty is enabled.
Definition: MESegment.h:472
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:624
int getCarNumber() const
Returns the total number of cars on the segment.
Definition: MESegment.h:124
double myOccupancy
The occupied space (in m) on the segment.
Definition: MESegment.h:463
bool overtake()
Definition: MESegment.cpp:481
bool initialise(MEVehicle *veh, SUMOTime time)
Inserts (emits) vehicle into the segment.
Definition: MESegment.cpp:279
SUMOTime getEntryBlockTime() const
return the next time at which a vehicle my enter this segment
Definition: MESegment.h:365
SUMOTime myEntryBlockTime
Definition: MESegment.h:495
double getEventTimeSeconds() const
Like getEventTime but returns seconds (for visualization)
Definition: MESegment.h:283
int getIndex() const
Returns the running index of the segment in the edge (0 is the most upstream).
Definition: MESegment.h:144
double getEntryBlockTimeSeconds() const
get the last headway time in seconds
Definition: MESegment.h:293
double jamThresholdForSpeed(double speed, double jamThresh) const
compute jam threshold for the given speed and jam-threshold option
Definition: MESegment.cpp:193
int myNumCars
The cached value for the number of cars.
Definition: MESegment.h:484
Notification
Definition of a vehicle state.
std::vector< MSMoveReminder * > myDetectorData
The data collection for all kinds of detectors.
Definition: MESegment.h:478
double getMaxPenaltySeconds() const
return the maximum tls penalty for all links from this edge
Definition: MESegment.cpp:748
static bool useMultiQueue(bool multiQueue, const MSEdge &parent)
whether the segment requires use of multiple queues
Definition: MESegment.cpp:138
double getTLSCapacity(const MEVehicle *veh) const
Returns the average green time as fraction of cycle time.
Definition: MESegment.cpp:734
const double myCapacity
The number of lanes * the length.
Definition: MESegment.h:460
bool hasBlockedLeader() const
whether a leader in any queue is blocked
Definition: MESegment.cpp:696
SUMOTime getEventTime() const
Returns the (planned) time at which the next vehicle leaves this segment.
Definition: MESegment.cpp:636
void setSpeedForQueue(double newSpeed, SUMOTime currentTime, SUMOTime blockTime, const std::vector< MEVehicle *> &vehs)
Definition: MESegment.cpp:596
SUMOTime getMinimumHeadwayTime() const
return the minimum headway-time with which vehicles may enter or leave this segment ...
Definition: MESegment.h:375
double myJamThreshold
The space (in m) which needs to be occupied before the segment is considered jammed.
Definition: MESegment.h:475
Queues myCarQues
The car queues. Vehicles are inserted in the front and removed in the back.
Definition: MESegment.h:481
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:252
static const double DO_NOT_PATCH_JAM_THRESHOLD
Definition: MESegment.h:379
void setEntryBlockTime(SUMOTime entryBlockTime)
set the next time at which a vehicle my enter this segment
Definition: MESegment.h:370
void writeVehicles(OutputDevice &of) const
Definition: MESegment.cpp:320
A road/street connecting two junctions.
Definition: MSEdge.h:76
void send(MEVehicle *veh, MESegment *next, SUMOTime time, const MSMoveReminder::Notification reason)
Removes the vehicle from the segment, adapting its parameters.
Definition: MESegment.cpp:459
SUMOTime getLinkPenalty(const MEVehicle *veh) const
Returns the penalty time for passing a link (if using gMesoTLSPenalty > 0 or gMesoMinorPenalty > 0) ...
Definition: MESegment.cpp:713
void receive(MEVehicle *veh, SUMOTime time, bool isDepart=false, bool afterTeleport=false)
Adds the vehicle to the segment, adapting its parameters.
Definition: MESegment.cpp:494
bool free() const
return whether this segment is considered free as opposed to jammed
Definition: MESegment.h:351
MESegment & operator=(const MESegment &)
Invalidated assignment operator.
SUMOTime myLastMeanSpeedUpdate
the time at which myMeanSpeed was last updated
Definition: MESegment.h:509
std::map< const MSEdge *, std::vector< int > > myFollowerMap
The follower edge to que index mapping for multi queue segments.
Definition: MESegment.h:487
const SUMOTime myTau_jf
Definition: MESegment.h:448
double myTau_length
Headway parameter for computing gross time headyway from net time headway, length and edge speed...
Definition: MESegment.h:450
static bool isInvalid(const MESegment *segment)
whether the given segment is 0 or encodes vaporization
Definition: MESegment.h:342
static MSEdge myDummyParent
Definition: MESegment.h:502
#define STEPS2TIME(x)
Definition: SUMOTime.h:57
void recomputeJamThreshold(double jamThresh)
compute a value for myJamThreshold if jamThresh is negative, compute a value which allows free flow a...
Definition: MESegment.cpp:143
void addDetector(MSMoveReminder *data)
Adds a data collector for a detector to this segment.
Definition: MESegment.cpp:212
Something on a lane to be noticed about vehicle movement.
double getBruttoOccupancy() const
Returns the occupany of the segment (the sum of the vehicle lengths + minGaps)
Definition: MESegment.h:168
bool vaporizeAnyCar(SUMOTime currentTime)
tries to remove any car from this segment
Definition: MESegment.cpp:578
std::vector< const MEVehicle * > getVehicles() const
returns all vehicles (for debugging)
Definition: MESegment.cpp:686
void removeDetector(MSMoveReminder *data)
Removes a data collector for a detector from this segment.
Definition: MESegment.cpp:223
Base class for objects which have an id.
Definition: Named.h:57
MEVehicle * removeCar(MEVehicle *v, SUMOTime leaveTime, const MSMoveReminder::Notification reason)
Removes the given car from the edge&#39;s que.
Definition: MESegment.cpp:330
const MSEdge & myEdge
The microsim edge this segment belongs to.
Definition: MESegment.h:436
SUMOTime getNextInsertionTime(SUMOTime earliestEntry) const
return a time after earliestEntry at which a vehicle may be inserted at full speed ...
Definition: MESegment.cpp:362
const SUMOTime myTau_jj
Definition: MESegment.h:448
void addReminders(MEVehicle *veh) const
add this lanes MoveReminders to the given vehicle
Definition: MESegment.cpp:487
const bool myTLSPenalty
Whether tls penalty is enabled.
Definition: MESegment.h:469
MESegment * myNextSegment
The next segment of this edge, 0 if this is the last segment of this edge.
Definition: MESegment.h:439
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:663
const double myHeadwayCapacity
The capacity of the segment in number of cars, used only in time headway calculation This parameter h...
Definition: MESegment.h:457
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:446
SUMOTime myLastHeadway
the last headway
Definition: MESegment.h:498
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:377
double getRelativeJamThreshold() const
Returns the relative occupany of the segment (percentage of road used)) at which the segment is consi...
Definition: MESegment.h:184
double getLastHeadwaySeconds() const
get the last headway time in seconds
Definition: MESegment.h:288
A single mesoscopic segment (cell)
Definition: MESegment.h:50
double getFlow() const
returns flow based on headway
Definition: MESegment.cpp:707
int numQueues() const
return the number of queues
Definition: MESegment.h:129
SUMOTime newArrival(const MEVehicle *const v, double newSpeed, SUMOTime currentTime)
compute the new arrival time when switching speed
Definition: MESegment.cpp:615
const bool myJunctionControl
Whether junction control is enabled.
Definition: MESegment.h:466
double myB
Definition: MESegment.h:453
const SUMOTime myTau_fj
Definition: MESegment.h:448
const Queue & getQueue(int index) const
Returns the cars in the queue with the given index for visualization.
Definition: MESegment.h:135
Static storage of an output device and its base (abstract) implementation.
Definition: OutputDevice.h:64
void saveState(OutputDevice &out)
Saves the state of this segment into the given stream.
Definition: MESegment.cpp:651
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:67
std::vector< SUMOTime > myBlockTimes
The block times.
Definition: MESegment.h:490
The class responsible for building and deletion of vehicles.
void prepareDetectorForWriting(MSMoveReminder &data)
Updates data of a detector for all vehicle queues.
Definition: MESegment.cpp:238
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:430
SUMOTime getTimeHeadway(const MESegment *pred, const MEVehicle *veh)
Definition: MESegment.cpp:353
int remainingVehicleCapacity(const double vehLength) const
return the remaining physical space on this segment
Definition: MESegment.h:356
const int myIndex
Running number of the segment in the edge.
Definition: MESegment.h:445
const MSEdge & getEdge() const
Returns the edge this segment belongs to.
Definition: MESegment.h:266
const SUMOTime myTau_ff
The time headway parameters, see the Eissfeldt thesis.
Definition: MESegment.h:448
std::vector< Queue > Queues
Definition: MESegment.h:80
Encapsulates binary reading operations on a file.
double myA
slope and axis offset for the jam-jam headway function
Definition: MESegment.h:453
const double myLength
The segment&#39;s length.
Definition: MESegment.h:442