SUMO - Simulation of Urban MObility
MSCalibrator.h
Go to the documentation of this file.
1 /****************************************************************************/
9 // Calibrates the flow on an edge by removing an inserting vehicles
10 /****************************************************************************/
11 // SUMO, Simulation of Urban MObility; see http://sumo.dlr.de/
12 // Copyright (C) 2005-2017 DLR (http://www.dlr.de/) and contributors
13 /****************************************************************************/
14 //
15 // This file is part of SUMO.
16 // SUMO is free software: you can redistribute it and/or modify
17 // it under the terms of the GNU General Public License as published by
18 // the Free Software Foundation, either version 3 of the License, or
19 // (at your option) any later version.
20 //
21 /****************************************************************************/
22 #ifndef MSCalibrator_h
23 #define MSCalibrator_h
24 
25 
26 // ===========================================================================
27 // included modules
28 // ===========================================================================
29 #ifdef _MSC_VER
30 #include <windows_config.h>
31 #else
32 #include <config.h>
33 #endif
34 
35 #include <string>
36 #include <vector>
37 #include <utils/common/Command.h>
41 
42 
43 // ===========================================================================
44 // class declarations
45 // ===========================================================================
46 class OutputDevice;
47 class MSRouteProbe;
48 
49 
50 // ===========================================================================
51 // class definitions
52 // ===========================================================================
57 class MSCalibrator : public MSTrigger, public MSRouteHandler, public Command {
58 public:
60  MSCalibrator(const std::string& id,
61  const MSEdge* const edge,
62  MSLane* lane,
63  const double pos,
64  const std::string& aXMLFilename,
65  const std::string& outputFilename,
66  const SUMOTime freq, const double length,
67  const MSRouteProbe* probe,
68  bool addLaneMeanData = true);
69 
71  virtual ~MSCalibrator();
72 
73 
76  virtual SUMOTime execute(SUMOTime currentTime);
77 
79  static void cleanup();
80 
81 
82 
83 protected:
84  class CalibratorCommand : public Command {
85  public:
87  myCalibrator(cali) {}
88 
89  SUMOTime execute(SUMOTime currentTime) {
90  return myCalibrator->execute(currentTime);
91  }
92 
93  private:
95  };
96 
97 
99 
100 
108  virtual void myStartElement(int element,
109  const SUMOSAXAttributes& attrs);
110 
117  virtual void myEndElement(int element);
119 
120 
121 
123  public:
124  VehicleRemover(MSLane* lane, int laneIndex, MSCalibrator* parent) :
125  MSMoveReminder(parent->getID(), lane, true), myLaneIndex(laneIndex), myParent(parent) {}
126 
128 
129 
140  virtual bool notifyEnter(SUMOVehicle& veh, MSMoveReminder::Notification reason, const MSLane* enteredLane = 0);
141 
142  void disable() {
143  myParent = 0;
144  }
145 
146  private:
149  };
150  friend class VehicleRemover;
151 
152  // @return whether the current state is active (GUI)
153  bool isActive() const {
154  return myAmActive;
155  }
156 
157 protected:
158 
159  struct AspiredState {
160  AspiredState() : begin(-1), end(-1), q(-1.), v(-1.), vehicleParameter(0) {}
163  double q;
164  double v;
166  };
167 
168  void writeXMLOutput();
169 
170  bool isCurrentStateActive(SUMOTime time);
171 
172  bool tryEmit(MSLane* lane, MSVehicle* vehicle);
173 
174  void init();
175 
176  inline virtual int passed() const {
177  // calibrator measures at start of segment
178  // vehicles drive to the end of an edge by default so they count as passed
179  // but vaporized vehicles do not count
180  // if the calibrator is located on a short edge, the vehicles are
181  // vaporized on the next edge so we cannot rely on myEdgeMeanData.nVehVaporized
183  }
184 
186  int totalWished() const;
187 
189  double currentFlow() const;
190 
192  double currentSpeed() const;
193 
194  /* @brief returns whether the lane is jammed although it should not be
195  * @param[in] lane The lane to check or all for negative values
196  */
197  bool invalidJam(int laneIndex) const;
198 
199  inline int inserted() const {
200  return myInserted;
201  }
202  inline int removed() const {
203  return myRemoved;
204  }
205  inline int clearedInJam() const {
206  return myClearedInJam;
207  }
208 
209  /* @brief returns the number of vehicles (of the current type) that still
210  * fit on the given lane
211  * @param[in] lane The lane to check (return the maximum of all lanes for negative values)
212  */
213  int remainingVehicleCapacity(int laneIndex) const;
214 
216  virtual void reset();
217 
219  virtual void updateMeanData();
220 
224  return myToRemove.insert(veh->getID()).second;
225  };
226 
227 
230  bool removePending();
231 
232 protected:
234  const MSEdge* const myEdge;
236  MSLane* const myLane;
238  const double myPos;
240  const MSRouteProbe* const myProbe;
242  std::vector<MSMeanData_Net::MSLaneMeanDataValues*> myLaneMeanData;
246  std::vector<AspiredState> myIntervals;
248  std::vector<AspiredState>::const_iterator myCurrentStateInterval;
249 
250  std::vector<VehicleRemover*> myVehicleRemovers;
251 
256  std::set<std::string> myToRemove;
257 
260 
274  bool myDidInit;
279 
282 
283  /* @brief objects which need to live longer than the MSCalibrator
284  * instance which created them */
285  static std::vector<MSMoveReminder*> LeftoverReminders;
286  static std::vector<SUMOVehicleParameter*> LeftoverVehicleParameters;
287 
288 };
289 
290 #endif
291 
292 /****************************************************************************/
SUMOTime execute(SUMOTime currentTime)
Executes the command.
Definition: MSCalibrator.h:89
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:124
bool tryEmit(MSLane *lane, MSVehicle *vehicle)
static std::vector< SUMOVehicleParameter * > LeftoverVehicleParameters
Definition: MSCalibrator.h:286
int inserted() const
Definition: MSCalibrator.h:199
virtual void myEndElement(int element)
Called on the closing of a tag;.
Writes routes of vehicles passing a certain edge.
Definition: MSRouteProbe.h:68
bool myDidSpeedAdaption
The information whether speed was adapted in the current interval.
Definition: MSCalibrator.h:272
int removed() const
Definition: MSCalibrator.h:202
Notification
Definition of a vehicle state.
bool myAmActive
whether the calibrator was active when last checking
Definition: MSCalibrator.h:281
bool myDidInit
The information whether init was called.
Definition: MSCalibrator.h:274
SUMOTime myFrequency
The frequeny with which to check for calibration.
Definition: MSCalibrator.h:262
int myRemoved
The number of vehicles that were removed in the current interval.
Definition: MSCalibrator.h:264
Base (microsim) event class.
Definition: Command.h:61
CalibratorCommand(MSCalibrator *cali)
Definition: MSCalibrator.h:86
int myClearedInJam
The number of vehicles that were removed when clearin a jam.
Definition: MSCalibrator.h:268
const MSEdge *const myEdge
the edge on which this calibrator lies
Definition: MSCalibrator.h:234
virtual void myStartElement(int element, const SUMOSAXAttributes &attrs)
Called on the opening of a tag;.
Data structure for mean (aggregated) edge/lane values.
int remainingVehicleCapacity(int laneIndex) const
const std::string & getID() const
Returns the id.
Definition: Named.h:66
A road/street connecting two junctions.
Definition: MSEdge.h:81
std::vector< AspiredState >::const_iterator myCurrentStateInterval
Iterator pointing to the current interval.
Definition: MSCalibrator.h:248
An abstract device that changes the state of the micro simulation.
Definition: MSTrigger.h:48
void writeXMLOutput()
Representation of a vehicle.
Definition: SUMOVehicle.h:67
Encapsulated SAX-Attributes.
double currentFlow() const
flow in the current interval in veh/h
bool invalidJam(int laneIndex) const
double myDefaultSpeed
The default (maximum) speed on the segment.
Definition: MSCalibrator.h:276
bool mySpeedIsDefault
The information whether the speed adaption has been reset.
Definition: MSCalibrator.h:270
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:223
std::vector< AspiredState > myIntervals
List of adaptation intervals.
Definition: MSCalibrator.h:246
virtual void reset()
reset collected vehicle data
bool myHaveWarnedAboutClearingJam
The default (maximum) speed on the segment.
Definition: MSCalibrator.h:278
MSLane *const myLane
the lane on which this calibrator lies (0 if the whole edge is covered at once)
Definition: MSCalibrator.h:236
std::vector< MSMeanData_Net::MSLaneMeanDataValues * > myLaneMeanData
data collector for the calibrator
Definition: MSCalibrator.h:242
static std::vector< MSMoveReminder * > LeftoverReminders
Definition: MSCalibrator.h:285
Structure representing possible vehicle parameter.
const double myPos
the position on the edge where this calibrator lies
Definition: MSCalibrator.h:238
SUMOVehicleParameter * vehicleParameter
Definition: MSCalibrator.h:165
const MSRouteProbe *const myProbe
the route probe to retrieve routes from
Definition: MSCalibrator.h:240
static void cleanup()
cleanup remaining data structures
OutputDevice * myOutput
The device for xml statistics.
Definition: MSCalibrator.h:259
virtual void updateMeanData()
aggregate lane values
virtual int passed() const
Definition: MSCalibrator.h:176
virtual ~MSCalibrator()
Calibrates the flow on a segment to a specified one.
Definition: MSCalibrator.h:57
virtual SUMOTime execute(SUMOTime currentTime)
Static storage of an output device and its base (abstract) implementation.
Definition: OutputDevice.h:71
double currentSpeed() const
measured speed in the current interval
long long int SUMOTime
Definition: TraCIDefs.h:52
bool removePending()
remove any vehicles which are scheduled for removal. return true if removals took place ...
int totalWished() const
number of vehicles expected to pass this interval
MSMeanData_Net::MSLaneMeanDataValues myEdgeMeanData
accumlated data for the whole edge
Definition: MSCalibrator.h:244
bool isCurrentStateActive(SUMOTime time)
std::vector< VehicleRemover * > myVehicleRemovers
Definition: MSCalibrator.h:250
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)
bool isActive() const
Definition: MSCalibrator.h:153
int clearedInJam() const
Definition: MSCalibrator.h:205
Representation of a lane in the micro simulation.
Definition: MSLane.h:79
std::set< std::string > myToRemove
set of vehicle ids to remove
Definition: MSCalibrator.h:256
Parser and container for routes during their loading.
int myInserted
The number of vehicles that were inserted in the current interval.
Definition: MSCalibrator.h:266
const std::string & getID() const
Returns the name of the vehicle.