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