SUMO - Simulation of Urban MObility
MSMoveReminder.cpp
Go to the documentation of this file.
1 /****************************************************************************/
2 // Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.org/sumo
3 // Copyright (C) 2008-2017 German Aerospace Center (DLR) and others.
4 /****************************************************************************/
5 //
6 // This program and the accompanying materials
7 // are made available under the terms of the Eclipse Public License v2.0
8 // which accompanies this distribution, and is available at
9 // http://www.eclipse.org/legal/epl-v20.html
10 //
11 /****************************************************************************/
19 // Something on a lane to be noticed about vehicle movement
20 /****************************************************************************/
21 
22 // ===========================================================================
23 // included modules
24 // ===========================================================================
25 #ifdef _MSC_VER
26 #include <windows_config.h>
27 #else
28 #include <config.h>
29 #endif
30 
31 #include <string>
32 #include "MSLane.h"
33 #include "MSMoveReminder.h"
34 
35 
36 // ===========================================================================
37 // method definitions
38 // ===========================================================================
39 MSMoveReminder::MSMoveReminder(const std::string& description, MSLane* const lane, const bool doAdd) :
40  myLane(lane),
41  myDescription(description) {
42  if (myLane != 0 && doAdd) {
43  // add reminder to lane
44  myLane->addMoveReminder(this);
45  }
46 }
47 
48 
49 void
50 MSMoveReminder::updateDetector(SUMOVehicle& veh, double entryPos, double leavePos,
51  SUMOTime entryTime, SUMOTime currentTime, SUMOTime leaveTime,
52  bool cleanUp) {
53  // each vehicle is tracked linearly across its segment. For each vehicle,
54  // the time and position of the previous call are maintained and only
55  // the increments are sent to notifyMoveInternal
56  if (entryTime > currentTime) {
57  return; // calibrator may insert vehicles a tiny bit into the future; ignore those
58  }
59  std::map<SUMOVehicle*, std::pair<SUMOTime, double> >::iterator j = myLastVehicleUpdateValues.find(&veh);
60  if (j != myLastVehicleUpdateValues.end()) {
61  // the vehicle already has reported its values before; use these
62  // however, if this was called from prepareDetectorForWriting the time
63  // only has a resolution of DELTA_T and might be invalid
64  const SUMOTime previousEntryTime = j->second.first;
65  if (previousEntryTime <= currentTime) {
66  entryTime = previousEntryTime;
67  entryPos = j->second.second;
68  }
69  }
70  assert(entryTime <= currentTime);
71  if ((entryTime < leaveTime) && (entryPos < leavePos)) {
72  const double timeOnLane = STEPS2TIME(currentTime - entryTime);
73  const double speed = (leavePos - entryPos) / STEPS2TIME(leaveTime - entryTime);
74  myLastVehicleUpdateValues[&veh] = std::pair<SUMOTime, double>(currentTime, entryPos + speed * timeOnLane);
75  assert(timeOnLane >= 0);
76  assert(speed >= 0);
77  notifyMoveInternal(veh, timeOnLane, timeOnLane, speed, speed, speed * timeOnLane, speed * timeOnLane, 0.);
78  } else {
79  // it would be natrual to
80  // assert(entryTime == leaveTime);
81  // assert(entryPos == leavePos);
82  // However, in the presence of calibrators, vehicles may jump a bit
83  myLastVehicleUpdateValues[&veh] = std::pair<SUMOTime, double>(leaveTime, leavePos);
84  }
85  if (cleanUp) {
86  // clean up after the vehicle has left the area of this reminder
88  }
89 }
90 
91 
92 void
94  myLastVehicleUpdateValues.erase(&veh);
95 }
96 /****************************************************************************/
97 
void updateDetector(SUMOVehicle &veh, double entryPos, double 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:219
MSMoveReminder(const std::string &description, MSLane *const lane=0, const bool doAdd=true)
Constructor.
virtual void notifyMoveInternal(const SUMOVehicle &veh, const double frontOnLane, const double timeOnLane, const double meanSpeedFrontOnLane, const double meanSpeedVehicleOnLane, const double travelledDistanceFrontOnLane, const double travelledDistanceVehicleOnLane, const double meanLengthOnLane)
Internal notification about the vehicle moves.
Representation of a vehicle.
Definition: SUMOVehicle.h:66
#define STEPS2TIME(x)
Definition: SUMOTime.h:64
std::map< SUMOVehicle *, std::pair< SUMOTime, double > > myLastVehicleUpdateValues
long long int SUMOTime
Definition: TraCIDefs.h:51
Representation of a lane in the micro simulation.
Definition: MSLane.h:77