Eclipse SUMO - Simulation of Urban MObility
MSCalibrator.h
Go to the documentation of this file.
1 /****************************************************************************/
2 // Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.org/sumo
3 // Copyright (C) 2005-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 /****************************************************************************/
17 // Calibrates the flow on an edge by removing an inserting vehicles
18 /****************************************************************************/
19 #ifndef MSCalibrator_h
20 #define MSCalibrator_h
21 
22 
23 // ===========================================================================
24 // included modules
25 // ===========================================================================
26 #include <config.h>
27 
28 #include <string>
29 #include <vector>
30 #include <utils/common/Command.h>
35 
36 
37 // ===========================================================================
38 // class declarations
39 // ===========================================================================
40 class OutputDevice;
41 class MSRouteProbe;
42 
43 
44 // ===========================================================================
45 // class definitions
46 // ===========================================================================
51 class MSCalibrator : public MSTrigger, public MSRouteHandler, public Command, public MSDetectorFileOutput {
52 public:
54  MSCalibrator(const std::string& id,
55  const MSEdge* const edge,
56  MSLane* lane,
57  const double pos,
58  const std::string& aXMLFilename,
59  const std::string& outputFilename,
60  const SUMOTime freq, const double length,
61  const MSRouteProbe* probe,
62  const std::string& vTypes,
63  bool addLaneMeanData = true);
64 
66  virtual ~MSCalibrator();
67 
74  void writeXMLOutput(OutputDevice& dev, SUMOTime startTime, SUMOTime stopTime);
75 
76 
85  void writeXMLDetectorProlog(OutputDevice& dev) const;
86 
89  virtual SUMOTime execute(SUMOTime currentTime);
90 
91  const std::string& getID() const {
93  return MSTrigger::getID();
94  }
95 
97  static void cleanup();
98 
99 
100 
101 protected:
102  class CalibratorCommand : public Command {
103  public:
105  myCalibrator(cali) {}
106 
107  SUMOTime execute(SUMOTime currentTime) {
108  return myCalibrator->execute(currentTime);
109  }
110 
111  private:
113  };
114 
115 
117 
118 
126  virtual void myStartElement(int element,
127  const SUMOSAXAttributes& attrs);
128 
135  virtual void myEndElement(int element);
137 
138 
139 
141  public:
142  VehicleRemover(MSLane* lane, int laneIndex, MSCalibrator* parent) :
143  MSMoveReminder(parent->getID(), lane, true), myLaneIndex(laneIndex), myParent(parent) {}
144 
146 
147 
158  virtual bool notifyEnter(SUMOTrafficObject& veh, MSMoveReminder::Notification reason, const MSLane* enteredLane = 0);
159 
160  void disable() {
161  myParent = 0;
162  }
163 
164  private:
167  };
168  friend class VehicleRemover;
169 
170  // @return whether the current state is active (GUI)
171  bool isActive() const {
172  return myAmActive;
173  }
174 
175 protected:
176 
177  struct AspiredState {
178  AspiredState() : begin(-1), end(-1), q(-1.), v(-1.), vehicleParameter(0) {}
181  double q;
182  double v;
184  };
185 
186  void intervalEnd();
187 
188  bool isCurrentStateActive(SUMOTime time);
189 
190  bool tryEmit(MSLane* lane, MSVehicle* vehicle);
191 
192  void init();
193 
194  inline virtual int passed() const {
195  // calibrator measures at start of segment
196  // vehicles drive to the end of an edge by default so they count as passed
197  // but vaporized vehicles do not count
198  // if the calibrator is located on a short edge, the vehicles are
199  // vaporized on the next edge so we cannot rely on myEdgeMeanData.nVehVaporized
201  }
202 
204  int totalWished() const;
205 
207  double currentFlow() const;
208 
210  double currentSpeed() const;
211 
212  /* @brief returns whether the lane is jammed although it should not be
213  * @param[in] lane The lane to check or all for negative values
214  */
215  bool invalidJam(int laneIndex) const;
216 
217  inline int inserted() const {
218  return myInserted;
219  }
220  inline int removed() const {
221  return myRemoved;
222  }
223  inline int clearedInJam() const {
224  return myClearedInJam;
225  }
226 
227  /* @brief returns the number of vehicles (of the current type) that still
228  * fit on the given lane
229  * @param[in] lane The lane to check (return the maximum of all lanes for negative values)
230  */
231  int remainingVehicleCapacity(int laneIndex) const;
232 
234  virtual void reset();
235 
237  virtual void updateMeanData();
238 
242  return myToRemove.insert(veh->getID()).second;
243  };
244 
245 
248  bool removePending();
249 
250 protected:
252  const MSEdge* const myEdge;
254  MSLane* const myLane;
256  const double myPos;
258  const MSRouteProbe* const myProbe;
260  std::vector<MSMeanData_Net::MSLaneMeanDataValues*> myLaneMeanData;
265 
267  std::vector<AspiredState> myIntervals;
269  std::vector<AspiredState>::const_iterator myCurrentStateInterval;
270 
271  std::vector<VehicleRemover*> myVehicleRemovers;
272 
277  std::set<std::string> myToRemove;
278 
281 
295  bool myDidInit;
300 
303 
304  /* @brief objects which need to live longer than the MSCalibrator
305  * instance which created them */
306  static std::vector<MSMoveReminder*> LeftoverReminders;
307  static std::vector<SUMOVehicleParameter*> LeftoverVehicleParameters;
308 
309 };
310 
311 #endif
312 
313 /****************************************************************************/
SUMOTime execute(SUMOTime currentTime)
Executes the command.
Definition: MSCalibrator.h:107
int nVehEntered
The number of vehicles that entered this lane within the sample interval.
Representation of a vehicle in the micro simulation.
Definition: MSVehicle.h:80
long long int SUMOTime
Definition: SUMOTime.h:35
VehicleRemover(MSLane *lane, int laneIndex, MSCalibrator *parent)
Definition: MSCalibrator.h:142
bool tryEmit(MSLane *lane, MSVehicle *vehicle)
static std::vector< SUMOVehicleParameter * > LeftoverVehicleParameters
Definition: MSCalibrator.h:307
virtual int passed() const
Definition: MSCalibrator.h:194
virtual void myEndElement(int element)
Called on the closing of a tag;.
Writes routes of vehicles passing a certain edge.
Definition: MSRouteProbe.h:61
bool myDidSpeedAdaption
The information whether speed was adapted in the current interval.
Definition: MSCalibrator.h:293
Notification
Definition of a vehicle state.
bool myAmActive
whether the calibrator was active when last checking
Definition: MSCalibrator.h:302
bool myDidInit
The information whether init was called.
Definition: MSCalibrator.h:295
const std::string & getID() const
Returns the id.
Definition: Named.h:77
SUMOTime myFrequency
The frequeny with which to check for calibration.
Definition: MSCalibrator.h:283
int myRemoved
The number of vehicles that were removed in the current interval.
Definition: MSCalibrator.h:285
Base (microsim) event class.
Definition: Command.h:53
CalibratorCommand(MSCalibrator *cali)
Definition: MSCalibrator.h:104
double currentSpeed() const
measured speed in the current interval
int myClearedInJam
The number of vehicles that were removed when clearin a jam.
Definition: MSCalibrator.h:289
const MSEdge *const myEdge
the edge on which this calibrator lies
Definition: MSCalibrator.h:252
virtual void myStartElement(int element, const SUMOSAXAttributes &attrs)
Called on the opening of a tag;.
Data structure for mean (aggregated) edge/lane values.
const std::string & getID() const
Definition: MSCalibrator.h:91
int totalWished() const
number of vehicles expected to pass this interval
A road/street connecting two junctions.
Definition: MSEdge.h:76
std::vector< AspiredState >::const_iterator myCurrentStateInterval
Iterator pointing to the current interval.
Definition: MSCalibrator.h:269
An abstract device that changes the state of the micro simulation.
Definition: MSTrigger.h:41
Encapsulated SAX-Attributes.
void writeXMLDetectorProlog(OutputDevice &dev) const
Open the XML-output.
double myDefaultSpeed
The default (maximum) speed on the segment.
Definition: MSCalibrator.h:297
bool mySpeedIsDefault
The information whether the speed adaption has been reset.
Definition: MSCalibrator.h:291
Something on a lane to be noticed about vehicle movement.
bool scheduleRemoval(MSVehicle *veh)
try to schedule the givne vehicle for removal. return true if it isn&#39;t already scheduled ...
Definition: MSCalibrator.h:241
bool isActive() const
Definition: MSCalibrator.h:171
std::vector< AspiredState > myIntervals
List of adaptation intervals.
Definition: MSCalibrator.h:267
virtual void reset()
reset collected vehicle data
bool myHaveWarnedAboutClearingJam
The default (maximum) speed on the segment.
Definition: MSCalibrator.h:299
MSMeanData_Net myMeanDataParent
dummy parent to retrieve vType filter
Definition: MSCalibrator.h:264
MSLane *const myLane
the lane on which this calibrator lies (0 if the whole edge is covered at once)
Definition: MSCalibrator.h:254
bool invalidJam(int laneIndex) const
std::vector< MSMeanData_Net::MSLaneMeanDataValues * > myLaneMeanData
data collector for the calibrator
Definition: MSCalibrator.h:260
void intervalEnd()
static std::vector< MSMoveReminder * > LeftoverReminders
Definition: MSCalibrator.h:306
Structure representing possible vehicle parameter.
Representation of a vehicle or person.
const double myPos
the position on the edge where this calibrator lies
Definition: MSCalibrator.h:256
SUMOVehicleParameter * vehicleParameter
Definition: MSCalibrator.h:183
int clearedInJam() const
Definition: MSCalibrator.h:223
const MSRouteProbe *const myProbe
the route probe to retrieve routes from
Definition: MSCalibrator.h:258
static void cleanup()
cleanup remaining data structures
OutputDevice * myOutput
The device for xml statistics.
Definition: MSCalibrator.h:280
virtual void updateMeanData()
aggregate lane values
virtual ~MSCalibrator()
Calibrates the flow on a segment to a specified one.
Definition: MSCalibrator.h:51
virtual SUMOTime execute(SUMOTime currentTime)
Static storage of an output device and its base (abstract) implementation.
Definition: OutputDevice.h:64
Network state mean data collector for edges/lanes.
MSCalibrator(const std::string &id, const MSEdge *const edge, MSLane *lane, const double pos, const std::string &aXMLFilename, const std::string &outputFilename, const SUMOTime freq, const double length, const MSRouteProbe *probe, const std::string &vTypes, bool addLaneMeanData=true)
bool removePending()
remove any vehicles which are scheduled for removal. return true if removals took place ...
MSMeanData_Net::MSLaneMeanDataValues myEdgeMeanData
accumlated data for the whole edge
Definition: MSCalibrator.h:262
bool isCurrentStateActive(SUMOTime time)
std::vector< VehicleRemover * > myVehicleRemovers
Definition: MSCalibrator.h:271
int removed() const
Definition: MSCalibrator.h:220
int remainingVehicleCapacity(int laneIndex) const
const std::string & getID() const
Returns the name of the vehicle.
void writeXMLOutput(OutputDevice &dev, SUMOTime startTime, SUMOTime stopTime)
Write the generated output to the given device.
Representation of a lane in the micro simulation.
Definition: MSLane.h:83
std::set< std::string > myToRemove
set of vehicle ids to remove
Definition: MSCalibrator.h:277
Parser and container for routes during their loading.
int myInserted
The number of vehicles that were inserted in the current interval.
Definition: MSCalibrator.h:287
Base of value-generating classes (detectors)
double currentFlow() const
flow in the current interval in veh/h
int inserted() const
Definition: MSCalibrator.h:217