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.org/sumo
3 // Copyright (C) 2013-2020 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 /****************************************************************************/
20 // An SSM-device logs encounters / conflicts of the carrying vehicle with other surrounding vehicles.
21 // XXX: Preliminary implementation. Use with care. Especially rerouting vehicles could be problematic.
22 /****************************************************************************/
23 #pragma once
24 #include <config.h>
25 
26 #include <queue>
27 #include "MSVehicleDevice.h"
28 #include <utils/common/SUMOTime.h>
30 #include <utils/geom/Position.h>
31 
32 
33 // ===========================================================================
34 // class declarations
35 // ===========================================================================
36 class SUMOVehicle;
37 class SUMOTrafficObject;
38 
39 
40 // ===========================================================================
41 // class definitions
42 // ===========================================================================
52 class MSCrossSection;
53 
54 class MSDevice_SSM : public MSVehicleDevice {
55 
56 private:
58  static std::set<MSDevice_SSM*, ComparatorNumericalIdLess>* myInstances;
59 
60 public:
64  // Other vehicle is closer than range, but not on a lane conflicting with the ego's route ahead
66  // Ego and foe vehicles' edges form a part of a consecutive sequence of edges
67  // This type may be specified further by ENCOUNTER_TYPE_FOLLOWING_LEADER or ENCOUNTER_TYPE_FOLLOWING_FOLLOWER
69  // Ego vehicle is on an edge that has a sequence of successors connected to the other vehicle's edge
71  // Other vehicle is on an edge that has a sequence of successors connected to the ego vehicle's current edge
73  // Other vehicle is on an edge that has a sequence of successors connected to the ego vehicle's current edge
75  // Ego and foe share an upcoming edge of their routes while the merging point for the routes is still ahead
76  // This type may be specified further by ENCOUNTER_TYPE_MERGING_LEADER or ENCOUNTER_TYPE_MERGING_FOLLOWER
78  // Other vehicle is on an edge that has a sequence of successors connected to an edge on the ego vehicle's route
79  // and the estimated arrival vehicle at the merge point is earlier for the ego than for the foe
81  // Other vehicle is on an edge that has a sequence of successors connected to an edge on the ego vehicle's route
82  // and the estimated arrival vehicle at the merge point is earlier for the foe than for the ego
84  // Vehicles' bestlanes lead to the same edge but to adjacent lanes
86  // Ego's and foe's routes have crossing edges
87  // This type may be specified further by ENCOUNTER_TYPE_CROSSING_LEADER or ENCOUNTER_TYPE_CROSSING_FOLLOWER
89  // 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
90  // and the estimated arrival vehicle at the merge point is earlier for the ego than for the foe
92  // 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
93  // and the estimated arrival vehicle at the merge point is earlier for the foe than for the ego
95  // The encounter is a possible crossing conflict, and the ego vehicle has entered the conflict area
97  // The encounter is a possible crossing conflict, and the foe vehicle has entered the conflict area
99  // The encounter has been a possible crossing conflict, but the ego vehicle has left the conflict area
101  // The encounter has been a possible crossing conflict, but the foe vehicle has left the conflict area
103  // 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)
105  // The encounter has been a possible crossing conflict, but both vehicle have left the conflict area
107  // FOLLOWING_PASSED and MERGING_PASSED are reserved to achieve that these encounter types may be tracked longer (see updatePassedEncounter)
108  // The encounter has been a following situation, but is not active any more
110  // The encounter has been a merging situation, but is not active any more
112  // Ego vehicle and foe are driving in opposite directions towards each other on the same lane (or sequence of consecutive lanes)
114  // Collision (currently unused, might be differentiated further)
116  };
117 
118  static std::string encounterToString(EncounterType type) {
119  switch (type) {
121  return ("NOCONFLICT_AHEAD");
123  return ("FOLLOWING");
125  return ("FOLLOWING_FOLLOWER");
127  return ("FOLLOWING_LEADER");
129  return ("ON_ADJACENT_LANES");
130  case (ENCOUNTER_TYPE_MERGING):
131  return ("MERGING");
133  return ("MERGING_LEADER");
135  return ("MERGING_FOLLOWER");
137  return ("MERGING_ADJACENT");
139  return ("CROSSING");
141  return ("CROSSING_LEADER");
143  return ("CROSSING_FOLLOWER");
145  return ("EGO_ENTERED_CONFLICT_AREA");
147  return ("FOE_ENTERED_CONFLICT_AREA");
149  return ("EGO_LEFT_CONFLICT_AREA");
151  return ("FOE_LEFT_CONFLICT_AREA");
153  return ("BOTH_ENTERED_CONFLICT_AREA");
155  return ("BOTH_LEFT_CONFLICT_AREA");
157  return ("FOLLOWING_PASSED");
159  return ("MERGING_PASSED");
161  return ("ONCOMING");
163  return ("COLLISION");
164  }
165  return ("UNKNOWN");
166  };
167 
168 private:
171  class Encounter {
172  private:
175  struct Trajectory {
176  // positions
178  // momentary speeds
180  };
185  double time;
193  double value;
194 
195  ConflictPointInfo(double time, Position x, EncounterType type, double ssmValue) :
196  time(time), pos(x), type(type), value(ssmValue) {};
197  };
198 
199  public:
201  Encounter(const MSVehicle* _ego, const MSVehicle* const _foe, double _begin, double extraTime);
203  ~Encounter();
204 
206  void add(double time, EncounterType type, Position egoX, Position egoV, Position foeX, Position foeV,
207  Position conflictPoint, double egoDistToConflict, double foeDistToConflict, double ttc, double drac, std::pair<double, double> pet);
208 
210  std::size_t size() const {
211  return timeSpan.size();
212  }
213 
215  void resetExtraTime(double value);
217  void countDownExtraTime(double amount);
219  double getRemainingExtraTime() const;
220 
222  struct compare {
223  typedef bool value_type;
224  bool operator()(Encounter* e1, Encounter* e2) {
225  if (e1->begin == e2->begin) {
226  return e1->foeID > e2->foeID;
227  } else {
228  return e1->begin > e2->begin;
229  }
230  };
231  };
232 
233 
234 
235  public:
236  const MSVehicle* ego;
237  const MSVehicle* foe;
238  const std::string egoID;
239  const std::string foeID;
240  double begin, end;
242 
245 
250 
252  std::vector<double> timeSpan;
254  std::vector<int> typeSpan;
260  std::vector<double> egoDistsToConflict;
262  std::vector<double> foeDistsToConflict;
263 
268 
270  std::vector<double> TTCspan;
272  std::vector<double> DRACspan;
273 
274 // /// @brief Cross sections at which a PET shall be calculated for the corresponding vehicle
275 // std::vector<std::pair<std::pair<const MSLane*, double>, double> > egoPETCrossSections;
276 // std::vector<std::pair<std::pair<const MSLane*, double>, double> > foePETCrossSections;
277 
284 
287 
288  private:
294  };
295 
296 
315  double ttc;
316  double drac;
317  std::pair<double, double> pet;
318  std::pair<const MSLane*, double> egoConflictEntryCrossSection;
319  std::pair<const MSLane*, double> foeConflictEntryCrossSection;
320  };
321 
322 
326  struct FoeInfo {
327  virtual ~FoeInfo() {};
330  };
331  // TODO: consider introducing a class foeCollector, which holds the foe info content
332  // plus a vehicle container to be used in findSurrounding vehicles.
333  // findSurroundingVehicles() would then deliver a vector of such foeCollectors
334  // (one for each possible egoConflictLane) instead of a map vehicle->foeInfo
335  // This could be helpful to resolve the resolution for several different
336  // projected conflicts with the same foe.
337 
338 
344  const MSEdge* edge;
345  double pos;
346  double range;
349  };
350 
351  typedef std::priority_queue<Encounter*, std::vector<Encounter*>, Encounter::compare> EncounterQueue;
352  typedef std::vector<Encounter*> EncounterVector;
353  typedef std::map<const MSVehicle*, FoeInfo*> FoeInfoMap;
354 public:
355 
359  static void insertOptions(OptionsCont& oc);
360 
361 
372  static void buildVehicleDevices(SUMOVehicle& v, std::vector<MSVehicleDevice*>& into);
373 
374 
377  static const std::set<MSDevice_SSM*, ComparatorNumericalIdLess>& getInstances();
378 
384  void updateAndWriteOutput();
385 
387  std::string getParameter(const std::string& key) const;
388 
390  void setParameter(const std::string& key, const std::string& value);
391 
392 private:
393  void update();
394  void writeOutConflict(Encounter* e);
395 
397  static void toGeo(Position& x);
399  static void toGeo(PositionVector& x);
400 
401 public:
404  static void cleanup();
405 
406 
407 public:
409  ~MSDevice_SSM();
410 
411 
423  static void findSurroundingVehicles(const MSVehicle& veh, double range, FoeInfoMap& foeCollector);
424 
427  static void getUpstreamVehicles(const UpstreamScanStartInfo& scanStart, FoeInfoMap& foeCollector, std::set<const MSLane*>& seenLanes, const std::set<const MSJunction*>& routeJunctions);
428 
431  static void getVehiclesOnJunction(const MSJunction*, const MSLane* egoJunctionLane, double egoDistToConflictLane, const MSLane* const egoConflictLane, FoeInfoMap& foeCollector, std::set<const MSLane*>& seenLanes);
432 
433 
436 
446  bool notifyMove(SUMOTrafficObject& veh, double oldPos,
447  double newPos, double newSpeed);
448 
449 
459  bool notifyEnter(SUMOTrafficObject& veh, MSMoveReminder::Notification reason, const MSLane* enteredLane = 0);
460 
461 
470  bool notifyLeave(SUMOTrafficObject& veh, double lastPos,
471  MSMoveReminder::Notification reason, const MSLane* enteredLane = 0);
473 
474 
476  const std::string deviceName() const {
477  return "ssm";
478  }
479 
486  void generateOutput(OutputDevice* tripinfoOut) const;
487 
488 
489 
490 private:
502  MSDevice_SSM(SUMOVehicle& holder, const std::string& id, std::string outputFilename, std::map<std::string, double> thresholds,
503  bool trajectories, double range, double extraTime, bool useGeoCoords);
504 
513  void processEncounters(FoeInfoMap& foes, bool forceClose = false);
514 
515 
520 
521 
522 
525  void createEncounters(FoeInfoMap& foes);
526 
527 
532  void computeGlobalMeasures();
533 
536  void resetEncounters();
537 
541  void flushConflicts(bool all = false);
542 
546  void flushGlobalMeasures();
547 
552  bool updateEncounter(Encounter* e, FoeInfo* foeInfo);
553 
564 
565 
576  EncounterType classifyEncounter(const FoeInfo* foeInfo, EncounterApproachInfo& eInfo) const;
577 
578 
584  static void determineConflictPoint(EncounterApproachInfo& eInfo);
585 
586 
596  static void estimateConflictTimes(EncounterApproachInfo& eInfo);
597 
598 
606 
607 
616  const MSLane* findFoeConflictLane(const MSVehicle* foe, const MSLane* egoConflictLane, double& distToConflictLane) const;
617 
620  void closeEncounter(Encounter* e);
621 
625 
630  void computeSSMs(EncounterApproachInfo& e) const;
631 
632 
636  void determinePET(EncounterApproachInfo& eInfo) const;
637 
638 
642  void determineTTCandDRAC(EncounterApproachInfo& eInfo) const;
643 
644 
648  double computeTTC(double gap, double followerSpeed, double leaderSpeed) const;
649 
650 
656  static double computeDRAC(double gap, double followerSpeed, double leaderSpeed);
657 
669  static double computeDRAC(const EncounterApproachInfo& eInfo);
670 
678  static std::string makeStringWithNAs(const std::vector<double>& v, const double NA);
679  static std::string makeStringWithNAs(const std::vector<double>& v, const std::vector<double>& NAs);
680  static std::string makeStringWithNAs(const PositionVector& v, const int precision);
681 
684  static std::string getOutputFilename(const SUMOVehicle& v, std::string deviceID);
685  static double getDetectionRange(const SUMOVehicle& v);
686  static double getExtraTime(const SUMOVehicle& v);
687  static bool useGeoCoords(const SUMOVehicle& v);
688  static bool requestsTrajectories(const SUMOVehicle& v);
689  static bool getMeasuresAndThresholds(const SUMOVehicle& v, std::string deviceID,
690  std::map<std::string, double>& thresholds);
692 
693 private:
698  std::map<std::string, double> myThresholds;
703  double myRange;
705  double myExtraTime;
712 
713 
723 
724 
725 
728  std::vector<double> myGlobalMeasuresTimeSpan;
730  std::vector<double> myBRspan;
732  std::vector<double> mySGAPspan;
734  std::vector<double> myTGAPspan;
737  std::pair<std::pair<double, Position>, double> myMaxBR;
738  std::pair<std::pair<std::pair<double, Position>, double>, std::string> myMinSGAP;
739  std::pair<std::pair<std::pair<double, Position>, double>, std::string> myMinTGAP;
742 
745 
747  static std::set<std::string> createdOutputFiles;
748 
749 
756  SSM_WARN_RANGE = 1 << 3,
758  SSM_WARN_FILE = 1 << 5,
759  SSM_WARN_GEO = 1 << 6
760  };
761 
762 
763 
764 private:
767 
770 
771 
772 };
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:171
const MSVehicle * foe
Definition: MSDevice_SSM.h:237
EncounterType currentType
Definition: MSDevice_SSM.h:241
double foeConflictEntryTime
Times when the foe vehicle entered/left the conflict area. Currently only applies for crossing situat...
Definition: MSDevice_SSM.h:249
std::vector< double > foeDistsToConflict
Evolution of the foe vehicle's distance to the conflict point.
Definition: MSDevice_SSM.h:262
Encounter & operator=(const Encounter &)
Invalidated assignment operator.
std::vector< double > timeSpan
time points corresponding to the trajectories
Definition: MSDevice_SSM.h:252
std::vector< int > typeSpan
Evolution of the encounter classification (.
Definition: MSDevice_SSM.h:254
bool closingRequested
this flag is set by updateEncounter() or directly in processEncounters(), where encounters are closed...
Definition: MSDevice_SSM.h:286
std::vector< double > TTCspan
All values for TTC.
Definition: MSDevice_SSM.h:270
void add(double time, EncounterType type, Position egoX, Position egoV, Position foeX, Position foeV, Position conflictPoint, double egoDistToConflict, double foeDistToConflict, double ttc, double drac, std::pair< double, double > pet)
add a new data point and update encounter type
std::size_t size() const
Returns the number of trajectory points stored.
Definition: MSDevice_SSM.h:210
void resetExtraTime(double value)
resets remainingExtraTime to the given value
double remainingExtraTime
Remaining extra time (decreases after an encounter ended)
Definition: MSDevice_SSM.h:244
const MSVehicle * ego
Definition: MSDevice_SSM.h:236
PositionVector conflictPointSpan
Predicted location of the conflict: In case of MERGING and CROSSING: entry point to conflict area for...
Definition: MSDevice_SSM.h:267
ConflictPointInfo maxDRAC
Definition: MSDevice_SSM.h:281
const std::string foeID
Definition: MSDevice_SSM.h:239
ConflictPointInfo minTTC
Definition: MSDevice_SSM.h:280
void countDownExtraTime(double amount)
decreases myRemaingExtraTime by given amount in seconds
Trajectory foeTrajectory
Trajectory of the foe vehicle.
Definition: MSDevice_SSM.h:258
std::vector< double > egoDistsToConflict
Evolution of the ego vehicle's distance to the conflict point.
Definition: MSDevice_SSM.h:260
Trajectory egoTrajectory
Trajectory of the ego vehicle.
Definition: MSDevice_SSM.h:256
double egoConflictEntryTime
Times when the ego vehicle entered/left the conflict area. Currently only applies for crossing situat...
Definition: MSDevice_SSM.h:247
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:282
const std::string egoID
Definition: MSDevice_SSM.h:238
Encounter(const Encounter &)
Invalidated Constructor.
std::vector< double > DRACspan
All values for DRAC.
Definition: MSDevice_SSM.h:272
A device which collects info on the vehicle trip (mainly on departure and arrival)
Definition: MSDevice_SSM.h:54
bool myComputeDRAC
Definition: MSDevice_SSM.h:709
std::map< const MSVehicle *, FoeInfo * > FoeInfoMap
Definition: MSDevice_SSM.h:353
double myExtraTime
Extra time in seconds to be logged after a conflict is over.
Definition: MSDevice_SSM.h:705
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:739
bool myComputeTTC
Flags for switching on / off comutation of different SSMs, derived from myMeasures.
Definition: MSDevice_SSM.h:709
bool myComputeSGAP
Definition: MSDevice_SSM.h:709
static std::set< std::string > createdOutputFiles
remember which files were created already (don't duplicate xml root-elements)
Definition: MSDevice_SSM.h:747
MSVehicle * myHolderMS
Definition: MSDevice_SSM.h:710
bool mySaveTrajectories
This determines whether the whole trajectories of the vehicles (position, speed, ssms) shall be saved...
Definition: MSDevice_SSM.h:701
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:709
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:63
@ ENCOUNTER_TYPE_EGO_ENTERED_CONFLICT_AREA
ENCOUNTER_TYPE_EGO_ENTERED_CONFLICT_AREA.
Definition: MSDevice_SSM.h:96
@ ENCOUNTER_TYPE_FOE_LEFT_CONFLICT_AREA
ENCOUNTER_TYPE_FOE_LEFT_CONFLICT_AREA.
Definition: MSDevice_SSM.h:102
@ ENCOUNTER_TYPE_MERGING
ENCOUNTER_TYPE_MERGING.
Definition: MSDevice_SSM.h:77
@ ENCOUNTER_TYPE_MERGING_FOLLOWER
ENCOUNTER_TYPE_MERGING_FOLLOWER.
Definition: MSDevice_SSM.h:83
@ ENCOUNTER_TYPE_FOLLOWING_FOLLOWER
ENCOUNTER_TYPE_FOLLOWING_FOLLOWER.
Definition: MSDevice_SSM.h:70
@ ENCOUNTER_TYPE_FOLLOWING
ENCOUNTER_TYPE_FOLLOWING.
Definition: MSDevice_SSM.h:68
@ ENCOUNTER_TYPE_MERGING_LEADER
ENCOUNTER_TYPE_MERGING_LEADER.
Definition: MSDevice_SSM.h:80
@ ENCOUNTER_TYPE_FOLLOWING_PASSED
ENCOUNTER_TYPE_FOLLOWING_PASSED.
Definition: MSDevice_SSM.h:109
@ ENCOUNTER_TYPE_FOLLOWING_LEADER
ENCOUNTER_TYPE_FOLLOWING_LEADER.
Definition: MSDevice_SSM.h:72
@ ENCOUNTER_TYPE_BOTH_LEFT_CONFLICT_AREA
ENCOUNTER_TYPE_BOTH_LEFT_CONFLICT_AREA.
Definition: MSDevice_SSM.h:106
@ ENCOUNTER_TYPE_FOE_ENTERED_CONFLICT_AREA
ENCOUNTER_TYPE_FOE_ENTERED_CONFLICT_AREA.
Definition: MSDevice_SSM.h:98
@ ENCOUNTER_TYPE_ONCOMING
Definition: MSDevice_SSM.h:113
@ ENCOUNTER_TYPE_MERGING_PASSED
ENCOUNTER_TYPE_FOLLOWING_PASSED.
Definition: MSDevice_SSM.h:111
@ ENCOUNTER_TYPE_ON_ADJACENT_LANES
ENCOUNTER_TYPE_ON_ADJACENT_LANES.
Definition: MSDevice_SSM.h:74
@ ENCOUNTER_TYPE_EGO_LEFT_CONFLICT_AREA
ENCOUNTER_TYPE_EGO_LEFT_CONFLICT_AREA.
Definition: MSDevice_SSM.h:100
@ ENCOUNTER_TYPE_BOTH_ENTERED_CONFLICT_AREA
ENCOUNTER_TYPE_BOTH_ENTERED_CONFLICT_AREA.
Definition: MSDevice_SSM.h:104
@ ENCOUNTER_TYPE_NOCONFLICT_AHEAD
ENCOUNTER_TYPE_NOCONFLICT_AHEAD.
Definition: MSDevice_SSM.h:65
@ ENCOUNTER_TYPE_COLLISION
ENCOUNTER_TYPE_COLLISION.
Definition: MSDevice_SSM.h:115
@ ENCOUNTER_TYPE_CROSSING
ENCOUNTER_TYPE_CROSSING.
Definition: MSDevice_SSM.h:88
@ ENCOUNTER_TYPE_CROSSING_FOLLOWER
ENCOUNTER_TYPE_CROSSING_FOLLOWER.
Definition: MSDevice_SSM.h:94
@ ENCOUNTER_TYPE_MERGING_ADJACENT
ENCOUNTER_TYPE_MERGING_ADJACENT.
Definition: MSDevice_SSM.h:85
@ ENCOUNTER_TYPE_CROSSING_LEADER
ENCOUNTER_TYPE_CROSSING_LEADER.
Definition: MSDevice_SSM.h:91
std::priority_queue< Encounter *, std::vector< Encounter * >, Encounter::compare > EncounterQueue
Definition: MSDevice_SSM.h:351
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:721
static bool useGeoCoords(const SUMOVehicle &v)
static int issuedParameterWarnFlags
bitset storing info whether warning has already been issued about unset parameter (warn only once!...
Definition: MSDevice_SSM.h:751
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)
Constructor.
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 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 double getDetectionRange(const SUMOVehicle &v)
static void cleanup()
Clean up remaining devices instances.
static void insertOptions(OptionsCont &oc)
Inserts MSDevice_SSM-options.
double myRange
Detection range. For vehicles closer than this distance from the ego vehicle, SSMs are traced.
Definition: MSDevice_SSM.h:703
const MSLane * findFoeConflictLane(const MSVehicle *foe, const MSLane *egoConflictLane, double &distToConflictLane) const
Computes the conflict lane for the foe.
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:352
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 ...
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:698
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 std::set< MSDevice_SSM *, ComparatorNumericalIdLess > * myInstances
All currently existing SSM devices.
Definition: MSDevice_SSM.h:58
std::pair< std::pair< std::pair< double, Position >, double >, std::string > myMinSGAP
Definition: MSDevice_SSM.h:738
OutputDevice * myOutputFile
Output device.
Definition: MSDevice_SSM.h:744
static double getExtraTime(const SUMOVehicle &v)
EncounterVector myActiveEncounters
Definition: MSDevice_SSM.h:717
std::vector< double > myGlobalMeasuresTimeSpan
Definition: MSDevice_SSM.h:728
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:118
double myOldestActiveEncounterBegin
begin time of the oldest active encounter
Definition: MSDevice_SSM.h:719
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 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.
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:737
std::vector< double > myBRspan
All values for brake rate.
Definition: MSDevice_SSM.h:730
void determineTTCandDRAC(EncounterApproachInfo &eInfo) const
Discriminates between different encounter types and correspondingly determines TTC and DRAC for those...
bool myUseGeoCoords
Whether to use the original coordinate system for output.
Definition: MSDevice_SSM.h:707
~MSDevice_SSM()
Destructor.
const std::string deviceName() const
return the name for this type of device
Definition: MSDevice_SSM.h:476
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:734
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.
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...
std::vector< double > mySGAPspan
All values for space gap.
Definition: MSDevice_SSM.h:732
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:82
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:60
A point in 2D or 3D with translation and scaling methods.
Definition: Position.h:36
A list of positions.
Representation of a vehicle, person, or container.
Representation of a vehicle.
Definition: SUMOVehicle.h:58
ConflictPointInfo stores some information on a specific conflict point (used to store information on ...
Definition: MSDevice_SSM.h:183
EncounterType type
Type of the conflict.
Definition: MSDevice_SSM.h:191
double time
time point of the conflict
Definition: MSDevice_SSM.h:185
ConflictPointInfo(double time, Position x, EncounterType type, double ssmValue)
Definition: MSDevice_SSM.h:195
Position pos
Predicted location of the conflict: In case of MERGING and CROSSING: entry point to conflict area for...
Definition: MSDevice_SSM.h:189
double value
value of the corresponding SSM
Definition: MSDevice_SSM.h:193
A trajectory encloses a series of positions x and speeds v for one vehicle (the times are stored only...
Definition: MSDevice_SSM.h:175
Compares encounters regarding to their start time.
Definition: MSDevice_SSM.h:222
bool operator()(Encounter *e1, Encounter *e2)
Definition: MSDevice_SSM.h:224
Structure to collect some info on the encounter needed during ssm calculation by various functions.
Definition: MSDevice_SSM.h:298
std::pair< const MSLane *, double > foeConflictEntryCrossSection
Definition: MSDevice_SSM.h:319
std::pair< const MSLane *, double > egoConflictEntryCrossSection
Definition: MSDevice_SSM.h:318
std::pair< double, double > pet
Definition: MSDevice_SSM.h:317
const MSLane * egoConflictLane
Definition: MSDevice_SSM.h:327
Auxiliary structure used to handle upstream scanning start points Upstream scan has to be started aft...
Definition: MSDevice_SSM.h:341
UpstreamScanStartInfo(const MSEdge *edge, double pos, double range, double egoDistToConflictLane, const MSLane *egoConflictLane)
Definition: MSDevice_SSM.h:342