Eclipse SUMO - Simulation of Urban MObility
Loading...
Searching...
No Matches
MSMoveReminder.cpp
Go to the documentation of this file.
1/****************************************************************************/
2// Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo
3// Copyright (C) 2008-2024 German Aerospace Center (DLR) and others.
4// This program and the accompanying materials are made available under the
5// terms of the Eclipse Public License 2.0 which is available at
6// https://www.eclipse.org/legal/epl-2.0/
7// This Source Code may also be made available under the following Secondary
8// Licenses when the conditions for such availability set forth in the Eclipse
9// Public License 2.0 are satisfied: GNU General Public License, version 2
10// or later which is available at
11// https://www.gnu.org/licenses/old-licenses/gpl-2.0-standalone.html
12// SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-or-later
13/****************************************************************************/
20// Something on a lane to be noticed about vehicle movement
21/****************************************************************************/
22#include <config.h>
23
24#include <string>
25#include "MSLane.h"
26#include "MSMoveReminder.h"
27
28
29// ===========================================================================
30// method definitions
31// ===========================================================================
32MSMoveReminder::MSMoveReminder(const std::string& description, MSLane* const lane, const bool doAdd) :
33 myLane(lane),
34 myDescription(description)
35#ifdef HAVE_FOX
36 , myNotificationMutex(true)
37#endif
38{
39 if (myLane != nullptr && doAdd) {
40 // add reminder to lane
42 }
43}
44
45
46void
47MSMoveReminder::updateDetector(SUMOTrafficObject& veh, double entryPos, double leavePos,
48 SUMOTime entryTime, SUMOTime currentTime, SUMOTime leaveTime,
49 bool cleanUp) {
50 // each vehicle is tracked linearly across its segment. For each vehicle,
51 // the time and position of the previous call are maintained and only
52 // the increments are sent to notifyMoveInternal
53 if (entryTime > currentTime) {
54 return; // calibrator may insert vehicles a tiny bit into the future; ignore those
55 }
56 auto j = myLastVehicleUpdateValues.find(veh.getNumericalID());
57 if (j != myLastVehicleUpdateValues.end()) {
58 // the vehicle already has reported its values before; use these
59 // however, if this was called from prepareDetectorForWriting the time
60 // only has a resolution of DELTA_T and might be invalid
61 const SUMOTime previousEntryTime = j->second.first;
62 if (previousEntryTime <= currentTime) {
63 entryTime = previousEntryTime;
64 entryPos = j->second.second;
65 }
66 }
67 assert(entryTime <= currentTime);
68 if ((entryTime < leaveTime) && (entryPos <= leavePos)) {
69 const double timeOnLane = STEPS2TIME(currentTime - entryTime);
70 const double speed = (leavePos - entryPos) / STEPS2TIME(leaveTime - entryTime);
71 myLastVehicleUpdateValues[veh.getNumericalID()] = std::pair<SUMOTime, double>(currentTime, entryPos + speed * timeOnLane);
72 assert(timeOnLane >= 0);
73 notifyMoveInternal(veh, timeOnLane, timeOnLane, speed, speed, speed * timeOnLane, speed * timeOnLane, 0.);
74 } else {
75 // it would be natural to
76 // assert(entryTime == leaveTime);
77 // assert(entryPos == leavePos);
78 // However, in the presence of calibrators, vehicles may jump a bit
79 myLastVehicleUpdateValues[veh.getNumericalID()] = std::pair<SUMOTime, double>(leaveTime, leavePos);
80 }
81 if (cleanUp) {
82 // clean up after the vehicle has left the area of this reminder
84 }
85}
86
87
88void
92
93
94/****************************************************************************/
long long int SUMOTime
Definition GUI.h:36
#define STEPS2TIME(x)
Definition SUMOTime.h:55
Representation of a lane in the micro simulation.
Definition MSLane.h:84
virtual void addMoveReminder(MSMoveReminder *rem)
Add a move-reminder to move-reminder container.
Definition MSLane.cpp:352
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.
std::map< long long int, std::pair< SUMOTime, double > > myLastVehicleUpdateValues
MSMoveReminder(const std::string &description, MSLane *const lane=nullptr, const bool doAdd=true)
Constructor.
MSLane * myLane
Lane on which the reminder works.
void removeFromVehicleUpdateValues(SUMOTrafficObject &veh)
void updateDetector(SUMOTrafficObject &veh, double entryPos, double leavePos, SUMOTime entryTime, SUMOTime currentTime, SUMOTime leaveTime, bool cleanUp)
Representation of a vehicle, person, or container.
virtual NumericalID getNumericalID() const =0
return the numerical ID which is only for internal usage