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-2017 German Aerospace Center (DLR) and others.
4 /****************************************************************************/
5 //
6 // This program and the accompanying materials
7 // are made available under the terms of the Eclipse Public License v2.0
8 // which accompanies this distribution, and is available at
9 // http://www.eclipse.org/legal/epl-v20.html
10 //
11 /****************************************************************************/
19 // Calibrates the flow on an edge by removing an inserting vehicles
20 /****************************************************************************/
21 #ifndef MSCalibrator_h
22 #define MSCalibrator_h
23 
24 
25 // ===========================================================================
26 // included modules
27 // ===========================================================================
28 #ifdef _MSC_VER
29 #include <windows_config.h>
30 #else
31 #include <config.h>
32 #endif
33 
34 #include <string>
35 #include <vector>
36 #include <utils/common/Command.h>
40 
41 
42 // ===========================================================================
43 // class declarations
44 // ===========================================================================
45 class OutputDevice;
46 class MSRouteProbe;
47 
48 
49 // ===========================================================================
50 // class definitions
51 // ===========================================================================
56 class MSCalibrator : public MSTrigger, public MSRouteHandler, public Command {
57 public:
59  MSCalibrator(const std::string& id,
60  const MSEdge* const edge,
61  MSLane* lane,
62  const double pos,
63  const std::string& aXMLFilename,
64  const std::string& outputFilename,
65  const SUMOTime freq, const double length,
66  const MSRouteProbe* probe,
67  bool addLaneMeanData = true);
68 
70  virtual ~MSCalibrator();
71 
72 
75  virtual SUMOTime execute(SUMOTime currentTime);
76 
78  static void cleanup();
79 
80 
81 
82 protected:
83  class CalibratorCommand : public Command {
84  public:
86  myCalibrator(cali) {}
87 
88  SUMOTime execute(SUMOTime currentTime) {
89  return myCalibrator->execute(currentTime);
90  }
91 
92  private:
94  };
95 
96 
98 
99 
107  virtual void myStartElement(int element,
108  const SUMOSAXAttributes& attrs);
109 
116  virtual void myEndElement(int element);
118 
119 
120 
122  public:
123  VehicleRemover(MSLane* lane, int laneIndex, MSCalibrator* parent) :
124  MSMoveReminder(parent->getID(), lane, true), myLaneIndex(laneIndex), myParent(parent) {}
125 
127 
128 
139  virtual bool notifyEnter(SUMOVehicle& veh, MSMoveReminder::Notification reason, const MSLane* enteredLane = 0);
140 
141  void disable() {
142  myParent = 0;
143  }
144 
145  private:
148  };
149  friend class VehicleRemover;
150 
151  // @return whether the current state is active (GUI)
152  bool isActive() const {
153  return myAmActive;
154  }
155 
156 protected:
157 
158  struct AspiredState {
159  AspiredState() : begin(-1), end(-1), q(-1.), v(-1.), vehicleParameter(0) {}
162  double q;
163  double v;
165  };
166 
167  void writeXMLOutput();
168 
169  bool isCurrentStateActive(SUMOTime time);
170 
171  bool tryEmit(MSLane* lane, MSVehicle* vehicle);
172 
173  void init();
174 
175  inline virtual int passed() const {
176  // calibrator measures at start of segment
177  // vehicles drive to the end of an edge by default so they count as passed
178  // but vaporized vehicles do not count
179  // if the calibrator is located on a short edge, the vehicles are
180  // vaporized on the next edge so we cannot rely on myEdgeMeanData.nVehVaporized
182  }
183 
185  int totalWished() const;
186 
188  double currentFlow() const;
189 
191  double currentSpeed() const;
192 
193  /* @brief returns whether the lane is jammed although it should not be
194  * @param[in] lane The lane to check or all for negative values
195  */
196  bool invalidJam(int laneIndex) const;
197 
198  inline int inserted() const {
199  return myInserted;
200  }
201  inline int removed() const {
202  return myRemoved;
203  }
204  inline int clearedInJam() const {
205  return myClearedInJam;
206  }
207 
208  /* @brief returns the number of vehicles (of the current type) that still
209  * fit on the given lane
210  * @param[in] lane The lane to check (return the maximum of all lanes for negative values)
211  */
212  int remainingVehicleCapacity(int laneIndex) const;
213 
215  virtual void reset();
216 
218  virtual void updateMeanData();
219 
223  return myToRemove.insert(veh->getID()).second;
224  };
225 
226 
229  bool removePending();
230 
231 protected:
233  const MSEdge* const myEdge;
235  MSLane* const myLane;
237  const double myPos;
239  const MSRouteProbe* const myProbe;
241  std::vector<MSMeanData_Net::MSLaneMeanDataValues*> myLaneMeanData;
245  std::vector<AspiredState> myIntervals;
247  std::vector<AspiredState>::const_iterator myCurrentStateInterval;
248 
249  std::vector<VehicleRemover*> myVehicleRemovers;
250 
255  std::set<std::string> myToRemove;
256 
259 
273  bool myDidInit;
278 
281 
282  /* @brief objects which need to live longer than the MSCalibrator
283  * instance which created them */
284  static std::vector<MSMoveReminder*> LeftoverReminders;
285  static std::vector<SUMOVehicleParameter*> LeftoverVehicleParameters;
286 
287 };
288 
289 #endif
290 
291 /****************************************************************************/
SUMOTime execute(SUMOTime currentTime)
Executes the command.
Definition: MSCalibrator.h:88
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:83
VehicleRemover(MSLane *lane, int laneIndex, MSCalibrator *parent)
Definition: MSCalibrator.h:123
bool tryEmit(MSLane *lane, MSVehicle *vehicle)
static std::vector< SUMOVehicleParameter * > LeftoverVehicleParameters
Definition: MSCalibrator.h:285
virtual int passed() const
Definition: MSCalibrator.h:175
virtual void myEndElement(int element)
Called on the closing of a tag;.
Writes routes of vehicles passing a certain edge.
Definition: MSRouteProbe.h:67
bool myDidSpeedAdaption
The information whether speed was adapted in the current interval.
Definition: MSCalibrator.h:271
Notification
Definition of a vehicle state.
bool myAmActive
whether the calibrator was active when last checking
Definition: MSCalibrator.h:280
bool myDidInit
The information whether init was called.
Definition: MSCalibrator.h:273
const std::string & getID() const
Returns the id.
Definition: Named.h:65
SUMOTime myFrequency
The frequeny with which to check for calibration.
Definition: MSCalibrator.h:261
int myRemoved
The number of vehicles that were removed in the current interval.
Definition: MSCalibrator.h:263
Base (microsim) event class.
Definition: Command.h:60
CalibratorCommand(MSCalibrator *cali)
Definition: MSCalibrator.h:85
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:267
const MSEdge *const myEdge
the edge on which this calibrator lies
Definition: MSCalibrator.h:233
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:80
std::vector< AspiredState >::const_iterator myCurrentStateInterval
Iterator pointing to the current interval.
Definition: MSCalibrator.h:247
An abstract device that changes the state of the micro simulation.
Definition: MSTrigger.h:47
void writeXMLOutput()
Representation of a vehicle.
Definition: SUMOVehicle.h:66
Encapsulated SAX-Attributes.
double myDefaultSpeed
The default (maximum) speed on the segment.
Definition: MSCalibrator.h:275
bool mySpeedIsDefault
The information whether the speed adaption has been reset.
Definition: MSCalibrator.h:269
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:222
bool isActive() const
Definition: MSCalibrator.h:152
std::vector< AspiredState > myIntervals
List of adaptation intervals.
Definition: MSCalibrator.h:245
virtual void reset()
reset collected vehicle data
bool myHaveWarnedAboutClearingJam
The default (maximum) speed on the segment.
Definition: MSCalibrator.h:277
MSLane *const myLane
the lane on which this calibrator lies (0 if the whole edge is covered at once)
Definition: MSCalibrator.h:235
bool invalidJam(int laneIndex) const
std::vector< MSMeanData_Net::MSLaneMeanDataValues * > myLaneMeanData
data collector for the calibrator
Definition: MSCalibrator.h:241
static std::vector< MSMoveReminder * > LeftoverReminders
Definition: MSCalibrator.h:284
Structure representing possible vehicle parameter.
const double myPos
the position on the edge where this calibrator lies
Definition: MSCalibrator.h:237
SUMOVehicleParameter * vehicleParameter
Definition: MSCalibrator.h:164
int clearedInJam() const
Definition: MSCalibrator.h:204
const MSRouteProbe *const myProbe
the route probe to retrieve routes from
Definition: MSCalibrator.h:239
static void cleanup()
cleanup remaining data structures
OutputDevice * myOutput
The device for xml statistics.
Definition: MSCalibrator.h:258
virtual void updateMeanData()
aggregate lane values
virtual ~MSCalibrator()
Calibrates the flow on a segment to a specified one.
Definition: MSCalibrator.h:56
virtual SUMOTime execute(SUMOTime currentTime)
Static storage of an output device and its base (abstract) implementation.
Definition: OutputDevice.h:70
long long int SUMOTime
Definition: TraCIDefs.h:51
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:243
bool isCurrentStateActive(SUMOTime time)
std::vector< VehicleRemover * > myVehicleRemovers
Definition: MSCalibrator.h:249
int removed() const
Definition: MSCalibrator.h:201
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:77
std::set< std::string > myToRemove
set of vehicle ids to remove
Definition: MSCalibrator.h:255
Parser and container for routes during their loading.
int myInserted
The number of vehicles that were inserted in the current interval.
Definition: MSCalibrator.h:265
double currentFlow() const
flow in the current interval in veh/h
int inserted() const
Definition: MSCalibrator.h:198