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-2016 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 void
52  SUMOTime entryTime, SUMOTime currentTime, SUMOTime leaveTime,
53  bool cleanUp) {
54  // each vehicle is tracked linearly across its segment. For each vehicle,
55  // the time and position of the previous call are maintained and only
56  // the increments are sent to notifyMoveInternal
57  if (entryTime > currentTime) {
58  return; // calibrator may insert vehicles a tiny bit into the future; ignore those
59  }
60  std::map<SUMOVehicle*, std::pair<SUMOTime, SUMOReal> >::iterator j = myLastVehicleUpdateValues.find(&veh);
61  if (j != myLastVehicleUpdateValues.end()) {
62  // the vehicle already has reported its values before; use these
63  // however, if this was called from prepareDetectorForWriting the time
64  // only has a resolution of DELTA_T and might be invalid
65  const SUMOTime previousEntryTime = j->second.first;
66  if (previousEntryTime <= currentTime) {
67  entryTime = previousEntryTime;
68  entryPos = j->second.second;
69  }
70  }
71  assert(entryTime <= currentTime);
72  if ((entryTime < leaveTime) && (entryPos < leavePos)) {
73  const SUMOReal timeOnLane = STEPS2TIME(currentTime - entryTime);
74  const SUMOReal speed = (leavePos - entryPos) / STEPS2TIME(leaveTime - entryTime);
75  myLastVehicleUpdateValues[&veh] = std::pair<SUMOTime, SUMOReal>(currentTime, entryPos + speed * timeOnLane);
76  assert(timeOnLane >= 0);
77  assert(speed >= 0);
78  notifyMoveInternal(veh, timeOnLane, speed);
79  } else {
80  // it would be natrual to
81  // assert(entryTime == leaveTime);
82  // assert(entryPos == leavePos);
83  // However, in the presence of calibrators, vehicles may jump a bit
84  myLastVehicleUpdateValues[&veh] = std::pair<SUMOTime, SUMOReal>(leaveTime, leavePos);
85  }
86  if (cleanUp) {
87  // clean up after the vehicle has left the area of this reminder
89  }
90 }
91 
92 
93 void
95  myLastVehicleUpdateValues.erase(&veh);
96 }
97 /****************************************************************************/
98 
long long int SUMOTime
Definition: SUMOTime.h:43
void updateDetector(SUMOVehicle &veh, SUMOReal entryPos, SUMOReal leavePos, SUMOTime entryTime, SUMOTime currentTime, SUMOTime leaveTime, bool cleanUp)
MSLane *const myLane
Lane on which the reminder works.
void removeFromVehicleUpdateValues(SUMOVehicle &veh)
virtual void addMoveReminder(MSMoveReminder *rem)
Add a move-reminder to move-reminder container.
Definition: MSLane.cpp:115
MSMoveReminder(const std::string &description, MSLane *const lane=0, const bool doAdd=true)
Constructor.
Representation of a vehicle.
Definition: SUMOVehicle.h:65
std::map< SUMOVehicle *, std::pair< SUMOTime, SUMOReal > > myLastVehicleUpdateValues
#define STEPS2TIME(x)
Definition: SUMOTime.h:65
virtual void notifyMoveInternal(SUMOVehicle &veh, SUMOReal timeOnLane, SUMOReal speed)
Internal notification about the vehicle moves.
#define SUMOReal
Definition: config.h:213
Representation of a lane in the micro simulation.
Definition: MSLane.h:77