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 :
29 : // ===========================================================================
30 : // method definitions
31 : // ===========================================================================
32 13207198 : MSMoveReminder::MSMoveReminder(const std::string& description, MSLane* const lane, const bool doAdd) :
33 13207198 : myLane(lane),
34 13207198 : myDescription(description)
35 : #ifdef HAVE_FOX
36 13207198 : , myNotificationMutex(true)
37 : #endif
38 : {
39 13207198 : if (myLane != nullptr && doAdd) {
40 : // add reminder to lane
41 137190 : myLane->addMoveReminder(this);
42 : }
43 13207198 : }
44 :
45 :
46 : void
47 31327646 : MSMoveReminder::updateDetector(SUMOTrafficObject& veh, double entryPos, double leavePos,
48 : SUMOTime entryTime, SUMOTime currentTime, SUMOTime leaveTime,
49 : bool cleanUp) {
50 : // each vehicle is tracked linearly across its segment. For each vehicle,
51 : // the time and position of the previous call are maintained and only
52 : // the increments are sent to notifyMoveInternal
53 31327646 : if (entryTime > currentTime) {
54 : return; // calibrator may insert vehicles a tiny bit into the future; ignore those
55 : }
56 31322872 : auto j = myLastVehicleUpdateValues.find(veh.getNumericalID());
57 31322872 : if (j != myLastVehicleUpdateValues.end()) {
58 : // the vehicle already has reported its values before; use these
59 : // however, if this was called from prepareDetectorForWriting the time
60 : // only has a resolution of DELTA_T and might be invalid
61 19202511 : const SUMOTime previousEntryTime = j->second.first;
62 19202511 : if (previousEntryTime <= currentTime) {
63 : entryTime = previousEntryTime;
64 19202507 : entryPos = j->second.second;
65 : }
66 : }
67 : assert(entryTime <= currentTime);
68 31322872 : if ((entryTime < leaveTime) && (entryPos <= leavePos)) {
69 31322784 : const double timeOnLane = STEPS2TIME(currentTime - entryTime);
70 31322784 : const double speed = (leavePos - entryPos) / STEPS2TIME(leaveTime - entryTime);
71 31322784 : myLastVehicleUpdateValues[veh.getNumericalID()] = std::pair<SUMOTime, double>(currentTime, entryPos + speed * timeOnLane);
72 : assert(timeOnLane >= 0);
73 31322784 : notifyMoveInternal(veh, timeOnLane, timeOnLane, speed, speed, speed * timeOnLane, speed * timeOnLane, 0.);
74 : } else {
75 : // it would be natural to
76 : // assert(entryTime == leaveTime);
77 : // assert(entryPos == leavePos);
78 : // However, in the presence of calibrators, vehicles may jump a bit
79 88 : myLastVehicleUpdateValues[veh.getNumericalID()] = std::pair<SUMOTime, double>(leaveTime, leavePos);
80 : }
81 31322872 : if (cleanUp) {
82 : // clean up after the vehicle has left the area of this reminder
83 4185118 : removeFromVehicleUpdateValues(veh);
84 : }
85 : }
86 :
87 :
88 : void
89 13235822 : MSMoveReminder::removeFromVehicleUpdateValues(SUMOTrafficObject& veh) {
90 13235822 : myLastVehicleUpdateValues.erase(veh.getNumericalID());
91 13235822 : }
92 :
93 :
94 : /****************************************************************************/
|