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