1 /****************************************************************************/
2 // Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.org/sumo
3 // Copyright (C) 2004-2019 German Aerospace Center (DLR) and others.
4 // This program and the accompanying materials
5 // are made available under the terms of the Eclipse Public License v2.0
6 // which accompanies this distribution, and is available at
7 // http://www.eclipse.org/legal/epl-v20.html
8 // SPDX-License-Identifier: EPL-2.0
9 /****************************************************************************/
10 /// @file    MSMeanData_Net.h
11 /// @author  Daniel Krajzewicz
12 /// @author  Sascha Krieg
13 /// @author  Michael Behrisch
14 /// @author  Jakob Erdmann
15 /// @date    Mon, 10.05.2004
16 /// @version $Id$
17 ///
18 // Network state mean data collector for edges/lanes
19 /****************************************************************************/
20 #ifndef MSMeanData_Net_h
21 #define MSMeanData_Net_h
22 
23 
24 // ===========================================================================
25 // included modules
26 // ===========================================================================
27 #include <config.h>
28 
29 #include <vector>
30 #include <set>
31 #include <limits>
32 #include "MSMeanData.h"
33 
34 
35 // ===========================================================================
36 // class declarations
37 // ===========================================================================
38 class OutputDevice;
39 class MSEdgeControl;
40 class MSEdge;
41 class MSLane;
42 
43 
44 // ===========================================================================
45 // class definitions
46 // ===========================================================================
47 /**
48  * @class MSMeanData_Net
49  * @brief Network state mean data collector for edges/lanes
50  *
51  * This structure does not contain the data itself, it is stored within
52  *  MSLaneMeanDataValues-MoveReminder objects.
53  * This class is used to build the output, optionally, in the case
54  *  of edge-based dump, aggregated over the edge's lanes.
55  *
56  * @todo consider error-handling on write (using IOError)
57  */
58 class MSMeanData_Net : public MSMeanData {
59 public:
60     /**
61      * @class MSLaneMeanDataValues
62      * @brief Data structure for mean (aggregated) edge/lane values
63      *
64      * Structure holding values that describe the flow and other physical
65      *  properties aggregated over some seconds.
66      */
67     class MSLaneMeanDataValues : public MSMeanData::MeanDataValues {
68     public:
69         /** @brief Constructor
70          * @param[in] length The length of the object for which the data gets collected
71          */
72         MSLaneMeanDataValues(MSLane* const lane, const double length, const bool doAdd,
73                              const MSMeanData_Net* parent);
74 
75         /** @brief Destructor */
76         virtual ~MSLaneMeanDataValues();
77 
78         /** @brief Resets values so they may be used for the next interval
79          */
80         void reset(bool afterWrite = false);
81 
82         /** @brief Add the values of this to the given one and store them there
83          *
84          * @param[in] val The meandata to add to
85          */
86         void addTo(MSMeanData::MeanDataValues& val) const;
87 
88         /// @name Methods inherited from MSMoveReminder
89         /// @{
90 
91         /** @brief Called if the vehicle leaves the reminder's lane
92          *
93          * @param veh The leaving vehicle.
94          * @param[in] lastPos Position on the lane when leaving.
95          * @param[in] isArrival whether the vehicle arrived at its destination
96          * @param[in] isLaneChange whether the vehicle changed from the lane
97          * @see MSMoveReminder
98          * @see MSMoveReminder::notifyLeave
99          */
100         bool notifyLeave(SUMOTrafficObject& veh, double lastPos, MSMoveReminder::Notification reason, const MSLane* enteredLane = 0);
101 
102 
103         /** @brief Computes current values and adds them to their sums
104          *
105          * The fraction of time the vehicle is on the lane is computed and
106          *  used as a weight for the vehicle's current values.
107          *  The "emitted" field is incremented, additionally.
108          *
109          * @param[in] veh The vehicle that enters the lane
110          * @param[in] veh The entering vehicle.
111          * @param[in] reason how the vehicle enters the lane
112          * @return Always true
113          * @see MSMoveReminder::notifyEnter
114          * @see MSMoveReminder::Notification
115          */
116         bool notifyEnter(SUMOTrafficObject& veh, MSMoveReminder::Notification reason, const MSLane* enteredLane = 0);
117         //@}
118 
119         bool isEmpty() const;
120 
121         /** @brief Writes output values into the given stream
122          *
123          * @param[in] dev The output device to write the data into
124          * @param[in] period Length of the period the data were gathered
125          * @param[in] numLanes The total number of lanes for which the data was collected
126          * @exception IOError If an error on writing occurs (!!! not yet implemented)
127          */
128         void write(OutputDevice& dev, const SUMOTime period,
129                    const double numLanes, const double defaultTravelTime,
130                    const int numVehicles = -1) const;
131 
132     protected:
133         /** @brief Internal notification about the vehicle moves
134          *  @see MSMoveReminder::notifyMoveInternal
135          */
136         void notifyMoveInternal(const SUMOTrafficObject& veh,
137                                 const double frontOnLane, const double timeOnLane, const double,
138                                 const double meanSpeedVehicleOnLane,
139                                 const double travelledDistanceFrontOnLane,
140                                 const double travelledDistanceVehicleOnLane,
141                                 const double meanLengthOnLane);
142 
143     private:
144 //        /// @brief Calculate the vehicle front's distance to myLane's end for a vehicle that called notifyMoveInternal()
145 //        ///        maxDist gives the maximal distance to search back from the vehicle's current lane to myLane
146 //        ///        returns INVALID_DOUBLE if myLane wasn't found in that range
147 //        double getVehicleDistToMyLane(const SUMOVehicle& veh, double maxDist);
148 
149     public:
150         /// @name Collected values
151         /// @{
152         /// @brief The number of vehicles that were emitted on the lane
153         int nVehDeparted;
154 
155         /// @brief The number of vehicles that finished on the lane
156         int nVehArrived;
157 
158         /// @brief The number of vehicles that entered this lane within the sample interval
159         int nVehEntered;
160 
161         /// @brief The number of vehicles that left this lane within the sample interval
162         int nVehLeft;
163 
164         /// @brief The number of vehicles that left this lane within the sample interval
165         int nVehVaporized;
166 
167         /// @brief The number of vehicle probes with small speed
168         double waitSeconds;
169 
170     private:
171         /// @brief The number of vehicles that changed from this lane
172         int nVehLaneChangeFrom;
173 
174         /// @brief The number of vehicles that changed to this lane
175         int nVehLaneChangeTo;
176 
177         /// @brief The number of vehicle probes regarding the vehicle front
178         double frontSampleSeconds;
179 
180         /// @brief The travelled distance regarding the vehicle front
181         double frontTravelledDistance;
182 
183         /// @brief The sum of the lengths the vehicles had
184         double vehLengthSum;
185 
186         /// @brief The sum of the occupation of the lane
187         double occupationSum;
188 
189         /// @brief minimal vehicle length in the current interval (used to determine a maximal density, see #3265)
190         double minimalVehicleLength;
191 
192         //@}
193 
194         /// @brief The meandata parent
195         const MSMeanData_Net* myParent;
196 
197     };
198 
199 
200 public:
201     /** @brief Constructor
202      *
203      * @param[in] id The id of the detector
204      * @param[in] dumpBegin Begin time of dump
205      * @param[in] dumpEnd End time of dump
206      * @param[in] useLanes Information whether lane-based or edge-based dump shall be generated
207      * @param[in] withEmpty Information whether empty lanes/edges shall be written
208      * @param[in] printDefaults Information whether defaults for empty lanes/edges shall be written
209      * @param[in] withInternal Information whether internal lanes/edges shall be written
210      * @param[in] trackVehicles Information whether vehicles shall be tracked
211      * @param[in] detectPersons Whether pedestrians shall be detected instead of vehicles
212      * @param[in] maxTravelTime the maximum travel time to output
213      * @param[in] minSamples the minimum number of sample seconds before the values are valid
214      * @param[in] haltSpeed the maximum speed to consider a vehicle waiting
215      * @param[in] vTypes the set of vehicle types to consider
216      */
217     MSMeanData_Net(const std::string& id,
218                    const SUMOTime dumpBegin, const SUMOTime dumpEnd,
219                    const bool useLanes, const bool withEmpty, const bool printDefaults,
220                    const bool withInternal, const bool trackVehicles, const int detectPersons,
221                    const double maxTravelTime, const double minSamples,
222                    const double haltSpeed, const std::string& vTypes);
223 
224 
225     /// @brief Destructor
226     virtual ~MSMeanData_Net();
227 
228 protected:
229     /** @brief Create an instance of MeanDataValues
230      *
231      * @param[in] lane The lane to create for
232      * @param[in] doAdd whether to add the values as reminder to the lane
233      */
234     MSMeanData::MeanDataValues* createValues(MSLane* const lane, const double length, const bool doAdd) const;
235 
236     /** @brief Resets network value in order to allow processing of the next interval
237      *
238      * Goes through the lists of edges and starts "resetOnly" for each edge.
239      * @param [in] edge The last time step that is reported
240      */
241     void resetOnly(SUMOTime stopTime);
242 
243 private:
244     /// @brief the minimum sample seconds
245     const double myHaltSpeed;
246 
247     /// @brief Invalidated copy constructor.
248     MSMeanData_Net(const MSMeanData_Net&);
249 
250     /// @brief Invalidated assignment operator.
251     MSMeanData_Net& operator=(const MSMeanData_Net&);
252 
253 };
254 
255 #endif
256 
257 /****************************************************************************/
258 
259