Line data Source code
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 : /****************************************************************************/
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 : {"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 :
49 : StringBijection<MSMoveReminder::Notification> MSMoveReminder::Notifications(
50 : MSMoveReminder::NotificationValues, MSMoveReminder::NOTIFICATION_NONE, false);
51 :
52 : // ===========================================================================
53 : // method definitions
54 : // ===========================================================================
55 13652038 : MSMoveReminder::MSMoveReminder(const std::string& description, MSLane* const lane, const bool doAdd) :
56 13652038 : myLane(lane),
57 13652038 : myDescription(description)
58 : #ifdef HAVE_FOX
59 13652038 : , myNotificationMutex(true)
60 : #endif
61 : {
62 13652038 : if (myLane != nullptr && doAdd) {
63 : // add reminder to lane
64 478686 : myLane->addMoveReminder(this);
65 : }
66 13652038 : }
67 :
68 :
69 : void
70 31329374 : MSMoveReminder::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 31329374 : if (entryTime > currentTime) {
77 : return; // calibrator may insert vehicles a tiny bit into the future; ignore those
78 : }
79 31324600 : auto j = myLastVehicleUpdateValues.find(veh.getNumericalID());
80 31324600 : 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 19202705 : const SUMOTime previousEntryTime = j->second.first;
85 19202705 : if (previousEntryTime <= currentTime) {
86 : entryTime = previousEntryTime;
87 19202701 : entryPos = j->second.second;
88 : }
89 : }
90 : assert(entryTime <= currentTime);
91 31324600 : if ((entryTime < leaveTime) && (entryPos <= leavePos)) {
92 31324512 : const double timeOnLane = STEPS2TIME(currentTime - entryTime);
93 31324512 : const double speed = (leavePos - entryPos) / STEPS2TIME(leaveTime - entryTime);
94 31324512 : myLastVehicleUpdateValues[veh.getNumericalID()] = std::pair<SUMOTime, double>(currentTime, entryPos + speed * timeOnLane);
95 : assert(timeOnLane >= 0);
96 31324512 : 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 88 : myLastVehicleUpdateValues[veh.getNumericalID()] = std::pair<SUMOTime, double>(leaveTime, leavePos);
103 : }
104 31324600 : if (cleanUp) {
105 : // clean up after the vehicle has left the area of this reminder
106 4186556 : removeFromVehicleUpdateValues(veh);
107 : }
108 : }
109 :
110 :
111 : void
112 13237940 : MSMoveReminder::removeFromVehicleUpdateValues(SUMOTrafficObject& veh) {
113 13237940 : myLastVehicleUpdateValues.erase(veh.getNumericalID());
114 13237940 : }
115 :
116 :
117 : /****************************************************************************/
|