Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
eclipse
GitHub Repository: eclipse/sumo
Path: blob/main/src/microsim/MSMoveReminder.h
185785 views
1
/****************************************************************************/
2
// Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo
3
// Copyright (C) 2003-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.h
15
/// @author Christian Roessel
16
/// @author Daniel Krajzewicz
17
/// @author Sascha Krieg
18
/// @author Michael Behrisch
19
/// @author Jakob Erdmann
20
/// @date 2003-05-21
21
///
22
// Something on a lane to be noticed about vehicle movement
23
/****************************************************************************/
24
#pragma once
25
#include <config.h>
26
27
#include <iostream>
28
#include <map>
29
#include <utils/common/SUMOTime.h>
30
#include <utils/common/StdDefs.h>
31
#include <utils/common/StringBijection.h>
32
#ifdef HAVE_FOX
33
#include <utils/foxtools/fxheader.h>
34
#endif
35
36
37
// ===========================================================================
38
// class declarations
39
// ===========================================================================
40
class SUMOTrafficObject;
41
class OutputDevice;
42
class MSLane;
43
44
45
// ===========================================================================
46
// class definitions
47
// ===========================================================================
48
/**
49
* @class MSMoveReminder
50
* @brief Something on a lane to be noticed about vehicle movement
51
*
52
* Base class of all move-reminders. During move, the vehicles call
53
* notifyMove() for all reminders on their current lane (all lanes
54
* they pass during one step). If a vehicle enters the lane the reminder is
55
* positioned at during insertion or lanechange notifyEnter() is
56
* called. If a vehicle leaves the reminder lane it calls notifyLeave().
57
*
58
* The reminder knows whom to tell about move, insertion and lanechange. The
59
* vehicles will remove the reminder that is not notifyMove() from
60
* their reminder container.
61
*
62
* @see MSLane::addMoveReminder
63
* @see MSLane::getMoveReminder
64
* @note: cannot inherit from Named because it would couse double inheritance
65
*/
66
class MSMoveReminder {
67
public:
68
/** @brief Constructor.
69
*
70
* @param[in] lane Lane on which the reminder will work.
71
* @param[in] doAdd whether to add the reminder to the lane
72
*/
73
MSMoveReminder(const std::string& description, MSLane* const lane = nullptr, const bool doAdd = true);
74
75
76
/** @brief Destructor
77
*/
78
virtual ~MSMoveReminder() {}
79
80
81
/** @brief Returns the lane the reminder works on.
82
*
83
* @return The lane the reminder is anchored on.
84
*/
85
const MSLane* getLane() const {
86
return myLane;
87
}
88
89
90
/// @brief Definition of a vehicle state
91
enum Notification {
92
/// @brief The vehicle has departed (was inserted into the network)
93
NOTIFICATION_DEPARTED,
94
/// @brief The vehicle arrived at a junction
95
NOTIFICATION_JUNCTION,
96
/// @brief The vehicle changes the segment (meso only)
97
NOTIFICATION_SEGMENT,
98
/// @brief The vehicle changes lanes (micro only)
99
NOTIFICATION_LANE_CHANGE,
100
/// @brief The vehicle has been loaded from a state file
101
NOTIFICATION_LOAD_STATE,
102
/* All notifications below must result in the vehicle not being on the net
103
* (onLeaveLane sets amOnNet=false if reason>=NOTIFICATION_TELEPORT) */
104
/// @brief The vehicle is being teleported
105
NOTIFICATION_TELEPORT,
106
/// @brief The vehicle continues being teleported past an edge
107
NOTIFICATION_TELEPORT_CONTINUATION,
108
/// @brief The vehicle starts or ends parking
109
NOTIFICATION_PARKING,
110
/// @brief The vehicle changed it's route
111
NOTIFICATION_REROUTE,
112
/// @brief The vehicle needs another parking area
113
NOTIFICATION_PARKING_REROUTE,
114
/// @brief The vehicle arrived at its destination (is deleted)
115
NOTIFICATION_ARRIVED, // arrived and everything after is treated as permanent deletion from the net
116
/// @brief The vehicle was teleported out of the net
117
NOTIFICATION_TELEPORT_ARRIVED,
118
/// @brief The vehicle got removed by a calibrator
119
NOTIFICATION_VAPORIZED_CALIBRATOR,
120
/// @brief The vehicle got removed by a collision
121
NOTIFICATION_VAPORIZED_COLLISION,
122
/// @brief The vehicle got removed via TraCI
123
NOTIFICATION_VAPORIZED_TRACI,
124
/// @brief The vehicle got removed via the GUI
125
NOTIFICATION_VAPORIZED_GUI,
126
/// @brief The vehicle got vaporized with a vaporizer
127
NOTIFICATION_VAPORIZED_VAPORIZER,
128
/// @brief The vehicle got removed via stationfinder device
129
NOTIFICATION_VAPORIZED_BREAKDOWN,
130
/// @brief must be the last one
131
NOTIFICATION_NONE
132
};
133
134
135
/// @name Interface methods, to be derived by subclasses
136
/// @{
137
138
/** @brief Checks whether the reminder is activated by a vehicle entering the lane
139
*
140
* Lane change means in this case that the vehicle changes to the lane
141
* the reminder is placed at.
142
*
143
* @param[in] veh The entering vehicle.
144
* @param[in] reason how the vehicle enters the lane
145
* @return True if vehicle enters the reminder.
146
* @see Notification
147
*/
148
virtual bool notifyEnter(SUMOTrafficObject& veh, Notification reason, const MSLane* enteredLane) {
149
UNUSED_PARAMETER(reason);
150
UNUSED_PARAMETER(&veh);
151
UNUSED_PARAMETER(&enteredLane);
152
return true;
153
}
154
155
156
/** @brief Checks whether the reminder still has to be notified about the vehicle moves
157
*
158
* Indicator if the reminders is still active for the passed
159
* vehicle/parameters. If false, the vehicle will erase this reminder
160
* from its reminder-container.
161
*
162
* @param[in] veh Vehicle that asks this reminder.
163
* @param[in] oldPos Position before move.
164
* @param[in] newPos Position after move with newSpeed.
165
* @param[in] newSpeed Moving speed.
166
*
167
* @return True if vehicle hasn't passed the reminder completely.
168
*/
169
virtual bool notifyMove(SUMOTrafficObject& veh,
170
double oldPos,
171
double newPos,
172
double newSpeed) {
173
UNUSED_PARAMETER(oldPos);
174
UNUSED_PARAMETER(newPos);
175
UNUSED_PARAMETER(newSpeed);
176
UNUSED_PARAMETER(&veh);
177
return true;
178
}
179
180
/** @brief Computes idling emission values and adds them to the emission sums
181
*
182
* Idling implied by zero velocity, acceleration and slope
183
*
184
* @param[in] veh The vehicle
185
*
186
* @see MSMoveReminder::notifyMove
187
* @see PollutantsInterface
188
*/
189
virtual bool notifyIdle(SUMOTrafficObject& veh) {
190
UNUSED_PARAMETER(&veh);
191
return true;
192
}
193
194
/// @brief called to update state for parking vehicles
195
virtual void notifyParking() {}
196
197
/// @brief called to update state for stopped vehicles
198
virtual void notifyStopEnded() {}
199
200
/** @brief Called if the vehicle leaves the reminder's lane
201
*
202
* Informs if vehicle leaves reminder lane (due to lane change, removal
203
* from the network, or leaving to the next lane).
204
* The default is to do nothing.
205
*
206
* @param[in] veh The leaving vehicle.
207
* @param[in] lastPos Position on the lane when leaving.
208
* @param[in] reason how the vehicle leaves the lane
209
* @see Notification
210
*
211
* @return True if the reminder wants to receive further info.
212
*/
213
virtual bool notifyLeave(SUMOTrafficObject& veh, double lastPos, Notification reason, const MSLane* enteredLane = nullptr) {
214
UNUSED_PARAMETER(&veh);
215
UNUSED_PARAMETER(lastPos);
216
UNUSED_PARAMETER(reason);
217
UNUSED_PARAMETER(enteredLane);
218
return true;
219
}
220
221
/** @brief Called if the vehicle's back leaves the reminder's lane
222
*
223
* Informs if vehicle back leaves reminder lane (due to lane change, removal
224
* from the network, or leaving to the next lane).
225
* The default is to do nothing.
226
*
227
* @param[in] veh The leaving vehicle.
228
* @param[in] reason how the vehicle leaves the lane
229
* @param[in] leftLane The lane that the vehicle's back left
230
* @see Notification
231
*
232
* @return True if the reminder wants to receive further info.
233
*/
234
virtual bool notifyLeaveBack(SUMOTrafficObject& veh, Notification reason, const MSLane* leftLane) {
235
UNUSED_PARAMETER(&veh);
236
UNUSED_PARAMETER(reason);
237
UNUSED_PARAMETER(leftLane);
238
return true;
239
}
240
241
/** @brief Called if the vehicle change it's route
242
* @param[in] veh The rerouted vehicle.
243
* @return True if the reminder wants to receive further info.
244
*/
245
virtual bool notifyReroute(SUMOTrafficObject& veh) {
246
UNUSED_PARAMETER(&veh);
247
return true;
248
}
249
250
// TODO: Documentation
251
void updateDetector(SUMOTrafficObject& veh, double entryPos, double leavePos,
252
SUMOTime entryTime, SUMOTime currentTime, SUMOTime leaveTime,
253
bool cleanUp);
254
255
/// @}
256
257
/** @brief Internal notification about the vehicle moves.
258
* @note meso uses this though it never calls notifyMove()
259
*
260
* Indicator if the reminders is still active for the passed
261
* vehicle/parameters. If false, the vehicle will erase this reminder
262
* from its reminder-container.
263
*
264
* @param[in] veh Vehicle that asks this reminder.
265
* @param[in] frontOnLane time the front of the vehicle spent on the lane.
266
* @param[in] timeOnLane time some part of the vehicle spent on the lane.
267
* @param[in] meanSpeedFrontOnLane Average speed for the time that the front is on the lane.
268
* @param[in] meanSpeedVehicleOnLane Average speed for the time that the vehicle is on the lane (with front or back).
269
* @param[in] travelledDistanceFrontOnLane distance travelled while overlapping with the lane.
270
* @param[in] travelledDistanceVehicleOnLane distance travelled while front was on the lane.
271
* @param[in] meanLengthOnLane the average length of the vehicle's part on the lane during the last step (==complete length in meso case)
272
*/
273
virtual void notifyMoveInternal(const SUMOTrafficObject& veh,
274
const double frontOnLane,
275
const double timeOnLane,
276
const double meanSpeedFrontOnLane,
277
const double meanSpeedVehicleOnLane,
278
const double travelledDistanceFrontOnLane,
279
const double travelledDistanceVehicleOnLane,
280
const double meanLengthOnLane) {
281
UNUSED_PARAMETER(&veh);
282
UNUSED_PARAMETER(frontOnLane);
283
UNUSED_PARAMETER(timeOnLane);
284
UNUSED_PARAMETER(meanSpeedFrontOnLane);
285
UNUSED_PARAMETER(meanSpeedVehicleOnLane);
286
UNUSED_PARAMETER(travelledDistanceFrontOnLane);
287
UNUSED_PARAMETER(travelledDistanceVehicleOnLane);
288
UNUSED_PARAMETER(meanLengthOnLane);
289
}
290
291
void setDescription(const std::string& description) {
292
myDescription = description;
293
}
294
295
const std::string& getDescription() const {
296
return myDescription;
297
}
298
299
// @brief return whether this moveReminder triggers parking reroute
300
virtual bool isParkingRerouter() const {
301
return false;
302
}
303
304
/** @brief Saves the current state into the given stream */
305
void saveReminderState(OutputDevice& out, const SUMOTrafficObject& veh);
306
307
void loadReminderState(long long int numID, SUMOTime time, double pos);
308
309
static StringBijection<Notification> Notifications;
310
311
protected:
312
void removeFromVehicleUpdateValues(SUMOTrafficObject& veh);
313
314
protected:
315
316
/// @brief Lane on which the reminder works
317
MSLane* myLane;
318
/// @brief a description of this moveReminder
319
std::string myDescription;
320
321
#ifdef HAVE_FOX
322
/// @brief the mutex for notifications
323
mutable FXMutex myNotificationMutex;
324
#endif
325
326
private:
327
std::map<long long int, std::pair<SUMOTime, double> > myLastVehicleUpdateValues;
328
static StringBijection<Notification>::Entry NotificationValues[];
329
330
331
private:
332
MSMoveReminder& operator=(const MSMoveReminder&); // just to avoid a compiler warning
333
334
};
335
336