Eclipse SUMO - Simulation of Urban MObility
MSDriverState.cpp
Go to the documentation of this file.
1 /****************************************************************************/
2 // Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.org/sumo
3 // Copyright (C) 2001-2019 German Aerospace Center (DLR) and others.
4 // This program and the accompanying materials
5 // are made available under the terms of the Eclipse Public License v2.0
6 // which accompanies this distribution, and is available at
7 // http://www.eclipse.org/legal/epl-v20.html
8 // SPDX-License-Identifier: EPL-2.0
9 /****************************************************************************/
17 // The common superclass for modelling transportable objects like persons and containers
18 /****************************************************************************/
19 
20 
21 // ===========================================================================
22 // included modules
23 // ===========================================================================
24 #include <config.h>
25 
26 #include <math.h>
27 #include <cmath>
29 #include <utils/common/SUMOTime.h>
30 //#include <microsim/MSVehicle.h>
32 //#include <microsim/MSLane.h>
33 #include <microsim/MSEdge.h>
34 //#include <microsim/MSGlobals.h>
35 //#include <microsim/MSNet.h>
38 #include "MSDriverState.h"
39 
40 // ===========================================================================
41 // DEBUG constants
42 // ===========================================================================
43 //#define DEBUG_OUPROCESS
44 //#define DEBUG_TRAFFIC_ITEMS
45 //#define DEBUG_AWARENESS
46 //#define DEBUG_PERCEPTION_ERRORS
47 //#define DEBUG_DRIVERSTATE
48 #define DEBUG_COND (true)
49 //#define DEBUG_COND (myVehicle->isSelected())
50 
51 
52 /* -------------------------------------------------------------------------
53  * static member definitions
54  * ----------------------------------------------------------------------- */
55 // hash function
56 //std::hash<std::string> MSDriverState::MSTrafficItem::hash = std::hash<std::string>();
57 std::mt19937 OUProcess::myRNG;
58 
59 // ===========================================================================
60 // Default value definitions
61 // ===========================================================================
62 //double TCIDefaults::myMinTaskCapability = 0.1;
63 //double TCIDefaults::myMaxTaskCapability = 10.0;
64 //double TCIDefaults::myMaxTaskDemand = 20.0;
65 //double TCIDefaults::myMaxDifficulty = 10.0;
66 //double TCIDefaults::mySubCriticalDifficultyCoefficient = 0.1;
67 //double TCIDefaults::mySuperCriticalDifficultyCoefficient = 1.0;
68 //double TCIDefaults::myOppositeDirectionDrivingFactor = 1.3;
69 //double TCIDefaults::myHomeostasisDifficulty = 1.5;
70 //double TCIDefaults::myCapabilityTimeScale = 0.5;
71 //double TCIDefaults::myAccelerationErrorTimeScaleCoefficient = 1.0;
72 //double TCIDefaults::myAccelerationErrorNoiseIntensityCoefficient = 1.0;
73 //double TCIDefaults::myActionStepLengthCoefficient = 1.0;
74 //double TCIDefaults::myMinActionStepLength = 0.0;
75 //double TCIDefaults::myMaxActionStepLength = 3.0;
76 //double TCIDefaults::mySpeedPerceptionErrorTimeScaleCoefficient = 1.0;
77 //double TCIDefaults::mySpeedPerceptionErrorNoiseIntensityCoefficient = 1.0;
78 //double TCIDefaults::myHeadwayPerceptionErrorTimeScaleCoefficient = 1.0;
79 //double TCIDefaults::myHeadwayPerceptionErrorNoiseIntensityCoefficient = 1.0;
80 
90 
91 
92 // ===========================================================================
93 // method definitions
94 // ===========================================================================
95 
96 OUProcess::OUProcess(double initialState, double timeScale, double noiseIntensity)
97  : myState(initialState),
98  myTimeScale(timeScale),
99  myNoiseIntensity(noiseIntensity) {}
100 
101 
103 
104 
105 void
106 OUProcess::step(double dt) {
107 #ifdef DEBUG_OUPROCESS
108  const double oldstate = myState;
109 #endif
110  myState = exp(-dt / myTimeScale) * myState + myNoiseIntensity * sqrt(2 * dt / myTimeScale) * RandHelper::randNorm(0, 1, &myRNG);
111 #ifdef DEBUG_OUPROCESS
112  std::cout << " OU-step (" << dt << " s.): " << oldstate << "->" << myState << std::endl;
113 #endif
114 }
115 
116 
117 double
119  return myState;
120 }
121 
122 
124  myVehicle(veh),
125  myAwareness(1.),
126  myMinAwareness(DriverStateDefaults::minAwareness),
127  myError(0., 1., 1.),
128  myErrorTimeScaleCoefficient(DriverStateDefaults::errorTimeScaleCoefficient),
129  myErrorNoiseIntensityCoefficient(DriverStateDefaults::errorNoiseIntensityCoefficient),
130  mySpeedDifferenceErrorCoefficient(DriverStateDefaults::speedDifferenceErrorCoefficient),
131  myHeadwayErrorCoefficient(DriverStateDefaults::headwayErrorCoefficient),
132  myHeadwayChangePerceptionThreshold(DriverStateDefaults::headwayChangePerceptionThreshold),
133  mySpeedDifferenceChangePerceptionThreshold(DriverStateDefaults::speedDifferenceChangePerceptionThreshold),
134  myOriginalReactionTime(veh->getActionStepLengthSecs()),
135  myMaximalReactionTime(DriverStateDefaults::maximalReactionTimeFactor * myOriginalReactionTime),
136 // myActionStepLength(TS),
137  myStepDuration(TS),
138  myLastUpdateTime(SIMTIME - TS),
139  myDebugLock(false) {
140 #ifdef DEBUG_DRIVERSTATE
141  std::cout << "Constructing driver state for veh '" << veh->getID() << "'." << std::endl;
142 #endif
143  updateError();
145 }
146 
147 
148 void
150 #ifdef DEBUG_AWARENESS
151  if (DEBUG_COND) {
152  std::cout << SIMTIME << " veh=" << myVehicle->getID() << ", DriverState::update()" << std::endl;
153  }
154 #endif
155  // Adapt step duration
157  // Update error
158  updateError();
159  // Update actionStepLength, aka reaction time
161  // Update assumed gaps
163 #ifdef DEBUG_AWARENESS
164  if (DEBUG_COND) {
165  std::cout << SIMTIME << " stepDuration=" << myStepDuration << ", error=" << myError.getState() << std::endl;
166  }
167 #endif
168 }
169 
170 void
173  myLastUpdateTime = SIMTIME;
174 }
175 
176 void
178  if (myAwareness == 1.0 || myAwareness == 0.0) {
179  myError.setState(0.);
180  } else {
184  }
185 }
186 
187 void
189  if (myAwareness == 1.0 || myAwareness == 0.0) {
191  } else {
192  const double theta = (myAwareness - myMinAwareness) / (1.0 - myMinAwareness);
194  // Round to multiple of simstep length
195  int quotient;
196  remquo(myActionStepLength, TS, &quotient);
197  myActionStepLength = TS * MAX2(quotient, 1);
198  }
199 }
200 
201 void
203  assert(value >= 0.);
204  assert(value <= 1.);
205 #ifdef DEBUG_AWARENESS
206  if (DEBUG_COND) {
207  std::cout << SIMTIME << " veh=" << myVehicle->getID() << ", setAwareness(" << MAX2(value, myMinAwareness) << ")" << std::endl;
208  }
209 #endif
210  myAwareness = MAX2(value, myMinAwareness);
211  if (myAwareness == 1.) {
212  myError.setState(0.);
213  }
215 }
216 
217 
218 double
219 MSSimpleDriverState::getPerceivedHeadway(const double trueGap, const void* objID) {
220 #ifdef DEBUG_PERCEPTION_ERRORS
221  if (DEBUG_COND) {
222  if (!debugLocked()) {
223  std::cout << SIMTIME << " getPerceivedHeadway() for veh '" << myVehicle->getID() << "'\n"
224  << " trueGap=" << trueGap << " objID=" << objID << std::endl;
225  }
226  }
227 #endif
228 
229  const double perceivedGap = trueGap + myHeadwayErrorCoefficient * myError.getState() * trueGap;
230  const auto assumedGap = myAssumedGap.find(objID);
231  if (assumedGap == myAssumedGap.end()
232  || fabs(perceivedGap - assumedGap->second) > myHeadwayChangePerceptionThreshold * trueGap * (1.0 - myAwareness)) {
233 
234 #ifdef DEBUG_PERCEPTION_ERRORS
235  if (!debugLocked()) {
236  std::cout << " new perceived gap (=" << perceivedGap << ") differs significantly from the assumed (="
237  << (assumedGap == myAssumedGap.end() ? "NA" : toString(assumedGap->second)) << ")" << std::endl;
238  }
239 #endif
240 
241  // new perceived gap differs significantly from the previous
242  myAssumedGap[objID] = perceivedGap;
243  return perceivedGap;
244  } else {
245 
246 #ifdef DEBUG_PERCEPTION_ERRORS
247  if (DEBUG_COND) {
248  if (!debugLocked()) {
249  std::cout << " new perceived gap (=" << perceivedGap << ") does *not* differ significantly from the assumed (="
250  << (assumedGap->second) << ")" << std::endl;
251  }
252  }
253 #endif
254  // new perceived gap doesn't differ significantly from the previous
255  return myAssumedGap[objID];
256  }
257 }
258 
259 void
261  for (auto& p : myAssumedGap) {
262  const void* objID = p.first;
263  const auto speedDiff = myLastPerceivedSpeedDifference.find(objID);
264  double assumedSpeedDiff;
265  if (speedDiff != myLastPerceivedSpeedDifference.end()) {
266  // update the assumed gap with the last perceived speed difference
267  assumedSpeedDiff = speedDiff->second;
268  } else {
269  // Assume the object is not moving, if no perceived speed difference is known.
270  assumedSpeedDiff = -myVehicle->getSpeed();
271  }
272  p.second += SPEED2DIST(assumedSpeedDiff);
273  }
274 }
275 
276 double
277 MSSimpleDriverState::getPerceivedSpeedDifference(const double trueSpeedDifference, const double trueGap, const void* objID) {
278 #ifdef DEBUG_PERCEPTION_ERRORS
279  if (DEBUG_COND) {
280  if (!debugLocked()) {
281  std::cout << SIMTIME << " getPerceivedSpeedDifference() for veh '" << myVehicle->getID() << "'\n"
282  << " trueGap=" << trueGap << " trueSpeedDifference=" << trueSpeedDifference << " objID=" << objID << std::endl;
283  }
284  }
285 #endif
286  const double perceivedSpeedDifference = trueSpeedDifference + mySpeedDifferenceErrorCoefficient * myError.getState() * trueGap;
287  const auto lastPerceivedSpeedDifference = myLastPerceivedSpeedDifference.find(objID);
288  if (lastPerceivedSpeedDifference == myLastPerceivedSpeedDifference.end()
289  || fabs(perceivedSpeedDifference - lastPerceivedSpeedDifference->second) > mySpeedDifferenceChangePerceptionThreshold * trueGap * (1.0 - myAwareness)) {
290 
291 #ifdef DEBUG_PERCEPTION_ERRORS
292  if (DEBUG_COND) {
293  if (!debugLocked()) {
294  std::cout << " new perceived speed difference (=" << perceivedSpeedDifference << ") differs significantly from the last perceived (="
295  << (lastPerceivedSpeedDifference == myLastPerceivedSpeedDifference.end() ? "NA" : toString(lastPerceivedSpeedDifference->second)) << ")"
296  << std::endl;
297  }
298  }
299 #endif
300 
301  // new perceived speed difference differs significantly from the previous
302  myLastPerceivedSpeedDifference[objID] = perceivedSpeedDifference;
303  return perceivedSpeedDifference;
304  } else {
305 #ifdef DEBUG_PERCEPTION_ERRORS
306  if (!debugLocked()) {
307  std::cout << " new perceived speed difference (=" << perceivedSpeedDifference << ") does *not* differ significantly from the last perceived (="
308  << (lastPerceivedSpeedDifference->second) << ")" << std::endl;
309  }
310 #endif
311  // new perceived speed difference doesn't differ significantly from the previous
312  return lastPerceivedSpeedDifference->second;
313  }
314 }
315 
316 
317 //MSDriverState::MSTrafficItem::MSTrafficItem(MSTrafficItemType type, const std::string& id, std::shared_ptr<MSTrafficItemCharacteristics> data) :
318 // type(type),
319 // id_hash(hash(id)),
320 // data(data),
321 // remainingIntegrationTime(0.),
322 // integrationDemand(0.),
323 // latentDemand(0.)
324 //{}
325 //
326 //MSDriverState::MSDriverState(MSVehicle* veh) :
327 // myVehicle(veh),
328 // myMinTaskCapability(TCIDefaults::myMinTaskCapability),
329 // myMaxTaskCapability(TCIDefaults::myMaxTaskCapability),
330 // myMaxTaskDemand(TCIDefaults::myMaxTaskDemand),
331 // myMaxDifficulty(TCIDefaults::myMaxDifficulty),
332 // mySubCriticalDifficultyCoefficient(TCIDefaults::mySubCriticalDifficultyCoefficient),
333 // mySuperCriticalDifficultyCoefficient(TCIDefaults::mySuperCriticalDifficultyCoefficient),
334 // myOppositeDirectionDrivingDemandFactor(TCIDefaults::myOppositeDirectionDrivingFactor),
335 // myHomeostasisDifficulty(TCIDefaults::myHomeostasisDifficulty),
336 // myCapabilityTimeScale(TCIDefaults::myCapabilityTimeScale),
337 // myAccelerationErrorTimeScaleCoefficient(TCIDefaults::myAccelerationErrorTimeScaleCoefficient),
338 // myAccelerationErrorNoiseIntensityCoefficient(TCIDefaults::myAccelerationErrorNoiseIntensityCoefficient),
339 // myActionStepLengthCoefficient(TCIDefaults::myActionStepLengthCoefficient),
340 // myMinActionStepLength(TCIDefaults::myMinActionStepLength),
341 // myMaxActionStepLength(TCIDefaults::myMaxActionStepLength),
342 // mySpeedPerceptionErrorTimeScaleCoefficient(TCIDefaults::mySpeedPerceptionErrorTimeScaleCoefficient),
343 // mySpeedPerceptionErrorNoiseIntensityCoefficient(TCIDefaults::mySpeedPerceptionErrorNoiseIntensityCoefficient),
344 // myHeadwayPerceptionErrorTimeScaleCoefficient(TCIDefaults::myHeadwayPerceptionErrorTimeScaleCoefficient),
345 // myHeadwayPerceptionErrorNoiseIntensityCoefficient(TCIDefaults::myHeadwayPerceptionErrorNoiseIntensityCoefficient),
346 // myAmOpposite(false),
347 // myAccelerationError(0., 1.,1.),
348 // myHeadwayPerceptionError(0., 1.,1.),
349 // mySpeedPerceptionError(0., 1.,1.),
350 // myTaskDemand(0.),
351 // myTaskCapability(myMaxTaskCapability),
352 // myCurrentDrivingDifficulty(myTaskDemand/myTaskCapability),
353 // myActionStepLength(TS),
354 // myStepDuration(TS),
355 // myLastUpdateTime(SIMTIME-TS),
356 // myCurrentSpeed(0.),
357 // myCurrentAcceleration(0.)
358 //{}
359 //
360 //
361 //void
362 //MSDriverState::updateStepDuration() {
363 // myStepDuration = SIMTIME - myLastUpdateTime;
364 // myLastUpdateTime = SIMTIME;
365 //}
366 //
367 //
368 //void
369 //MSDriverState::calculateDrivingDifficulty() {
370 // if (myAmOpposite) {
371 // myCurrentDrivingDifficulty = difficultyFunction(myOppositeDirectionDrivingDemandFactor*myTaskDemand/myTaskCapability);
372 // } else {
373 // myCurrentDrivingDifficulty = difficultyFunction(myTaskDemand/myTaskCapability);
374 // }
375 //}
376 //
377 //
378 //double
379 //MSDriverState::difficultyFunction(double demandCapabilityQuotient) const {
380 // double difficulty;
381 // if (demandCapabilityQuotient <= 1) {
382 // // demand does not exceed capability -> we are in the region for a slight ascend of difficulty
383 // difficulty = mySubCriticalDifficultyCoefficient*demandCapabilityQuotient;
384 // } else {
385 // // demand exceeds capability -> we are in the region for a steeper ascend of the effect of difficulty
386 // difficulty = mySubCriticalDifficultyCoefficient + (demandCapabilityQuotient - 1)*mySuperCriticalDifficultyCoefficient;
387 // }
388 // return MIN2(myMaxDifficulty, difficulty);
389 //}
390 //
391 //
392 //void
393 //MSDriverState::adaptTaskCapability() {
394 // myTaskCapability = myTaskCapability + myCapabilityTimeScale*myStepDuration*(myTaskDemand - myHomeostasisDifficulty*myTaskCapability);
395 //}
396 //
397 //
398 //void
399 //MSDriverState::updateAccelerationError() {
400 //#ifdef DEBUG_OUPROCESS
401 // if (DEBUG_COND) {
402 // std::cout << SIMTIME << " Updating acceleration error (for " << myStepDuration << " s.):\n "
403 // << myAccelerationError.getState() << " -> ";
404 // }
405 //#endif
406 //
407 // updateErrorProcess(myAccelerationError, myAccelerationErrorTimeScaleCoefficient, myAccelerationErrorNoiseIntensityCoefficient);
408 //
409 //#ifdef DEBUG_OUPROCESS
410 // if (DEBUG_COND) {
411 // std::cout << myAccelerationError.getState() << std::endl;
412 // }
413 //#endif
414 //}
415 //
416 //void
417 //MSDriverState::updateSpeedPerceptionError() {
418 //#ifdef DEBUG_OUPROCESS
419 // if (DEBUG_COND) {
420 // std::cout << SIMTIME << " Updating speed perception error (for " << myStepDuration << " s.):\n "
421 // << mySpeedPerceptionError.getState() << " -> ";
422 // }
423 //#endif
424 //
425 // updateErrorProcess(mySpeedPerceptionError, mySpeedPerceptionErrorTimeScaleCoefficient, mySpeedPerceptionErrorNoiseIntensityCoefficient);
426 //
427 //#ifdef DEBUG_OUPROCESS
428 // if (DEBUG_COND) {
429 // std::cout << mySpeedPerceptionError.getState() << std::endl;
430 // }
431 //#endif
432 //}
433 //
434 //void
435 //MSDriverState::updateHeadwayPerceptionError() {
436 //#ifdef DEBUG_OUPROCESS
437 // if (DEBUG_COND) {
438 // std::cout << SIMTIME << " Updating headway perception error (for " << myStepDuration << " s.):\n "
439 // << myHeadwayPerceptionError.getState() << " -> ";
440 // }
441 //#endif
442 //
443 // updateErrorProcess(myHeadwayPerceptionError, myHeadwayPerceptionErrorTimeScaleCoefficient, myHeadwayPerceptionErrorNoiseIntensityCoefficient);
444 //
445 //#ifdef DEBUG_OUPROCESS
446 // if (DEBUG_COND) {
447 // std::cout << myHeadwayPerceptionError.getState() << std::endl;
448 // }
449 //#endif
450 //}
451 //
452 //void
453 //MSDriverState::updateActionStepLength() {
454 //#ifdef DEBUG_OUPROCESS
455 // if (DEBUG_COND) {
456 // std::cout << SIMTIME << " Updating action step length (for " << myStepDuration << " s.): \n" << myActionStepLength;
457 // }
458 //#endif
459 // if (myActionStepLengthCoefficient*myCurrentDrivingDifficulty <= myMinActionStepLength) {
460 // myActionStepLength = myMinActionStepLength;
461 // } else {
462 // myActionStepLength = MIN2(myActionStepLengthCoefficient*myCurrentDrivingDifficulty - myMinActionStepLength, myMaxActionStepLength);
463 // }
464 //#ifdef DEBUG_OUPROCESS
465 // if (DEBUG_COND) {
466 // std::cout << " -> " << myActionStepLength << std::endl;
467 // }
468 //#endif
469 //}
470 //
471 //
472 //void
473 //MSDriverState::updateErrorProcess(OUProcess& errorProcess, double timeScaleCoefficient, double noiseIntensityCoefficient) const {
474 // if (myCurrentDrivingDifficulty == 0) {
475 // errorProcess.setState(0.);
476 // } else {
477 // errorProcess.setTimeScale(timeScaleCoefficient/myCurrentDrivingDifficulty);
478 // errorProcess.setNoiseIntensity(myCurrentDrivingDifficulty*noiseIntensityCoefficient);
479 // errorProcess.step(myStepDuration);
480 // }
481 //}
482 //
483 //void
484 //MSDriverState::registerLeader(const MSVehicle* leader, double gap, double relativeSpeed, double latGap) {
485 // std::shared_ptr<MSTrafficItemCharacteristics> tic = std::dynamic_pointer_cast<MSTrafficItemCharacteristics>(std::make_shared<VehicleCharacteristics>(leader, gap, latGap, relativeSpeed));
486 // std::shared_ptr<MSTrafficItem> ti = std::make_shared<MSTrafficItem>(TRAFFIC_ITEM_VEHICLE, leader->getID(), tic);
487 // registerTrafficItem(ti);
488 //}
489 //
490 //void
491 //MSDriverState::registerPedestrian(const MSPerson* pedestrian, double gap) {
492 // std::shared_ptr<MSTrafficItemCharacteristics> tic = std::dynamic_pointer_cast<MSTrafficItemCharacteristics>(std::make_shared<PedestrianCharacteristics>(pedestrian, gap));
493 // std::shared_ptr<MSTrafficItem> ti = std::make_shared<MSTrafficItem>(TRAFFIC_ITEM_PEDESTRIAN, pedestrian->getID(), tic);
494 // registerTrafficItem(ti);
495 //}
496 //
497 //void
498 //MSDriverState::registerSpeedLimit(const MSLane* lane, double speedLimit, double dist) {
499 // std::shared_ptr<MSTrafficItemCharacteristics> tic = std::dynamic_pointer_cast<MSTrafficItemCharacteristics>(std::make_shared<SpeedLimitCharacteristics>(lane, dist, speedLimit));
500 // std::shared_ptr<MSTrafficItem> ti = std::make_shared<MSTrafficItem>(TRAFFIC_ITEM_SPEED_LIMIT, lane->getID(), tic);
501 // registerTrafficItem(ti);
502 //}
503 //
504 //void
505 //MSDriverState::registerJunction(MSLink* link, double dist) {
506 // const MSJunction* junction = link->getJunction();
507 // std::shared_ptr<MSTrafficItemCharacteristics> tic = std::dynamic_pointer_cast<MSTrafficItemCharacteristics>(std::make_shared<JunctionCharacteristics>(junction, link, dist));
508 // std::shared_ptr<MSTrafficItem> ti = std::make_shared<MSTrafficItem>(TRAFFIC_ITEM_JUNCTION, junction->getID(), tic);
509 // registerTrafficItem(ti);
510 //}
511 //
512 //void
513 //MSDriverState::registerEgoVehicleState() {
514 // myAmOpposite = myVehicle->getLaneChangeModel().isOpposite();
515 // myCurrentSpeed = myVehicle->getSpeed();
516 // myCurrentAcceleration = myVehicle->getAcceleration();
517 //}
518 //
519 //void
520 //MSDriverState::update() {
521 // // Adapt step duration
522 // updateStepDuration();
523 //
524 // // Replace traffic items from previous step with the newly encountered.
525 // myTrafficItems = myNewTrafficItems;
526 //
527 // // Iterate through present traffic items and take into account the corresponding
528 // // task demands. Further update the item's integration progress.
529 // for (auto& hashItemPair : myTrafficItems) {
530 // // Traffic item
531 // auto ti = hashItemPair.second;
532 // // Take into account the task demand associated with the item
533 // integrateDemand(ti);
534 // // Update integration progress
535 // if (ti->remainingIntegrationTime>0) {
536 // updateItemIntegration(ti);
537 // }
538 // }
539 //
540 // // Update capability (~attention) according to the changed demand
541 // // NOTE: Doing this before recalculating the errors seems more adequate
542 // // than after adjusting the errors, since a very fast time scale
543 // // for the capability could not be captured otherwise. A slow timescale
544 // // could still be tuned to have a desired effect.
545 // adaptTaskCapability();
546 //
547 // // Update driving difficulty
548 // calculateDrivingDifficulty();
549 //
550 // // Update errors
551 // updateAccelerationError();
552 // updateSpeedPerceptionError();
553 // updateHeadwayPerceptionError();
554 // updateActionStepLength();
555 //}
556 //
557 //
558 //void
559 //MSDriverState::integrateDemand(std::shared_ptr<MSTrafficItem> ti) {
560 // myMaxTaskDemand += ti->integrationDemand;
561 // myMaxTaskDemand += ti->latentDemand;
562 //}
563 //
564 //
565 //void
566 //MSDriverState::registerTrafficItem(std::shared_ptr<MSTrafficItem> ti) {
567 // if (myNewTrafficItems.find(ti->id_hash) == myNewTrafficItems.end()) {
568 //
569 // // Update demand associated with the item
570 // auto knownTiIt = myTrafficItems.find(ti->id_hash);
571 // if (knownTiIt == myTrafficItems.end()) {
572 // // new item --> init integration demand and latent task demand
573 // calculateIntegrationDemandAndTime(ti);
574 // } else {
575 // // known item --> only update latent task demand associated with the item
576 // ti = knownTiIt->second;
577 // }
578 // calculateLatentDemand(ti);
579 //
580 // // Track item
581 // myNewTrafficItems[ti->id_hash] = ti;
582 // }
583 //}
584 //
585 //
586 //void
587 //MSDriverState::updateItemIntegration(std::shared_ptr<MSTrafficItem> ti) const {
588 // // Eventually decrease integration time and take into account integration cost.
589 // ti->remainingIntegrationTime -= myStepDuration;
590 // if (ti->remainingIntegrationTime <= 0.) {
591 // ti->remainingIntegrationTime = 0.;
592 // ti->integrationDemand = 0.;
593 // }
594 //}
595 //
596 //
597 //void
598 //MSDriverState::calculateIntegrationDemandAndTime(std::shared_ptr<MSTrafficItem> ti) const {
599 // // @todo Idea is that the integration demand is the quantitatively the same for a specific
600 // // item type with definite characteristics but it can be stretched over time,
601 // // if the integration is less urgent (item farther away), thus resulting in
602 // // smaller effort for a longer time.
603 // switch (ti->type) {
604 // case TRAFFIC_ITEM_JUNCTION: {
605 // std::shared_ptr<JunctionCharacteristics> ch = std::dynamic_pointer_cast<JunctionCharacteristics>(ti->data);
606 // const double totalIntegrationDemand = calculateJunctionIntegrationDemand(ch);
607 // const double integrationTime = calculateIntegrationTime(ch->dist, myVehicle->getSpeed());
608 // ti->integrationDemand = totalIntegrationDemand/integrationTime;
609 // ti->remainingIntegrationTime = integrationTime;
610 // }
611 // break;
612 // case TRAFFIC_ITEM_PEDESTRIAN: {
613 // std::shared_ptr<PedestrianCharacteristics> ch = std::dynamic_pointer_cast<PedestrianCharacteristics>(ti->data);
614 // const double totalIntegrationDemand = calculatePedestrianIntegrationDemand(ch);
615 // const double integrationTime = calculateIntegrationTime(ch->dist, myVehicle->getSpeed());
616 // ti->integrationDemand = totalIntegrationDemand/integrationTime;
617 // ti->remainingIntegrationTime = integrationTime;
618 // }
619 // break;
620 // case TRAFFIC_ITEM_SPEED_LIMIT: {
621 // std::shared_ptr<SpeedLimitCharacteristics> ch = std::dynamic_pointer_cast<SpeedLimitCharacteristics>(ti->data);
622 // const double totalIntegrationDemand = calculateSpeedLimitIntegrationDemand(ch);
623 // const double integrationTime = calculateIntegrationTime(ch->dist, myVehicle->getSpeed());
624 // ti->integrationDemand = totalIntegrationDemand/integrationTime;
625 // ti->remainingIntegrationTime = integrationTime;
626 // }
627 // break;
628 // case TRAFFIC_ITEM_VEHICLE: {
629 // std::shared_ptr<VehicleCharacteristics> ch = std::dynamic_pointer_cast<VehicleCharacteristics>(ti->data);
630 // ti->latentDemand = calculateLatentVehicleDemand(ch);
631 // const double totalIntegrationDemand = calculateVehicleIntegrationDemand(ch);
632 // const double integrationTime = calculateIntegrationTime(ch->longitudinalDist, ch->relativeSpeed);
633 // ti->integrationDemand = totalIntegrationDemand/integrationTime;
634 // ti->remainingIntegrationTime = integrationTime;
635 // }
636 // break;
637 // default:
638 // WRITE_WARNING("Unknown traffic item type!")
639 // break;
640 // }
641 //}
642 //
643 //
644 //double
645 //MSDriverState::calculatePedestrianIntegrationDemand(std::shared_ptr<PedestrianCharacteristics> ch) const {
646 // // Integration demand for a pedestrian
647 // const double INTEGRATION_DEMAND_PEDESTRIAN = 0.5;
648 // return INTEGRATION_DEMAND_PEDESTRIAN;
649 //}
650 //
651 //
652 //double
653 //MSDriverState::calculateSpeedLimitIntegrationDemand(std::shared_ptr<SpeedLimitCharacteristics> ch) const {
654 // // Integration demand for speed limit
655 // const double INTEGRATION_DEMAND_SPEEDLIMIT = 0.1;
656 // return INTEGRATION_DEMAND_SPEEDLIMIT;
657 //}
658 //
659 //
660 //double
661 //MSDriverState::calculateJunctionIntegrationDemand(std::shared_ptr<JunctionCharacteristics> ch) const {
662 // // Latent demand for junction is proportional to number of conflicting lanes
663 // // for the vehicle's path plus a factor for the total number of incoming lanes
664 // // at the junction. Further, the distance to the junction is inversely proportional
665 // // to the induced demand [~1/(c*dist + 1)].
666 // // Traffic lights induce an additional demand
667 // const MSJunction* j = ch->junction;
668 //
669 // // Basic junction integration demand
670 // const double INTEGRATION_DEMAND_JUNCTION_BASE = 0.3;
671 //
672 // // Surplus integration demands
673 // const double INTEGRATION_DEMAND_JUNCTION_TLS = 0.2;
674 // const double INTEGRATION_DEMAND_JUNCTION_FOE_LANE = 0.3; // per foe lane
675 // const double INTEGRATION_DEMAND_JUNCTION_LANE = 0.1; // per lane
676 // const double INTEGRATION_DEMAND_JUNCTION_RAIL = 0.2;
677 // const double INTEGRATION_DEMAND_JUNCTION_ZIPPER = 0.3;
678 //
679 // double result = INTEGRATION_DEMAND_JUNCTION_BASE;
681 // switch (ch->junction->getType()) {
682 // case NODETYPE_NOJUNCTION:
683 // case NODETYPE_UNKNOWN:
684 // case NODETYPE_DISTRICT:
685 // case NODETYPE_DEAD_END:
686 // case NODETYPE_DEAD_END_DEPRECATED:
687 // case NODETYPE_RAIL_SIGNAL: {
688 // result = 0.;
689 // }
690 // break;
691 // case NODETYPE_RAIL_CROSSING: {
692 // result += INTEGRATION_DEMAND_JUNCTION_RAIL;
693 // }
694 // break;
695 // case NODETYPE_TRAFFIC_LIGHT:
696 // case NODETYPE_TRAFFIC_LIGHT_NOJUNCTION:
697 // case NODETYPE_TRAFFIC_LIGHT_RIGHT_ON_RED: {
698 // // TODO: Take into account traffic light state?
710 // result += INTEGRATION_DEMAND_JUNCTION_TLS;
711 // }
712 // // no break. TLS has extra integration demand.
713 // case NODETYPE_PRIORITY:
714 // case NODETYPE_PRIORITY_STOP:
715 // case NODETYPE_RIGHT_BEFORE_LEFT:
716 // case NODETYPE_ALLWAY_STOP:
717 // case NODETYPE_INTERNAL: {
718 // // TODO: Consider link type (major or minor...)
719 // double junctionComplexity = (INTEGRATION_DEMAND_JUNCTION_LANE*j->getNrOfIncomingLanes()
720 // + INTEGRATION_DEMAND_JUNCTION_FOE_LANE*j->getFoeLinks(ch->approachingLink).size());
721 // result += junctionComplexity;
722 // }
723 // break;
724 // case NODETYPE_ZIPPER: {
725 // result += INTEGRATION_DEMAND_JUNCTION_ZIPPER;
726 // }
727 // break;
728 // default:
729 // assert(false);
730 // result = 0.;
731 // }
732 // return result;
733 //
734 //}
735 //
736 //
737 //double
738 //MSDriverState::calculateVehicleIntegrationDemand(std::shared_ptr<VehicleCharacteristics> ch) const {
739 // // TODO
740 // return 0.;
741 //}
742 //
743 //
744 //double
745 //MSDriverState::calculateIntegrationTime(double dist, double speed) const {
746 // // Fraction of encounter time, which is accounted for the corresponding traffic item's integration
747 // const double INTEGRATION_TIME_COEFF = 0.5;
748 // // Maximal time to be accounted for integration
749 // const double MAX_INTEGRATION_TIME = 5.;
750 // if (speed <= 0.) {
751 // return MAX_INTEGRATION_TIME;
752 // } else {
753 // return MIN2(MAX_INTEGRATION_TIME, INTEGRATION_TIME_COEFF*dist/speed);
754 // }
755 //}
756 //
757 //
758 //void
759 //MSDriverState::calculateLatentDemand(std::shared_ptr<MSTrafficItem> ti) const {
760 // switch (ti->type) {
761 // case TRAFFIC_ITEM_JUNCTION: {
762 // std::shared_ptr<JunctionCharacteristics> ch = std::dynamic_pointer_cast<JunctionCharacteristics>(ti->data);
763 // ti->latentDemand = calculateLatentJunctionDemand(ch);
764 // }
765 // break;
766 // case TRAFFIC_ITEM_PEDESTRIAN: {
767 // std::shared_ptr<PedestrianCharacteristics> ch = std::dynamic_pointer_cast<PedestrianCharacteristics>(ti->data);
768 // ti->latentDemand = calculateLatentPedestrianDemand(ch);
769 // }
770 // break;
771 // case TRAFFIC_ITEM_SPEED_LIMIT: {
772 // std::shared_ptr<SpeedLimitCharacteristics> ch = std::dynamic_pointer_cast<SpeedLimitCharacteristics>(ti->data);
773 // ti->latentDemand = calculateLatentSpeedLimitDemand(ch);
774 // }
775 // break;
776 // case TRAFFIC_ITEM_VEHICLE: {
777 // std::shared_ptr<VehicleCharacteristics> ch = std::dynamic_pointer_cast<VehicleCharacteristics>(ti->data);
778 // ti->latentDemand = calculateLatentVehicleDemand(ch);
779 // }
780 // break;
781 // default:
782 // WRITE_WARNING("Unknown traffic item type!")
783 // break;
784 // }
785 //}
786 //
787 //
788 //double
789 //MSDriverState::calculateLatentPedestrianDemand(std::shared_ptr<PedestrianCharacteristics> ch) const {
790 // // Latent demand for pedestrian is proportional to the euclidean distance to the
791 // // pedestrian (i.e. its potential to 'jump in front of the car) [~1/(c*dist + 1)]
792 // const double LATENT_DEMAND_COEFF_PEDESTRIAN_DIST = 0.1;
793 // const double LATENT_DEMAND_COEFF_PEDESTRIAN = 0.5;
794 // double result = LATENT_DEMAND_COEFF_PEDESTRIAN/(1. + LATENT_DEMAND_COEFF_PEDESTRIAN_DIST*ch->dist);
795 // return result;
796 //}
797 //
798 //
799 //double
800 //MSDriverState::calculateLatentSpeedLimitDemand(std::shared_ptr<SpeedLimitCharacteristics> ch) const {
801 // // Latent demand for speed limit is proportional to speed difference to current vehicle speed
802 // // during approach [~c*(1+deltaV) if dist<threshold].
803 // const double LATENT_DEMAND_COEFF_SPEEDLIMIT_TIME_THRESH = 5;
804 // const double LATENT_DEMAND_COEFF_SPEEDLIMIT = 0.1;
805 // double dist_thresh = LATENT_DEMAND_COEFF_SPEEDLIMIT_TIME_THRESH*myVehicle->getSpeed();
806 // double result = 0.;
807 // if (ch->dist <= dist_thresh && myVehicle->getSpeed() > ch->limit*myVehicle->getChosenSpeedFactor()) {
808 // // Upcoming speed limit does require a slowdown and is close enough.
809 // double dv = myVehicle->getSpeed() - ch->limit*myVehicle->getChosenSpeedFactor();
810 // result = LATENT_DEMAND_COEFF_SPEEDLIMIT*(1 + dv);
811 // }
812 // return result;
813 //}
814 //
815 //
816 //double
817 //MSDriverState::calculateLatentVehicleDemand(std::shared_ptr<VehicleCharacteristics> ch) const {
818 //
819 //
820 // // TODO
821 //
822 //
823 // // Latent demand for neighboring vehicle is determined from the relative and absolute speed,
824 // // and from the lateral and longitudinal distance.
825 // double result = 0.;
826 // const MSVehicle* foe = ch->foe;
827 // if (foe->getEdge() == myVehicle->getEdge()) {
828 // // on same edge
829 // } else if (foe->getEdge() == myVehicle->getEdge()->getOppositeEdge()) {
830 // // on opposite edges
831 // }
832 // return result;
833 //}
834 //
835 //
836 //
837 //double
838 //MSDriverState::calculateLatentJunctionDemand(std::shared_ptr<JunctionCharacteristics> ch) const {
839 // // Latent demand for junction is proportional to number of conflicting lanes
840 // // for the vehicle's path plus a factor for the total number of incoming lanes
841 // // at the junction. Further, the distance to the junction is inversely proportional
842 // // to the induced demand [~1/(c*dist + 1)].
843 // // Traffic lights induce an additional demand
844 // const MSJunction* j = ch->junction;
845 // const double LATENT_DEMAND_COEFF_JUNCTION_TIME_DIST_THRESH = 5; // seconds till arrival, below which junction is relevant
846 // const double LATENT_DEMAND_COEFF_JUNCTION_INCOMING = 0.1;
847 // const double LATENT_DEMAND_COEFF_JUNCTION_FOES = 0.5;
848 // const double LATENT_DEMAND_COEFF_JUNCTION_DIST = 0.1;
849 //
850 // double v = myVehicle->getSpeed();
851 // double dist_thresh = LATENT_DEMAND_COEFF_JUNCTION_TIME_DIST_THRESH*v;
852 //
853 // if (ch->dist > dist_thresh) {
854 // return 0.;
855 // }
856 // double result = 0.;
857 // LinkState linkState = ch->approachingLink->getState();
858 // switch (ch->junction->getType()) {
859 // case NODETYPE_NOJUNCTION:
860 // case NODETYPE_UNKNOWN:
861 // case NODETYPE_DISTRICT:
862 // case NODETYPE_DEAD_END:
863 // case NODETYPE_DEAD_END_DEPRECATED:
864 // case NODETYPE_RAIL_SIGNAL: {
865 // result = 0.;
866 // }
867 // break;
868 // case NODETYPE_RAIL_CROSSING: {
869 // result = 0.5;
870 // }
871 // break;
872 // case NODETYPE_TRAFFIC_LIGHT:
873 // case NODETYPE_TRAFFIC_LIGHT_NOJUNCTION:
874 // case NODETYPE_TRAFFIC_LIGHT_RIGHT_ON_RED: {
875 // // Take into account traffic light state
876 // switch (linkState) {
877 // case LINKSTATE_TL_GREEN_MAJOR:
878 // result = 0;
879 // break;
880 // case LINKSTATE_TL_GREEN_MINOR:
881 // result = 0.2*(1. + 0.1*v);
882 // break;
883 // case LINKSTATE_TL_RED:
884 // result = 0.1*(1. + 0.1*v);
885 // break;
886 // case LINKSTATE_TL_REDYELLOW:
887 // result = 0.2*(1. + 0.1*v);
888 // break;
889 // case LINKSTATE_TL_YELLOW_MAJOR:
890 // result = 0.1*(1. + 0.1*v);
891 // break;
892 // case LINKSTATE_TL_YELLOW_MINOR:
893 // result = 0.2*(1. + 0.1*v);
894 // break;
895 // case LINKSTATE_TL_OFF_BLINKING:
896 // result = 0.3*(1. + 0.1*v);
897 // break;
898 // case LINKSTATE_TL_OFF_NOSIGNAL:
899 // result = 0.2*(1. + 0.1*v);
900 // }
901 // }
902 // // no break, TLS is accounted extra
903 // case NODETYPE_PRIORITY:
904 // case NODETYPE_PRIORITY_STOP:
905 // case NODETYPE_RIGHT_BEFORE_LEFT:
906 // case NODETYPE_ALLWAY_STOP:
907 // case NODETYPE_INTERNAL: {
908 // // TODO: Consider link type (major or minor...)
909 // double junctionComplexity = (LATENT_DEMAND_COEFF_JUNCTION_INCOMING*j->getNrOfIncomingLanes()
910 // + LATENT_DEMAND_COEFF_JUNCTION_FOES*j->getFoeLinks(ch->approachingLink).size())
911 // /(1 + ch->dist*LATENT_DEMAND_COEFF_JUNCTION_DIST);
912 // result += junctionComplexity;
913 // }
914 // break;
915 // case NODETYPE_ZIPPER: {
916 // result = 0.5*(1. + 0.1*v);
917 // }
918 // break;
919 // default:
920 // assert(false);
921 // result = 0.;
922 // }
923 // return result;
924 //}
925 //
926 
927 
928 
929 
930 
931 
932 /****************************************************************************/
double myAwareness
Driver&#39;s &#39;awareness&#39; [0,1].
double getState() const
Obtain the current state of the process.
double myLastUpdateTime
Time point of the last state update.
double myMinAwareness
Minimal value for &#39;awareness&#39; [0,1].
~OUProcess()
destructor
Representation of a vehicle in the micro simulation.
Definition: MSVehicle.h:80
bool debugLocked() const
#define SPEED2DIST(x)
Definition: SUMOTime.h:47
static double headwayChangePerceptionThreshold
void setNoiseIntensity(double noiseIntensity)
set the process&#39; noise intensity to a new value
Definition: MSDriverState.h:56
#define DEBUG_COND
double myActionStepLength
Action step length (~current maximal reaction time) induced by awareness level.
double myTimeScale
The time scale of the process.
Definition: MSDriverState.h:89
T MAX2(T a, T b)
Definition: StdDefs.h:80
static double minAwareness
void setState(double state)
set the process&#39; state to a new value
Definition: MSDriverState.h:61
double myOriginalReactionTime
Maximal reaction time (value set for the actionStepLength at awareness=1)
#define TS
Definition: SUMOTime.h:44
MSSimpleDriverState(MSVehicle *veh)
void update()
Trigger updates for the errorProcess, assumed gaps, etc.
double myHeadwayErrorCoefficient
static double initialAwareness
MSVehicle * myVehicle
Vehicle corresponding to this driver state.
#define SIMTIME
Definition: SUMOTime.h:64
OUProcess(double initialState, double timeScale, double noiseIntensity)
constructor
static double headwayErrorCoefficient
static double errorTimeScaleCoefficient
double myMaximalReactionTime
Maximal reaction time (value set for the actionStepLength at awareness=myMinAwareness) ...
std::map< const void *, double > myLastPerceivedSpeedDifference
The last perceived speed differences to the corresponding objects.
static double randNorm(double mean, double variance, std::mt19937 *rng=0)
Access to a random number from a normal distribution.
Definition: RandHelper.h:140
std::string toString(const T &t, std::streamsize accuracy=gPrecision)
Definition: ToString.h:48
double myState
The current state of the process.
Definition: MSDriverState.h:85
static double speedDifferenceErrorCoefficient
void setTimeScale(double timeScale)
set the process&#39; timescale to a new value
Definition: MSDriverState.h:51
static double speedDifferenceChangePerceptionThreshold
void updateAssumedGaps()
Update the assumed gaps to the known objects according to the corresponding perceived speed differenc...
static std::mt19937 myRNG
Random generator for OUProcesses.
Definition: MSDriverState.h:96
double myErrorNoiseIntensityCoefficient
Coefficient controlling the impact of awareness on the noise intensity of the error process...
std::map< const void *, double > myAssumedGap
The assumed gaps to different objects.
double myNoiseIntensity
The noise intensity of the process.
Definition: MSDriverState.h:93
Informs about leader.
double getPerceivedHeadway(const double trueGap, const void *objID=nullptr)
double mySpeedDifferenceErrorCoefficient
Scaling coefficients for the magnitude of errors.
double myErrorTimeScaleCoefficient
Coefficient controlling the impact of awareness on the time scale of the error process.
void setAwareness(const double value)
double mySpeedDifferenceChangePerceptionThreshold
OUProcess myError
Driver&#39;s &#39;error&#39;,.
void step(double dt)
evolve for a time step of length dt.
static double maximalReactionTimeFactor
double myHeadwayChangePerceptionThreshold
Thresholds above a change in the corresponding quantity is perceived.
static double errorNoiseIntensityCoefficient
double getSpeed() const
Returns the vehicle&#39;s current speed.
Definition: MSVehicle.h:477
const std::string & getID() const
Returns the name of the vehicle.
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...