Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
eclipse
GitHub Repository: eclipse/sumo
Path: blob/main/src/microsim/MSMoveReminder.cpp
185785 views
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
/****************************************************************************/
14
/// @file MSMoveReminder.cpp
15
/// @author Daniel Krajzewicz
16
/// @author Michael Behrisch
17
/// @author Jakob Erdmann
18
/// @date 2008-10-27
19
///
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
StringBijection<MSMoveReminder::Notification>::Entry MSMoveReminder::NotificationValues[] = {
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
50
StringBijection<MSMoveReminder::Notification> MSMoveReminder::Notifications(
51
MSMoveReminder::NotificationValues, MSMoveReminder::NOTIFICATION_NONE, false);
52
53
// ===========================================================================
54
// method definitions
55
// ===========================================================================
56
MSMoveReminder::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
65
myLane->addMoveReminder(this);
66
}
67
}
68
69
70
void
71
MSMoveReminder::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 previousUpdateTime = j->second.first;
86
if (previousUpdateTime <= currentTime) {
87
entryTime = previousUpdateTime;
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
107
removeFromVehicleUpdateValues(veh);
108
}
109
}
110
111
void
112
MSMoveReminder::saveReminderState(OutputDevice& out, const SUMOTrafficObject& veh) {
113
auto j = myLastVehicleUpdateValues.find(veh.getNumericalID());
114
if (j != myLastVehicleUpdateValues.end()) {
115
out.openTag(SUMO_TAG_REMINDER);
116
out.writeAttr(SUMO_ATTR_ID, getDescription());
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
124
void
125
MSMoveReminder::loadReminderState(long long int numID, SUMOTime time, double pos) {
126
myLastVehicleUpdateValues[numID] = std::make_pair(time, pos);
127
}
128
129
130
void
131
MSMoveReminder::removeFromVehicleUpdateValues(SUMOTrafficObject& veh) {
132
myLastVehicleUpdateValues.erase(veh.getNumericalID());
133
}
134
135
136
/****************************************************************************/
137
138