Eclipse 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-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 // Something on a lane to be noticed about vehicle movement
18 /****************************************************************************/
19 
20 // ===========================================================================
21 // included modules
22 // ===========================================================================
23 #include <config.h>
24 
25 #include <string>
26 #include "MSLane.h"
27 #include "MSMoveReminder.h"
28 
29 
30 // ===========================================================================
31 // method definitions
32 // ===========================================================================
33 MSMoveReminder::MSMoveReminder(const std::string& description, MSLane* const lane, const bool doAdd) :
34  myLane(lane),
35  myDescription(description) {
36  if (myLane != nullptr && doAdd) {
37  // add reminder to lane
38  myLane->addMoveReminder(this);
39  }
40 }
41 
42 
43 void
44 MSMoveReminder::updateDetector(SUMOTrafficObject& veh, double entryPos, double leavePos,
45  SUMOTime entryTime, SUMOTime currentTime, SUMOTime leaveTime,
46  bool cleanUp) {
47  // each vehicle is tracked linearly across its segment. For each vehicle,
48  // the time and position of the previous call are maintained and only
49  // the increments are sent to notifyMoveInternal
50  if (entryTime > currentTime) {
51  return; // calibrator may insert vehicles a tiny bit into the future; ignore those
52  }
53  auto j = myLastVehicleUpdateValues.find(&veh);
54  if (j != myLastVehicleUpdateValues.end()) {
55  // the vehicle already has reported its values before; use these
56  // however, if this was called from prepareDetectorForWriting the time
57  // only has a resolution of DELTA_T and might be invalid
58  const SUMOTime previousEntryTime = j->second.first;
59  if (previousEntryTime <= currentTime) {
60  entryTime = previousEntryTime;
61  entryPos = j->second.second;
62  }
63  }
64  assert(entryTime <= currentTime);
65  if ((entryTime < leaveTime) && (entryPos <= leavePos)) {
66  const double timeOnLane = STEPS2TIME(currentTime - entryTime);
67  const double speed = (leavePos - entryPos) / STEPS2TIME(leaveTime - entryTime);
68  myLastVehicleUpdateValues[&veh] = std::pair<SUMOTime, double>(currentTime, entryPos + speed * timeOnLane);
69  assert(timeOnLane >= 0);
70  notifyMoveInternal(veh, timeOnLane, timeOnLane, speed, speed, speed * timeOnLane, speed * timeOnLane, 0.);
71  } else {
72  // it would be natrual to
73  // assert(entryTime == leaveTime);
74  // assert(entryPos == leavePos);
75  // However, in the presence of calibrators, vehicles may jump a bit
76  myLastVehicleUpdateValues[&veh] = std::pair<SUMOTime, double>(leaveTime, leavePos);
77  }
78  if (cleanUp) {
79  // clean up after the vehicle has left the area of this reminder
81  }
82 }
83 
84 
85 void
87  myLastVehicleUpdateValues.erase(&veh);
88 }
89 /****************************************************************************/
90 
SUMOTrafficObject
Representation of a vehicle or person.
Definition: SUMOTrafficObject.h:48
MSLane
Representation of a lane in the micro simulation.
Definition: MSLane.h:83
SUMOTime
long long int SUMOTime
Definition: SUMOTime.h:35
MSMoveReminder.h
MSMoveReminder::updateDetector
void updateDetector(SUMOTrafficObject &veh, double entryPos, double leavePos, SUMOTime entryTime, SUMOTime currentTime, SUMOTime leaveTime, bool cleanUp)
Definition: MSMoveReminder.cpp:44
MSLane::addMoveReminder
virtual void addMoveReminder(MSMoveReminder *rem)
Add a move-reminder to move-reminder container.
Definition: MSLane.cpp:258
STEPS2TIME
#define STEPS2TIME(x)
Definition: SUMOTime.h:57
MSMoveReminder::removeFromVehicleUpdateValues
void removeFromVehicleUpdateValues(SUMOTrafficObject &veh)
Definition: MSMoveReminder.cpp:86
MSMoveReminder::MSMoveReminder
MSMoveReminder(const std::string &description, MSLane *const lane=0, const bool doAdd=true)
Constructor.
Definition: MSMoveReminder.cpp:33
MSMoveReminder::myLastVehicleUpdateValues
std::map< SUMOTrafficObject *, std::pair< SUMOTime, double > > myLastVehicleUpdateValues
Definition: MSMoveReminder.h:243
config.h
MSLane.h
MSMoveReminder::notifyMoveInternal
virtual void notifyMoveInternal(const SUMOTrafficObject &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.
Definition: MSMoveReminder.h:206
MSMoveReminder::myLane
MSLane *const myLane
Lane on which the reminder works.
Definition: MSMoveReminder.h:238