SUMO - Simulation of Urban MObility
MSMoveReminder.cpp
Go to the documentation of this file.
1 /****************************************************************************/
9 // Something on a lane to be noticed about vehicle movement
10 /****************************************************************************/
11 // SUMO, Simulation of Urban MObility; see http://sumo.dlr.de/
12 // Copyright (C) 2008-2015 DLR (http://www.dlr.de/) and contributors
13 /****************************************************************************/
14 //
15 // This file is part of SUMO.
16 // SUMO is free software: you can redistribute it and/or modify
17 // it under the terms of the GNU General Public License as published by
18 // the Free Software Foundation, either version 3 of the License, or
19 // (at your option) any later version.
20 //
21 /****************************************************************************/
22 
23 // ===========================================================================
24 // included modules
25 // ===========================================================================
26 #ifdef _MSC_VER
27 #include <windows_config.h>
28 #else
29 #include <config.h>
30 #endif
31 
32 #include <string>
33 #include "MSLane.h"
34 #include "MSMoveReminder.h"
35 
36 
37 // ===========================================================================
38 // method definitions
39 // ===========================================================================
40 MSMoveReminder::MSMoveReminder(const std::string& description, MSLane* const lane, const bool doAdd) :
41  myLane(lane),
42  myDescription(description) {
43  if (myLane != 0 && doAdd) {
44  // add reminder to lane
45  myLane->addMoveReminder(this);
46  }
47 }
48 
49 
50 #ifdef HAVE_INTERNAL
51 void
52 MSMoveReminder::updateDetector(SUMOVehicle& veh, SUMOReal entryPos, SUMOReal leavePos,
53  SUMOTime entryTime, SUMOTime currentTime, SUMOTime leaveTime,
54  bool cleanUp) {
55  // each vehicle is tracked linearly across its segment. For each vehicle,
56  // the time and position of the previous call are maintained and only
57  // the increments are sent to notifyMoveInternal
58  if (entryTime > currentTime) {
59  return; // calibrator may insert vehicles a tiny bit into the future; ignore those
60  }
61  std::map<SUMOVehicle*, std::pair<SUMOTime, SUMOReal> >::iterator j = myLastVehicleUpdateValues.find(&veh);
62  if (j != myLastVehicleUpdateValues.end()) {
63  // the vehicle already has reported its values before; use these
64  // however, if this was called from prepareDetectorForWriting the time
65  // only has a resolution of DELTA_T and might be invalid
66  const SUMOTime previousEntryTime = j->second.first;
67  if (previousEntryTime <= currentTime) {
68  entryTime = previousEntryTime;
69  entryPos = j->second.second;
70  }
71  }
72  assert(entryTime <= currentTime);
73  if ((entryTime < leaveTime) && (entryPos < leavePos)) {
74  const SUMOReal timeOnLane = STEPS2TIME(currentTime - entryTime);
75  const SUMOReal speed = (leavePos - entryPos) / STEPS2TIME(leaveTime - entryTime);
76  myLastVehicleUpdateValues[&veh] = std::pair<SUMOTime, SUMOReal>(currentTime, entryPos + speed * timeOnLane);
77  assert(timeOnLane >= 0);
78  assert(speed >= 0);
79  notifyMoveInternal(veh, timeOnLane, speed);
80  } else {
81  // it would be natrual to
82  // assert(entryTime == leaveTime);
83  // assert(entryPos == leavePos);
84  // However, in the presence of calibrators, vehicles may jump a bit
85  myLastVehicleUpdateValues[&veh] = std::pair<SUMOTime, SUMOReal>(leaveTime, leavePos);
86  }
87  if (cleanUp) {
88  // clean up after the vehicle has left the area of this reminder
89  removeFromVehicleUpdateValues(veh);
90  }
91 }
92 
93 
94 void
95 MSMoveReminder::removeFromVehicleUpdateValues(SUMOVehicle& veh) {
96  myLastVehicleUpdateValues.erase(&veh);
97 }
98 #endif
99 /****************************************************************************/
100 
MSLane *const myLane
Lane on which the reminder works.
virtual void addMoveReminder(MSMoveReminder *rem)
Add a move-reminder to move-reminder container.
Definition: MSLane.cpp:114
MSMoveReminder(const std::string &description, MSLane *const lane=0, const bool doAdd=true)
Constructor.
Representation of a vehicle.
Definition: SUMOVehicle.h:65
#define STEPS2TIME(x)
Definition: SUMOTime.h:65
virtual void notifyMoveInternal(SUMOVehicle &veh, SUMOReal timeOnLane, SUMOReal speed)
Internal notification about the vehicle moves.
int SUMOTime
Definition: SUMOTime.h:43
#define SUMOReal
Definition: config.h:218
Representation of a lane in the micro simulation.
Definition: MSLane.h:77