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-2017 German Aerospace Center (DLR) and others.
4 /****************************************************************************/
5 //
6 // This program and the accompanying materials
7 // are made available under the terms of the Eclipse Public License v2.0
8 // which accompanies this distribution, and is available at
9 // http://www.eclipse.org/legal/epl-v20.html
10 //
11 /****************************************************************************/
17 // A single mesoscopic segment (cell)
18 /****************************************************************************/
19 #ifndef MESegment_h
20 #define MESegment_h
21 
22 
23 // ===========================================================================
24 // included modules
25 // ===========================================================================
26 #ifdef _MSC_VER
27 #include <windows_config.h>
28 #else
29 #include <config.h>
30 #endif
31 
32 #include <vector>
33 #include <utils/common/Named.h>
34 #include <utils/common/SUMOTime.h>
35 
36 
37 // ===========================================================================
38 // class declarations
39 // ===========================================================================
40 class MSEdge;
41 class MSLink;
42 class MSMoveReminder;
43 class MSVehicleControl;
44 class MEVehicle;
45 class BinaryInputDevice;
46 class OutputDevice;
47 
48 
49 // ===========================================================================
50 // class definitions
51 // ===========================================================================
56 class MESegment : public Named {
57 public:
75  MESegment(const std::string& id,
76  const MSEdge& parent, MESegment* next,
77  double length, double speed,
78  int idx,
79  SUMOTime tauff, SUMOTime taufj,
80  SUMOTime taujf, SUMOTime taujj,
81  double jamThresh,
82  bool multiQueue, bool junctionControl);
83 
84 
85  typedef std::vector<MEVehicle*> Queue;
86  typedef std::vector<Queue> Queues;
89 
94  void addDetector(MSMoveReminder* data);
95 
100  void removeDetector(MSMoveReminder* data);
101 
108 
116  bool hasSpaceFor(const MEVehicle* veh, SUMOTime entryTime, bool init = false) const;
117 
124  bool initialise(MEVehicle* veh, SUMOTime time);
125 
130  int getCarNumber() const;
131 
133  inline int numQueues() const {
134  return (int)myCarQues.size();
135  }
139  inline const Queue& getQueue(int index) const {
140  assert(index < (int)myCarQues.size());
141  return myCarQues[index];
142  }
143 
148  inline int getIndex() const {
149  return myIndex;
150  }
151 
156  inline MESegment* getNextSegment() const {
157  return myNextSegment;
158  }
159 
164  inline double getLength() const {
165  return myLength;
166  }
167 
172  inline double getBruttoOccupancy() const {
173  return myOccupancy;
174  }
175 
176 
180  inline double getRelativeOccupancy() const {
181  return myOccupancy / myCapacity;
182  }
183 
188  inline double getRelativeJamThreshold() const {
189  return myJamThreshold / myCapacity;
190  }
191 
202  double getMeanSpeed(bool useCache) const;
203 
205  inline double getMeanSpeed() const {
206  return getMeanSpeed(true);
207  }
208 
209 
210  void writeVehicles(OutputDevice& of) const;
211 
219  MEVehicle* removeCar(MEVehicle* v, SUMOTime leaveTime, MESegment* next);
220 
230  MSLink* getLink(const MEVehicle* veh, bool tlsPenalty = false) const;
231 
239  bool isOpen(const MEVehicle* veh) const;
240 
248  void send(MEVehicle* veh, MESegment* next, SUMOTime time);
249 
257  void receive(MEVehicle* veh, SUMOTime time, bool isDepart = false, bool afterTeleport = false);
258 
259 
265  bool vaporizeAnyCar(SUMOTime currentTime);
266 
270  inline const MSEdge& getEdge() const {
271  return myEdge;
272  }
273 
274 
279  void setSpeed(double newSpeed, SUMOTime currentTime, double jamThresh = DO_NOT_PATCH_JAM_THRESHOLD);
280 
284  SUMOTime getEventTime() const;
285 
287  inline double getEventTimeSeconds() const {
288  return STEPS2TIME(getEventTime());
289  }
290 
292  inline double getLastHeadwaySeconds() const {
293  return STEPS2TIME(myLastHeadway);
294  }
295 
298 
308  void saveState(OutputDevice& out);
309 
325  void loadState(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:
402  void updateDetectorsOnLeave(MEVehicle* v, SUMOTime currentTime, MESegment* next);
403 
404  bool overtake();
405 
406  SUMOTime getTimeHeadway(const MESegment* pred, const MEVehicle* veh);
407 
408  void setSpeedForQueue(double newSpeed, SUMOTime currentTime,
409  SUMOTime blockTime, const std::vector<MEVehicle*>& vehs);
410 
413  SUMOTime newArrival(const MEVehicle* const v, double newSpeed, SUMOTime currentTime);
414 
416  bool hasBlockedLeader() const;
417 
422  void recomputeJamThreshold(double jamThresh);
423 
425  double jamThresholdForSpeed(double speed, double jamThresh) const;
426 
428  bool limitedControlOverride(const MSLink* link) const;
429 
431  double getMaxPenaltySeconds() const;
432 
434  static bool useMultiQueue(bool multiQueue, const MSEdge& parent);
435 
437  inline SUMOTime tauWithVehLength(SUMOTime tau, double lengthWithGap) const {
438  return tau + (SUMOTime)(lengthWithGap / myTau_length);
439  }
440 
441 private:
443  const MSEdge& myEdge;
444 
447 
449  const double myLength;
450 
452  const int myIndex;
453 
457  double myTau_length;
458 
460  double myA, myB;
461 
464  const double myHeadwayCapacity;
465 
467  const double myCapacity;
468 
470  double myOccupancy;
471 
473  const bool myJunctionControl;
474 
476  const bool myTLSPenalty;
477 
479  const bool myMinorPenalty;
480 
483 
485  std::vector<MSMoveReminder*> myDetectorData;
486 
488  Queues myCarQues;
489 
491  std::map<const MSEdge*, std::vector<int> > myFollowerMap;
492 
494  std::vector<SUMOTime> myBlockTimes;
495 
496  /* @brief The block time for vehicles who wish to enter this segment.
497  * @note since we do not know which queue will be used there is only one
498  * value for all queues */
500 
503 
504  /* @brief segment for signifying vaporization. This segment has invalid
505  * data and should only be used as a unique pointer */
508 
510  mutable double myMeanSpeed;
511 
514 
515 private:
517  MESegment(const MESegment&);
518 
520  MESegment& operator=(const MESegment&);
521 
523  MESegment(const std::string& id);
524 };
525 
526 
527 #endif
528 
529 /****************************************************************************/
MESegment * getNextSegment() const
Returns the following segment on the same edge (0 if it is the last).
Definition: MESegment.h:156
double myMeanSpeed
the mean speed on this segment. Updated at event time or on demand
Definition: MESegment.h:510
static MESegment myVaporizationTarget
Definition: MESegment.h:507
double getRelativeOccupancy() const
Returns the relative occupany of the segment (percentage of road used))
Definition: MESegment.h:180
bool isOpen(const MEVehicle *veh) const
Returns whether the vehicle may use the next link.
Definition: MESegment.cpp:425
std::vector< MEVehicle * > Queue
Definition: MESegment.h:85
double getMeanSpeed() const
wrapper to satisfy the FunctionBinding signature
Definition: MESegment.h:205
A vehicle from the mesoscopic point of view.
Definition: MEVehicle.h:51
double getLength() const
Returns the length of the segment in meters.
Definition: MESegment.h:164
const bool myMinorPenalty
Whether minor penalty is enabled.
Definition: MESegment.h:479
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:612
int getCarNumber() const
Returns the total number of cars on the segment.
Definition: MESegment.cpp:302
MEVehicle * removeCar(MEVehicle *v, SUMOTime leaveTime, MESegment *next)
Removes the given car from the edge&#39;s que.
Definition: MESegment.cpp:348
double myOccupancy
The occupied space (in m) on the segment.
Definition: MESegment.h:470
bool overtake()
Definition: MESegment.cpp:473
bool initialise(MEVehicle *veh, SUMOTime time)
Inserts (emits) vehicle into the segment.
Definition: MESegment.cpp:287
SUMOTime getEntryBlockTime() const
return the next time at which a vehicle my enter this segment
Definition: MESegment.h:364
SUMOTime myEntryBlockTime
Definition: MESegment.h:499
double getEventTimeSeconds() const
Like getEventTime but returns seconds (for visualization)
Definition: MESegment.h:287
int getIndex() const
Returns the running index of the segment in the edge (0 is the most upstream).
Definition: MESegment.h:148
double jamThresholdForSpeed(double speed, double jamThresh) const
compute jam threshold for the given speed and jam-threshold option
Definition: MESegment.cpp:191
std::vector< MSMoveReminder * > myDetectorData
The data collection for all kinds of detectors.
Definition: MESegment.h:485
double getMaxPenaltySeconds() const
return the maximum tls penalty for all links from this edge
Definition: MESegment.cpp:733
static bool useMultiQueue(bool multiQueue, const MSEdge &parent)
whether the segment requires use of multiple queues
Definition: MESegment.cpp:136
double getTLSCapacity(const MEVehicle *veh) const
Returns the average green time as fraction of cycle time.
Definition: MESegment.cpp:719
const double myCapacity
The number of lanes * the length.
Definition: MESegment.h:467
bool hasBlockedLeader() const
whether a leader in any queue is blocked
Definition: MESegment.cpp:681
SUMOTime getEventTime() const
Returns the (planned) time at which the next vehicle leaves this segment.
Definition: MESegment.cpp:624
void setSpeedForQueue(double newSpeed, SUMOTime currentTime, SUMOTime blockTime, const std::vector< MEVehicle *> &vehs)
Definition: MESegment.cpp:584
SUMOTime getMinimumHeadwayTime() const
return the minimum headway-time with which vehicles may enter or leave this segment ...
Definition: MESegment.h:374
double myJamThreshold
The space (in m) which needs to be occupied before the segment is considered jammed.
Definition: MESegment.h:482
Queues myCarQues
The car queues. Vehicles are inserted in the front and removed in the back.
Definition: MESegment.h:488
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:260
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:651
static const double DO_NOT_PATCH_JAM_THRESHOLD
Definition: MESegment.h:378
void setEntryBlockTime(SUMOTime entryBlockTime)
set the next time at which a vehicle my enter this segment
Definition: MESegment.h:369
void writeVehicles(OutputDevice &of) const
Definition: MESegment.cpp:338
A road/street connecting two junctions.
Definition: MSEdge.h:80
SUMOTime getLinkPenalty(const MEVehicle *veh) const
Returns the penalty time for passing a link (if using gMesoTLSPenalty > 0 or gMesoMinorPenalty > 0) ...
Definition: MESegment.cpp:698
void receive(MEVehicle *veh, SUMOTime time, bool isDepart=false, bool afterTeleport=false)
Adds the vehicle to the segment, adapting its parameters.
Definition: MESegment.cpp:486
bool free() const
return whether this segment is considered free as opposed to jammed
Definition: MESegment.h:350
MESegment & operator=(const MESegment &)
Invalidated assignment operator.
SUMOTime myLastMeanSpeedUpdate
the time at which myMeanSpeed was last updated
Definition: MESegment.h:513
std::map< const MSEdge *, std::vector< int > > myFollowerMap
The follower edge to que index mapping for multi queue segments.
Definition: MESegment.h:491
const SUMOTime myTau_jf
Definition: MESegment.h:455
double myTau_length
Headway parameter for computing gross time headyway from net time headway, length and edge speed...
Definition: MESegment.h:457
static bool isInvalid(const MESegment *segment)
whether the given segment is 0 or encodes vaporization
Definition: MESegment.h:341
static MSEdge myDummyParent
Definition: MESegment.h:506
void updateDetectorsOnLeave(MEVehicle *v, SUMOTime currentTime, MESegment *next)
Updates data of all detectors for a leaving vehicle.
Definition: MESegment.cpp:230
#define STEPS2TIME(x)
Definition: SUMOTime.h:64
void recomputeJamThreshold(double jamThresh)
compute a value for myJamThreshold if jamThresh is negative, compute a value which allows free flow a...
Definition: MESegment.cpp:141
void addDetector(MSMoveReminder *data)
Adds a data collector for a detector to this segment.
Definition: MESegment.cpp:204
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:172
bool vaporizeAnyCar(SUMOTime currentTime)
tries to remove any car from this segment
Definition: MESegment.cpp:566
std::vector< const MEVehicle * > getVehicles() const
returns all vehicles (for debugging)
Definition: MESegment.cpp:671
void removeDetector(MSMoveReminder *data)
Removes a data collector for a detector from this segment.
Definition: MESegment.cpp:215
Base class for objects which have an id.
Definition: Named.h:54
const MSEdge & myEdge
The microsim edge this segment belongs to.
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:379
const SUMOTime myTau_jj
Definition: MESegment.h:455
void addReminders(MEVehicle *veh) const
add this lanes MoveReminders to the given vehicle
Definition: MESegment.cpp:479
const bool myTLSPenalty
Whether tls penalty is enabled.
Definition: MESegment.h:476
MESegment * myNextSegment
The next segment of this edge, 0 if this is the last segment of this edge.
Definition: MESegment.h:446
const double myHeadwayCapacity
The capacity of the segment in number of cars, used only in time headway calculation This parameter h...
Definition: MESegment.h:464
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:441
SUMOTime myLastHeadway
the last headway
Definition: MESegment.h:502
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:394
double getRelativeJamThreshold() const
Returns the relative occupany of the segment (percentage of road used)) at which the segment is consi...
Definition: MESegment.h:188
double getLastHeadwaySeconds() const
get the last headway time in seconds
Definition: MESegment.h:292
A single mesoscopic segment (cell)
Definition: MESegment.h:56
double getFlow() const
returns flow based on headway
Definition: MESegment.cpp:692
int numQueues() const
return the number of queues
Definition: MESegment.h:133
SUMOTime newArrival(const MEVehicle *const v, double newSpeed, SUMOTime currentTime)
compute the new arrival time when switching speed
Definition: MESegment.cpp:603
const bool myJunctionControl
Whether junction control is enabled.
Definition: MESegment.h:473
double myB
Definition: MESegment.h:460
const SUMOTime myTau_fj
Definition: MESegment.h:455
const Queue & getQueue(int index) const
Returns the cars in the queue with the given index for visualization.
Definition: MESegment.h:139
Static storage of an output device and its base (abstract) implementation.
Definition: OutputDevice.h:70
void saveState(OutputDevice &out)
Saves the state of this segment into the given stream.
Definition: MESegment.cpp:639
long long int SUMOTime
Definition: TraCIDefs.h:51
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
std::vector< SUMOTime > myBlockTimes
The block times.
Definition: MESegment.h:494
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:246
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:437
SUMOTime getTimeHeadway(const MESegment *pred, const MEVehicle *veh)
Definition: MESegment.cpp:370
void send(MEVehicle *veh, MESegment *next, SUMOTime time)
Removes the vehicle from the segment, adapting its parameters.
Definition: MESegment.cpp:454
int remainingVehicleCapacity(const double vehLength) const
return the remaining physical space on this segment
Definition: MESegment.h:355
const int myIndex
Running number of the segment in the edge.
Definition: MESegment.h:452
const MSEdge & getEdge() const
Returns the edge this segment belongs to.
Definition: MESegment.h:270
const SUMOTime myTau_ff
The time headway parameters, see the Eissfeldt thesis.
Definition: MESegment.h:455
std::vector< Queue > Queues
Definition: MESegment.h:86
Encapsulates binary reading operations on a file.
double myA
slope and axis offset for the jam-jam headway function
Definition: MESegment.h:460
const double myLength
The segment&#39;s length.
Definition: MESegment.h:449