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  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  int getCarNumber() const;
133 
135  inline int numQueues() const {
136  return (int)myCarQues.size();
137  }
141  inline const Queue& getQueue(int index) const {
142  assert(index < (int)myCarQues.size());
143  return myCarQues[index];
144  }
145 
150  inline 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 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) || myTLSPenalty;
349  }
350 
352  inline 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 (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 
389  SUMOTime getTLSPenalty(const MEVehicle* veh) const;
390 
391 private:
398  void updateDetectorsOnLeave(MEVehicle* v, SUMOTime currentTime, MESegment* next);
399 
400  bool overtake();
401 
402  SUMOTime getTimeHeadway(bool predecessorIsFree, SUMOReal leaderLength);
403 
404  void setSpeedForQueue(SUMOReal newSpeed, SUMOTime currentTime,
405  SUMOTime blockTime, const std::vector<MEVehicle*>& vehs);
406 
409  SUMOTime newArrival(const MEVehicle* const v, SUMOReal newSpeed, SUMOTime currentTime);
410 
411 
416  void recomputeJamThreshold(SUMOReal jamThresh);
417 
419  SUMOReal jamThresholdForSpeed(SUMOReal speed, SUMOReal jamThresh) const;
420 
422  bool limitedControlOverride(const MSLink* link) const;
423 
424 private:
426  const MSEdge& myEdge;
427 
430 
433 
435  const int myIndex;
436 
441 
444 
448 
451 
454 
456  const bool myJunctionControl;
457 
459  const bool myTLSPenalty;
460 
463 
465  std::vector<MSMoveReminder*> myDetectorData;
466 
468  Queues myCarQues;
469 
471  std::map<const MSEdge*, std::vector<int> > myFollowerMap;
472 
474  std::vector<SUMOTime> myBlockTimes;
475 
476  /* @brief The block time for vehicles who wish to enter this segment.
477  * @note since we do not know which queue will be used there is only one
478  * value for all queues */
480 
481  // precomputed factor between geometrical length and given length
483 
484  /* @brief segment for signifying vaporization. This segment has invalid
485  * data and should only be used as a unique pointer */
488 
491 
494 
495 private:
497  MESegment(const MESegment&);
498 
500  MESegment& operator=(const MESegment&);
501 
503  MESegment(const std::string& id);
504 };
505 
506 
507 #endif
508 
509 /****************************************************************************/
static MESegment myVaporizationTarget
Definition: MESegment.h:487
long long int SUMOTime
Definition: SUMOTime.h:43
SUMOReal getFlow() const
returns flow based on headway
Definition: MESegment.cpp:673
std::vector< MEVehicle * > Queue
Definition: MESegment.h:87
const SUMOReal myCapacity
The number of lanes * the length.
Definition: MESegment.h:450
std::vector< const MEVehicle * > getVehicles() const
returns all vehicles (for debugging)
Definition: MESegment.cpp:663
A vehicle from the mesoscopic point of view.
Definition: MEVehicle.h:52
MEVehicle * removeCar(MEVehicle *v, SUMOTime leaveTime, MESegment *next)
Removes the given car from the edge&#39;s que.
Definition: MESegment.cpp:334
SUMOReal jamThresholdForSpeed(SUMOReal speed, SUMOReal jamThresh) const
compute jam threshold for the given speed and jam-threshold option
Definition: MESegment.cpp:180
bool overtake()
Definition: MESegment.cpp:465
bool initialise(MEVehicle *veh, SUMOTime time)
Inserts (emits) vehicle into the segment.
Definition: MESegment.cpp:273
MESegment(const std::string &id, const MSEdge &parent, MESegment *next, SUMOReal length, SUMOReal speed, int idx, SUMOTime tauff, SUMOTime taufj, SUMOTime taujf, SUMOTime taujj, SUMOReal jamThresh, bool multiQueue, bool junctionControl, SUMOReal lengthGeometryFactor)
constructor
Definition: MESegment.cpp:71
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:434
SUMOTime myEntryBlockTime
Definition: MESegment.h:479
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:465
SUMOReal myOccupancy
The occupied space (in m) on the segment.
Definition: MESegment.h:453
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:595
void setSpeedForQueue(SUMOReal newSpeed, SUMOTime currentTime, SUMOTime blockTime, const std::vector< MEVehicle * > &vehs)
Definition: MESegment.cpp:576
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:468
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:643
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:387
A road/street connecting two junctions.
Definition: MSEdge.h:80
const SUMOReal myHeadwayCapacity
The capacity of the segment in number of cars, used only in time headway calculation This parameter h...
Definition: MESegment.h:447
void receive(MEVehicle *veh, SUMOTime time, bool isDepart=false, bool afterTeleport=false)
Adds the vehicle to the segment, adapting its parameters.
Definition: MESegment.cpp:478
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:324
MESegment & operator=(const MESegment &)
Invalidated assignment operator.
SUMOTime myLastMeanSpeedUpdate
the time at which myMeanSpeed was last updated
Definition: MESegment.h:493
std::map< const MSEdge *, std::vector< int > > myFollowerMap
The follower edge to que index mapping for multi queue segments.
Definition: MESegment.h:471
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:438
static bool isInvalid(const MESegment *segment)
whether the given segment is 0 or encodes vaporization
Definition: MESegment.h:338
SUMOReal getLength() const
Returns the length of the segment in meters.
Definition: MESegment.h:166
static MSEdge myDummyParent
Definition: MESegment.h:486
SUMOTime getMinimumHeadwayTime() const
return the minimum headway-time with which vehicles may enter or leave this segment ...
Definition: MESegment.h:371
void updateDetectorsOnLeave(MEVehicle *v, SUMOTime currentTime, MESegment *next)
Updates data of all detectors for a leaving vehicle.
Definition: MESegment.cpp:220
#define STEPS2TIME(x)
Definition: SUMOTime.h:65
SUMOReal myTau_length
Headway paramter for computing gross time headyway from net time heawdway, length and edge speed...
Definition: MESegment.h:440
const SUMOReal myLength
The segment&#39;s length.
Definition: MESegment.h:432
void addDetector(MSMoveReminder *data)
Adds a data collector for a detector to this segment.
Definition: MESegment.cpp:194
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:558
SUMOReal myJamThreshold
The space (in m) which needs to be occupied before the segment is considered jammed.
Definition: MESegment.h:462
void removeDetector(MSMoveReminder *data)
Removes a data collector for a detector from this segment.
Definition: MESegment.cpp:205
Base class for objects which have an id.
Definition: Named.h:46
bool isOpen(const MEVehicle *veh) const
Returns whether the vehicle may use the next link.
Definition: MESegment.cpp:418
SUMOTime getTLSPenalty(const MEVehicle *veh) const
Returns the penalty time for passing a tls-controlled link (if using gMesoTLSPenalty > 0) ...
Definition: MESegment.cpp:679
const MSEdge & myEdge
The microsim edge this segment belongs to.
Definition: MESegment.h:426
SUMOReal myA
slope and axis offset for the jam-jam headway function
Definition: MESegment.h:443
const SUMOTime myTau_jj
Definition: MESegment.h:438
int numQueues() const
return the number of queues
Definition: MESegment.h:135
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:604
const bool myTLSPenalty
Whether tls penalty is enabled.
Definition: MESegment.h:459
MESegment * myNextSegment
The next segment of this edge, 0 if this is the last segment of this edge.
Definition: MESegment.h:429
SUMOReal getRelativeOccupancy() const
Returns the relative occupany of the segment (percentage of road used))
Definition: MESegment.h:182
SUMOReal myB
Definition: MESegment.h:443
SUMOTime getEventTime() const
Returns the (planned) time at which the next vehicle leaves this segment.
Definition: MESegment.cpp:616
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:250
const bool myJunctionControl
Whether junction control is enabled.
Definition: MESegment.h:456
int getCarNumber() const
Returns the total number of cars on the segment.
Definition: MESegment.cpp:288
const SUMOReal myLengthGeometryFactor
Definition: MESegment.h:482
int getIndex() const
Returns the running index of the segment in the edge (0 is the most upstream).
Definition: MESegment.h:150
const SUMOTime myTau_fj
Definition: MESegment.h:438
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:631
const Queue & getQueue(int index) const
Returns the cars in the queue with the given index for visualization.
Definition: MESegment.h:141
SUMOTime getNextInsertionTime(SUMOTime earliestEntry) const
return a time after earliestEntry at which a vehicle may be inserted at full speed ...
Definition: MESegment.cpp:372
std::vector< SUMOTime > myBlockTimes
The block times.
Definition: MESegment.h:474
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:236
void send(MEVehicle *veh, MESegment *next, SUMOTime time)
Removes the vehicle from the segment, adapting its parameters.
Definition: MESegment.cpp:447
SUMOReal myMeanSpeed
the mean speed on this segment. Updated at event time or on demand
Definition: MESegment.h:490
const int myIndex
Running number of the segment in the edge.
Definition: MESegment.h:435
int remainingVehicleCapacity(const SUMOReal vehLength) const
return the remaining physical space on this segment
Definition: MESegment.h:352
const SUMOTime myTau_ff
The time headway parameters, see the Eissfeldt thesis.
Definition: MESegment.h:438
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:471
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:137
SUMOTime getTimeHeadway(bool predecessorIsFree, SUMOReal leaderLength)
Definition: MESegment.cpp:356