Line data Source code
1 : /****************************************************************************/
2 : // Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo
3 : // Copyright (C) 2001-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 MSRouteProbe.h
15 : /// @author Michael Behrisch
16 : /// @author Daniel Krajzewicz
17 : /// @author Tino Morenz
18 : /// @date Thu, 04.12.2008
19 : ///
20 : // Writes route distributions at a certain edge
21 : /****************************************************************************/
22 : #pragma once
23 : #include <config.h>
24 :
25 : #include <string>
26 : #include <microsim/output/MSDetectorFileOutput.h>
27 : #include <microsim/MSMoveReminder.h>
28 : #include <utils/distribution/RandomDistributor.h>
29 :
30 :
31 : // ===========================================================================
32 : // class declarations
33 : // ===========================================================================
34 : class MSEdge;
35 : class MSRoute;
36 : class MSVehicle;
37 : class OutputDevice;
38 :
39 :
40 : // ===========================================================================
41 : // class definitions
42 : // ===========================================================================
43 : /**
44 : * @class MSRouteProbe
45 : * @brief Writes routes of vehicles passing a certain edge
46 : *
47 : * This device allows to create route distributions of all vehicles
48 : * running over a certain edge.
49 : *
50 : * A frequency can be specified to generate the output in certain intervals,
51 : * (e.g. every 900 seconds) and is used via the detector control by
52 : * calling the appropriate methods derived from MSDetectorFileOutput.
53 : *
54 : * @see MSDetectorFileOutput
55 : * @see Named
56 : */
57 :
58 : class MSRouteProbe : public MSDetectorFileOutput, public MSMoveReminder {
59 : public:
60 : /** @brief Constructor
61 : *
62 : * @param[in] id The id of the route probe
63 : * @param[in] edge The edge where the distribution shall be estimated
64 : * @param[in] distID The id of the distribution to add values to
65 : * @param[in] lastID The id of the last completed distribution to use for getRoute
66 : */
67 : MSRouteProbe(const std::string& id, const MSEdge* edge,
68 : const std::string& distID, const std::string& lastID,
69 : const std::string& vTypes);
70 :
71 :
72 : /// @brief Destructor
73 : virtual ~MSRouteProbe();
74 :
75 :
76 : /// @name Methods inherited from MSMoveReminder
77 : /// @{
78 :
79 : /** @brief Returns whether the vehicle shall be aware of this entry
80 : *
81 : * Returns true if the vehicle is in front of the entry, so that it
82 : * may enter it in later steps.
83 : *
84 : * @param[in] veh The entering vehicle.
85 : * @param[in] reason how the vehicle enters the lane
86 : * @return False, if vehicle passed the entry, else true.
87 : * @see MSMoveReminder::notifyEnter
88 : * @see MSMoveReminder::Notification
89 : */
90 : bool notifyEnter(SUMOTrafficObject& veh, MSMoveReminder::Notification reason, const MSLane* enteredLane = 0) override;
91 : /// @}
92 :
93 :
94 : /// @name Methods inherited from MSDetectorFileOutput.
95 : /// @{
96 :
97 : /** @brief Writes values into the given stream
98 : *
99 : * This method writes the distribution of routes collected
100 : * in the last interval.
101 : * As a side effect the distribution is added to the global
102 : * route distribution container.
103 : *
104 : * @param[in] dev The output device to write the data into
105 : * @param[in] startTime First time step the data were gathered
106 : * @param[in] stopTime Last time step the data were gathered
107 : * @see MSDetectorFileOutput::writeXMLOutput
108 : * @exception IOError If an error on writing occurs (!!! not yet implemented)
109 : */
110 : void writeXMLOutput(OutputDevice& dev, SUMOTime startTime, SUMOTime stopTime) override;
111 :
112 :
113 : /** @brief Opens the XML-output using "detector" as root element
114 : *
115 : * @param[in] dev The output device to write the root into
116 : * @see MSDetectorFileOutput::writeXMLDetectorProlog
117 : * @todo What happens with the additional information if several detectors use the same output?
118 : * @exception IOError If an error on writing occurs (!!! not yet implemented)
119 : */
120 : void writeXMLDetectorProlog(OutputDevice& dev) const override;
121 : /// @}
122 :
123 : /* @brief sample a route from the routeDistribution
124 : * @param[in] last Retrieve route from the previous (complete) collection interval
125 : */
126 : ConstMSRoutePtr sampleRoute(bool last = true) const;
127 :
128 : const MSEdge* getEdge() {
129 5 : return myEdge;
130 : }
131 :
132 : void clearState(SUMOTime step) override;
133 :
134 : private:
135 : void initDistributions();
136 :
137 : private:
138 : std::string myDistID;
139 : std::string myLastID;
140 :
141 : /// @brief The previous distribution of routes (probability->route)
142 : RandomDistributor<ConstMSRoutePtr>* myLastRouteDistribution;
143 :
144 : /// @brief The current distribution of routes (probability->route)
145 : RandomDistributor<ConstMSRoutePtr>* myCurrentRouteDistribution;
146 :
147 : /// @brief the edge of this route probe
148 : const MSEdge* myEdge;
149 :
150 :
151 : private:
152 : /// @brief Invalidated copy constructor.
153 : MSRouteProbe(const MSRouteProbe&);
154 :
155 : /// @brief Invalidated assignment operator.
156 : MSRouteProbe& operator=(const MSRouteProbe&);
157 :
158 :
159 : };
|