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
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 {"parkingReroute", NOTIFICATION_PARKING_REROUTE},
38 {"arrived", NOTIFICATION_ARRIVED},
39 {"teleportArrived", NOTIFICATION_TELEPORT_ARRIVED},
40 {"vaporizedCalibrator", NOTIFICATION_VAPORIZED_CALIBRATOR},
41 {"vaporizedCollision", NOTIFICATION_VAPORIZED_COLLISION},
42 {"vaporizedTraCI", NOTIFICATION_VAPORIZED_TRACI},
43 {"vaporizedGUI", NOTIFICATION_VAPORIZED_GUI},
44 {"vaporizer", NOTIFICATION_VAPORIZED_VAPORIZER},
45 {"vaporizedBreakdown", NOTIFICATION_VAPORIZED_BREAKDOWN},
46 {"none", NOTIFICATION_NONE}
47};
48
51
52// ===========================================================================
53// method definitions
54// ===========================================================================
55MSMoveReminder::MSMoveReminder(const std::string& description, MSLane* const lane, const bool doAdd) :
56 myLane(lane),
57 myDescription(description)
58#ifdef HAVE_FOX
59 , myNotificationMutex(true)
60#endif
61{
62 if (myLane != nullptr && doAdd) {
63 // add reminder to lane
65 }
66}
67
68
69void
70MSMoveReminder::updateDetector(SUMOTrafficObject& veh, double entryPos, double leavePos,
71 SUMOTime entryTime, SUMOTime currentTime, SUMOTime leaveTime,
72 bool cleanUp) {
73 // each vehicle is tracked linearly across its segment. For each vehicle,
74 // the time and position of the previous call are maintained and only
75 // the increments are sent to notifyMoveInternal
76 if (entryTime > currentTime) {
77 return; // calibrator may insert vehicles a tiny bit into the future; ignore those
78 }
79 auto j = myLastVehicleUpdateValues.find(veh.getNumericalID());
80 if (j != myLastVehicleUpdateValues.end()) {
81 // the vehicle already has reported its values before; use these
82 // however, if this was called from prepareDetectorForWriting the time
83 // only has a resolution of DELTA_T and might be invalid
84 const SUMOTime previousEntryTime = j->second.first;
85 if (previousEntryTime <= currentTime) {
86 entryTime = previousEntryTime;
87 entryPos = j->second.second;
88 }
89 }
90 assert(entryTime <= currentTime);
91 if ((entryTime < leaveTime) && (entryPos <= leavePos)) {
92 const double timeOnLane = STEPS2TIME(currentTime - entryTime);
93 const double speed = (leavePos - entryPos) / STEPS2TIME(leaveTime - entryTime);
94 myLastVehicleUpdateValues[veh.getNumericalID()] = std::pair<SUMOTime, double>(currentTime, entryPos + speed * timeOnLane);
95 assert(timeOnLane >= 0);
96 notifyMoveInternal(veh, timeOnLane, timeOnLane, speed, speed, speed * timeOnLane, speed * timeOnLane, 0.);
97 } else {
98 // it would be natural to
99 // assert(entryTime == leaveTime);
100 // assert(entryPos == leavePos);
101 // However, in the presence of calibrators, vehicles may jump a bit
102 myLastVehicleUpdateValues[veh.getNumericalID()] = std::pair<SUMOTime, double>(leaveTime, leavePos);
103 }
104 if (cleanUp) {
105 // clean up after the vehicle has left the area of this reminder
107 }
108}
109
110
111void
115
116
117/****************************************************************************/
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
static StringBijection< Notification >::Entry NotificationValues[]
@ 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)
Representation of a vehicle, person, or container.
virtual NumericalID getNumericalID() const =0
return the numerical ID which is only for internal usage