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  SUMOReal length, SUMOReal speed,
79  unsigned int idx,
80  SUMOTime tauff, SUMOTime taufj,
81  SUMOTime taujf, SUMOTime taujj,
82  SUMOReal jamThresh,
83  bool multiQueue, bool junctionControl,
84  SUMOReal lengthGeometryFactor);
85 
86 
87  typedef std::vector<MEVehicle*> Queue;
88  typedef std::vector<Queue> Queues;
91 
96  void addDetector(MSMoveReminder* data);
97 
102  void removeDetector(MSMoveReminder* data);
103 
110 
118  bool hasSpaceFor(const MEVehicle* veh, SUMOTime entryTime, bool init = false) const;
119 
126  bool initialise(MEVehicle* veh, SUMOTime time);
127 
132  size_t getCarNumber() const;
133 
135  inline size_t numQueues() const {
136  return myCarQues.size();
137  }
141  inline const Queue& getQueue(size_t index) const {
142  assert(index < myCarQues.size());
143  return myCarQues[index];
144  }
145 
150  inline unsigned int getIndex() const {
151  return myIndex;
152  }
153 
158  inline MESegment* getNextSegment() const {
159  return myNextSegment;
160  }
161 
166  inline SUMOReal getLength() const {
167  return myLength;
168  }
169 
174  inline SUMOReal getBruttoOccupancy() const {
175  return myOccupancy;
176  }
177 
178 
183  return myOccupancy / myCapacity;
184  }
185 
191  return myJamThreshold / myCapacity;
192  }
193 
204  SUMOReal getMeanSpeed(bool useCache) const;
205 
207  inline SUMOReal getMeanSpeed() const {
208  return getMeanSpeed(true);
209  }
210 
211 
212  void writeVehicles(OutputDevice& of) const;
213 
221  MEVehicle* removeCar(MEVehicle* v, SUMOTime leaveTime, MESegment* next);
222 
232  MSLink* getLink(const MEVehicle* veh, bool tlsPenalty = false) const;
233 
241  bool isOpen(const MEVehicle* veh) const;
242 
250  void send(MEVehicle* veh, MESegment* next, SUMOTime time);
251 
259  void receive(MEVehicle* veh, SUMOTime time, bool isDepart = false, bool afterTeleport = false);
260 
261 
267  bool vaporizeAnyCar(SUMOTime currentTime);
268 
272  inline const MSEdge& getEdge() const {
273  return myEdge;
274  }
275 
276 
281  void setSpeed(SUMOReal newSpeed, SUMOTime currentTime, SUMOReal jamThresh = DO_NOT_PATCH_JAM_THRESHOLD);
282 
286  SUMOTime getEventTime() const;
287 
289  inline SUMOReal getEventTimeSeconds() const {
290  return STEPS2TIME(getEventTime());
291  }
292 
295 
305  void saveState(OutputDevice& out);
306 
322  void loadState(std::vector<std::string>& vehIDs, MSVehicleControl& vc, const SUMOTime blockTime, const unsigned int queIdx);
324 
325 
328  std::vector<const MEVehicle*> getVehicles() const;
329 
330 
334  SUMOReal getFlow() const;
335 
336 
338  static inline bool isInvalid(const MESegment* segment) {
339  return segment == 0 || segment == &myVaporizationTarget;
340  }
341 
343  SUMOTime getNextInsertionTime(SUMOTime earliestEntry) const;
344 
347  inline bool free() const {
348  return myOccupancy <= myJamThreshold;
349  }
350 
352  inline unsigned int remainingVehicleCapacity(const SUMOReal vehLength) const {
353  if (myOccupancy == 0. && myCapacity < vehLength) {
354  // even small segments can hold at least one vehicle
355  return 1;
356  }
357  return static_cast<int>((myCapacity - myOccupancy) / vehLength);
358  }
359 
361  inline SUMOTime getEntryBlockTime() const {
362  return myEntryBlockTime;
363  }
364 
366  inline void setEntryBlockTime(SUMOTime entryBlockTime) {
367  myEntryBlockTime = entryBlockTime;
368  }
369 
372  return myTau_ff;
373  }
374 
376 
378  void addReminders(MEVehicle* veh) const;
379 
382  return myLengthGeometryFactor;
383  }
384 
385 private:
392  void updateDetectorsOnLeave(MEVehicle* v, SUMOTime currentTime, MESegment* next);
393 
394  bool overtake();
395 
396  SUMOTime getTimeHeadway(bool predecessorIsFree);
397 
398  void setSpeedForQueue(SUMOReal newSpeed, SUMOTime currentTime,
399  SUMOTime blockTime, const std::vector<MEVehicle*>& vehs);
400 
403  SUMOTime newArrival(const MEVehicle* const v, SUMOReal newSpeed, SUMOTime currentTime);
404 
405 
410  void recomputeJamThreshold(SUMOReal jamThresh);
411 
414 
416  bool limitedControlOverride(const MSLink* link) const;
417 
418 protected:
423  SUMOTime getTLSPenalty(const MEVehicle* veh) const;
424 
425 private:
427  const MSEdge& myEdge;
428 
431 
434 
436  const unsigned int myIndex;
437 
440 
444 
447 
450 
452  const bool myJunctionControl;
453 
455  const bool myTLSPenalty;
456 
459 
461  std::vector<MSMoveReminder*> myDetectorData;
462 
464  Queues myCarQues;
465 
467  std::map<const MSEdge*, std::vector<size_t> > myFollowerMap;
468 
470  std::vector<SUMOTime> myBlockTimes;
471 
472  /* @brief The block time for vehicles who wish to enter this segment.
473  * @note since we do not know which queue will be used there is only one
474  * value for all queues */
476 
477  // precomputed factor between geometrical length and given length
479 
480  /* @brief segment for signifying vaporization. This segment has invalid
481  * data and should only be used as a unique pointer */
484 
487 
490 
491 private:
493  MESegment(const MESegment&);
494 
496  MESegment& operator=(const MESegment&);
497 
499  MESegment(const std::string& id);
500 };
501 
502 
503 #endif
504 
505 /****************************************************************************/
size_t numQueues() const
return the number of queues
Definition: MESegment.h:135
static MESegment myVaporizationTarget
Definition: MESegment.h:483
const unsigned int myIndex
Running number of the segment in the edge.
Definition: MESegment.h:436
long long int SUMOTime
Definition: SUMOTime.h:43
SUMOReal getFlow() const
returns flow based on headway
Definition: MESegment.cpp:637
std::vector< MEVehicle * > Queue
Definition: MESegment.h:87
const SUMOReal myCapacity
The number of lanes * the length.
Definition: MESegment.h:446
std::vector< const MEVehicle * > getVehicles() const
returns all vehicles (for debugging)
Definition: MESegment.cpp:627
A vehicle from the mesoscopic point of view.
Definition: MEVehicle.h:52
MESegment(const std::string &id, const MSEdge &parent, MESegment *next, SUMOReal length, SUMOReal speed, unsigned int idx, SUMOTime tauff, SUMOTime taufj, SUMOTime taujf, SUMOTime taujj, SUMOReal jamThresh, bool multiQueue, bool junctionControl, SUMOReal lengthGeometryFactor)
constructor
Definition: MESegment.cpp:67
MEVehicle * removeCar(MEVehicle *v, SUMOTime leaveTime, MESegment *next)
Removes the given car from the edge&#39;s que.
Definition: MESegment.cpp:299
bool overtake()
Definition: MESegment.cpp:431
bool initialise(MEVehicle *veh, SUMOTime time)
Inserts (emits) vehicle into the segment.
Definition: MESegment.cpp:238
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:400
SUMOTime myEntryBlockTime
Definition: MESegment.h:475
static const SUMOReal DO_NOT_PATCH_JAM_THRESHOLD
Definition: MESegment.h:375
std::vector< MSMoveReminder * > myDetectorData
The data collection for all kinds of detectors.
Definition: MESegment.h:461
SUMOReal myOccupancy
The occupied space (in m) on the segment.
Definition: MESegment.h:449
SUMOReal getMeanSpeed() const
wrapper to satisfy the FunctionBinding signature
Definition: MESegment.h:207
SUMOTime getEntryBlockTime() const
return the next time at which a vehicle my enter this segment
Definition: MESegment.h:361
SUMOTime newArrival(const MEVehicle *const v, SUMOReal newSpeed, SUMOTime currentTime)
compute the new arrival time when switching speed
Definition: MESegment.cpp:560
unsigned int getIndex() const
Returns the running index of the segment in the edge (0 is the most upstream).
Definition: MESegment.h:150
void setSpeedForQueue(SUMOReal newSpeed, SUMOTime currentTime, SUMOTime blockTime, const std::vector< MEVehicle * > &vehs)
Definition: MESegment.cpp:542
const MSEdge & getEdge() const
Returns the edge this segment belongs to.
Definition: MESegment.h:272
Queues myCarQues
The car queues. Vehicles are inserted in the front and removed in the back.
Definition: MESegment.h:464
void setEntryBlockTime(SUMOTime entryBlockTime)
set the next time at which a vehicle my enter this segment
Definition: MESegment.h:366
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:353
A road/street connecting two junctions.
Definition: MSEdge.h:80
const Queue & getQueue(size_t index) const
Returns the cars in the queue with the given index for visualization.
Definition: MESegment.h:141
const SUMOReal myHeadwayCapacity
The capacity of the segment in number of cars, used only in time headway calculation This parameter h...
Definition: MESegment.h:443
void receive(MEVehicle *veh, SUMOTime time, bool isDepart=false, bool afterTeleport=false)
Adds the vehicle to the segment, adapting its parameters.
Definition: MESegment.cpp:444
MESegment * getNextSegment() const
Returns the following segment on the same edge (0 if it is the last).
Definition: MESegment.h:158
void writeVehicles(OutputDevice &of) const
Definition: MESegment.cpp:289
MESegment & operator=(const MESegment &)
Invalidated assignment operator.
SUMOTime myLastMeanSpeedUpdate
the time at which myMeanSpeed was last updated
Definition: MESegment.h:489
bool free() const
return whether this segment is considered free as opposed to jammed
Definition: MESegment.h:347
const SUMOTime myTau_jf
Definition: MESegment.h:439
static bool isInvalid(const MESegment *segment)
whether the given segment is 0 or encodes vaporization
Definition: MESegment.h:338
void loadState(std::vector< std::string > &vehIDs, MSVehicleControl &vc, const SUMOTime blockTime, const unsigned int queIdx)
Loads the state of this segment with the given parameters.
Definition: MESegment.cpp:607
SUMOReal getLength() const
Returns the length of the segment in meters.
Definition: MESegment.h:166
static MSEdge myDummyParent
Definition: MESegment.h:482
SUMOTime getMinimumHeadwayTime() const
return the minimum headway-time with which vehicles may enter or leave this segment ...
Definition: MESegment.h:371
size_t getCarNumber() const
Returns the total number of cars on the segment.
Definition: MESegment.cpp:253
void updateDetectorsOnLeave(MEVehicle *v, SUMOTime currentTime, MESegment *next)
Updates data of all detectors for a leaving vehicle.
Definition: MESegment.cpp:185
#define STEPS2TIME(x)
Definition: SUMOTime.h:65
SUMOTime getTimeHeadway(bool predecessorIsFree)
Definition: MESegment.cpp:321
const SUMOReal myLength
The segment&#39;s length.
Definition: MESegment.h:433
void addDetector(MSMoveReminder *data)
Adds a data collector for a detector to this segment.
Definition: MESegment.cpp:159
Something on a lane to be noticed about vehicle movement.
bool vaporizeAnyCar(SUMOTime currentTime)
tries to remove any car from this segment
Definition: MESegment.cpp:524
SUMOReal myJamThreshold
The space (in m) which needs to be occupied before the segment is considered jammed.
Definition: MESegment.h:458
SUMOReal jamThresholdForSpeed(SUMOReal speed) const
compute jam threshold for the given speed
Definition: MESegment.cpp:147
void removeDetector(MSMoveReminder *data)
Removes a data collector for a detector from this segment.
Definition: MESegment.cpp:170
Base class for objects which have an id.
Definition: Named.h:45
bool isOpen(const MEVehicle *veh) const
Returns whether the vehicle may use the next link.
Definition: MESegment.cpp:384
SUMOTime getTLSPenalty(const MEVehicle *veh) const
Returns the penalty time for passing a tls-controlled link (if using gMesoTLSPenalty > 0) ...
Definition: MESegment.cpp:643
const MSEdge & myEdge
The microsim edge this segment belongs to.
Definition: MESegment.h:427
const SUMOTime myTau_jj
Definition: MESegment.h:439
void setSpeed(SUMOReal newSpeed, SUMOTime currentTime, SUMOReal jamThresh=DO_NOT_PATCH_JAM_THRESHOLD)
reset mySpeed and patch the speed of all vehicles in it. Also set/recompute myJamThreshold ...
Definition: MESegment.cpp:569
const bool myTLSPenalty
Whether tls penalty is enabled.
Definition: MESegment.h:455
MESegment * myNextSegment
The next segment of this edge, 0 if this is the last segment of this edge.
Definition: MESegment.h:430
SUMOReal getRelativeOccupancy() const
Returns the relative occupany of the segment (percentage of road used))
Definition: MESegment.h:182
SUMOTime getEventTime() const
Returns the (planned) time at which the next vehicle leaves this segment.
Definition: MESegment.cpp:580
A single mesoscopic segment (cell)
Definition: MESegment.h:57
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:215
const bool myJunctionControl
Whether junction control is enabled.
Definition: MESegment.h:452
unsigned int remainingVehicleCapacity(const SUMOReal vehLength) const
return the remaining physical space on this segment
Definition: MESegment.h:352
const SUMOReal myLengthGeometryFactor
Definition: MESegment.h:478
const SUMOTime myTau_fj
Definition: MESegment.h:439
std::map< const MSEdge *, std::vector< size_t > > myFollowerMap
The follower edge to que index mapping for multi queue segments.
Definition: MESegment.h:467
SUMOReal getBruttoOccupancy() const
Returns the occupany of the segment (the sum of the vehicle lengths + minGaps)
Definition: MESegment.h:174
Static storage of an output device and its base (abstract) implementation.
Definition: OutputDevice.h:71
#define SUMOReal
Definition: config.h:213
void saveState(OutputDevice &out)
Saves the state of this segment into the given stream.
Definition: MESegment.cpp:595
SUMOTime getNextInsertionTime(SUMOTime earliestEntry) const
return a time after earliestEntry at which a vehicle may be inserted at full speed ...
Definition: MESegment.cpp:338
std::vector< SUMOTime > myBlockTimes
The block times.
Definition: MESegment.h:470
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:201
void send(MEVehicle *veh, MESegment *next, SUMOTime time)
Removes the vehicle from the segment, adapting its parameters.
Definition: MESegment.cpp:413
SUMOReal myMeanSpeed
the mean speed on this segment. Updated at event time or on demand
Definition: MESegment.h:486
const SUMOTime myTau_ff
The time headway parameters, see the Eissfeldt thesis.
Definition: MESegment.h:439
std::vector< Queue > Queues
Definition: MESegment.h:88
Encapsulates binary reading operations on a file.
void addReminders(MEVehicle *veh) const
add this lanes MoveReminders to the given vehicle
Definition: MESegment.cpp:437
SUMOReal getRelativeJamThreshold() const
Returns the relative occupany of the segment (percentage of road used)) at which the segment is consi...
Definition: MESegment.h:190
SUMOReal getLengthGeometryFactor() const
return precomputed geometrical length / myLength
Definition: MESegment.h:381
SUMOReal getEventTimeSeconds() const
Like getEventTime but returns seconds (for visualization)
Definition: MESegment.h:289
void recomputeJamThreshold(SUMOReal jamThresh)
compute a value for myJamThreshold if jamThresh is negative, compute a value which allows free flow a...
Definition: MESegment.cpp:132