Eclipse SUMO - Simulation of Urban MObility
Loading...
Searching...
No Matches
MSDriverState.h
Go to the documentation of this file.
1/****************************************************************************/
2// Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo
3// Copyright (C) 2001-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/****************************************************************************/
18// A class representing a vehicle driver's current mental state
19/****************************************************************************/
20
21
23
24
25#pragma once
26#include <config.h>
27
28#include <memory>
31
32
33// ===========================================================================
34// class definitions
35// ===========================================================================
38class OUProcess {
39public:
41 OUProcess(double initialState, double timeScale, double noiseIntensity);
43 ~OUProcess();
44
46 void step(double dt);
48 static double step(double state, double dt, double timeScale, double noiseIntensity);
49
51 void setTimeScale(double timeScale) {
52 myTimeScale = timeScale;
53 };
54
56 void setNoiseIntensity(double noiseIntensity) {
57 myNoiseIntensity = noiseIntensity;
58 };
59
61 void setState(double state) {
62 myState = state;
63 };
64
65 inline double getNoiseIntensity() const {
66 return myNoiseIntensity;
67 };
68
69 inline double getTimeScale() const {
70 return myTimeScale;
71 };
72
73
75 double getState() const;
76
77
78 static SumoRNG* getRNG() {
79 return &myRNG;
80 }
81
82private:
85 double myState;
86
90
94
96 static SumoRNG myRNG;
97};
98
99
104
105public:
108
109
112 inline double getMinAwareness() const {
113 return myMinAwareness;
114 }
115
116 inline double getInitialAwareness() const {
117 return myInitialAwareness;
118 }
119
120 inline double getErrorTimeScaleCoefficient() const {
122 }
123
127
128 inline double getErrorTimeScale() const {
129 return myError.getTimeScale();
130 }
131
132 inline double getErrorNoiseIntensity() const {
133 return myError.getNoiseIntensity();
134 }
135
139
140 inline double getHeadwayErrorCoefficient() const {
142 }
143
144 inline double getFreeSpeedErrorCoefficient() const {
146 }
147
151
155
156 inline double getAwareness() const {
157 return myAwareness;
158 }
159
160 inline double getMaximalReactionTime() const {
162 }
163
164 inline double getOriginalReactionTime() const {
166 }
167
168 inline double getActionStepLength() const {
169 return myActionStepLength;
170 }
171
172 inline double getErrorState() const {
173 return myError.getState();
174 };
176
177
180 inline void setMinAwareness(const double value) {
181 myMinAwareness = value;
182 }
183
184 inline void setInitialAwareness(const double value) {
185 myInitialAwareness = value;
186 }
187
188 inline void setErrorTimeScaleCoefficient(const double value) {
190 }
191
192 inline void setErrorNoiseIntensityCoefficient(const double value) {
194 }
195
196 inline void setSpeedDifferenceErrorCoefficient(const double value) {
198 }
199
200 inline void setHeadwayErrorCoefficient(const double value) {
202 }
203
204 inline void setFreeSpeedErrorCoefficient(const double value) {
206 }
207
211
212 inline void setHeadwayChangePerceptionThreshold(const double value) {
214 }
215
216 inline void setMaximalReactionTime(const double value) {
217 myMaximalReactionTime = value;
219 }
220
221 inline void setOriginalReactionTime(const double value) {
224 }
225
226 void setAwareness(const double value);
227
228 inline void setErrorState(const double state) {
229 myError.setState(state);
230 };
231
232 inline void setErrorTimeScale(const double value) {
233 myError.setTimeScale(value);
234 }
235
236 inline void setErrorNoiseIntensity(const double value) {
238 }
240
242 void update();
243
244
247 void updateAssumedGaps();
248
252// /// @see myAccelerationError
253// inline double getAppliedAcceleration(double desiredAccel) {
254// return desiredAccel + myError.getState();
255// };
256
258 double getPerceivedOwnSpeed(double speed);
259
264 double getPerceivedSpeedDifference(const double trueSpeedDifference, const double trueGap, const void* objID = nullptr);
266 double getPerceivedHeadway(const double trueGap, const void* objID = nullptr);
268
269 inline void lockDebug() {
270 myDebugLock = true;
271 }
272
273 inline void unlockDebug() {
274 myDebugLock = false;
275 }
276
277 inline bool debugLocked() const {
278 return myDebugLock;
279 }
280
281private:
282 // @brief Update the current step duration
283 void updateStepDuration();
284 // Update the error process
285 void updateError();
286 // Update the reaction time (actionStepLength)
287 void updateReactionTime();
288
289private:
290
293
306
316// // @brief if a perception threshold is passed for some object, a flag is set to induce a reaction to the object
317// std::map<void*, bool> myReactionFlag;
318
327
335
336
339 std::map<const void*, double> myAssumedGap;
341 std::map<const void*, double> myLastPerceivedSpeedDifference;
343
346};
347
348
349
350
351
353// * @brief An object representing a traffic item. Used for influencing
354// * the task demand of the TCI car-following model.
355// * @see MSCFModel_TCI
356// */
357//class MSDriverState {
358//
359//protected:
360// /// @brief base class for VehicleCharacteristics, TLSCharacteristics, PedestrianCharacteristics, SpeedLimitCharacteristics, Junction Characteristics...
361// /// @see TrafficItemType, @see MSCFModel_TCI
362// struct MSTrafficItemCharacteristics {
363// inline virtual ~MSTrafficItemCharacteristics() {};
364// };
365//
366// // @brief Types of traffic items, @see TrafficItem
367// enum MSTrafficItemType {
368// TRAFFIC_ITEM_VEHICLE,
369// TRAFFIC_ITEM_PEDESTRIAN,
370// TRAFFIC_ITEM_SPEED_LIMIT,
371// TRAFFIC_ITEM_JUNCTION
372// };
373//
374// /** @class MSTrafficItem
375// * @brief An object representing a traffic item. Used for influencing
376// * the task demand of the TCI car-following model.
377// * @see MSCFModel_TCI
378// */
379// struct MSTrafficItem {
380// MSTrafficItem(MSTrafficItemType type, const std::string& id, std::shared_ptr<MSTrafficItemCharacteristics> data);
381// static std::hash<std::string> hash;
382// MSTrafficItemType type;
383// size_t id_hash;
384// std::shared_ptr<MSTrafficItemCharacteristics> data;
385// double remainingIntegrationTime;
386// double integrationDemand;
387// double latentDemand;
388// };
389//
390// struct JunctionCharacteristics : MSTrafficItemCharacteristics {
391// JunctionCharacteristics(const MSJunction* junction, const MSLink* egoLink, double dist) :
392// junction(junction), approachingLink(egoLink), dist(dist) {};
393// const MSJunction* junction;
394// const MSLink* approachingLink;
395// double dist;
396// };
397//
398// struct PedestrianCharacteristics : MSTrafficItemCharacteristics {
399// PedestrianCharacteristics(const MSPerson* pedestrian, double dist) :
400// pedestrian(pedestrian), dist(dist) {};
401// const MSPerson* pedestrian;
402// double dist;
403// };
404//
405// struct SpeedLimitCharacteristics : MSTrafficItemCharacteristics {
406// SpeedLimitCharacteristics(const MSLane* lane, double dist, double limit) :
407// dist(dist), limit(limit), lane(lane) {};
408// const MSLane* lane;
409// double dist;
410// double limit;
411// };
412//
413// struct VehicleCharacteristics : MSTrafficItemCharacteristics {
414// VehicleCharacteristics(const MSVehicle* foe, double longitudinalDist, double lateralDist, double relativeSpeed) :
415// longitudinalDist(longitudinalDist), lateralDist(lateralDist), foe(foe), relativeSpeed(relativeSpeed) {};
416// const MSVehicle* foe;
417// double longitudinalDist;
418// double lateralDist;
419// double relativeSpeed;
420// };
421//
422//
423//public:
424//
425// MSDriverState(MSVehicle* veh);
426// virtual ~MSDriverState() {};
427//
428// /// @name Interfaces to inform Driver Model about traffic items, which potentially
429// /// influence the driving difficulty.
430// /// @{
431// /** @brief Informs about leader.
432// */
433// virtual void registerLeader(const MSVehicle* leader, double gap, double relativeSpeed, double latGap = -1.);
434//
435// /** @brief Informs about pedestrian.
436// */
437// virtual void registerPedestrian(const MSPerson* pedestrian, double gap);
438//
439// /** @brief Informs about upcoming speed limit reduction.
440// */
441// virtual void registerSpeedLimit(const MSLane* lane, double speedLimit, double dist);
442//
443// /** @brief Informs about upcoming junction.
444// */
445// virtual void registerJunction(MSLink* link, double dist);
446//
447// /** @brief Takes into account vehicle-specific factors for the driving demand
448// * For instance, whether vehicle drives on an opposite direction lane, absolute speed, etc.
449// */
450// virtual void registerEgoVehicleState();
451//
452// /** @brief Trigger updates for the state variables according to the traffic situation
453// * (present traffic items)
454// */
455// virtual void update();
456// /// @}
457//
458//
459// /// @name Methods to obtain the current error quantities to be used by the car-following model
460// /// @see TCIModel
461// /// @{
462// /// @see myAccelerationError
463// inline double getAppliedAcceleration(double desiredAccel) {
464// return desiredAccel + myAccelerationError.getState();
465// };
466// /// @see mySpeedPerceptionError
467// inline double getPerceivedSpeedDifference(double trueSpeedDifference) {
468// return trueSpeedDifference + mySpeedPerceptionError.getState();
469// };
470// /// @see myHeadwayPerceptionError
471// inline double getPerceivedHeadway(double trueGap) {
472// return trueGap + myHeadwayPerceptionError.getState();
473// };
474// /// @see myActionStepLength
475// inline double getActionStepLength(){
476// return myActionStepLength;
477// };
478// /// @}
479//
480//
481//private:
482//
483// /** @brief Updates the internal variables to track the time between
484// * two calls to the state update (i.e., two action points). Needed for a consistent
485// * evolution of the error processes.
486// */
487// void updateStepDuration();
488//
489// /** @brief Calculates a value for the task difficulty given the capability and the demand
490// * and stores the result in myCurrentDrivingDifficulty.
491// * @see difficultyFunction()
492// */
493// void calculateDrivingDifficulty();
494//
495//
496// /** @brief Transformation of the quotient demand/capability to obtain the actual
497// * difficulty value used to control driving performance.
498// * @note The current implementation is a continuous piecewise affine function.
499// * It has two regions with different slopes. A slight ascend, where the capability
500// * is larger than the demand and a region of steeper ascend, where the demand
501// * exceeds the capability.
502// */
503// double difficultyFunction(double demandCapabilityQuotient) const;
504//
505//
506// /** @brief Updates the myTaskCapability in dependence of the myTaskDifficulty to model a reactive
507// * level of attention. The characteristics of the process are determined by myHomeostasisDifficulty
508// * and myCapabilityTimeScale.
509// * @todo Review the implementation as simple exponential process.
510// */
511// void adaptTaskCapability();
512//
513//
514// /// @name Updater for error processes.
515// /// @{
516// void updateAccelerationError();
517// void updateSpeedPerceptionError();
518// void updateHeadwayPerceptionError();
519// void updateActionStepLength();
520// /// @}
521//
522//
523// /// @brief Updates the given error process
524// void updateErrorProcess(OUProcess& errorProcess, double timeScaleCoefficient, double noiseIntensityCoefficient) const;
525//
526// /// @brief Initialize newly appeared traffic item
527// void calculateLatentDemand(std::shared_ptr<MSTrafficItem> ti) const;
528//
529// /// @brief Calculate demand induced by the given junction
530// double calculateLatentJunctionDemand(std::shared_ptr<JunctionCharacteristics> ch) const;
531// /// @brief Calculate demand induced by the given pedestrian
532// double calculateLatentPedestrianDemand(std::shared_ptr<PedestrianCharacteristics> ch) const;
533// /// @brief Calculate demand induced by the given pedestrian
534// double calculateLatentSpeedLimitDemand(std::shared_ptr<SpeedLimitCharacteristics> ch) const;
535// /// @brief Calculate demand induced by the given vehicle
536// double calculateLatentVehicleDemand(std::shared_ptr<VehicleCharacteristics> ch) const;
537//
538// /// @brief Calculate integration demand induced by the given junction
539// double calculateJunctionIntegrationDemand(std::shared_ptr<JunctionCharacteristics> ch) const;
540// /// @brief Calculate integration demand induced by the given pedestrian
541// double calculatePedestrianIntegrationDemand(std::shared_ptr<PedestrianCharacteristics> ch) const;
542// /// @brief Calculate integration demand induced by the given pedestrian
543// double calculateSpeedLimitIntegrationDemand(std::shared_ptr<SpeedLimitCharacteristics> ch) const;
544// /// @brief Calculate integration demand induced by the given vehicle
545// double calculateVehicleIntegrationDemand(std::shared_ptr<VehicleCharacteristics> ch) const;
546//
547// /// @brief Register known traffic item to persist
548// void updateItemIntegration(std::shared_ptr<MSTrafficItem> ti) const;
549//
550// /// @brief Determine the integration demand and duration for a newly encountered traffic item (updated in place)
551// /// The integration demand takes effect during a short period after the first appearance of the item.
552// void calculateIntegrationDemandAndTime(std::shared_ptr<MSTrafficItem> ti) const;
553//
554// /// @brief Calculate the integration time for an item approached with the given speed at given dist
555// double calculateIntegrationTime(double dist, double speed) const;
556//
557// /// @brief Incorporate the item's demand into the total task demand.
558// void integrateDemand(std::shared_ptr<MSTrafficItem> ti);
559//
560// /// @brief Called whenever the vehicle is notified about a traffic item encounter.
561// void registerTrafficItem(std::shared_ptr<MSTrafficItem> ti);
562//
563//private:
564//
565// MSVehicle* myVehicle;
566//
567// /// @name Variables for tracking update instants
568// /// @see updateStepDuration()
569// /// @{
570//
571// /// @brief Elapsed time since the last state update
572// double myStepDuration;
573// /// @brief Time point of the last state update
574// double myLastUpdateTime;
575//
576// /// @}
577//
578//
579// /// @name Dynamical quantities for the driving performance
580// /// @{
581//
582// /** @brief Task capability (combines static and dynamic factors specific to the driver and the situation,
583// * total capability, attention, etc.). Follows myTaskDemand with some inertia (task-difficulty-homeostasis).
584// */
585// double myTaskCapability;
586// double myMinTaskCapability, myMaxTaskCapability;
587//
588// /** @brief Task Demand (dynamic variable representing the total demand imposed on the driver by the driving situation and environment.
589// * For instance, number, novelty and type of traffic participants in neighborhood, speed differences, road curvature,
590// * headway to leader, number of lanes, traffic density, street signs, traffic lights)
591// */
592// double myTaskDemand;
593// double myMaxTaskDemand;
594//
595// /** @brief Cached current value of the difficulty resulting from the combination of task capability and demand.
596// * @see calculateDrivingDifficulty()
597// */
598// double myCurrentDrivingDifficulty;
599// /// @brief Upper bound for myCurrentDrivingDifficulty
600// double myMaxDifficulty;
601// /** @brief Slopes for the dependence of the difficulty on the quotient of demand and capability.
602// * @see difficultyFunction();
603// */
604// double mySubCriticalDifficultyCoefficient, mySuperCriticalDifficultyCoefficient;
605//
606// /// @}
607//
608// /// @name Field that reflect the current driving situation
609// /// @{
610// /// @brief Whether vehicle is driving on an opposite direction lane
611// bool myAmOpposite;
612// double myCurrentSpeed;
613// double myCurrentAcceleration;
614// /// @}
615//
616// /// @name Parameters for the dynamic adaptation of capability (attention) and demand
617// /// @{
618//
619// /** @brief The desired value of the quotient myTaskDemand/myTaskCapability. Influences the fixed point of the
620// * process myTaskCapability -> myTaskDemand, @see adaptTaskCapability()
621// */
622// double myHomeostasisDifficulty;
623//
624// /** @brief Determines the time scale for the adaptation process of task capability towards the
625// * task difficulty.
626// */
627// double myCapabilityTimeScale;
628//
629// /** @brief Factor for the demand if driving on an opposite direction lane
630// */
631// double myOppositeDirectionDrivingDemandFactor;
632//
633// /// @}
634//
635//
636//
637// /** @brief Traffic items in the current neighborhood of the vehicle.
638// */
639// std::map<size_t, std::shared_ptr<MSTrafficItem> > myTrafficItems;
640// std::map<size_t, std::shared_ptr<MSTrafficItem> > myNewTrafficItems;
641//
642// /// @name Actuation errors
643// /// @{
644//
645// /** @brief Acceleration error. Modelled as an Ornstein-Uhlenbeck process.
646// * @see updateAccelerationError()
647// */
648// OUProcess myAccelerationError;
649// /// @brief Coefficient controlling the impact of driving difficulty on the time scale of the acceleration error process
650// double myAccelerationErrorTimeScaleCoefficient;
651// /// @brief Coefficient controlling the impact of driving difficulty on the noise intensity of the acceleration error process
652// double myAccelerationErrorNoiseIntensityCoefficient;
653//
654// /// @brief Action step length (increases with task difficulty, is similar to reaction time)
655// double myActionStepLength;
656// /// @brief Proportionality factor of myActionStepLength and driving difficulty
657// double myActionStepLengthCoefficient;
658// /// @brief Bounds for the action step length
659// double myMinActionStepLength, myMaxActionStepLength;
660//
661// /// @}
662//
663//
664// /// @name Perception errors
665// /// @{
666//
667// /** @brief Error of estimation of the relative speeds of neighboring vehicles
668// */
669// OUProcess mySpeedPerceptionError;
670// /// @brief Coefficient controlling the impact of driving difficulty on the time scale of the relative speed error process
671// double mySpeedPerceptionErrorTimeScaleCoefficient;
672// /// @brief Coefficient controlling the impact of driving difficulty on the noise intensity of the relative speed error process
673// double mySpeedPerceptionErrorNoiseIntensityCoefficient;
674//
675// /** @brief Error of estimation of the distance/headways of neighboring vehicles
676// */
677// OUProcess myHeadwayPerceptionError;
678// /// @brief Coefficient controlling the impact of driving difficulty on the time scale of the headway error process
679// double myHeadwayPerceptionErrorTimeScaleCoefficient;
680// /// @brief Coefficient controlling the impact of driving difficulty on the noise intensity of the headway error process
681// double myHeadwayPerceptionErrorNoiseIntensityCoefficient;
682//
683// /// @}
684//};
685
686
687
690// static double myMinTaskCapability;
691// static double myMaxTaskCapability;
692// static double myMaxTaskDemand;
693// static double myMaxDifficulty;
694// static double mySubCriticalDifficultyCoefficient;
695// static double mySuperCriticalDifficultyCoefficient;
696// static double myHomeostasisDifficulty;
697// static double myCapabilityTimeScale;
698// static double myAccelerationErrorTimeScaleCoefficient;
699// static double myAccelerationErrorNoiseIntensityCoefficient;
700// static double myActionStepLengthCoefficient;
701// static double myMinActionStepLength;
702// static double myMaxActionStepLength;
703// static double mySpeedPerceptionErrorTimeScaleCoefficient;
704// static double mySpeedPerceptionErrorNoiseIntensityCoefficient;
705// static double myHeadwayPerceptionErrorTimeScaleCoefficient;
706// static double myHeadwayPerceptionErrorNoiseIntensityCoefficient;
707// static double myOppositeDirectionDrivingFactor;
708
709 // for MSSimpleDriverState
710 static double minAwareness;
711 static double initialAwareness;
720};
Provides an interface to an error whose fluctuation is controlled via the driver's 'awareness',...
double getPerceivedSpeedDifference(const double trueSpeedDifference, const double trueGap, const void *objID=nullptr)
This method checks whether the errorneous speed difference that would be perceived for this step diff...
double getSpeedDifferenceChangePerceptionThreshold() const
double getErrorTimeScaleCoefficient() const
double getErrorNoiseIntensity() const
double myMinAwareness
Minimal value for 'awareness' \in [0,1].
void setErrorTimeScale(const double value)
double myHeadwayChangePerceptionThreshold
Thresholds above a change in the corresponding quantity is perceived.
double getHeadwayErrorCoefficient() const
OUProcess myError
Driver's 'error',.
double getOriginalReactionTime() const
double myActionStepLength
Action step length (~current maximal reaction time) induced by awareness level.
double getInitialAwareness() const
double myErrorNoiseIntensityCoefficient
Coefficient controlling the impact of awareness on the noise intensity of the error process.
double getPerceivedHeadway(const double trueGap, const void *objID=nullptr)
void setErrorTimeScaleCoefficient(const double value)
double myInitialAwareness
Initial value for 'awareness' \in [0,1].
void setSpeedDifferenceChangePerceptionThreshold(const double value)
double getMaximalReactionTime() const
double getErrorState() const
double myAwareness
Driver's 'awareness' \in [0,1].
double mySpeedDifferenceErrorCoefficient
Scaling coefficients for the magnitude of errors.
double getPerceivedOwnSpeed(double speed)
apply perception error to own speed
double myMaximalReactionTime
Maximal reaction time (value set for the actionStepLength at awareness=myMinAwareness)
void setMinAwareness(const double value)
double getMinAwareness() const
void setHeadwayChangePerceptionThreshold(const double value)
void setInitialAwareness(const double value)
double getErrorTimeScale() const
void setSpeedDifferenceErrorCoefficient(const double value)
std::map< const void *, double > myAssumedGap
The assumed gaps to different objects.
bool debugLocked() const
double getActionStepLength() const
void setOriginalReactionTime(const double value)
void setHeadwayErrorCoefficient(const double value)
double getErrorNoiseIntensityCoefficient() const
MSVehicle * myVehicle
Vehicle corresponding to this driver state.
double myFreeSpeedErrorCoefficient
void setMaximalReactionTime(const double value)
double getSpeedDifferenceErrorCoefficient() const
void setErrorState(const double state)
double myOriginalReactionTime
Maximal reaction time (value set for the actionStepLength at awareness=1)
void setErrorNoiseIntensityCoefficient(const double value)
void setAwareness(const double value)
void update()
Trigger updates for the errorProcess, assumed gaps, etc.
std::map< const void *, double > myLastPerceivedSpeedDifference
The last perceived speed differences to the corresponding objects.
void setErrorNoiseIntensity(const double value)
void updateAssumedGaps()
Update the assumed gaps to the known objects according to the corresponding perceived speed differenc...
double mySpeedDifferenceChangePerceptionThreshold
double getFreeSpeedErrorCoefficient() const
double getHeadwayChangePerceptionThreshold() const
virtual ~MSSimpleDriverState()
double getAwareness() const
double myErrorTimeScaleCoefficient
Coefficient controlling the impact of awareness on the time scale of the error process.
bool myDebugLock
Used to prevent infinite loops in debugging outputs,.
void setFreeSpeedErrorCoefficient(const double value)
double myLastUpdateTime
Time point of the last state update.
Representation of a vehicle in the micro simulation.
Definition MSVehicle.h:77
An Ornstein-Uhlenbeck stochastic process.
double getState() const
Obtain the current state of the process.
double getTimeScale() const
static SumoRNG myRNG
Random generator for OUProcesses.
void setTimeScale(double timeScale)
set the process' timescale to a new value
double myState
The current state of the process.
double myTimeScale
The time scale of the process.
double getNoiseIntensity() const
~OUProcess()
destructor
double myNoiseIntensity
The noise intensity of the process.
void step(double dt)
evolve for a time step of length dt.
static SumoRNG * getRNG()
void setNoiseIntensity(double noiseIntensity)
set the process' noise intensity to a new value
void setState(double state)
set the process' state to a new value
Default values for the MSDriverState parameters.
static double speedDifferenceChangePerceptionThreshold
static double headwayChangePerceptionThreshold
static double initialAwareness
static double maximalReactionTimeFactor
static double minAwareness
static double freeSpeedErrorCoefficient
static double headwayErrorCoefficient
static double errorTimeScaleCoefficient
static double errorNoiseIntensityCoefficient
static double speedDifferenceErrorCoefficient