20 #ifndef MSDevice_SSM_h 21 #define MSDevice_SSM_h 61 static std::set<MSDevice_SSM*, ComparatorNumericalIdLess>*
myInstances;
124 return (
"NOCONFLICT_AHEAD");
126 return (
"FOLLOWING");
128 return (
"FOLLOWING_FOLLOWER");
130 return (
"FOLLOWING_LEADER");
132 return (
"ON_ADJACENT_LANES");
136 return (
"MERGING_LEADER");
138 return (
"MERGING_FOLLOWER");
140 return (
"MERGING_ADJACENT");
144 return (
"CROSSING_LEADER");
146 return (
"CROSSING_FOLLOWER");
148 return (
"EGO_ENTERED_CONFLICT_AREA");
150 return (
"FOE_ENTERED_CONFLICT_AREA");
152 return (
"EGO_LEFT_CONFLICT_AREA");
154 return (
"FOE_LEFT_CONFLICT_AREA");
156 return (
"BOTH_ENTERED_CONFLICT_AREA");
158 return (
"BOTH_LEFT_CONFLICT_AREA");
160 return (
"FOLLOWING_PASSED");
162 return (
"MERGING_PASSED");
166 return (
"COLLISION");
199 time(time), pos(x), type(type), value(ssmValue) {};
210 Position conflictPoint,
double egoDistToConflict,
double foeDistToConflict,
double ttc,
double drac, std::pair<double, double> pet);
320 std::pair<double, double>
pet;
331 const MSLane* egoConflictLane;
346 edge(edge), pos(pos), range(range), egoDistToConflictLane(egoDistToConflictLane), egoConflictLane(egoConflictLane) {};
380 static const std::set<MSDevice_SSM*, ComparatorNumericalIdLess>&
getInstances();
444 double newPos,
double newSpeed);
499 MSDevice_SSM(
SUMOVehicle& holder,
const std::string&
id, std::string outputFilename, std::map<std::string, double> thresholds,
500 bool trajectories,
double range,
double extraTime,
bool useGeoCoords);
645 double computeTTC(
double gap,
double followerSpeed,
double leaderSpeed)
const;
653 static double computeDRAC(
double gap,
double followerSpeed,
double leaderSpeed);
675 static std::string
makeStringWithNAs(std::vector<double>
v,
double NA, std::string sep =
" ");
676 static std::string
makeStringWithNAs(std::vector<double> v, std::vector<double> NAs, std::string sep =
" ");
686 std::map<std::string, double>& thresholds);
733 std::pair<std::pair<double, Position>,
double>
myMaxBR;
734 std::pair<std::pair<std::pair<double, Position>,
double>, std::string>
myMinSGAP;
735 std::pair<std::pair<std::pair<double, Position>,
double>, std::string>
myMinTGAP;
double foeConflictAreaLength
bool myUseGeoCoords
Whether to use the original coordinate system for output.
static void determineConflictPoint(EncounterApproachInfo &eInfo)
Calculates the (x,y)-coordinate for the eventually predicted conflict point and stores the result in ...
std::vector< double > myBRspan
All values for brake rate.
std::pair< const MSLane *, double > egoConflictEntryCrossSection
ENCOUNTER_TYPE_MERGING_ADJACENT.
static void getVehiclesOnJunction(const MSJunction *, double egoDistToConflictLane, const MSLane *const egoConflictLane, FoeInfoMap &foeCollector)
Collects all vehicles on the junction into foeCollector.
Representation of a vehicle in the micro simulation.
void createEncounters(FoeInfoMap &foes)
Makes new encounters for all given vehicles (these should be the ones entering the device's range in ...
bool operator()(Encounter *e1, Encounter *e2)
A simple description of a position on a lane (crossing of a lane)
ConflictPointInfo maxDRAC
static void cleanup()
Clean up remaining devices instances.
EncounterType
Different types of encounters corresponding to relative positions of the vehicles. The name describes the type from the ego perspective.
PositionVector conflictPointSpan
Predicted location of the conflict: In case of MERGING and CROSSING: entry point to conflict area for...
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...
static void insertOptions(OptionsCont &oc)
Inserts MSDevice_SSM-options.
double egoConflictEntryTime
Times when the ego vehicle entered/left the conflict area. Currently only applies for crossing situat...
void determinePET(EncounterApproachInfo &eInfo) const
Discriminates between different encounter types and correspondingly determines the PET for those case...
ConflictPointInfo(double time, Position x, EncounterType type, double ssmValue)
A device which collects info on the vehicle trip (mainly on departure and arrival) ...
bool updateEncounter(Encounter *e, FoeInfo *foeInfo)
Updates the encounter (adds a new trajectory point).
void determineTTCandDRAC(EncounterApproachInfo &eInfo) const
Discriminates between different encounter types and correspondingly determines TTC and DRAC for those...
std::pair< std::pair< double, Position >, double > myMaxBR
Extremal values for the global measures (as <<<time, Position>, value>, [leaderID]>-pairs) ...
The base class for an intersection.
EncounterVector myActiveEncounters
double foeEstimatedConflictExitTime
Notification
Definition of a vehicle state.
ENCOUNTER_TYPE_FOLLOWING_PASSED.
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...
EncounterType classifyEncounter(const FoeInfo *foeInfo, EncounterApproachInfo &eInfo) const
Classifies the current type of the encounter provided some information on the opponents.
std::vector< double > myGlobalMeasuresTimeSpan
void closeEncounter(Encounter *e)
Finalizes the encounter and calculates SSM values.
static double getDetectionRange(const SUMOVehicle &v)
ENCOUNTER_TYPE_COLLISION.
static void toGeo(Position &x)
convert SUMO-positions to geo coordinates (in place)
std::vector< double > TTCspan
All values for TTC.
ENCOUNTER_TYPE_EGO_ENTERED_CONFLICT_AREA.
Position pos
Predicted location of the conflict: In case of MERGING and CROSSING: entry point to conflict area for...
double time
time point of the conflict
double foeEstimatedConflictEntryTime
void generateOutput() const
Finalizes output. Called on vehicle removal.
void resetExtraTime(double value)
resets remainingExtraTime to the given value
double egoConflictEntryDist
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.
ENCOUNTER_TYPE_CROSSING_FOLLOWER.
double egoConflictExitTime
ENCOUNTER_TYPE_BOTH_ENTERED_CONFLICT_AREA.
std::pair< const MSLane *, double > foeConflictEntryCrossSection
std::vector< double > mySGAPspan
All values for space gap.
static bool requestsTrajectories(const SUMOVehicle &v)
Encounter(const MSVehicle *_ego, const MSVehicle *const _foe, double _begin, double extraTime)
Constructor.
double egoDistToConflictLane
ENCOUNTER_TYPE_CROSSING_LEADER.
EncounterType currentType
std::vector< double > DRACspan
All values for DRAC.
ENCOUNTER_TYPE_FOLLOWING_LEADER.
double foeConflictExitTime
A road/street connecting two junctions.
ENCOUNTER_TYPE_MERGING_FOLLOWER.
std::size_t size() const
Returns the number of trajectory points stored.
static bool getMeasuresAndThresholds(const SUMOVehicle &v, std::string deviceID, std::map< std::string, double > &thresholds)
ENCOUNTER_TYPE_BOTH_LEFT_CONFLICT_AREA.
double egoConflictExitDist
std::vector< double > myTGAPspan
All values for time gap.
Representation of a vehicle.
static std::string toString(EncounterType type)
static double computeDRAC(double gap, double followerSpeed, double leaderSpeed)
Computes the DRAC (deceleration to avoid a collision) for a lead/follow situation as defined...
static const std::set< MSDevice_SSM *, ComparatorNumericalIdLess > & getInstances()
returns all currently existing SSM devices
UpstreamScanStartInfo(const MSEdge *edge, double pos, double range, double egoDistToConflictLane, const MSLane *egoConflictLane)
void processEncounters(FoeInfoMap &foes, bool forceClose=false)
Finds encounters for which the foe vehicle has disappeared from range. remainingExtraTime is decrease...
A point in 2D or 3D with translation and scaling methods.
A trajectory encloses a series of positions x and speeds v for one vehicle (the times are stored only...
bool myComputeTTC
Flags for switching on / off comutation of different SSMs, derived from myMeasures.
OutputDevice * myOutputFile
Output device.
ENCOUNTER_TYPE_FOE_LEFT_CONFLICT_AREA.
void resetEncounters()
Closes all current Encounters and moves conflicts to myPastConflicts,.
double getRemainingExtraTime() const
returns the remaining extra time
double myRange
Detection range. For vehicles closer than this distance from the ego vehicle, SSMs are traced...
std::vector< double > egoDistsToConflict
Evolution of the ego vehicle's distance to the conflict point.
static std::set< MSDevice_SSM *, ComparatorNumericalIdLess > * myInstances
All currently existing SSM devices.
const MSLane * egoConflictLane
static int issuedParameterWarnFlags
bitset storing info whether warning has already been issued about unset parameter (warn only once!) ...
ENCOUNTER_TYPE_FOLLOWING_FOLLOWER.
ENCOUNTER_TYPE_NOCONFLICT_AHEAD.
void computeSSMs(EncounterApproachInfo &e) const
Compute current values of the logged SSMs (myMeasures) for the given encounter 'e' and update 'e' acc...
double egoEstimatedConflictExitTime
bool qualifiesAsConflict(Encounter *e)
Tests if the SSM values exceed the threshold for qualification as conflict.
static void checkConflictEntryAndExit(EncounterApproachInfo &eInfo)
Checks whether ego or foe have entered or left the conflict area in the last step and eventually writ...
ENCOUNTER_TYPE_MERGING_LEADER.
std::pair< std::pair< std::pair< double, Position >, double >, std::string > myMinTGAP
ENCOUNTER_TYPE_FOE_ENTERED_CONFLICT_AREA.
void updateAndWriteOutput()
This is called once per time step in MSNet::writeOutput() and collects the surrounding vehicles...
void flushGlobalMeasures()
Write out all non-encounter specific measures as headways and braking rates.
const MSLane * findFoeConflictLane(const MSVehicle *foe, const MSLane *egoConflictLane, double &distToConflictLane) const
Computes the conflict lane for the foe.
EncounterType type
Type of the conflict.
double myOldestActiveEncounterBegin
begin time of the oldest active encounter
bool notifyLeave(SUMOTrafficObject &veh, double lastPos, MSMoveReminder::Notification reason, const MSLane *enteredLane=0)
Called whenever the holder leaves a lane.
void storeEncountersExceedingMaxLength()
Closes encounters, whose duration exceeds the maximal encounter length. If it is classified as confli...
ENCOUNTER_TYPE_FOLLOWING.
bool mySaveTrajectories
This determines whether the whole trajectories of the vehicles (position, speed, ssms) shall be saved...
static std::string getOutputFilename(const SUMOVehicle &v, std::string deviceID)
static double getExtraTime(const SUMOVehicle &v)
void flushConflicts(bool all=false)
Writes out all past conflicts that have begun earlier than the oldest active encounter.
static std::string makeStringWithNAs(std::vector< double > v, double NA, std::string sep=" ")
make a string of a double vector and treat a special value as invalid ("NA")
Compares encounters regarding to their start time.
std::vector< double > foeDistsToConflict
Evolution of the foe vehicle's distance to the conflict point.
bool closingRequested
this flag is set by updateEncounter() or directly in processEncounters(), where encounters are closed...
ENCOUNTER_TYPE_FOLLOWING_PASSED.
std::vector< Encounter * > EncounterVector
static bool useGeoCoords(const SUMOVehicle &v)
bool notifyMove(SUMOTrafficObject &veh, double oldPos, double newPos, double newSpeed)
Checks for waiting steps when the vehicle moves.
void countDownExtraTime(double amount)
decreases myRemaingExtraTime by given amount in seconds
Representation of a vehicle or person.
double foeConflictEntryTime
Times when the foe vehicle entered/left the conflict area. Currently only applies for crossing situat...
std::map< const MSVehicle *, FoeInfo * > FoeInfoMap
Trajectory egoTrajectory
Trajectory of the ego vehicle.
~MSDevice_SSM()
Destructor.
bool notifyEnter(SUMOTrafficObject &veh, MSMoveReminder::Notification reason, const MSLane *enteredLane=0)
Called whenever the holder enteres a lane.
void computeGlobalMeasures()
Stores measures, that are not associated to a specific encounter as headways and brake rates...
Structure to collect some info on the encounter needed during ssm calculation by various functions...
std::vector< double > timeSpan
time points corresponding to the trajectories
A storage for options typed value containers)
double egoDistToConflictLane
ENCOUNTER_TYPE_EGO_LEFT_CONFLICT_AREA.
Abstract in-vehicle device.
std::pair< double, double > pet
double egoEstimatedConflictEntryTime
std::map< std::string, double > myThresholds
double foeConflictExitDist
ConflictPointInfo stores some information on a specific conflict point (used to store information on ...
Encounter & operator=(const Encounter &)
Invalidated assignment operator.
std::pair< std::pair< std::pair< double, Position >, double >, std::string > myMinSGAP
Static storage of an output device and its base (abstract) implementation.
An encounter is an episode involving two vehicles, which are closer to each other than some specified...
Auxiliary structure used to handle upstream scanning start points Upstream scan has to be started aft...
double myExtraTime
Extra time in seconds to be logged after a conflict is over.
std::vector< int > typeSpan
Evolution of the encounter classification (.
double remainingExtraTime
Remaining extra time (decreases after an encounter ended)
ENCOUNTER_TYPE_ON_ADJACENT_LANES.
static void estimateConflictTimes(EncounterApproachInfo &eInfo)
Estimates the time until conflict for the vehicles based on the distance to the conflict entry points...
double foeConflictEntryDist
void writeOutConflict(Encounter *e)
static std::set< std::string > createdOutputFiles
remember which files were created already (don't duplicate xml root-elements)
Representation of a lane in the micro simulation.
EncounterQueue myPastConflicts
Past encounters that where qualified as conflicts and are not yet flushed to the output file...
double egoConflictAreaLength
double value
value of the corresponding SSM
static void getUpstreamVehicles(const UpstreamScanStartInfo &scanStart, FoeInfoMap &foeCollector, std::set< const MSJunction *> &seenJunctions)
Collects all vehicles within range 'range' upstream of the position 'pos' on the edge 'edge' into foe...
Trajectory foeTrajectory
Trajectory of the foe vehicle.
static void findSurroundingVehicles(const MSVehicle &veh, double range, FoeInfoMap &foeCollector)
Returns all vehicles, which are within the given range of the given vehicle.
static void buildVehicleDevices(SUMOVehicle &v, std::vector< MSVehicleDevice *> &into)
Build devices for the given vehicle, if needed.
std::priority_queue< Encounter *, std::vector< Encounter * >, Encounter::compare > EncounterQueue
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
const std::string deviceName() const
return the name for this type of device