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-2026 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 {"teleportContinuationArrived", NOTIFICATION_TELEPORT_CONTINUATION_ARRIVED},
42 {"vaporizedCalibrator", NOTIFICATION_VAPORIZED_CALIBRATOR},
43 {"vaporizedCollision", NOTIFICATION_VAPORIZED_COLLISION},
44 {"vaporizedTraCI", NOTIFICATION_VAPORIZED_TRACI},
45 {"vaporizedGUI", NOTIFICATION_VAPORIZED_GUI},
46 {"vaporizer", NOTIFICATION_VAPORIZED_VAPORIZER},
47 {"vaporizedBreakdown", NOTIFICATION_VAPORIZED_BREAKDOWN},
48 {"none", NOTIFICATION_NONE}
49};
50
53
54// ===========================================================================
55// method definitions
56// ===========================================================================
57MSMoveReminder::MSMoveReminder(const std::string& description, MSLane* const lane, const bool doAdd) :
58 myLane(lane),
59 myDescription(description)
60#ifdef HAVE_FOX
61 , myNotificationMutex(true)
62#endif
63{
64 if (myLane != nullptr && doAdd) {
65 // add reminder to lane
67 }
68}
69
70
71void
72MSMoveReminder::updateDetector(SUMOTrafficObject& veh, double entryPos, double leavePos,
73 SUMOTime entryTime, SUMOTime currentTime, SUMOTime leaveTime,
74 bool cleanUp) {
75 // each vehicle is tracked linearly across its segment. For each vehicle,
76 // the time and position of the previous call are maintained and only
77 // the increments are sent to notifyMoveInternal
78 if (entryTime > currentTime) {
79 return; // calibrator may insert vehicles a tiny bit into the future; ignore those
80 }
81 auto j = myLastVehicleUpdateValues.find(veh.getNumericalID());
82 if (j != myLastVehicleUpdateValues.end()) {
83 // the vehicle already has reported its values before; use these
84 // however, if this was called from prepareDetectorForWriting the time
85 // only has a resolution of DELTA_T and might be invalid
86 const SUMOTime previousUpdateTime = j->second.first;
87 if (previousUpdateTime <= currentTime) {
88 entryTime = previousUpdateTime;
89 entryPos = j->second.second;
90 }
91 }
92 assert(entryTime <= currentTime);
93 if ((entryTime < leaveTime) && (entryPos <= leavePos)) {
94 const double timeOnLane = STEPS2TIME(currentTime - entryTime);
95 const double speed = (leavePos - entryPos) / STEPS2TIME(leaveTime - entryTime);
96 myLastVehicleUpdateValues[veh.getNumericalID()] = std::pair<SUMOTime, double>(currentTime, entryPos + speed * timeOnLane);
97 assert(timeOnLane >= 0);
98 notifyMoveInternal(veh, timeOnLane, timeOnLane, speed, speed, speed * timeOnLane, speed * timeOnLane, 0.);
99 } else {
100 // it would be natural to
101 // assert(entryTime == leaveTime);
102 // assert(entryPos == leavePos);
103 // However, in the presence of calibrators, vehicles may jump a bit
104 myLastVehicleUpdateValues[veh.getNumericalID()] = std::pair<SUMOTime, double>(leaveTime, leavePos);
105 }
106 if (cleanUp) {
107 // clean up after the vehicle has left the area of this reminder
109 }
110}
111
112void
114 auto j = myLastVehicleUpdateValues.find(veh.getNumericalID());
115 if (j != myLastVehicleUpdateValues.end()) {
118 out.writeAttr(SUMO_ATTR_TIME, (*j).second.first);
119 out.writeAttr(SUMO_ATTR_POSITION, (*j).second.second);
120 out.closeTag();
121 }
122}
123
124
125void
126MSMoveReminder::loadReminderState(long long int numID, SUMOTime time, double pos) {
127 myLastVehicleUpdateValues[numID] = std::make_pair(time, pos);
128}
129
130
131void
135
136
137/****************************************************************************/
long long int SUMOTime
Definition GUI.h:36
#define STEPS2TIME(x)
Definition SUMOTime.h:58
@ 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 & openTag(const std::string &xmlElement)
Opens an XML tag.
OutputDevice & writeAttr(const ATTR_TYPE &attr, const T &val, const bool isNull=false, const bool escape=false)
writes a named attribute
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