1 /****************************************************************************/ 2 // Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.org/sumo 3 // Copyright (C) 2001-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_Amitran.h 11 /// @author Daniel Krajzewicz 12 /// @author Sascha Krieg 13 /// @author Michael Behrisch 14 /// @date Mon, 10.05.2004 15 /// @version $Id$ 16 /// 17 // Network state mean data collector for edges/lanes 18 /****************************************************************************/ 19 #ifndef MSMeanData_Amitran_h 20 #define MSMeanData_Amitran_h 21 22 23 // =========================================================================== 24 // included modules 25 // =========================================================================== 26 #include <config.h> 27 28 #include <vector> 29 #include <set> 30 #include <limits> 31 #include "MSMeanData.h" 32 33 34 // =========================================================================== 35 // class declarations 36 // =========================================================================== 37 class OutputDevice; 38 class MSEdgeControl; 39 class MSEdge; 40 class MSLane; 41 42 43 // =========================================================================== 44 // class definitions 45 // =========================================================================== 46 /** 47 * @class MSMeanData_Amitran 48 * @brief Network state mean data collector for edges/lanes 49 * 50 * This structure does not contain the data itself, it is stored within 51 * MSLaneMeanDataValues-MoveReminder objects. 52 * This class is used to build the output, optionally, in the case 53 * of edge-based dump, aggregated over the edge's lanes. 54 * 55 * @todo consider error-handling on write (using IOError) 56 */ 57 class MSMeanData_Amitran : public MSMeanData { 58 public: 59 /** 60 * @class MSLaneMeanDataValues 61 * @brief Data structure for mean (aggregated) edge/lane values 62 * 63 * Structure holding values that describe the flow and other physical 64 * properties aggregated over some seconds. 65 */ 66 class MSLaneMeanDataValues : public MSMeanData::MeanDataValues { 67 public: 68 /** @brief Constructor 69 * @param[in] length The length of the object for which the data gets collected 70 */ 71 MSLaneMeanDataValues(MSLane* const lane, const double length, const bool doAdd, 72 const MSMeanData_Amitran* parent); 73 74 /** @brief Destructor */ 75 virtual ~MSLaneMeanDataValues(); 76 77 /** @brief Resets values so they may be used for the next interval 78 */ 79 void reset(bool afterWrite = false); 80 81 /** @brief Add the values of this to the given one and store them there 82 * 83 * @param[in] val The meandata to add to 84 */ 85 void addTo(MSMeanData::MeanDataValues& val) const; 86 87 /// @name Methods inherited from MSMoveReminder 88 /// @{ 89 90 /** @brief Computes current values and adds them to their sums 91 * 92 * The fraction of time the vehicle is on the lane is computed and 93 * used as a weight for the vehicle's current values. 94 * The "emitted" field is incremented, additionally. 95 * 96 * @param[in] veh The vehicle that enters the lane 97 * @param[in] veh The entering vehicle. 98 * @param[in] reason how the vehicle enters the lane 99 * @return Always true 100 * @see MSMoveReminder::notifyEnter 101 * @see MSMoveReminder::Notification 102 */ 103 bool notifyEnter(SUMOTrafficObject& veh, MSMoveReminder::Notification reason, const MSLane* enteredLane = 0); 104 //@} 105 106 bool isEmpty() const; 107 108 /** @brief Writes output values into the given stream 109 * 110 * @param[in] dev The output device to write the data into 111 * @param[in] period Length of the period the data were gathered 112 * @param[in] numLanes The total number of lanes for which the data was collected 113 * @exception IOError If an error on writing occurs (!!! not yet implemented) 114 */ 115 void write(OutputDevice& dev, const SUMOTime period, 116 const double numLanes, const double defaultTravelTime, 117 const int numVehicles = -1) const; 118 119 protected: 120 /** @brief Internal notification about the vehicle moves 121 * @see MSMoveReminder::notifyMoveInternal() 122 */ 123 void notifyMoveInternal(const SUMOTrafficObject& veh, const double /* frontOnLane */, const double timeOnLane, const double /*meanSpeedFrontOnLane*/, const double meanSpeedVehicleOnLane, const double travelledDistanceFrontOnLane, const double travelledDistanceVehicleOnLane, const double /* meanLengthOnLane */); 124 125 private: 126 /// @name Collected values 127 /// @{ 128 /// @brief The number of vehicles that entered this lane within the sample interval 129 int amount; 130 131 /// @brief The number of vehicles that entered this lane within the sample interval by type 132 std::map<const MSVehicleType*, int> typedAmount; 133 134 /// @brief The number of sampled vehicle movements by type (in s) 135 std::map<const MSVehicleType*, double> typedSamples; 136 137 /// @brief The sum of the distances the vehicles travelled by type 138 std::map<const MSVehicleType*, double> typedTravelDistance; 139 //@} 140 141 }; 142 143 144 public: 145 /** @brief Constructor 146 * 147 * @param[in] id The id of the detector 148 * @param[in] dumpBegin Begin time of dump 149 * @param[in] dumpEnd End time of dump 150 * @param[in] useLanes Information whether lane-based or edge-based dump shall be generated 151 * @param[in] withEmpty Information whether empty lanes/edges shall be written 152 * @param[in] printDefaults Information whether defaults for empty lanes/edges shall be written 153 * @param[in] withInternal Information whether internal lanes/edges shall be written 154 * @param[in] trackVehicles Information whether vehicles shall be tracked 155 * @param[in] detectPersons Whether pedestrians shall be detected instead of vehicles 156 * @param[in] maxTravelTime the maximum travel time to output 157 * @param[in] minSamples the minimum number of sample seconds before the values are valid 158 * @param[in] haltSpeed the maximum speed to consider a vehicle waiting 159 * @param[in] vTypes the set of vehicle types to consider 160 */ 161 MSMeanData_Amitran(const std::string& id, 162 const SUMOTime dumpBegin, const SUMOTime dumpEnd, 163 const bool useLanes, const bool withEmpty, const bool printDefaults, 164 const bool withInternal, const bool trackVehicles, const int detectPersons, 165 const double maxTravelTime, const double minSamples, 166 const double haltSpeed, const std::string& vTypes); 167 168 169 /// @brief Destructor 170 virtual ~MSMeanData_Amitran(); 171 172 /// @name Methods inherited from MSDetectorFileOutput. 173 /// @{ 174 175 /** @brief Opens the XML-output using "netstats" as root element 176 * 177 * @param[in] dev The output device to write the root into 178 * @see MSDetectorFileOutput::writeXMLDetectorProlog 179 * @exception IOError If an error on writing occurs (!!! not yet implemented) 180 */ 181 virtual void writeXMLDetectorProlog(OutputDevice& dev) const; 182 /// @} 183 184 /** @brief Return the relevant edge id 185 * 186 * @param[in] edge The edge to retrieve the id for 187 */ 188 virtual std::string getEdgeID(const MSEdge* const edge); 189 190 /** @brief Writes the interval opener 191 * 192 * @param[in] dev The output device to write the data into 193 * @param[in] startTime First time step the data were gathered 194 * @param[in] stopTime Last time step the data were gathered 195 */ 196 virtual void openInterval(OutputDevice& dev, const SUMOTime startTime, const SUMOTime stopTime); 197 198 /** @brief Checks for emptiness and writes prefix into the given stream 199 * 200 * @param[in] dev The output device to write the data into 201 * @param[in] values The values to check for emptiness 202 * @param[in] tag The xml tag to write (lane / edge) 203 * @param[in] id The id for the lane / edge to write 204 * @return whether further output should be generated 205 * @exception IOError If an error on writing occurs (!!! not yet implemented) 206 */ 207 virtual bool writePrefix(OutputDevice& dev, const MeanDataValues& values, 208 const SumoXMLTag tag, const std::string id) const; 209 210 protected: 211 /** @brief Create an instance of MeanDataValues 212 * 213 * @param[in] lane The lane to create for 214 * @param[in] doAdd whether to add the values as reminder to the lane 215 */ 216 MSMeanData::MeanDataValues* createValues(MSLane* const lane, const double length, const bool doAdd) const; 217 218 /** @brief Resets network value in order to allow processing of the next interval 219 * 220 * Goes through the lists of edges and starts "resetOnly" for each edge. 221 * @param [in] edge The last time step that is reported 222 */ 223 void resetOnly(SUMOTime stopTime); 224 225 private: 226 /// @brief the minimum sample seconds 227 const double myHaltSpeed; 228 229 /// @brief Invalidated copy constructor. 230 MSMeanData_Amitran(const MSMeanData_Amitran&); 231 232 /// @brief Invalidated assignment operator. 233 MSMeanData_Amitran& operator=(const MSMeanData_Amitran&); 234 235 }; 236 237 238 #endif 239 240 /****************************************************************************/ 241 242