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-2015 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, const SUMOReal pos,
62  const std::string& aXMLFilename,
63  const std::string& outputFilename,
64  const SUMOTime freq, const SUMOReal length,
65  const MSRouteProbe* probe, const bool addLaneMeanData = true);
66 
68  virtual ~MSCalibrator();
69 
70 
73  virtual SUMOTime execute(SUMOTime currentTime);
74 
76  static void cleanup();
77 
78 
79 
80 protected:
82 
83 
91  virtual void myStartElement(int element,
92  const SUMOSAXAttributes& attrs);
93 
100  virtual void myEndElement(int element);
102 
103 
104 
106  public:
107  VehicleRemover(MSLane* lane, int laneIndex, MSCalibrator* parent) :
108  MSMoveReminder(parent->getID(), lane, true), myLaneIndex(laneIndex), myParent(parent) {}
109 
111 
112 
123  virtual bool notifyEnter(SUMOVehicle& veh, Notification reason);
124 
125  void disable() {
126  myParent = 0;
127  }
128 
129  private:
132  };
133  friend class VehicleRemover;
134 
135  // @return whether the current state is active (GUI)
136  bool isActive() const {
137  return myAmActive;
138  }
139 
140 protected:
141 
142  struct AspiredState {
143  AspiredState() : begin(-1), end(-1), q(-1.), v(-1.), vehicleParameter(0) {}
149  };
150 
151  void writeXMLOutput();
152 
153  bool isCurrentStateActive(SUMOTime time);
154 
155  bool tryEmit(MSLane* lane, MSVehicle* vehicle);
156 
157  void init();
158 
159  inline virtual int passed() const {
160  // calibrator measures at start of segment
161  // vehicles drive to the end of an edge by default so they count as passed
162  // but vaporized vehicles do not count
163  // if the calibrator is located on a short edge, the vehicles are
164  // vaporized on the next edge so we cannot rely on myEdgeMeanData.nVehVaporized
166  }
167 
169  int totalWished() const;
170 
171  /* @brief returns whether the lane is jammed although it should not be
172  * @param[in] lane The lane to check or all for negative values
173  */
174  bool invalidJam(int laneIndex) const;
175 
176  inline int inserted() const {
177  return myInserted;
178  }
179  inline int removed() const {
180  return myRemoved;
181  }
182  inline int clearedInJam() const {
183  return myClearedInJam;
184  }
185 
186  /* @brief returns the number of vehicles (of the current type) that still
187  * fit on the given lane
188  * @param[in] lane The lane to check (return the maximum of all lanes for negative values)
189  */
190  int remainingVehicleCapacity(int laneIndex) const;
191 
193  virtual void reset();
194 
196  virtual void updateMeanData();
197 
201  return myToRemove.insert(veh->getID()).second;
202  };
203 
204 
207  bool removePending();
208 
209 protected:
211  const MSEdge* const myEdge;
215  const MSRouteProbe* const myProbe;
217  std::vector<MSMeanData_Net::MSLaneMeanDataValues*> myLaneMeanData;
221  std::vector<AspiredState> myIntervals;
223  std::vector<AspiredState>::const_iterator myCurrentStateInterval;
224 
225  std::vector<VehicleRemover*> myVehicleRemovers;
226 
231  std::set<std::string> myToRemove;
232 
235 
239  unsigned int myRemoved;
241  unsigned int myInserted;
243  unsigned int myClearedInJam;
249  bool myDidInit;
254 
257 
258  /* @brief objects which need to live longer than the MSCalibrator
259  * instance which created them */
260  static std::vector<MSMoveReminder*> LeftoverReminders;
261  static std::vector<SUMOVehicleParameter*> LeftoverVehicleParameters;
262 
263 };
264 
265 #endif
266 
267 /****************************************************************************/
MSCalibrator(const std::string &id, const MSEdge *const edge, const SUMOReal pos, const std::string &aXMLFilename, const std::string &outputFilename, const SUMOTime freq, const SUMOReal length, const MSRouteProbe *probe, const bool addLaneMeanData=true)
Representation of a vehicle in the micro simulation.
Definition: MSVehicle.h:80
VehicleRemover(MSLane *lane, int laneIndex, MSCalibrator *parent)
Definition: MSCalibrator.h:107
bool tryEmit(MSLane *lane, MSVehicle *vehicle)
static std::vector< SUMOVehicleParameter * > LeftoverVehicleParameters
Definition: MSCalibrator.h:261
int inserted() const
Definition: MSCalibrator.h:176
virtual void myEndElement(int element)
Called on the closing of a tag;.
Writes routes of vehicles passing a certain edge.
Definition: MSRouteProbe.h:68
unsigned int myClearedInJam
The number of vehicles that were removed when clearin a jam.
Definition: MSCalibrator.h:243
bool myDidSpeedAdaption
The information whether speed was adapted in the current interval.
Definition: MSCalibrator.h:247
int removed() const
Definition: MSCalibrator.h:179
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:256
bool myDidInit
The information whether init was called.
Definition: MSCalibrator.h:249
const SUMOReal myPos
the position on the edge where this calibrator lies
Definition: MSCalibrator.h:213
SUMOTime myFrequency
The frequeny with which to check for calibration.
Definition: MSCalibrator.h:237
Base (microsim) event class.
Definition: Command.h:61
const MSEdge *const myEdge
the edge on which this calibrator lies
Definition: MSCalibrator.h:211
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:60
A road/street connecting two junctions.
Definition: MSEdge.h:81
unsigned int myInserted
The number of vehicles that were inserted in the current interval.
Definition: MSCalibrator.h:241
std::vector< AspiredState >::const_iterator myCurrentStateInterval
Iterator pointing to the current interval.
Definition: MSCalibrator.h:223
An abstract device that changes the state of the micro simulation.
Definition: MSTrigger.h:48
void writeXMLOutput()
Representation of a vehicle.
Definition: SUMOVehicle.h:65
Encapsulated SAX-Attributes.
bool invalidJam(int laneIndex) const
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:245
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't already scheduled ...
Definition: MSCalibrator.h:200
std::vector< AspiredState > myIntervals
List of adaptation intervals.
Definition: MSCalibrator.h:221
virtual void reset()
reset collected vehicle data
bool myHaveWarnedAboutClearingJam
The default (maximum) speed on the segment.
Definition: MSCalibrator.h:253
std::vector< MSMeanData_Net::MSLaneMeanDataValues * > myLaneMeanData
data collector for the calibrator
Definition: MSCalibrator.h:217
static std::vector< MSMoveReminder * > LeftoverReminders
Definition: MSCalibrator.h:260
Structure representing possible vehicle parameter.
SUMOVehicleParameter * vehicleParameter
Definition: MSCalibrator.h:148
int SUMOTime
Definition: SUMOTime.h:43
const MSRouteProbe *const myProbe
the route probe to retrieve routes from
Definition: MSCalibrator.h:215
static void cleanup()
cleanup remaining data structures
OutputDevice * myOutput
The device for xml statistics.
Definition: MSCalibrator.h:234
virtual void updateMeanData()
aggregate lane values
virtual int passed() const
Definition: MSCalibrator.h:159
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
#define SUMOReal
Definition: config.h:218
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:219
bool isCurrentStateActive(SUMOTime time)
std::vector< VehicleRemover * > myVehicleRemovers
Definition: MSCalibrator.h:225
bool isActive() const
Definition: MSCalibrator.h:136
int clearedInJam() const
Definition: MSCalibrator.h:182
Representation of a lane in the micro simulation.
Definition: MSLane.h:77
unsigned int myRemoved
The number of vehicles that were removed in the current interval.
Definition: MSCalibrator.h:239
std::set< std::string > myToRemove
set of vehicle ids to remove
Definition: MSCalibrator.h:231
Parser and container for routes during their loading.
SUMOReal myDefaultSpeed
The default (maximum) speed on the segment.
Definition: MSCalibrator.h:251
const std::string & getID() const
Returns the name of the vehicle.