SUMO - Simulation of Urban MObility
MESegment.h
Go to the documentation of this file.
1 /****************************************************************************/
7 // A single mesoscopic segment (cell)
8 /****************************************************************************/
9 // SUMO, Simulation of Urban MObility; see http://sumo.dlr.de/
10 // Copyright (C) 2001-2016 DLR (http://www.dlr.de/) and contributors
11 /****************************************************************************/
12 //
13 // This file is part of SUMO.
14 // SUMO is free software: you can redistribute it and/or modify
15 // it under the terms of the GNU General Public License as published by
16 // the Free Software Foundation, either version 3 of the License, or
17 // (at your option) any later version.
18 //
19 /****************************************************************************/
20 #ifndef MESegment_h
21 #define MESegment_h
22 
23 
24 // ===========================================================================
25 // included modules
26 // ===========================================================================
27 #ifdef _MSC_VER
28 #include <windows_config.h>
29 #else
30 #include <config.h>
31 #endif
32 
33 #include <vector>
34 #include <utils/common/Named.h>
35 #include <utils/common/SUMOTime.h>
36 
37 
38 // ===========================================================================
39 // class declarations
40 // ===========================================================================
41 class MSEdge;
42 class MSLink;
43 class MSMoveReminder;
44 class MSVehicleControl;
45 class MEVehicle;
46 class BinaryInputDevice;
47 class OutputDevice;
48 
49 
50 // ===========================================================================
51 // class definitions
52 // ===========================================================================
57 class MESegment : public Named {
58 public:
76  MESegment(const std::string& id,
77  const MSEdge& parent, MESegment* next,
78  double length, double speed,
79  int idx,
80  SUMOTime tauff, SUMOTime taufj,
81  SUMOTime taujf, SUMOTime taujj,
82  double jamThresh,
83  bool multiQueue, bool junctionControl);
84 
85 
86  typedef std::vector<MEVehicle*> Queue;
87  typedef std::vector<Queue> Queues;
90 
95  void addDetector(MSMoveReminder* data);
96 
101  void removeDetector(MSMoveReminder* data);
102 
109 
117  bool hasSpaceFor(const MEVehicle* veh, SUMOTime entryTime, bool init = false) const;
118 
125  bool initialise(MEVehicle* veh, SUMOTime time);
126 
131  int getCarNumber() const;
132 
134  inline int numQueues() const {
135  return (int)myCarQues.size();
136  }
140  inline const Queue& getQueue(int index) const {
141  assert(index < (int)myCarQues.size());
142  return myCarQues[index];
143  }
144 
149  inline int getIndex() const {
150  return myIndex;
151  }
152 
157  inline MESegment* getNextSegment() const {
158  return myNextSegment;
159  }
160 
165  inline double getLength() const {
166  return myLength;
167  }
168 
173  inline double getBruttoOccupancy() const {
174  return myOccupancy;
175  }
176 
177 
181  inline double getRelativeOccupancy() const {
182  return myOccupancy / myCapacity;
183  }
184 
189  inline double getRelativeJamThreshold() const {
190  return myJamThreshold / myCapacity;
191  }
192 
203  double getMeanSpeed(bool useCache) const;
204 
206  inline double getMeanSpeed() const {
207  return getMeanSpeed(true);
208  }
209 
210 
211  void writeVehicles(OutputDevice& of) const;
212 
220  MEVehicle* removeCar(MEVehicle* v, SUMOTime leaveTime, MESegment* next);
221 
231  MSLink* getLink(const MEVehicle* veh, bool tlsPenalty = false) const;
232 
240  bool isOpen(const MEVehicle* veh) const;
241 
249  void send(MEVehicle* veh, MESegment* next, SUMOTime time);
250 
258  void receive(MEVehicle* veh, SUMOTime time, bool isDepart = false, bool afterTeleport = false);
259 
260 
266  bool vaporizeAnyCar(SUMOTime currentTime);
267 
271  inline const MSEdge& getEdge() const {
272  return myEdge;
273  }
274 
275 
280  void setSpeed(double newSpeed, SUMOTime currentTime, double jamThresh = DO_NOT_PATCH_JAM_THRESHOLD);
281 
285  SUMOTime getEventTime() const;
286 
288  inline double getEventTimeSeconds() const {
289  return STEPS2TIME(getEventTime());
290  }
291 
293  inline double getLastHeadwaySeconds() const {
294  return STEPS2TIME(myLastHeadway);
295  }
296 
299 
309  void saveState(OutputDevice& out);
310 
326  void loadState(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:
403  void updateDetectorsOnLeave(MEVehicle* v, SUMOTime currentTime, MESegment* next);
404 
405  bool overtake();
406 
407  SUMOTime getTimeHeadway(const MESegment* pred, const MEVehicle* veh);
408 
409  void setSpeedForQueue(double newSpeed, SUMOTime currentTime,
410  SUMOTime blockTime, const std::vector<MEVehicle*>& vehs);
411 
414  SUMOTime newArrival(const MEVehicle* const v, double newSpeed, SUMOTime currentTime);
415 
417  bool hasBlockedLeader() const;
418 
423  void recomputeJamThreshold(double jamThresh);
424 
426  double jamThresholdForSpeed(double speed, double jamThresh) const;
427 
429  bool limitedControlOverride(const MSLink* link) const;
430 
432  double getMaxPenaltySeconds() const;
433 
435  static bool useMultiQueue(bool multiQueue, const MSEdge& parent);
436 
438  inline SUMOTime tauWithVehLength(SUMOTime tau, double lengthWithGap) const {
439  return tau + (SUMOTime)(lengthWithGap / myTau_length);
440  }
441 
442 private:
444  const MSEdge& myEdge;
445 
448 
450  const double myLength;
451 
453  const int myIndex;
454 
458  double myTau_length;
459 
461  double myA, myB;
462 
465  const double myHeadwayCapacity;
466 
468  const double myCapacity;
469 
471  double myOccupancy;
472 
474  const bool myJunctionControl;
475 
477  const bool myTLSPenalty;
478 
480  const bool myMinorPenalty;
481 
484 
486  std::vector<MSMoveReminder*> myDetectorData;
487 
489  Queues myCarQues;
490 
492  std::map<const MSEdge*, std::vector<int> > myFollowerMap;
493 
495  std::vector<SUMOTime> myBlockTimes;
496 
497  /* @brief The block time for vehicles who wish to enter this segment.
498  * @note since we do not know which queue will be used there is only one
499  * value for all queues */
501 
504 
505  /* @brief segment for signifying vaporization. This segment has invalid
506  * data and should only be used as a unique pointer */
509 
511  mutable double myMeanSpeed;
512 
515 
516 private:
518  MESegment(const MESegment&);
519 
521  MESegment& operator=(const MESegment&);
522 
524  MESegment(const std::string& id);
525 };
526 
527 
528 #endif
529 
530 /****************************************************************************/
MESegment * getNextSegment() const
Returns the following segment on the same edge (0 if it is the last).
Definition: MESegment.h:157
double myMeanSpeed
the mean speed on this segment. Updated at event time or on demand
Definition: MESegment.h:511
static MESegment myVaporizationTarget
Definition: MESegment.h:508
double getRelativeOccupancy() const
Returns the relative occupany of the segment (percentage of road used))
Definition: MESegment.h:181
bool isOpen(const MEVehicle *veh) const
Returns whether the vehicle may use the next link.
Definition: MESegment.cpp:426
std::vector< MEVehicle * > Queue
Definition: MESegment.h:86
double getMeanSpeed() const
wrapper to satisfy the FunctionBinding signature
Definition: MESegment.h:206
A vehicle from the mesoscopic point of view.
Definition: MEVehicle.h:52
double getLength() const
Returns the length of the segment in meters.
Definition: MESegment.h:165
const bool myMinorPenalty
Whether minor penalty is enabled.
Definition: MESegment.h:480
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:613
int getCarNumber() const
Returns the total number of cars on the segment.
Definition: MESegment.cpp:303
MEVehicle * removeCar(MEVehicle *v, SUMOTime leaveTime, MESegment *next)
Removes the given car from the edge&#39;s que.
Definition: MESegment.cpp:349
double myOccupancy
The occupied space (in m) on the segment.
Definition: MESegment.h:471
bool overtake()
Definition: MESegment.cpp:474
bool initialise(MEVehicle *veh, SUMOTime time)
Inserts (emits) vehicle into the segment.
Definition: MESegment.cpp:288
SUMOTime getEntryBlockTime() const
return the next time at which a vehicle my enter this segment
Definition: MESegment.h:365
SUMOTime myEntryBlockTime
Definition: MESegment.h:500
double getEventTimeSeconds() const
Like getEventTime but returns seconds (for visualization)
Definition: MESegment.h:288
int getIndex() const
Returns the running index of the segment in the edge (0 is the most upstream).
Definition: MESegment.h:149
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:486
double getMaxPenaltySeconds() const
return the maximum tls penalty for all links from this edge
Definition: MESegment.cpp:734
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:720
const double myCapacity
The number of lanes * the length.
Definition: MESegment.h:468
bool hasBlockedLeader() const
whether a leader in any queue is blocked
Definition: MESegment.cpp:682
SUMOTime getEventTime() const
Returns the (planned) time at which the next vehicle leaves this segment.
Definition: MESegment.cpp:625
void setSpeedForQueue(double newSpeed, SUMOTime currentTime, SUMOTime blockTime, const std::vector< MEVehicle *> &vehs)
Definition: MESegment.cpp:585
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:483
Queues myCarQues
The car queues. Vehicles are inserted in the front and removed in the back.
Definition: MESegment.h:489
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:261
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:652
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:339
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:699
void receive(MEVehicle *veh, SUMOTime time, bool isDepart=false, bool afterTeleport=false)
Adds the vehicle to the segment, adapting its parameters.
Definition: MESegment.cpp:487
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:514
std::map< const MSEdge *, std::vector< int > > myFollowerMap
The follower edge to que index mapping for multi queue segments.
Definition: MESegment.h:492
const SUMOTime myTau_jf
Definition: MESegment.h:456
double myTau_length
Headway parameter for computing gross time headyway from net time headway, length and edge speed...
Definition: MESegment.h:458
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:507
void updateDetectorsOnLeave(MEVehicle *v, SUMOTime currentTime, MESegment *next)
Updates data of all detectors for a leaving vehicle.
Definition: MESegment.cpp:231
#define STEPS2TIME(x)
Definition: SUMOTime.h:65
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:205
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:173
bool vaporizeAnyCar(SUMOTime currentTime)
tries to remove any car from this segment
Definition: MESegment.cpp:567
std::vector< const MEVehicle * > getVehicles() const
returns all vehicles (for debugging)
Definition: MESegment.cpp:672
void removeDetector(MSMoveReminder *data)
Removes a data collector for a detector from this segment.
Definition: MESegment.cpp:216
Base class for objects which have an id.
Definition: Named.h:46
const MSEdge & myEdge
The microsim edge this segment belongs to.
Definition: MESegment.h:444
SUMOTime getNextInsertionTime(SUMOTime earliestEntry) const
return a time after earliestEntry at which a vehicle may be inserted at full speed ...
Definition: MESegment.cpp:380
const SUMOTime myTau_jj
Definition: MESegment.h:456
void addReminders(MEVehicle *veh) const
add this lanes MoveReminders to the given vehicle
Definition: MESegment.cpp:480
const bool myTLSPenalty
Whether tls penalty is enabled.
Definition: MESegment.h:477
MESegment * myNextSegment
The next segment of this edge, 0 if this is the last segment of this edge.
Definition: MESegment.h:447
const double myHeadwayCapacity
The capacity of the segment in number of cars, used only in time headway calculation This parameter h...
Definition: MESegment.h:465
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:442
SUMOTime myLastHeadway
the last headway
Definition: MESegment.h:503
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:395
double getRelativeJamThreshold() const
Returns the relative occupany of the segment (percentage of road used)) at which the segment is consi...
Definition: MESegment.h:189
double getLastHeadwaySeconds() const
get the last headway time in seconds
Definition: MESegment.h:293
A single mesoscopic segment (cell)
Definition: MESegment.h:57
double getFlow() const
returns flow based on headway
Definition: MESegment.cpp:693
int numQueues() const
return the number of queues
Definition: MESegment.h:134
SUMOTime newArrival(const MEVehicle *const v, double newSpeed, SUMOTime currentTime)
compute the new arrival time when switching speed
Definition: MESegment.cpp:604
const bool myJunctionControl
Whether junction control is enabled.
Definition: MESegment.h:474
double myB
Definition: MESegment.h:461
const SUMOTime myTau_fj
Definition: MESegment.h:456
const Queue & getQueue(int index) const
Returns the cars in the queue with the given index for visualization.
Definition: MESegment.h:140
Static storage of an output device and its base (abstract) implementation.
Definition: OutputDevice.h:71
void saveState(OutputDevice &out)
Saves the state of this segment into the given stream.
Definition: MESegment.cpp:640
long long int SUMOTime
Definition: TraCIDefs.h:52
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:495
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:247
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:438
SUMOTime getTimeHeadway(const MESegment *pred, const MEVehicle *veh)
Definition: MESegment.cpp:371
void send(MEVehicle *veh, MESegment *next, SUMOTime time)
Removes the vehicle from the segment, adapting its parameters.
Definition: MESegment.cpp:455
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:453
const MSEdge & getEdge() const
Returns the edge this segment belongs to.
Definition: MESegment.h:271
const SUMOTime myTau_ff
The time headway parameters, see the Eissfeldt thesis.
Definition: MESegment.h:456
std::vector< Queue > Queues
Definition: MESegment.h:87
Encapsulates binary reading operations on a file.
double myA
slope and axis offset for the jam-jam headway function
Definition: MESegment.h:461
const double myLength
The segment&#39;s length.
Definition: MESegment.h:450