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-2018 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>
34 
35 
36 // ===========================================================================
37 // class declarations
38 // ===========================================================================
39 class OutputDevice;
40 class MSRouteProbe;
41 
42 
43 // ===========================================================================
44 // class definitions
45 // ===========================================================================
50 class MSCalibrator : public MSTrigger, public MSRouteHandler, public Command {
51 public:
53  MSCalibrator(const std::string& id,
54  const MSEdge* const edge,
55  MSLane* lane,
56  const double pos,
57  const std::string& aXMLFilename,
58  const std::string& outputFilename,
59  const SUMOTime freq, const double length,
60  const MSRouteProbe* probe,
61  bool addLaneMeanData = true);
62 
64  virtual ~MSCalibrator();
65 
66 
69  virtual SUMOTime execute(SUMOTime currentTime);
70 
72  static void cleanup();
73 
74 
75 
76 protected:
77  class CalibratorCommand : public Command {
78  public:
80  myCalibrator(cali) {}
81 
82  SUMOTime execute(SUMOTime currentTime) {
83  return myCalibrator->execute(currentTime);
84  }
85 
86  private:
88  };
89 
90 
92 
93 
101  virtual void myStartElement(int element,
102  const SUMOSAXAttributes& attrs);
103 
110  virtual void myEndElement(int element);
112 
113 
114 
116  public:
117  VehicleRemover(MSLane* lane, int laneIndex, MSCalibrator* parent) :
118  MSMoveReminder(parent->getID(), lane, true), myLaneIndex(laneIndex), myParent(parent) {}
119 
121 
122 
133  virtual bool notifyEnter(SUMOVehicle& veh, MSMoveReminder::Notification reason, const MSLane* enteredLane = 0);
134 
135  void disable() {
136  myParent = 0;
137  }
138 
139  private:
142  };
143  friend class VehicleRemover;
144 
145  // @return whether the current state is active (GUI)
146  bool isActive() const {
147  return myAmActive;
148  }
149 
150 protected:
151 
152  struct AspiredState {
153  AspiredState() : begin(-1), end(-1), q(-1.), v(-1.), vehicleParameter(0) {}
156  double q;
157  double v;
159  };
160 
161  void writeXMLOutput();
162 
163  bool isCurrentStateActive(SUMOTime time);
164 
165  bool tryEmit(MSLane* lane, MSVehicle* vehicle);
166 
167  void init();
168 
169  inline virtual int passed() const {
170  // calibrator measures at start of segment
171  // vehicles drive to the end of an edge by default so they count as passed
172  // but vaporized vehicles do not count
173  // if the calibrator is located on a short edge, the vehicles are
174  // vaporized on the next edge so we cannot rely on myEdgeMeanData.nVehVaporized
176  }
177 
179  int totalWished() const;
180 
182  double currentFlow() const;
183 
185  double currentSpeed() const;
186 
187  /* @brief returns whether the lane is jammed although it should not be
188  * @param[in] lane The lane to check or all for negative values
189  */
190  bool invalidJam(int laneIndex) const;
191 
192  inline int inserted() const {
193  return myInserted;
194  }
195  inline int removed() const {
196  return myRemoved;
197  }
198  inline int clearedInJam() const {
199  return myClearedInJam;
200  }
201 
202  /* @brief returns the number of vehicles (of the current type) that still
203  * fit on the given lane
204  * @param[in] lane The lane to check (return the maximum of all lanes for negative values)
205  */
206  int remainingVehicleCapacity(int laneIndex) const;
207 
209  virtual void reset();
210 
212  virtual void updateMeanData();
213 
217  return myToRemove.insert(veh->getID()).second;
218  };
219 
220 
223  bool removePending();
224 
225 protected:
227  const MSEdge* const myEdge;
229  MSLane* const myLane;
231  const double myPos;
233  const MSRouteProbe* const myProbe;
235  std::vector<MSMeanData_Net::MSLaneMeanDataValues*> myLaneMeanData;
239  std::vector<AspiredState> myIntervals;
241  std::vector<AspiredState>::const_iterator myCurrentStateInterval;
242 
243  std::vector<VehicleRemover*> myVehicleRemovers;
244 
249  std::set<std::string> myToRemove;
250 
253 
267  bool myDidInit;
272 
275 
276  /* @brief objects which need to live longer than the MSCalibrator
277  * instance which created them */
278  static std::vector<MSMoveReminder*> LeftoverReminders;
279  static std::vector<SUMOVehicleParameter*> LeftoverVehicleParameters;
280 
281 };
282 
283 #endif
284 
285 /****************************************************************************/
SUMOTime execute(SUMOTime currentTime)
Executes the command.
Definition: MSCalibrator.h:82
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:79
long long int SUMOTime
Definition: SUMOTime.h:36
VehicleRemover(MSLane *lane, int laneIndex, MSCalibrator *parent)
Definition: MSCalibrator.h:117
bool tryEmit(MSLane *lane, MSVehicle *vehicle)
static std::vector< SUMOVehicleParameter * > LeftoverVehicleParameters
Definition: MSCalibrator.h:279
virtual int passed() const
Definition: MSCalibrator.h:169
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:265
Notification
Definition of a vehicle state.
bool myAmActive
whether the calibrator was active when last checking
Definition: MSCalibrator.h:274
bool myDidInit
The information whether init was called.
Definition: MSCalibrator.h:267
const std::string & getID() const
Returns the id.
Definition: Named.h:78
SUMOTime myFrequency
The frequeny with which to check for calibration.
Definition: MSCalibrator.h:255
int myRemoved
The number of vehicles that were removed in the current interval.
Definition: MSCalibrator.h:257
Base (microsim) event class.
Definition: Command.h:54
CalibratorCommand(MSCalibrator *cali)
Definition: MSCalibrator.h:79
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:261
const MSEdge *const myEdge
the edge on which this calibrator lies
Definition: MSCalibrator.h:227
virtual void myStartElement(int element, const SUMOSAXAttributes &attrs)
Called on the opening of a tag;.
Data structure for mean (aggregated) edge/lane values.
int totalWished() const
number of vehicles expected to pass this interval
A road/street connecting two junctions.
Definition: MSEdge.h:75
std::vector< AspiredState >::const_iterator myCurrentStateInterval
Iterator pointing to the current interval.
Definition: MSCalibrator.h:241
An abstract device that changes the state of the micro simulation.
Definition: MSTrigger.h:41
void writeXMLOutput()
Representation of a vehicle.
Definition: SUMOVehicle.h:60
Encapsulated SAX-Attributes.
double myDefaultSpeed
The default (maximum) speed on the segment.
Definition: MSCalibrator.h:269
bool mySpeedIsDefault
The information whether the speed adaption has been reset.
Definition: MSCalibrator.h:263
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:216
bool isActive() const
Definition: MSCalibrator.h:146
std::vector< AspiredState > myIntervals
List of adaptation intervals.
Definition: MSCalibrator.h:239
virtual void reset()
reset collected vehicle data
bool myHaveWarnedAboutClearingJam
The default (maximum) speed on the segment.
Definition: MSCalibrator.h:271
MSLane *const myLane
the lane on which this calibrator lies (0 if the whole edge is covered at once)
Definition: MSCalibrator.h:229
bool invalidJam(int laneIndex) const
std::vector< MSMeanData_Net::MSLaneMeanDataValues * > myLaneMeanData
data collector for the calibrator
Definition: MSCalibrator.h:235
static std::vector< MSMoveReminder * > LeftoverReminders
Definition: MSCalibrator.h:278
Structure representing possible vehicle parameter.
const double myPos
the position on the edge where this calibrator lies
Definition: MSCalibrator.h:231
SUMOVehicleParameter * vehicleParameter
Definition: MSCalibrator.h:158
int clearedInJam() const
Definition: MSCalibrator.h:198
const MSRouteProbe *const myProbe
the route probe to retrieve routes from
Definition: MSCalibrator.h:233
static void cleanup()
cleanup remaining data structures
OutputDevice * myOutput
The device for xml statistics.
Definition: MSCalibrator.h:252
virtual void updateMeanData()
aggregate lane values
virtual ~MSCalibrator()
Calibrates the flow on a segment to a specified one.
Definition: MSCalibrator.h:50
virtual SUMOTime execute(SUMOTime currentTime)
Static storage of an output device and its base (abstract) implementation.
Definition: OutputDevice.h:64
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:237
bool isCurrentStateActive(SUMOTime time)
std::vector< VehicleRemover * > myVehicleRemovers
Definition: MSCalibrator.h:243
int removed() const
Definition: MSCalibrator.h:195
int remainingVehicleCapacity(int laneIndex) const
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, bool addLaneMeanData=true)
const std::string & getID() const
Returns the name of the vehicle.
Representation of a lane in the micro simulation.
Definition: MSLane.h:78
std::set< std::string > myToRemove
set of vehicle ids to remove
Definition: MSCalibrator.h:249
Parser and container for routes during their loading.
int myInserted
The number of vehicles that were inserted in the current interval.
Definition: MSCalibrator.h:259
double currentFlow() const
flow in the current interval in veh/h
int inserted() const
Definition: MSCalibrator.h:192