SUMO - Simulation of Urban MObility
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
MSCalibrator.h
Go to the documentation of this file.
1 /****************************************************************************/
8 // Calibrates the flow on an edge by removing an inserting vehicles
9 /****************************************************************************/
10 // SUMO, Simulation of Urban MObility; see http://sumo-sim.org/
11 // Copyright (C) 2001-2011 DLR (http://www.dlr.de/) and contributors
12 /****************************************************************************/
13 //
14 // This program is free software; you can redistribute it and/or modify
15 // it under the terms of the GNU General Public License as published by
16 // the Free Software Foundation; either version 2 of the License, or
17 // (at your option) any later version.
18 //
19 /****************************************************************************/
20 #ifndef MSCalibrator_h
21 #define MSCalibrator_h
22 
23 
24 // ===========================================================================
25 // included modules
26 // ===========================================================================
27 #ifdef _MSC_VER
28 #include <windows_config.h>
29 #else
30 #include <config.h>
31 #endif
32 
33 #include <string>
34 #include <vector>
36 #include <utils/common/Command.h>
40 
41 
42 // ===========================================================================
43 // class definitions
44 // ===========================================================================
49 class MSCalibrator : public MSTrigger, public MSRouteHandler, public Command {
50 public:
52  MSCalibrator(const std::string& id,
53  MSEdge* edge, SUMOReal pos,
54  const std::string& aXMLFilename,
55  const std::string& outputFilename,
56  const SUMOTime freq);
57 
59  virtual ~MSCalibrator();
60 
61 
64  SUMOTime execute(SUMOTime currentTime);
65 
67  static void cleanup();
68 
69 
70 
71 protected:
73 
74 
82  virtual void myStartElement(int element,
83  const SUMOSAXAttributes& attrs);
84 
91  virtual void myEndElement(int element);
93 
94 
95 
96  class VehicleRemover : public MSMoveReminder {
97  public:
98  VehicleRemover(MSLane* lane, int laneIndex, MSCalibrator* parent) :
99  MSMoveReminder(parent->getID(), lane, true), myLaneIndex(laneIndex), myParent(parent) {}
100 
102 
103 
114  virtual bool notifyEnter(SUMOVehicle& veh, Notification reason);
115 
116  void disable() {
117  myParent = 0;
118  }
119 
120  private:
123  };
124  friend class VehicleRemover;
125 
126  // @return whether the current state is active (GUI)
127  bool isActive() const {
128  return myAmActive;
129  }
130 
131 protected:
132 
133  struct AspiredState {
134  AspiredState() : begin(-1), end(-1), q(-1.), v(-1.), vehicleParameter(0) {}
140  };
141 
142  void writeXMLOutput();
143 
144  bool isCurrentStateActive(SUMOTime time);
145 
146  bool tryEmit(MSLane* lane, MSVehicle* vehicle);
147 
148  void init();
149 
150  inline int passed() const {
151  // calibrator measures at start of segment
152  // vehicles drive to the end of an edge by default so they count as passed
153  // but vaporized vehicles do not count
154  // if the calibrator is located on a short edge, the vehicles are
155  // vaporized on the next edge so we cannot rely on myEdgeMeanData.nVehVaporized
157  }
158 
160  int totalWished() const;
161 
162  /* @brief returns whether the lane is jammed although it should not be
163  * @param[in] lane The lane to check or all for negative values
164  */
165  bool invalidJam(int laneIndex = -1) const;
166 
167  inline int inserted() const {
168  return myInserted;
169  }
170  inline int removed() const {
171  return myRemoved;
172  }
173  inline int clearedInJam() const {
174  return myClearedInJam;
175  }
176 
177  /* @brief returns the number of vehicles (of the current type) that still
178  * fit on the given lane
179  * @param[in] lane The lane to check (return the maximum of all lanes for negative values)
180  */
181  int remainingVehicleCapacity(int laneIndex = -1) const;
182 
184  void reset();
185 
187  void updateMeanData();
188 
192  return myToRemove.insert(veh).second;
193  };
194 
195 protected:
197  MSEdge* const myEdge;
201  std::vector<MSMeanData_Net::MSLaneMeanDataValues*> myLaneMeanData;
205  std::vector<AspiredState> myIntervals;
207  std::vector<AspiredState>::const_iterator myCurrentStateInterval;
208 
209  std::vector<VehicleRemover*> myVehicleRemovers;
210 
211  std::set<MSVehicle*> myToRemove;
212 
215 
219  unsigned int myRemoved;
221  unsigned int myInserted;
223  unsigned int myClearedInJam;
229  bool myDidInit;
234 
237 
238  /* @brief objects which need to live longer than the MSCalibrator
239  * instance which created them */
240  static std::vector<MSMoveReminder*> LeftoverReminders;
241  static std::vector<SUMOVehicleParameter*> LeftoverVehicleParameters;
242 
243 };
244 
245 #endif
246 
247 /****************************************************************************/
MSEdge *const myEdge
the edge on which this calibrator lies
Definition: MSCalibrator.h:193
Representation of a vehicle in the micro simulation.
Definition: MSVehicle.h:77
VehicleRemover(MSLane *lane, int laneIndex, MSCalibrator *parent)
Definition: MSCalibrator.h:98
bool tryEmit(MSLane *lane, MSVehicle *vehicle)
static std::vector< SUMOVehicleParameter * > LeftoverVehicleParameters
Definition: MSCalibrator.h:241
int inserted() const
Definition: MSCalibrator.h:167
virtual void myEndElement(int element)
Called on the closing of a tag;.
unsigned int myClearedInJam
The number of vehicles that were removed when clearin a jam.
Definition: MSCalibrator.h:223
bool myDidSpeedAdaption
The information whether speed was adapted in the current interval.
Definition: MSCalibrator.h:227
int removed() const
Definition: MSCalibrator.h:170
virtual bool notifyEnter(SUMOVehicle &veh, Notification reason)
Checks whether the reminder is activated by a vehicle entering the lane.
Notification
Definition of a vehicle state.
bool myAmActive
whether the calibrator was active when last checking
Definition: MSCalibrator.h:236
std::set< MSVehicle * > myToRemove
Definition: MSCalibrator.h:211
bool myDidInit
The information whether init was called.
Definition: MSCalibrator.h:229
const SUMOReal myPos
the position on the edge where this calibrator lies
Definition: MSCalibrator.h:199
int remainingVehicleCapacity(int laneIndex=-1) const
SUMOTime myFrequency
The frequeny with which to check for calibration.
Definition: MSCalibrator.h:217
Base (microsim) event class.
Definition: Command.h:61
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
Returns the id.
Definition: Named.h:60
A road/street connecting two junctions.
Definition: MSEdge.h:73
int passed() const
Definition: MSCalibrator.h:150
unsigned int myInserted
The number of vehicles that were inserted in the current interval.
Definition: MSCalibrator.h:221
std::vector< AspiredState >::const_iterator myCurrentStateInterval
Iterator pointing to the current interval.
Definition: MSCalibrator.h:207
An abstract device that changes the state of the micro simulation.
Definition: MSTrigger.h:48
void writeXMLOutput()
Representation of a vehicle.
Definition: SUMOVehicle.h:63
Encapsulated SAX-Attributes.
MSCalibrator(const std::string &id, MSEdge *edge, SUMOReal pos, const std::string &aXMLFilename, const std::string &outputFilename, const SUMOTime freq)
unsigned nVehEntered
The number of vehicles that entered this lane within the sample interval.
bool mySpeedIsDefault
The information whether the speed adaption has been reset.
Definition: MSCalibrator.h:225
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:191
std::vector< AspiredState > myIntervals
List of adaptation intervals.
Definition: MSCalibrator.h:205
void reset()
reset collected vehicle data
bool myHaveWarnedAboutClearingJam
The default (maximum) speed on the segment.
Definition: MSCalibrator.h:233
std::vector< MSMeanData_Net::MSLaneMeanDataValues * > myLaneMeanData
data collector for the calibrator
Definition: MSCalibrator.h:201
static std::vector< MSMoveReminder * > LeftoverReminders
Definition: MSCalibrator.h:240
Structure representing possible vehicle parameter.
bool invalidJam(int laneIndex=-1) const
SUMOVehicleParameter * vehicleParameter
Definition: MSCalibrator.h:139
static void cleanup()
cleanup remaining data structures
OutputDevice * myOutput
The device for xml statistics.
Definition: MSCalibrator.h:214
void updateMeanData()
aggregate lane values
virtual ~MSCalibrator()
Calibrates the flow on a segment to a specified one.
Definition: MSCalibrator.h:49
SUMOTime execute(SUMOTime currentTime)
Static storage of an output device and its base (abstract) implementation.
Definition: OutputDevice.h:70
#define SUMOReal
Definition: config.h:221
int totalWished() const
number of vehicles expected to pass this interval
MSMeanData_Net::MSLaneMeanDataValues myEdgeMeanData
accumlated data for the whole edge
Definition: MSCalibrator.h:203
bool isCurrentStateActive(SUMOTime time)
std::vector< VehicleRemover * > myVehicleRemovers
Definition: MSCalibrator.h:209
bool isActive() const
Definition: MSCalibrator.h:127
int clearedInJam() const
Definition: MSCalibrator.h:173
Representation of a lane in the micro simulation.
Definition: MSLane.h:73
unsigned int myRemoved
The number of vehicles that were removed in the current interval.
Definition: MSCalibrator.h:219
Parser and container for routes during their loading.
SUMOReal myDefaultSpeed
The default (maximum) speed on the segment.
Definition: MSCalibrator.h:231