Line data Source code
1 : /****************************************************************************/
2 : // Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo
3 : // Copyright (C) 2011-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 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 :
67 :
68 : /// @brief Destructor
69 : ~MSInstantInductLoop();
70 :
71 :
72 :
73 : /// @name Methods inherited from MSMoveReminder
74 : /// @{
75 :
76 : /** @brief Checks whether the vehicle shall be counted and/or shall still touch this MSMoveReminder
77 : *
78 : * As soon a vehicle enters the detector, its entry time is computed and stored
79 : * in myVehiclesOnDet via enterDetectorByMove. If it passes the detector, the
80 : * according leaving time is computed and stored, too, using leaveDetectorByMove.
81 : *
82 : * @param[in] veh Vehicle that asks this remider.
83 : * @param[in] oldPos Position before move.
84 : * @param[in] newPos Position after move with newSpeed.
85 : * @param[in] newSpeed Moving speed.
86 : * @return True if vehicle hasn't passed the detector completely.
87 : * @see MSMoveReminder
88 : * @see MSMoveReminder::notifyMove
89 : * @see enterDetectorByMove
90 : * @see leaveDetectorByMove
91 : */
92 : bool notifyMove(SUMOTrafficObject& veh, double oldPos, double newPos, double newSpeed);
93 :
94 :
95 : /** @brief Dismisses the vehicle if it is on the detector due to a lane change
96 : *
97 : * If the vehicle is on the detector, it will be dismissed by incrementing
98 : * myDismissedVehicleNumber and removing this vehicle's entering time from
99 : * myVehiclesOnDet.
100 : *
101 : * @param[in] veh The leaving vehicle.
102 : * @param[in] lastPos Position on the lane when leaving.
103 : * @param[in] isArrival whether the vehicle arrived at its destination
104 : * @param[in] isLaneChange whether the vehicle changed from the lane
105 : * @see MSMoveReminder
106 : * @see MSMoveReminder::notifyLeave
107 : */
108 : bool notifyLeave(SUMOTrafficObject& veh, double lastPos, MSMoveReminder::Notification reason, const MSLane* enteredLane = 0);
109 : //@}
110 :
111 :
112 :
113 : /** @brief Write the generated output to the given device
114 : *
115 : * This method is not used - output is written as soon as a vehicle visits the detector.
116 : *
117 : * @param[in] dev The output device to write the data into
118 : * @param[in] startTime First time step the data were gathered
119 : * @param[in] stopTime Last time step the data were gathered
120 : * @exception IOError If an error on writing occurs
121 : */
122 0 : void writeXMLOutput(OutputDevice& dev,
123 : SUMOTime startTime, SUMOTime stopTime) {
124 : UNUSED_PARAMETER(dev);
125 : UNUSED_PARAMETER(startTime);
126 : UNUSED_PARAMETER(stopTime);
127 0 : }
128 :
129 :
130 : /** @brief Open the XML-output
131 : *
132 : * The implementing function should open an xml element using
133 : * OutputDevice::writeXMLHeader.
134 : *
135 : * @param[in] dev The output device to write the root into
136 : * @exception IOError If an error on writing occurs
137 : */
138 : void writeXMLDetectorProlog(OutputDevice& dev) const;
139 :
140 :
141 : protected:
142 : /** @brief Writes an event line
143 : * @param[in] state The current state to report
144 : * @param[in] t The event time
145 : * @param[in] veh The vehicle responsible for the event
146 : * @param[in] speed The speed of the vehicle
147 : * @param[in] add An optional attribute to report
148 : * @param[in] addValue The value of the optional attribute
149 : */
150 : void write(const char* state, double t, SUMOTrafficObject& veh, double speed, const char* add = 0, double addValue = -1);
151 :
152 :
153 : protected:
154 : /// @brief name
155 : const std::string myName;
156 :
157 : /// @brief The output device to use
158 : OutputDevice& myOutputDevice;
159 :
160 : /// @brief Detector's position on lane [m]
161 : const double myPosition;
162 :
163 : /// @brief The last exit time
164 : double myLastExitTime;
165 :
166 : /// @brief The last exit time
167 : std::map<SUMOTrafficObject*, double> myEntryTimes;
168 :
169 : private:
170 : /// @brief Invalidated copy constructor.
171 : MSInstantInductLoop(const MSInstantInductLoop&);
172 :
173 : /// @brief Invalidated assignment operator.
174 : MSInstantInductLoop& operator=(const MSInstantInductLoop&);
175 :
176 :
177 : };
|