Line data Source code
1 : /****************************************************************************/
2 : // Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo
3 : // Copyright (C) 2011-2026 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 MSInstantInductLoop.h
15 : /// @author Daniel Krajzewicz
16 : /// @author Michael Behrisch
17 : /// @date 2011-09.08
18 : ///
19 : // An instantaneous induction loop
20 : /****************************************************************************/
21 : #pragma once
22 : #include <config.h>
23 :
24 : #include <string>
25 : #include <deque>
26 : #include <map>
27 : #include <functional>
28 : #include <microsim/MSMoveReminder.h>
29 : #include <microsim/output/MSDetectorFileOutput.h>
30 :
31 :
32 : // ===========================================================================
33 : // class declarations
34 : // ===========================================================================
35 : class MSLane;
36 : class MSVehicle;
37 : class OutputDevice;
38 : class SUMOTrafficObject;
39 :
40 :
41 : // ===========================================================================
42 : // class definitions
43 : // ===========================================================================
44 : /**
45 : * @class MSInstantInductLoop
46 : * @brief An instantaneous induction loop
47 : *
48 : * @see MSMoveReminder
49 : * @see MSDetectorFileOutput
50 : */
51 : class MSInstantInductLoop
52 : : public MSMoveReminder, public MSDetectorFileOutput {
53 : public:
54 : /**
55 : * @brief Constructor.
56 : *
57 : * @param[in] id Unique id
58 : * @param[in] od The device to write to
59 : * @param[in] lane Lane where detector woks on.
60 : * @param[in] position Position of the detector within the lane.
61 : */
62 : MSInstantInductLoop(const std::string& id, OutputDevice& od,
63 : MSLane* const lane, double positionInMeters,
64 : const std::string name, const std::string& vTypes,
65 : const std::string& nextEdges,
66 : int detectPersons);
67 :
68 :
69 : /// @brief Destructor
70 : ~MSInstantInductLoop();
71 :
72 :
73 :
74 : /// @name Methods inherited from MSMoveReminder
75 : /// @{
76 :
77 : /// @name Methods inherited from MSMoveReminder
78 : /// @{
79 : /** @brief Checks whether the reminder is activated by a vehicle entering the lane
80 : *
81 : * Lane change means in this case that the vehicle changes to the lane
82 : * the reminder is placed at.
83 : *
84 : * @param[in] veh The entering vehicle.
85 : * @param[in] reason how the vehicle enters the lane
86 : * @return True if vehicle enters the induction loop
87 : * @see Notification
88 : */
89 : bool notifyEnter(SUMOTrafficObject& veh, Notification reason, const MSLane* enteredLane = 0);
90 :
91 : /** @brief Checks whether the vehicle shall be counted and/or shall still touch this MSMoveReminder
92 : *
93 : * As soon a vehicle enters the detector, its entry time is computed and stored
94 : * in myVehiclesOnDet via enterDetectorByMove. If it passes the detector, the
95 : * according leaving time is computed and stored, too, using leaveDetectorByMove.
96 : *
97 : * @param[in] veh Vehicle that asks this remider.
98 : * @param[in] oldPos Position before move.
99 : * @param[in] newPos Position after move with newSpeed.
100 : * @param[in] newSpeed Moving speed.
101 : * @return True if vehicle hasn't passed the detector completely.
102 : * @see MSMoveReminder
103 : * @see MSMoveReminder::notifyMove
104 : * @see enterDetectorByMove
105 : * @see leaveDetectorByMove
106 : */
107 : bool notifyMove(SUMOTrafficObject& veh, double oldPos, double newPos, double newSpeed);
108 :
109 :
110 : /** @brief Dismisses the vehicle if it is on the detector due to a lane change
111 : *
112 : * If the vehicle is on the detector, it will be dismissed by incrementing
113 : * myDismissedVehicleNumber and removing this vehicle's entering time from
114 : * myVehiclesOnDet.
115 : *
116 : * @param[in] veh The leaving vehicle.
117 : * @param[in] lastPos Position on the lane when leaving.
118 : * @param[in] isArrival whether the vehicle arrived at its destination
119 : * @param[in] isLaneChange whether the vehicle changed from the lane
120 : * @see MSMoveReminder
121 : * @see MSMoveReminder::notifyLeave
122 : */
123 : bool notifyLeave(SUMOTrafficObject& veh, double lastPos, MSMoveReminder::Notification reason, const MSLane* enteredLane = 0);
124 : //@}
125 :
126 :
127 :
128 : /** @brief Write the generated output to the given device
129 : *
130 : * This method is not used - output is written as soon as a vehicle visits the detector.
131 : *
132 : * @param[in] dev The output device to write the data into
133 : * @param[in] startTime First time step the data were gathered
134 : * @param[in] stopTime Last time step the data were gathered
135 : * @exception IOError If an error on writing occurs
136 : */
137 0 : void writeXMLOutput(OutputDevice& dev,
138 : SUMOTime startTime, SUMOTime stopTime) {
139 : UNUSED_PARAMETER(dev);
140 : UNUSED_PARAMETER(startTime);
141 : UNUSED_PARAMETER(stopTime);
142 0 : }
143 :
144 :
145 : /** @brief Open the XML-output
146 : *
147 : * The implementing function should open an xml element using
148 : * OutputDevice::writeXMLHeader.
149 : *
150 : * @param[in] dev The output device to write the root into
151 : * @exception IOError If an error on writing occurs
152 : */
153 : void writeXMLDetectorProlog(OutputDevice& dev) const;
154 :
155 :
156 : protected:
157 : /** @brief Writes an event line
158 : * @param[in] state The current state to report
159 : * @param[in] t The event time
160 : * @param[in] veh The vehicle responsible for the event
161 : * @param[in] speed The speed of the vehicle
162 : * @param[in] add An optional attribute to report
163 : * @param[in] addValue The value of the optional attribute
164 : */
165 : void write(const char* state, double t, SUMOTrafficObject& veh, double speed, const char* add = 0, double addValue = -1);
166 :
167 :
168 : protected:
169 : /// @brief name
170 : const std::string myName;
171 :
172 : /// @brief The output device to use
173 : OutputDevice& myOutputDevice;
174 :
175 : /// @brief Detector's position on lane [m]
176 : const double myPosition;
177 :
178 : /// @brief The last exit time
179 : double myLastExitTime;
180 :
181 : /// @brief The last exit time
182 : std::map<SUMOTrafficObject*, double> myEntryTimes;
183 :
184 : private:
185 : /// @brief Invalidated copy constructor.
186 : MSInstantInductLoop(const MSInstantInductLoop&);
187 :
188 : /// @brief Invalidated assignment operator.
189 : MSInstantInductLoop& operator=(const MSInstantInductLoop&);
190 :
191 :
192 : };
|