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-2018 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  int getCarNumber() const;
125 
127  inline int numQueues() const {
128  return (int)myCarQues.size();
129  }
133  inline const Queue& getQueue(int index) const {
134  assert(index < (int)myCarQues.size());
135  return myCarQues[index];
136  }
137 
142  inline int getIndex() const {
143  return myIndex;
144  }
145 
150  inline MESegment* getNextSegment() const {
151  return myNextSegment;
152  }
153 
158  inline double getLength() const {
159  return myLength;
160  }
161 
166  inline double getBruttoOccupancy() const {
167  return myOccupancy;
168  }
169 
170 
174  inline double getRelativeOccupancy() const {
175  return myOccupancy / myCapacity;
176  }
177 
182  inline double getRelativeJamThreshold() const {
183  return myJamThreshold / myCapacity;
184  }
185 
196  double getMeanSpeed(bool useCache) const;
197 
199  inline double getMeanSpeed() const {
200  return getMeanSpeed(true);
201  }
202 
203 
204  void writeVehicles(OutputDevice& of) const;
205 
213  MEVehicle* removeCar(MEVehicle* v, SUMOTime leaveTime, MESegment* next);
214 
224  MSLink* getLink(const MEVehicle* veh, bool tlsPenalty = false) const;
225 
233  bool isOpen(const MEVehicle* veh) const;
234 
242  void send(MEVehicle* veh, MESegment* next, SUMOTime time);
243 
251  void receive(MEVehicle* veh, SUMOTime time, bool isDepart = false, bool afterTeleport = false);
252 
253 
259  bool vaporizeAnyCar(SUMOTime currentTime);
260 
264  inline const MSEdge& getEdge() const {
265  return myEdge;
266  }
267 
268 
273  void setSpeed(double newSpeed, SUMOTime currentTime, double jamThresh = DO_NOT_PATCH_JAM_THRESHOLD);
274 
278  SUMOTime getEventTime() const;
279 
281  inline double getEventTimeSeconds() const {
282  return STEPS2TIME(getEventTime());
283  }
284 
286  inline double getLastHeadwaySeconds() const {
287  return STEPS2TIME(myLastHeadway);
288  }
289 
291  inline double getEntryBlockTimeSeconds() const {
293  }
294 
297 
307  void saveState(OutputDevice& out);
308 
324  void loadState(std::vector<std::string>& vehIDs, MSVehicleControl& vc, const SUMOTime blockTime, const int queIdx);
326 
327 
330  std::vector<const MEVehicle*> getVehicles() const;
331 
332 
336  double getFlow() const;
337 
338 
340  static inline bool isInvalid(const MESegment* segment) {
341  return segment == 0 || segment == &myVaporizationTarget;
342  }
343 
345  SUMOTime getNextInsertionTime(SUMOTime earliestEntry) const;
346 
349  inline bool free() const {
350  return myOccupancy <= myJamThreshold;
351  }
352 
354  inline int remainingVehicleCapacity(const double vehLength) const {
355  if (myOccupancy == 0. && myCapacity < vehLength) {
356  // even small segments can hold at least one vehicle
357  return 1;
358  }
359  return (int)((myCapacity - myOccupancy) / vehLength);
360  }
361 
363  inline SUMOTime getEntryBlockTime() const {
364  return myEntryBlockTime;
365  }
366 
368  inline void setEntryBlockTime(SUMOTime entryBlockTime) {
369  myEntryBlockTime = entryBlockTime;
370  }
371 
374  return myTau_ff;
375  }
376 
377  static const double DO_NOT_PATCH_JAM_THRESHOLD;
378 
380  void addReminders(MEVehicle* veh) const;
381 
386  SUMOTime getLinkPenalty(const MEVehicle* veh) const;
387 
392  double getTLSCapacity(const MEVehicle* veh) const;
393 
394 private:
401  void updateDetectorsOnLeave(MEVehicle* v, SUMOTime currentTime, MESegment* next);
402 
403  bool overtake();
404 
405  SUMOTime getTimeHeadway(const MESegment* pred, const MEVehicle* veh);
406 
407  void setSpeedForQueue(double newSpeed, SUMOTime currentTime,
408  SUMOTime blockTime, const std::vector<MEVehicle*>& vehs);
409 
412  SUMOTime newArrival(const MEVehicle* const v, double newSpeed, SUMOTime currentTime);
413 
415  bool hasBlockedLeader() const;
416 
421  void recomputeJamThreshold(double jamThresh);
422 
424  double jamThresholdForSpeed(double speed, double jamThresh) const;
425 
427  bool limitedControlOverride(const MSLink* link) const;
428 
430  double getMaxPenaltySeconds() const;
431 
433  static bool useMultiQueue(bool multiQueue, const MSEdge& parent);
434 
436  inline SUMOTime tauWithVehLength(SUMOTime tau, double lengthWithGap) const {
437  return tau + (SUMOTime)(lengthWithGap / myTau_length);
438  }
439 
440 private:
442  const MSEdge& myEdge;
443 
446 
448  const double myLength;
449 
451  const int myIndex;
452 
456  double myTau_length;
457 
459  double myA, myB;
460 
463  const double myHeadwayCapacity;
464 
466  const double myCapacity;
467 
469  double myOccupancy;
470 
472  const bool myJunctionControl;
473 
475  const bool myTLSPenalty;
476 
478  const bool myMinorPenalty;
479 
482 
484  std::vector<MSMoveReminder*> myDetectorData;
485 
487  Queues myCarQues;
488 
490  std::map<const MSEdge*, std::vector<int> > myFollowerMap;
491 
493  std::vector<SUMOTime> myBlockTimes;
494 
495  /* @brief The block time for vehicles who wish to enter this segment.
496  * @note since we do not know which queue will be used there is only one
497  * value for all queues */
499 
502 
503  /* @brief segment for signifying vaporization. This segment has invalid
504  * data and should only be used as a unique pointer */
507 
509  mutable double myMeanSpeed;
510 
513 
514 private:
516  MESegment(const MESegment&);
517 
519  MESegment& operator=(const MESegment&);
520 
522  MESegment(const std::string& id);
523 };
524 
525 
526 #endif
527 
528 /****************************************************************************/
MESegment * getNextSegment() const
Returns the following segment on the same edge (0 if it is the last).
Definition: MESegment.h:150
double myMeanSpeed
the mean speed on this segment. Updated at event time or on demand
Definition: MESegment.h:509
static MESegment myVaporizationTarget
Definition: MESegment.h:506
double getRelativeOccupancy() const
Returns the relative occupany of the segment (percentage of road used))
Definition: MESegment.h:174
long long int SUMOTime
Definition: SUMOTime.h:36
bool isOpen(const MEVehicle *veh) const
Returns whether the vehicle may use the next link.
Definition: MESegment.cpp:432
std::vector< MEVehicle * > Queue
Definition: MESegment.h:79
double getMeanSpeed() const
wrapper to satisfy the FunctionBinding signature
Definition: MESegment.h:199
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:158
const bool myMinorPenalty
Whether minor penalty is enabled.
Definition: MESegment.h:478
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:647
int getCarNumber() const
Returns the total number of cars on the segment.
Definition: MESegment.cpp:309
MEVehicle * removeCar(MEVehicle *v, SUMOTime leaveTime, MESegment *next)
Removes the given car from the edge&#39;s que.
Definition: MESegment.cpp:355
double myOccupancy
The occupied space (in m) on the segment.
Definition: MESegment.h:469
bool overtake()
Definition: MESegment.cpp:505
bool initialise(MEVehicle *veh, SUMOTime time)
Inserts (emits) vehicle into the segment.
Definition: MESegment.cpp:294
SUMOTime getEntryBlockTime() const
return the next time at which a vehicle my enter this segment
Definition: MESegment.h:363
SUMOTime myEntryBlockTime
Definition: MESegment.h:498
double getEventTimeSeconds() const
Like getEventTime but returns seconds (for visualization)
Definition: MESegment.h:281
int getIndex() const
Returns the running index of the segment in the edge (0 is the most upstream).
Definition: MESegment.h:142
double getEntryBlockTimeSeconds() const
get the last headway time in seconds
Definition: MESegment.h:291
double jamThresholdForSpeed(double speed, double jamThresh) const
compute jam threshold for the given speed and jam-threshold option
Definition: MESegment.cpp:192
std::vector< MSMoveReminder * > myDetectorData
The data collection for all kinds of detectors.
Definition: MESegment.h:484
double getMaxPenaltySeconds() const
return the maximum tls penalty for all links from this edge
Definition: MESegment.cpp:770
static bool useMultiQueue(bool multiQueue, const MSEdge &parent)
whether the segment requires use of multiple queues
Definition: MESegment.cpp:137
double getTLSCapacity(const MEVehicle *veh) const
Returns the average green time as fraction of cycle time.
Definition: MESegment.cpp:756
const double myCapacity
The number of lanes * the length.
Definition: MESegment.h:466
bool hasBlockedLeader() const
whether a leader in any queue is blocked
Definition: MESegment.cpp:718
SUMOTime getEventTime() const
Returns the (planned) time at which the next vehicle leaves this segment.
Definition: MESegment.cpp:659
void setSpeedForQueue(double newSpeed, SUMOTime currentTime, SUMOTime blockTime, const std::vector< MEVehicle *> &vehs)
Definition: MESegment.cpp:619
SUMOTime getMinimumHeadwayTime() const
return the minimum headway-time with which vehicles may enter or leave this segment ...
Definition: MESegment.h:373
double myJamThreshold
The space (in m) which needs to be occupied before the segment is considered jammed.
Definition: MESegment.h:481
Queues myCarQues
The car queues. Vehicles are inserted in the front and removed in the back.
Definition: MESegment.h:487
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:267
void loadState(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:686
static const double DO_NOT_PATCH_JAM_THRESHOLD
Definition: MESegment.h:377
void setEntryBlockTime(SUMOTime entryBlockTime)
set the next time at which a vehicle my enter this segment
Definition: MESegment.h:368
void writeVehicles(OutputDevice &of) const
Definition: MESegment.cpp:345
A road/street connecting two junctions.
Definition: MSEdge.h:75
SUMOTime getLinkPenalty(const MEVehicle *veh) const
Returns the penalty time for passing a link (if using gMesoTLSPenalty > 0 or gMesoMinorPenalty > 0) ...
Definition: MESegment.cpp:735
void receive(MEVehicle *veh, SUMOTime time, bool isDepart=false, bool afterTeleport=false)
Adds the vehicle to the segment, adapting its parameters.
Definition: MESegment.cpp:518
bool free() const
return whether this segment is considered free as opposed to jammed
Definition: MESegment.h:349
MESegment & operator=(const MESegment &)
Invalidated assignment operator.
SUMOTime myLastMeanSpeedUpdate
the time at which myMeanSpeed was last updated
Definition: MESegment.h:512
std::map< const MSEdge *, std::vector< int > > myFollowerMap
The follower edge to que index mapping for multi queue segments.
Definition: MESegment.h:490
const SUMOTime myTau_jf
Definition: MESegment.h:454
double myTau_length
Headway parameter for computing gross time headyway from net time headway, length and edge speed...
Definition: MESegment.h:456
static bool isInvalid(const MESegment *segment)
whether the given segment is 0 or encodes vaporization
Definition: MESegment.h:340
static MSEdge myDummyParent
Definition: MESegment.h:505
void updateDetectorsOnLeave(MEVehicle *v, SUMOTime currentTime, MESegment *next)
Updates data of all detectors for a leaving vehicle.
Definition: MESegment.cpp:237
#define STEPS2TIME(x)
Definition: SUMOTime.h:58
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
void addDetector(MSMoveReminder *data)
Adds a data collector for a detector to this segment.
Definition: MESegment.cpp:211
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:166
bool vaporizeAnyCar(SUMOTime currentTime)
tries to remove any car from this segment
Definition: MESegment.cpp:601
std::vector< const MEVehicle * > getVehicles() const
returns all vehicles (for debugging)
Definition: MESegment.cpp:708
void removeDetector(MSMoveReminder *data)
Removes a data collector for a detector from this segment.
Definition: MESegment.cpp:222
Base class for objects which have an id.
Definition: Named.h:49
const MSEdge & myEdge
The microsim edge this segment belongs to.
Definition: MESegment.h:442
SUMOTime getNextInsertionTime(SUMOTime earliestEntry) const
return a time after earliestEntry at which a vehicle may be inserted at full speed ...
Definition: MESegment.cpp:386
const SUMOTime myTau_jj
Definition: MESegment.h:454
void addReminders(MEVehicle *veh) const
add this lanes MoveReminders to the given vehicle
Definition: MESegment.cpp:511
const bool myTLSPenalty
Whether tls penalty is enabled.
Definition: MESegment.h:475
MESegment * myNextSegment
The next segment of this edge, 0 if this is the last segment of this edge.
Definition: MESegment.h:445
const double myHeadwayCapacity
The capacity of the segment in number of cars, used only in time headway calculation This parameter h...
Definition: MESegment.h:463
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:470
SUMOTime myLastHeadway
the last headway
Definition: MESegment.h:501
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:401
double getRelativeJamThreshold() const
Returns the relative occupany of the segment (percentage of road used)) at which the segment is consi...
Definition: MESegment.h:182
double getLastHeadwaySeconds() const
get the last headway time in seconds
Definition: MESegment.h:286
A single mesoscopic segment (cell)
Definition: MESegment.h:50
double getFlow() const
returns flow based on headway
Definition: MESegment.cpp:729
int numQueues() const
return the number of queues
Definition: MESegment.h:127
SUMOTime newArrival(const MEVehicle *const v, double newSpeed, SUMOTime currentTime)
compute the new arrival time when switching speed
Definition: MESegment.cpp:638
const bool myJunctionControl
Whether junction control is enabled.
Definition: MESegment.h:472
double myB
Definition: MESegment.h:459
const SUMOTime myTau_fj
Definition: MESegment.h:454
const Queue & getQueue(int index) const
Returns the cars in the queue with the given index for visualization.
Definition: MESegment.h:133
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:674
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:493
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:253
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:436
SUMOTime getTimeHeadway(const MESegment *pred, const MEVehicle *veh)
Definition: MESegment.cpp:377
void send(MEVehicle *veh, MESegment *next, SUMOTime time)
Removes the vehicle from the segment, adapting its parameters.
Definition: MESegment.cpp:483
int remainingVehicleCapacity(const double vehLength) const
return the remaining physical space on this segment
Definition: MESegment.h:354
const int myIndex
Running number of the segment in the edge.
Definition: MESegment.h:451
const MSEdge & getEdge() const
Returns the edge this segment belongs to.
Definition: MESegment.h:264
const SUMOTime myTau_ff
The time headway parameters, see the Eissfeldt thesis.
Definition: MESegment.h:454
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:459
const double myLength
The segment&#39;s length.
Definition: MESegment.h:448