Eclipse SUMO - Simulation of Urban MObility
MSDevice_SSM.h
Go to the documentation of this file.
1 /****************************************************************************/
2 // Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo
3 // Copyright (C) 2013-2024 German Aerospace Center (DLR) and others.
4 // This program and the accompanying materials are made available under the
5 // terms of the Eclipse Public License 2.0 which is available at
6 // https://www.eclipse.org/legal/epl-2.0/
7 // This Source Code may also be made available under the following Secondary
8 // Licenses when the conditions for such availability set forth in the Eclipse
9 // Public License 2.0 are satisfied: GNU General Public License, version 2
10 // or later which is available at
11 // https://www.gnu.org/licenses/old-licenses/gpl-2.0-standalone.html
12 // SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-or-later
13 /****************************************************************************/
21 // An SSM-device logs encounters / conflicts of the carrying vehicle with other surrounding vehicles.
22 // XXX: Preliminary implementation. Use with care. Especially rerouting vehicles could be problematic.
23 /****************************************************************************/
24 #pragma once
25 #include <config.h>
26 
27 #include <queue>
28 #include "MSVehicleDevice.h"
29 #include <utils/common/SUMOTime.h>
31 #include <utils/geom/Position.h>
32 
33 
34 // ===========================================================================
35 // class declarations
36 // ===========================================================================
37 class SUMOVehicle;
38 class SUMOTrafficObject;
39 
40 
41 // ===========================================================================
42 // class definitions
43 // ===========================================================================
53 class MSCrossSection;
54 
55 class MSDevice_SSM : public MSVehicleDevice {
56 
57 private:
59  static std::set<MSDevice_SSM*, ComparatorNumericalIdLess>* myInstances;
60 
61 public:
65  // Other vehicle is closer than range, but not on a lane conflicting with the ego's route ahead
67  // Ego and foe vehicles' edges form a part of a consecutive sequence of edges
68  // This type may be specified further by ENCOUNTER_TYPE_FOLLOWING_LEADER or ENCOUNTER_TYPE_FOLLOWING_FOLLOWER
70  // Ego vehicle is on an edge that has a sequence of successors connected to the other vehicle's edge
72  // Other vehicle is on an edge that has a sequence of successors connected to the ego vehicle's current edge
74  // Other vehicle is on an edge that has a sequence of successors connected to the ego vehicle's current edge
76  // Ego and foe share an upcoming edge of their routes while the merging point for the routes is still ahead
77  // This type may be specified further by ENCOUNTER_TYPE_MERGING_LEADER or ENCOUNTER_TYPE_MERGING_FOLLOWER
79  // Other vehicle is on an edge that has a sequence of successors connected to an edge on the ego vehicle's route
80  // and the estimated arrival vehicle at the merge point is earlier for the ego than for the foe
82  // Other vehicle is on an edge that has a sequence of successors connected to an edge on the ego vehicle's route
83  // and the estimated arrival vehicle at the merge point is earlier for the foe than for the ego
85  // Vehicles' bestlanes lead to the same edge but to adjacent lanes
87  // Ego's and foe's routes have crossing edges
88  // This type may be specified further by ENCOUNTER_TYPE_CROSSING_LEADER or ENCOUNTER_TYPE_CROSSING_FOLLOWER
90  // Other vehicle is on an edge that has a sequence of successors leading to an internal edge that crosses the ego vehicle's edge at a junction
91  // and the estimated arrival vehicle at the merge point is earlier for the ego than for the foe
93  // Other vehicle is on an edge that has a sequence of successors leading to an internal edge that crosses the ego vehicle's edge at a junction
94  // and the estimated arrival vehicle at the merge point is earlier for the foe than for the ego
96  // The encounter is a possible crossing conflict, and the ego vehicle has entered the conflict area
98  // The encounter is a possible crossing conflict, and the foe vehicle has entered the conflict area
100  // The encounter has been a possible crossing conflict, but the ego vehicle has left the conflict area
102  // The encounter has been a possible crossing conflict, but the foe vehicle has left the conflict area
104  // The encounter has been a possible crossing conflict, and both vehicles have entered the conflict area (one must have already left, otherwise this must be a collision)
106  // The encounter has been a possible crossing conflict, but both vehicle have left the conflict area
108  // FOLLOWING_PASSED and MERGING_PASSED are reserved to achieve that these encounter types may be tracked longer (see updatePassedEncounter)
109  // The encounter has been a following situation, but is not active any more
111  // The encounter has been a merging situation, but is not active any more
113  // Ego vehicle and foe are driving in opposite directions towards each other on the same lane (or sequence of consecutive lanes)
115  // Collision (currently unused, might be differentiated further)
117  };
118 
119  static std::string encounterToString(EncounterType type) {
120  switch (type) {
122  return ("NOCONFLICT_AHEAD");
124  return ("FOLLOWING");
126  return ("FOLLOWING_FOLLOWER");
128  return ("FOLLOWING_LEADER");
130  return ("ON_ADJACENT_LANES");
131  case (ENCOUNTER_TYPE_MERGING):
132  return ("MERGING");
134  return ("MERGING_LEADER");
136  return ("MERGING_FOLLOWER");
138  return ("MERGING_ADJACENT");
140  return ("CROSSING");
142  return ("CROSSING_LEADER");
144  return ("CROSSING_FOLLOWER");
146  return ("EGO_ENTERED_CONFLICT_AREA");
148  return ("FOE_ENTERED_CONFLICT_AREA");
150  return ("EGO_LEFT_CONFLICT_AREA");
152  return ("FOE_LEFT_CONFLICT_AREA");
154  return ("BOTH_ENTERED_CONFLICT_AREA");
156  return ("BOTH_LEFT_CONFLICT_AREA");
158  return ("FOLLOWING_PASSED");
160  return ("MERGING_PASSED");
162  return ("ONCOMING");
164  return ("COLLISION");
165  }
166  return ("UNKNOWN");
167  };
168 
169 private:
172  class Encounter {
173  private:
176  struct Trajectory {
177  // positions
179  // lane IDs
180  std::vector<std::string> lane;
181  // lane positions
182  std::vector<double> lanePos;
183  // momentary speeds
185  };
190  double time;
198  double value;
200  double speed;
201 
202  ConflictPointInfo(double time, Position x, EncounterType type, double ssmValue, double speed) :
203  time(time), pos(x), type(type), value(ssmValue), speed(speed) {};
204  };
205 
206  public:
208  Encounter(const MSVehicle* _ego, const MSVehicle* const _foe, double _begin, double extraTime);
210  ~Encounter();
211 
213  void add(double time, EncounterType type, Position egoX, std::string egoLane, double egoLanePos,
214  Position egoV, Position foeX, std::string foeLane, double foeLanePos, Position foeV,
215  Position conflictPoint, double egoDistToConflict, double foeDistToConflict, double ttc, double drac, std::pair<double, double> pet, double ppet, double mdrac);
216 
218  std::size_t size() const {
219  return timeSpan.size();
220  }
221 
223  void resetExtraTime(double value);
225  void countDownExtraTime(double amount);
227  double getRemainingExtraTime() const;
228 
230  struct compare {
231  typedef bool value_type;
232  bool operator()(Encounter* e1, Encounter* e2) {
233  if (e1->begin == e2->begin) {
234  return e1->foeID > e2->foeID;
235  } else {
236  return e1->begin > e2->begin;
237  }
238  };
239  };
240 
241 
242 
243  public:
244  const MSVehicle* ego;
245  const MSVehicle* foe;
246  const std::string egoID;
247  const std::string foeID;
248  double begin, end;
250 
253 
258 
260  std::vector<double> timeSpan;
262  std::vector<int> typeSpan;
268  std::vector<double> egoDistsToConflict;
270  std::vector<double> foeDistsToConflict;
271 
276 
278  std::vector<double> TTCspan;
280  std::vector<double> DRACspan;
282  std::vector<double> MDRACspan;
284  std::vector<double> PPETspan;
285 
286 // /// @brief Cross sections at which a PET shall be calculated for the corresponding vehicle
287 // std::vector<std::pair<std::pair<const MSLane*, double>, double> > egoPETCrossSections;
288 // std::vector<std::pair<std::pair<const MSLane*, double>, double> > foePETCrossSections;
289 
298 
301 
302  private:
308  };
309 
310 
327  double ttc;
328  double drac;
329  double mdrac;
330  std::pair<double, double> pet; // (egoConflictEntryTime, PET);
331  double ppet;
332  std::pair<const MSLane*, double> egoConflictEntryCrossSection;
333  std::pair<const MSLane*, double> foeConflictEntryCrossSection;
334  };
335 
336 
340  struct FoeInfo {
341  virtual ~FoeInfo() {};
344  };
345  // TODO: consider introducing a class foeCollector, which holds the foe info content
346  // plus a vehicle container to be used in findSurrounding vehicles.
347  // findSurroundingVehicles() would then deliver a vector of such foeCollectors
348  // (one for each possible egoConflictLane) instead of a map vehicle->foeInfo
349  // This could be helpful to resolve the resolution for several different
350  // projected conflicts with the same foe.
351 
352 
358  const MSEdge* edge;
359  double pos;
360  double range;
363  };
364 
365  typedef std::priority_queue<Encounter*, std::vector<Encounter*>, Encounter::compare> EncounterQueue;
366  typedef std::vector<Encounter*> EncounterVector;
367  typedef std::map<const MSVehicle*, FoeInfo*> FoeInfoMap;
368 public:
369 
373  static void insertOptions(OptionsCont& oc);
374 
375 
386  static void buildVehicleDevices(SUMOVehicle& v, std::vector<MSVehicleDevice*>& into);
387 
388 
391  static const std::set<MSDevice_SSM*, ComparatorNumericalIdLess>& getInstances();
392 
394  static const std::set<const MSEdge*>& getEdgeFilter() {
395  return myEdgeFilter;
396  }
397 
403  void updateAndWriteOutput();
404 
406  std::string getParameter(const std::string& key) const;
407 
409  void setParameter(const std::string& key, const std::string& value);
410 
411 private:
412  void update();
413  void writeOutConflict(Encounter* e);
414 
416  static void toGeo(Position& x);
418  static void toGeo(PositionVector& x);
419 
420 public:
423  static void cleanup();
424 
425 
426 public:
428  ~MSDevice_SSM();
429 
430 
442  static void findSurroundingVehicles(const MSVehicle& veh, double range, FoeInfoMap& foeCollector);
443 
446  static void getUpstreamVehicles(const UpstreamScanStartInfo& scanStart, FoeInfoMap& foeCollector, std::set<const MSLane*>& seenLanes, const std::set<const MSJunction*>& routeJunctions);
447 
450  static void getVehiclesOnJunction(const MSJunction*, const MSLane* egoJunctionLane, double egoDistToConflictLane, const MSLane* const egoConflictLane, FoeInfoMap& foeCollector, std::set<const MSLane*>& seenLanes);
451 
452 
455 
465  bool notifyMove(SUMOTrafficObject& veh, double oldPos,
466  double newPos, double newSpeed);
467 
468 
478  bool notifyEnter(SUMOTrafficObject& veh, MSMoveReminder::Notification reason, const MSLane* enteredLane = 0);
479 
480 
489  bool notifyLeave(SUMOTrafficObject& veh, double lastPos,
490  MSMoveReminder::Notification reason, const MSLane* enteredLane = 0);
492 
493 
495  const std::string deviceName() const {
496  return "ssm";
497  }
498 
505  void generateOutput(OutputDevice* tripinfoOut) const;
506 
507 
508 
509 private:
524  MSDevice_SSM(SUMOVehicle& holder, const std::string& id, std::string outputFilename, std::map<std::string, double> thresholds,
525  bool trajectories, double range, double extraTime, bool useGeoCoords, bool writePositions, bool writeLanesPositions,
526  std::vector<int> conflictOrder);
527 
536  void processEncounters(FoeInfoMap& foes, bool forceClose = false);
537 
538 
543 
544 
545 
548  void createEncounters(FoeInfoMap& foes);
549 
550 
555  void computeGlobalMeasures();
556 
559  void resetEncounters();
560 
564  void flushConflicts(bool all = false);
565 
569  void flushGlobalMeasures();
570 
575  bool updateEncounter(Encounter* e, FoeInfo* foeInfo);
576 
587 
588 
599  EncounterType classifyEncounter(const FoeInfo* foeInfo, EncounterApproachInfo& eInfo) const;
600 
601 
607  static void determineConflictPoint(EncounterApproachInfo& eInfo);
608 
609 
619  static void estimateConflictTimes(EncounterApproachInfo& eInfo);
620 
621 
629 
630 
639  const MSLane* findFoeConflictLane(const MSVehicle* foe, const MSLane* egoConflictLane, double& distToConflictLane) const;
640 
643  void closeEncounter(Encounter* e);
644 
648 
653  void computeSSMs(EncounterApproachInfo& e) const;
654 
655 
659  void determinePET(EncounterApproachInfo& eInfo) const;
660 
661 
666 
667 
671  double computeTTC(double gap, double followerSpeed, double leaderSpeed) const;
672 
678  static double computeDRAC(double gap, double followerSpeed, double leaderSpeed);
679 
685  static double computeMDRAC(double gap, double followerSpeed, double leaderSpeed, double prt);
686 
698  static double computeDRAC(const EncounterApproachInfo& eInfo);
699 
707  static std::string makeStringWithNAs(const std::vector<double>& v, const double NA);
708  static std::string makeStringWithNAs(const std::vector<double>& v, const std::vector<double>& NAs);
709  std::string makeStringWithNAs(const PositionVector& v);
710  std::string makeStringWithNAs(const Position& p);
711  static std::string writeNA(double v, double NA = INVALID_DOUBLE);
712 
715  static std::string getOutputFilename(const SUMOVehicle& v, std::string deviceID);
716  static double getDetectionRange(const SUMOVehicle& v);
717  static double getMDRAC_PRT(const SUMOVehicle& v);
718  static double getExtraTime(const SUMOVehicle& v);
719  static bool useGeoCoords(const SUMOVehicle& v);
720  static bool writePositions(const SUMOVehicle& v);
721  static bool writeLanesPositions(const SUMOVehicle& v);
722  static bool filterByConflictType(const SUMOVehicle& v, std::string deviceID, std::vector<int>& conflictTypes);
723  static bool requestsTrajectories(const SUMOVehicle& v);
724  static bool getMeasuresAndThresholds(const SUMOVehicle& v, std::string deviceID,
725  std::map<std::string, double>& thresholds);
727 
729  static void initEdgeFilter();
730 
731 
732 private:
737  std::map<std::string, double> myThresholds;
742  double myRange;
744  double myMDRACPRT;
746  double myExtraTime;
756  std::vector<int> myDroppedConflictTypes;
757 
762 
763 
773 
774 
775 
778  std::vector<double> myGlobalMeasuresTimeSpan;
782  std::vector<std::string> myGlobalMeasuresLaneIDs;
784  std::vector<double> myGlobalMeasuresLanesPositions;
786  std::vector<double> myBRspan;
788  std::vector<double> mySGAPspan;
790  std::vector<double> myTGAPspan;
793  std::pair<std::pair<double, Position>, double> myMaxBR;
794  std::pair<std::pair<std::pair<double, Position>, double>, std::string> myMinSGAP;
795  std::pair<std::pair<std::pair<double, Position>, double>, std::string> myMinTGAP;
798 
800  static std::set<const MSEdge*> myEdgeFilter;
802  static bool myEdgeFilterActive;
803 
806 
808  static std::set<std::string> myCreatedOutputFiles;
809 
810 
817  SSM_WARN_RANGE = 1 << 3,
820  SSM_WARN_FILE = 1 << 5,
821  SSM_WARN_GEO = 1 << 6,
822  SSM_WARN_POS = 1 << 7,
824  SSM_WARN_CONFLICTFILTER = 1 << 9
825  };
826 
827  static const std::set<int> FOE_ENCOUNTERTYPES;
828  static const std::set<int> EGO_ENCOUNTERTYPES;
829 
830 private:
833 
836 
837 
838 };
const double INVALID_DOUBLE
invalid double
Definition: StdDefs.h:64
A simple description of a position on a lane (crossing of a lane)
An encounter is an episode involving two vehicles, which are closer to each other than some specified...
Definition: MSDevice_SSM.h:172
const MSVehicle * foe
Definition: MSDevice_SSM.h:245
ConflictPointInfo minPPET
Definition: MSDevice_SSM.h:296
EncounterType currentType
Definition: MSDevice_SSM.h:249
double foeConflictEntryTime
Times when the foe vehicle entered/left the conflict area. Currently only applies for crossing situat...
Definition: MSDevice_SSM.h:257
std::vector< double > foeDistsToConflict
Evolution of the foe vehicle's distance to the conflict point.
Definition: MSDevice_SSM.h:270
Encounter & operator=(const Encounter &)
Invalidated assignment operator.
std::vector< double > timeSpan
time points corresponding to the trajectories
Definition: MSDevice_SSM.h:260
std::vector< int > typeSpan
Evolution of the encounter classification (.
Definition: MSDevice_SSM.h:262
bool closingRequested
this flag is set by updateEncounter() or directly in processEncounters(), where encounters are closed...
Definition: MSDevice_SSM.h:300
std::vector< double > TTCspan
All values for TTC.
Definition: MSDevice_SSM.h:278
std::size_t size() const
Returns the number of trajectory points stored.
Definition: MSDevice_SSM.h:218
std::vector< double > MDRACspan
All values for MDRAC.
Definition: MSDevice_SSM.h:282
void resetExtraTime(double value)
resets remainingExtraTime to the given value
double remainingExtraTime
Remaining extra time (decreases after an encounter ended)
Definition: MSDevice_SSM.h:252
ConflictPointInfo maxMDRAC
Definition: MSDevice_SSM.h:294
const MSVehicle * ego
Definition: MSDevice_SSM.h:244
PositionVector conflictPointSpan
Predicted location of the conflict: In case of MERGING and CROSSING: entry point to conflict area for...
Definition: MSDevice_SSM.h:275
ConflictPointInfo maxDRAC
Definition: MSDevice_SSM.h:293
const std::string foeID
Definition: MSDevice_SSM.h:247
ConflictPointInfo minTTC
Definition: MSDevice_SSM.h:292
void countDownExtraTime(double amount)
decreases myRemaingExtraTime by given amount in seconds
Trajectory foeTrajectory
Trajectory of the foe vehicle.
Definition: MSDevice_SSM.h:266
std::vector< double > egoDistsToConflict
Evolution of the ego vehicle's distance to the conflict point.
Definition: MSDevice_SSM.h:268
Trajectory egoTrajectory
Trajectory of the ego vehicle.
Definition: MSDevice_SSM.h:264
double egoConflictEntryTime
Times when the ego vehicle entered/left the conflict area. Currently only applies for crossing situat...
Definition: MSDevice_SSM.h:255
Encounter(const MSVehicle *_ego, const MSVehicle *const _foe, double _begin, double extraTime)
Constructor.
double getRemainingExtraTime() const
returns the remaining extra time
ConflictPointInfo PET
Definition: MSDevice_SSM.h:295
const std::string egoID
Definition: MSDevice_SSM.h:246
std::vector< double > PPETspan
All values for PPET.
Definition: MSDevice_SSM.h:284
void add(double time, EncounterType type, Position egoX, std::string egoLane, double egoLanePos, Position egoV, Position foeX, std::string foeLane, double foeLanePos, Position foeV, Position conflictPoint, double egoDistToConflict, double foeDistToConflict, double ttc, double drac, std::pair< double, double > pet, double ppet, double mdrac)
add a new data point and update encounter type
Encounter(const Encounter &)
Invalidated Constructor.
std::vector< double > DRACspan
All values for DRAC.
Definition: MSDevice_SSM.h:280
A device which collects info on the vehicle trip (mainly on departure and arrival)
Definition: MSDevice_SSM.h:55
bool myComputeDRAC
Definition: MSDevice_SSM.h:759
std::map< const MSVehicle *, FoeInfo * > FoeInfoMap
Definition: MSDevice_SSM.h:367
double myExtraTime
Extra time in seconds to be logged after a conflict is over.
Definition: MSDevice_SSM.h:746
void generateOutput(OutputDevice *tripinfoOut) const
Finalizes output. Called on vehicle removal.
std::pair< std::pair< std::pair< double, Position >, double >, std::string > myMinTGAP
Definition: MSDevice_SSM.h:795
bool myComputeTTC
Flags for switching on / off comutation of different SSMs, derived from myMeasures.
Definition: MSDevice_SSM.h:759
PositionVector myGlobalMeasuresPositions
All values for positions (coordinates)
Definition: MSDevice_SSM.h:780
bool myComputeSGAP
Definition: MSDevice_SSM.h:759
static std::set< std::string > myCreatedOutputFiles
remember which files were created already (don't duplicate xml root-elements)
Definition: MSDevice_SSM.h:808
MSVehicle * myHolderMS
Definition: MSDevice_SSM.h:760
bool mySaveTrajectories
This determines whether the whole trajectories of the vehicles (position, speed, ssms) shall be saved...
Definition: MSDevice_SSM.h:740
bool updateEncounter(Encounter *e, FoeInfo *foeInfo)
Updates the encounter (adds a new trajectory point).
static bool requestsTrajectories(const SUMOVehicle &v)
static bool getMeasuresAndThresholds(const SUMOVehicle &v, std::string deviceID, std::map< std::string, double > &thresholds)
std::string getParameter(const std::string &key) const
try to retrieve the given parameter from this device. Throw exception for unsupported key
MSDevice_SSM & operator=(const MSDevice_SSM &)
Invalidated assignment operator.
bool myComputeTGAP
Definition: MSDevice_SSM.h:759
EncounterType classifyEncounter(const FoeInfo *foeInfo, EncounterApproachInfo &eInfo) const
Classifies the current type of the encounter provided some information on the opponents.
void computeSSMs(EncounterApproachInfo &e) const
Compute current values of the logged SSMs (myMeasures) for the given encounter 'e' and update 'e' acc...
static void buildVehicleDevices(SUMOVehicle &v, std::vector< MSVehicleDevice * > &into)
Build devices for the given vehicle, if needed.
void writeOutConflict(Encounter *e)
EncounterType
Different types of encounters corresponding to relative positions of the vehicles....
Definition: MSDevice_SSM.h:64
@ ENCOUNTER_TYPE_EGO_ENTERED_CONFLICT_AREA
ENCOUNTER_TYPE_EGO_ENTERED_CONFLICT_AREA.
Definition: MSDevice_SSM.h:97
@ ENCOUNTER_TYPE_FOE_LEFT_CONFLICT_AREA
ENCOUNTER_TYPE_FOE_LEFT_CONFLICT_AREA.
Definition: MSDevice_SSM.h:103
@ ENCOUNTER_TYPE_MERGING
ENCOUNTER_TYPE_MERGING.
Definition: MSDevice_SSM.h:78
@ ENCOUNTER_TYPE_MERGING_FOLLOWER
ENCOUNTER_TYPE_MERGING_FOLLOWER.
Definition: MSDevice_SSM.h:84
@ ENCOUNTER_TYPE_FOLLOWING_FOLLOWER
ENCOUNTER_TYPE_FOLLOWING_FOLLOWER.
Definition: MSDevice_SSM.h:71
@ ENCOUNTER_TYPE_FOLLOWING
ENCOUNTER_TYPE_FOLLOWING.
Definition: MSDevice_SSM.h:69
@ ENCOUNTER_TYPE_MERGING_LEADER
ENCOUNTER_TYPE_MERGING_LEADER.
Definition: MSDevice_SSM.h:81
@ ENCOUNTER_TYPE_FOLLOWING_PASSED
ENCOUNTER_TYPE_FOLLOWING_PASSED.
Definition: MSDevice_SSM.h:110
@ ENCOUNTER_TYPE_FOLLOWING_LEADER
ENCOUNTER_TYPE_FOLLOWING_LEADER.
Definition: MSDevice_SSM.h:73
@ ENCOUNTER_TYPE_BOTH_LEFT_CONFLICT_AREA
ENCOUNTER_TYPE_BOTH_LEFT_CONFLICT_AREA.
Definition: MSDevice_SSM.h:107
@ ENCOUNTER_TYPE_FOE_ENTERED_CONFLICT_AREA
ENCOUNTER_TYPE_FOE_ENTERED_CONFLICT_AREA.
Definition: MSDevice_SSM.h:99
@ ENCOUNTER_TYPE_ONCOMING
Definition: MSDevice_SSM.h:114
@ ENCOUNTER_TYPE_MERGING_PASSED
ENCOUNTER_TYPE_FOLLOWING_PASSED.
Definition: MSDevice_SSM.h:112
@ ENCOUNTER_TYPE_ON_ADJACENT_LANES
ENCOUNTER_TYPE_ON_ADJACENT_LANES.
Definition: MSDevice_SSM.h:75
@ ENCOUNTER_TYPE_EGO_LEFT_CONFLICT_AREA
ENCOUNTER_TYPE_EGO_LEFT_CONFLICT_AREA.
Definition: MSDevice_SSM.h:101
@ ENCOUNTER_TYPE_BOTH_ENTERED_CONFLICT_AREA
ENCOUNTER_TYPE_BOTH_ENTERED_CONFLICT_AREA.
Definition: MSDevice_SSM.h:105
@ ENCOUNTER_TYPE_NOCONFLICT_AHEAD
ENCOUNTER_TYPE_NOCONFLICT_AHEAD.
Definition: MSDevice_SSM.h:66
@ ENCOUNTER_TYPE_COLLISION
ENCOUNTER_TYPE_COLLISION.
Definition: MSDevice_SSM.h:116
@ ENCOUNTER_TYPE_CROSSING
ENCOUNTER_TYPE_CROSSING.
Definition: MSDevice_SSM.h:89
@ ENCOUNTER_TYPE_CROSSING_FOLLOWER
ENCOUNTER_TYPE_CROSSING_FOLLOWER.
Definition: MSDevice_SSM.h:95
@ ENCOUNTER_TYPE_MERGING_ADJACENT
ENCOUNTER_TYPE_MERGING_ADJACENT.
Definition: MSDevice_SSM.h:86
@ ENCOUNTER_TYPE_CROSSING_LEADER
ENCOUNTER_TYPE_CROSSING_LEADER.
Definition: MSDevice_SSM.h:92
std::priority_queue< Encounter *, std::vector< Encounter * >, Encounter::compare > EncounterQueue
Definition: MSDevice_SSM.h:365
static std::string writeNA(double v, double NA=INVALID_DOUBLE)
static void initEdgeFilter()
initialize edge filter (once)
std::vector< double > myGlobalMeasuresLanesPositions
All values for positions on the lanes.
Definition: MSDevice_SSM.h:784
bool notifyMove(SUMOTrafficObject &veh, double oldPos, double newPos, double newSpeed)
Checks for waiting steps when the vehicle moves.
static void determineConflictPoint(EncounterApproachInfo &eInfo)
Calculates the (x,y)-coordinate for the eventually predicted conflict point and stores the result in ...
void storeEncountersExceedingMaxLength()
Closes encounters, whose duration exceeds the maximal encounter length. If it is classified as confli...
static double computeDRAC(double gap, double followerSpeed, double leaderSpeed)
Computes the DRAC (deceleration to avoid a collision) for a lead/follow situation as defined,...
EncounterQueue myPastConflicts
Past encounters that where qualified as conflicts and are not yet flushed to the output file.
Definition: MSDevice_SSM.h:771
static bool useGeoCoords(const SUMOVehicle &v)
void setParameter(const std::string &key, const std::string &value)
try to set the given parameter for this device. Throw exception for unsupported key
static double getMDRAC_PRT(const SUMOVehicle &v)
static bool myEdgeFilterInitialized
Definition: MSDevice_SSM.h:801
static const std::set< MSDevice_SSM *, ComparatorNumericalIdLess > & getInstances()
returns all currently existing SSM devices
void closeEncounter(Encounter *e)
Finalizes the encounter and calculates SSM values.
static std::string makeStringWithNAs(const std::vector< double > &v, const double NA)
make a string of a double vector and treat a special value as invalid ("NA")
static bool writePositions(const SUMOVehicle &v)
void determineTTCandDRACandPPETandMDRAC(EncounterApproachInfo &eInfo) const
Discriminates between different encounter types and correspondingly determines TTC and DRAC for those...
static double getDetectionRange(const SUMOVehicle &v)
static void cleanup()
Clean up remaining devices instances.
static void insertOptions(OptionsCont &oc)
Inserts MSDevice_SSM-options.
static const std::set< const MSEdge * > & getEdgeFilter()
return the edges where the SSM device should scan
Definition: MSDevice_SSM.h:394
double myRange
Detection range. For vehicles closer than this distance from the ego vehicle, SSMs are traced.
Definition: MSDevice_SSM.h:742
const MSLane * findFoeConflictLane(const MSVehicle *foe, const MSLane *egoConflictLane, double &distToConflictLane) const
Computes the conflict lane for the foe.
std::vector< std::string > myGlobalMeasuresLaneIDs
All values for lanes.
Definition: MSDevice_SSM.h:782
std::vector< int > myDroppedConflictTypes
Which conflict types to exclude from the output.
Definition: MSDevice_SSM.h:756
static int myIssuedParameterWarnFlags
bitset storing info whether warning has already been issued about unset parameter (warn only once!...
Definition: MSDevice_SSM.h:812
bool notifyLeave(SUMOTrafficObject &veh, double lastPos, MSMoveReminder::Notification reason, const MSLane *enteredLane=0)
Called whenever the holder leaves a lane.
std::vector< Encounter * > EncounterVector
Definition: MSDevice_SSM.h:366
static void getUpstreamVehicles(const UpstreamScanStartInfo &scanStart, FoeInfoMap &foeCollector, std::set< const MSLane * > &seenLanes, const std::set< const MSJunction * > &routeJunctions)
Collects all vehicles within range 'range' upstream of the position 'pos' on the edge 'edge' into foe...
void createEncounters(FoeInfoMap &foes)
Makes new encounters for all given vehicles (these should be the ones entering the device's range in ...
static const std::set< int > FOE_ENCOUNTERTYPES
Definition: MSDevice_SSM.h:827
bool qualifiesAsConflict(Encounter *e)
Tests if the SSM values exceed the threshold for qualification as conflict.
std::map< std::string, double > myThresholds
Definition: MSDevice_SSM.h:737
static std::string getOutputFilename(const SUMOVehicle &v, std::string deviceID)
void updateAndWriteOutput()
This is called once per time step in MSNet::writeOutput() and collects the surrounding vehicles,...
static double computeMDRAC(double gap, double followerSpeed, double leaderSpeed, double prt)
Computes the MDRAC (deceleration to avoid a collision) for a lead/follow situation as defined conside...
static std::set< MSDevice_SSM *, ComparatorNumericalIdLess > * myInstances
All currently existing SSM devices.
Definition: MSDevice_SSM.h:59
std::pair< std::pair< std::pair< double, Position >, double >, std::string > myMinSGAP
Definition: MSDevice_SSM.h:794
OutputDevice * myOutputFile
Output device.
Definition: MSDevice_SSM.h:805
static double getExtraTime(const SUMOVehicle &v)
EncounterVector myActiveEncounters
Definition: MSDevice_SSM.h:767
std::vector< double > myGlobalMeasuresTimeSpan
Definition: MSDevice_SSM.h:778
void computeGlobalMeasures()
Stores measures, that are not associated to a specific encounter as headways and brake rates.
static std::string encounterToString(EncounterType type)
Definition: MSDevice_SSM.h:119
double myOldestActiveEncounterBegin
begin time of the oldest active encounter
Definition: MSDevice_SSM.h:769
static void checkConflictEntryAndExit(EncounterApproachInfo &eInfo)
Checks whether ego or foe have entered or left the conflict area in the last step and eventually writ...
double computeTTC(double gap, double followerSpeed, double leaderSpeed) const
Computes the time to collision (in seconds) for two vehicles with a given initial gap under the assum...
void flushConflicts(bool all=false)
Writes out all past conflicts that have begun earlier than the oldest active encounter.
void determinePET(EncounterApproachInfo &eInfo) const
Discriminates between different encounter types and correspondingly determines the PET for those case...
static std::set< const MSEdge * > myEdgeFilter
spatial filter for SSM device output
Definition: MSDevice_SSM.h:800
MSDevice_SSM(SUMOVehicle &holder, const std::string &id, std::string outputFilename, std::map< std::string, double > thresholds, bool trajectories, double range, double extraTime, bool useGeoCoords, bool writePositions, bool writeLanesPositions, std::vector< int > conflictOrder)
Constructor.
static const std::set< int > EGO_ENCOUNTERTYPES
Definition: MSDevice_SSM.h:828
static void toGeo(Position &x)
convert SUMO-positions to geo coordinates (in place)
static void findSurroundingVehicles(const MSVehicle &veh, double range, FoeInfoMap &foeCollector)
Returns all vehicles, which are within the given range of the given vehicle.
bool myWritePositions
Wether to print the positions for all timesteps.
Definition: MSDevice_SSM.h:750
void resetEncounters()
Closes all current Encounters and moves conflicts to myPastConflicts,.
std::pair< std::pair< double, Position >, double > myMaxBR
Extremal values for the global measures (as <<<time, Position>, value>, [leaderID]>-pairs)
Definition: MSDevice_SSM.h:793
std::vector< double > myBRspan
All values for brake rate.
Definition: MSDevice_SSM.h:786
bool myFilterConflictTypes
Whether to exclude certain conflicts containing certain conflict types from the output.
Definition: MSDevice_SSM.h:754
bool myUseGeoCoords
Whether to use the original coordinate system for output.
Definition: MSDevice_SSM.h:748
bool myWriteLanesPositions
Wether to print the lanes and positions for all timesteps and conflicts.
Definition: MSDevice_SSM.h:752
@ SSM_WARN_CONFLICTFILTER
Definition: MSDevice_SSM.h:824
static bool filterByConflictType(const SUMOVehicle &v, std::string deviceID, std::vector< int > &conflictTypes)
~MSDevice_SSM()
Destructor.
double myMDRACPRT
perception reaction time for MDRAC
Definition: MSDevice_SSM.h:744
const std::string deviceName() const
return the name for this type of device
Definition: MSDevice_SSM.h:495
bool myComputeMDRAC
Definition: MSDevice_SSM.h:759
static bool myEdgeFilterActive
Definition: MSDevice_SSM.h:802
void flushGlobalMeasures()
Write out all non-encounter specific measures as headways and braking rates.
std::vector< double > myTGAPspan
All values for time gap.
Definition: MSDevice_SSM.h:790
static void getVehiclesOnJunction(const MSJunction *, const MSLane *egoJunctionLane, double egoDistToConflictLane, const MSLane *const egoConflictLane, FoeInfoMap &foeCollector, std::set< const MSLane * > &seenLanes)
Collects all vehicles on the junction into foeCollector.
static void estimateConflictTimes(EncounterApproachInfo &eInfo)
Estimates the time until conflict for the vehicles based on the distance to the conflict entry points...
bool notifyEnter(SUMOTrafficObject &veh, MSMoveReminder::Notification reason, const MSLane *enteredLane=0)
Called whenever the holder enteres a lane.
bool myComputePPET
Definition: MSDevice_SSM.h:759
void updatePassedEncounter(Encounter *e, FoeInfo *foeInfo, EncounterApproachInfo &eInfo)
Updates an encounter, which was classified as ENCOUNTER_TYPE_NOCONFLICT_AHEAD this may be the case be...
void processEncounters(FoeInfoMap &foes, bool forceClose=false)
Finds encounters for which the foe vehicle has disappeared from range. remainingExtraTime is decrease...
static bool writeLanesPositions(const SUMOVehicle &v)
std::vector< double > mySGAPspan
All values for space gap.
Definition: MSDevice_SSM.h:788
MSDevice_SSM(const MSDevice_SSM &)
Invalidated copy constructor.
A road/street connecting two junctions.
Definition: MSEdge.h:77
The base class for an intersection.
Definition: MSJunction.h:58
Representation of a lane in the micro simulation.
Definition: MSLane.h:84
Notification
Definition of a vehicle state.
Abstract in-vehicle device.
Representation of a vehicle in the micro simulation.
Definition: MSVehicle.h:77
A storage for options typed value containers)
Definition: OptionsCont.h:89
Static storage of an output device and its base (abstract) implementation.
Definition: OutputDevice.h:61
A point in 2D or 3D with translation and scaling methods.
Definition: Position.h:37
A list of positions.
Representation of a vehicle, person, or container.
Representation of a vehicle.
Definition: SUMOVehicle.h:60
ConflictPointInfo stores some information on a specific conflict point (used to store information on ...
Definition: MSDevice_SSM.h:188
EncounterType type
Type of the conflict.
Definition: MSDevice_SSM.h:196
double time
time point of the conflict
Definition: MSDevice_SSM.h:190
double speed
speed of the reporting vehicle at the given time/position
Definition: MSDevice_SSM.h:200
ConflictPointInfo(double time, Position x, EncounterType type, double ssmValue, double speed)
Definition: MSDevice_SSM.h:202
Position pos
Predicted location of the conflict: In case of MERGING and CROSSING: entry point to conflict area for...
Definition: MSDevice_SSM.h:194
double value
value of the corresponding SSM
Definition: MSDevice_SSM.h:198
A trajectory encloses a series of positions x and speeds v for one vehicle (the times are stored only...
Definition: MSDevice_SSM.h:176
std::vector< std::string > lane
Definition: MSDevice_SSM.h:180
Compares encounters regarding to their start time.
Definition: MSDevice_SSM.h:230
bool operator()(Encounter *e1, Encounter *e2)
Definition: MSDevice_SSM.h:232
Structure to collect some info on the encounter needed during ssm calculation by various functions.
Definition: MSDevice_SSM.h:312
std::pair< const MSLane *, double > foeConflictEntryCrossSection
Definition: MSDevice_SSM.h:333
std::pair< const MSLane *, double > egoConflictEntryCrossSection
Definition: MSDevice_SSM.h:332
std::pair< double, double > pet
Definition: MSDevice_SSM.h:330
const MSLane * egoConflictLane
Definition: MSDevice_SSM.h:341
Auxiliary structure used to handle upstream scanning start points Upstream scan has to be started aft...
Definition: MSDevice_SSM.h:355
UpstreamScanStartInfo(const MSEdge *edge, double pos, double range, double egoDistToConflictLane, const MSLane *egoConflictLane)
Definition: MSDevice_SSM.h:356