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-2025 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
29 {"departed", NOTIFICATION_DEPARTED},
30 {"junction", NOTIFICATION_JUNCTION},
31 {"segment", NOTIFICATION_SEGMENT},
32 {"laneChange", NOTIFICATION_LANE_CHANGE},
33 {"loadState", NOTIFICATION_LOAD_STATE},
34 {"teleport", NOTIFICATION_TELEPORT},
35 {"teleportContinuation", NOTIFICATION_TELEPORT_CONTINUATION},
36 {"parking", NOTIFICATION_PARKING},
37 {"reroute", NOTIFICATION_REROUTE},
38 {"parkingReroute", NOTIFICATION_PARKING_REROUTE},
39 {"arrived", NOTIFICATION_ARRIVED},
40 {"teleportArrived", NOTIFICATION_TELEPORT_ARRIVED},
41 {"vaporizedCalibrator", NOTIFICATION_VAPORIZED_CALIBRATOR},
42 {"vaporizedCollision", NOTIFICATION_VAPORIZED_COLLISION},
43 {"vaporizedTraCI", NOTIFICATION_VAPORIZED_TRACI},
44 {"vaporizedGUI", NOTIFICATION_VAPORIZED_GUI},
45 {"vaporizer", NOTIFICATION_VAPORIZED_VAPORIZER},
46 {"vaporizedBreakdown", NOTIFICATION_VAPORIZED_BREAKDOWN},
47 {"none", NOTIFICATION_NONE}
48};
49
52
53// ===========================================================================
54// method definitions
55// ===========================================================================
56MSMoveReminder::MSMoveReminder(const std::string& description, MSLane* const lane, const bool doAdd) :
57 myLane(lane),
58 myDescription(description)
59#ifdef HAVE_FOX
60 , myNotificationMutex(true)
61#endif
62{
63 if (myLane != nullptr && doAdd) {
64 // add reminder to lane
66 }
67}
68
69
70void
71MSMoveReminder::updateDetector(SUMOTrafficObject& veh, double entryPos, double leavePos,
72 SUMOTime entryTime, SUMOTime currentTime, SUMOTime leaveTime,
73 bool cleanUp) {
74 // each vehicle is tracked linearly across its segment. For each vehicle,
75 // the time and position of the previous call are maintained and only
76 // the increments are sent to notifyMoveInternal
77 if (entryTime > currentTime) {
78 return; // calibrator may insert vehicles a tiny bit into the future; ignore those
79 }
80 auto j = myLastVehicleUpdateValues.find(veh.getNumericalID());
81 if (j != myLastVehicleUpdateValues.end()) {
82 // the vehicle already has reported its values before; use these
83 // however, if this was called from prepareDetectorForWriting the time
84 // only has a resolution of DELTA_T and might be invalid
85 const SUMOTime previousEntryTime = j->second.first;
86 if (previousEntryTime <= currentTime) {
87 entryTime = previousEntryTime;
88 entryPos = j->second.second;
89 }
90 }
91 assert(entryTime <= currentTime);
92 if ((entryTime < leaveTime) && (entryPos <= leavePos)) {
93 const double timeOnLane = STEPS2TIME(currentTime - entryTime);
94 const double speed = (leavePos - entryPos) / STEPS2TIME(leaveTime - entryTime);
95 myLastVehicleUpdateValues[veh.getNumericalID()] = std::pair<SUMOTime, double>(currentTime, entryPos + speed * timeOnLane);
96 assert(timeOnLane >= 0);
97 notifyMoveInternal(veh, timeOnLane, timeOnLane, speed, speed, speed * timeOnLane, speed * timeOnLane, 0.);
98 } else {
99 // it would be natural to
100 // assert(entryTime == leaveTime);
101 // assert(entryPos == leavePos);
102 // However, in the presence of calibrators, vehicles may jump a bit
103 myLastVehicleUpdateValues[veh.getNumericalID()] = std::pair<SUMOTime, double>(leaveTime, leavePos);
104 }
105 if (cleanUp) {
106 // clean up after the vehicle has left the area of this reminder
108 }
109}
110
111void
113 auto j = myLastVehicleUpdateValues.find(veh.getNumericalID());
114 if (j != myLastVehicleUpdateValues.end()) {
117 out.writeAttr(SUMO_ATTR_TIME, (*j).second.first);
118 out.writeAttr(SUMO_ATTR_POSITION, (*j).second.second);
119 out.closeTag();
120 }
121}
122
123
124void
125MSMoveReminder::loadReminderState(long long int numID, SUMOTime time, double pos) {
126 myLastVehicleUpdateValues[numID] = std::make_pair(time, pos);
127}
128
129
130void
134
135
136/****************************************************************************/
long long int SUMOTime
Definition GUI.h:36
#define STEPS2TIME(x)
Definition SUMOTime.h:55
@ SUMO_TAG_REMINDER
@ SUMO_ATTR_ID
@ SUMO_ATTR_POSITION
@ SUMO_ATTR_TIME
trigger: the time of the step
Representation of a lane in the micro simulation.
Definition MSLane.h:84
virtual void addMoveReminder(MSMoveReminder *rem, bool addToVehicles=true)
Add a move-reminder to move-reminder container.
Definition MSLane.cpp:362
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
const std::string & getDescription() const
void loadReminderState(long long int numID, SUMOTime time, double pos)
static StringBijection< Notification >::Entry NotificationValues[]
void saveReminderState(OutputDevice &out, const SUMOTrafficObject &veh)
Saves the current state into the given stream.
@ NOTIFICATION_NONE
must be the last one
static StringBijection< Notification > Notifications
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)
Static storage of an output device and its base (abstract) implementation.
OutputDevice & writeAttr(const SumoXMLAttr attr, const T &val)
writes a named attribute
OutputDevice & openTag(const std::string &xmlElement)
Opens an XML tag.
bool closeTag(const std::string &comment="")
Closes the most recently opened tag and optionally adds a comment.
Representation of a vehicle, person, or container.
virtual NumericalID getNumericalID() const =0
return the numerical ID which is only for internal usage
bijection entry