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-2014 DLR (http://www.dlr.de/) and contributors
12 /****************************************************************************/
13 //
14 // This file is part of SUMO.
15 // SUMO is free software: you can redistribute it and/or modify
16 // it under the terms of the GNU General Public License as published by
17 // the Free Software Foundation, either version 3 of the License, or
18 // (at your option) any later version.
19 //
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, const SUMOReal pos,
61  const std::string& aXMLFilename,
62  const std::string& outputFilename,
63  const SUMOTime freq, const SUMOReal length,
64  const MSRouteProbe* probe, const bool addLaneMeanData = true);
65 
67  virtual ~MSCalibrator();
68 
69 
72  virtual SUMOTime execute(SUMOTime currentTime);
73 
75  static void cleanup();
76 
77 
78 
79 protected:
81 
82 
90  virtual void myStartElement(int element,
91  const SUMOSAXAttributes& attrs);
92 
99  virtual void myEndElement(int element);
101 
102 
103 
105  public:
106  VehicleRemover(MSLane* lane, int laneIndex, MSCalibrator* parent) :
107  MSMoveReminder(parent->getID(), lane, true), myLaneIndex(laneIndex), myParent(parent) {}
108 
110 
111 
122  virtual bool notifyEnter(SUMOVehicle& veh, Notification reason);
123 
124  void disable() {
125  myParent = 0;
126  }
127 
128  private:
131  };
132  friend class VehicleRemover;
133 
134  // @return whether the current state is active (GUI)
135  bool isActive() const {
136  return myAmActive;
137  }
138 
139 protected:
140 
141  struct AspiredState {
142  AspiredState() : begin(-1), end(-1), q(-1.), v(-1.), vehicleParameter(0) {}
148  };
149 
150  void writeXMLOutput();
151 
152  bool isCurrentStateActive(SUMOTime time);
153 
154  bool tryEmit(MSLane* lane, MSVehicle* vehicle);
155 
156  void init();
157 
158  inline virtual int passed() const {
159  // calibrator measures at start of segment
160  // vehicles drive to the end of an edge by default so they count as passed
161  // but vaporized vehicles do not count
162  // if the calibrator is located on a short edge, the vehicles are
163  // vaporized on the next edge so we cannot rely on myEdgeMeanData.nVehVaporized
165  }
166 
168  int totalWished() const;
169 
170  /* @brief returns whether the lane is jammed although it should not be
171  * @param[in] lane The lane to check or all for negative values
172  */
173  bool invalidJam(int laneIndex) const;
174 
175  inline int inserted() const {
176  return myInserted;
177  }
178  inline int removed() const {
179  return myRemoved;
180  }
181  inline int clearedInJam() const {
182  return myClearedInJam;
183  }
184 
185  /* @brief returns the number of vehicles (of the current type) that still
186  * fit on the given lane
187  * @param[in] lane The lane to check (return the maximum of all lanes for negative values)
188  */
189  int remainingVehicleCapacity(int laneIndex) const;
190 
192  virtual void reset();
193 
195  virtual void updateMeanData();
196 
200  return myToRemove.insert(veh->getID()).second;
201  };
202 
203 
206  bool removePending();
207 
208 protected:
210  const MSEdge* const myEdge;
214  const MSRouteProbe* const myProbe;
216  std::vector<MSMeanData_Net::MSLaneMeanDataValues*> myLaneMeanData;
220  std::vector<AspiredState> myIntervals;
222  std::vector<AspiredState>::const_iterator myCurrentStateInterval;
223 
224  std::vector<VehicleRemover*> myVehicleRemovers;
225 
230  std::set<std::string> myToRemove;
231 
234 
238  unsigned int myRemoved;
240  unsigned int myInserted;
242  unsigned int myClearedInJam;
248  bool myDidInit;
253 
256 
257  /* @brief objects which need to live longer than the MSCalibrator
258  * instance which created them */
259  static std::vector<MSMoveReminder*> LeftoverReminders;
260  static std::vector<SUMOVehicleParameter*> LeftoverVehicleParameters;
261 
262 };
263 
264 #endif
265 
266 /****************************************************************************/
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:77
VehicleRemover(MSLane *lane, int laneIndex, MSCalibrator *parent)
Definition: MSCalibrator.h:106
bool tryEmit(MSLane *lane, MSVehicle *vehicle)
static std::vector< SUMOVehicleParameter * > LeftoverVehicleParameters
Definition: MSCalibrator.h:260
int inserted() 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:68
unsigned int myClearedInJam
The number of vehicles that were removed when clearin a jam.
Definition: MSCalibrator.h:242
bool myDidSpeedAdaption
The information whether speed was adapted in the current interval.
Definition: MSCalibrator.h:246
int removed() const
Definition: MSCalibrator.h:178
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:255
bool myDidInit
The information whether init was called.
Definition: MSCalibrator.h:248
const SUMOReal myPos
the position on the edge where this calibrator lies
Definition: MSCalibrator.h:212
SUMOTime myFrequency
The frequeny with which to check for calibration.
Definition: MSCalibrator.h:236
Base (microsim) event class.
Definition: Command.h:61
const MSEdge *const myEdge
the edge on which this calibrator lies
Definition: MSCalibrator.h:210
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:73
unsigned int myInserted
The number of vehicles that were inserted in the current interval.
Definition: MSCalibrator.h:240
std::vector< AspiredState >::const_iterator myCurrentStateInterval
Iterator pointing to the current interval.
Definition: MSCalibrator.h:222
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.
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:244
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:199
std::vector< AspiredState > myIntervals
List of adaptation intervals.
Definition: MSCalibrator.h:220
virtual void reset()
reset collected vehicle data
bool myHaveWarnedAboutClearingJam
The default (maximum) speed on the segment.
Definition: MSCalibrator.h:252
std::vector< MSMeanData_Net::MSLaneMeanDataValues * > myLaneMeanData
data collector for the calibrator
Definition: MSCalibrator.h:216
static std::vector< MSMoveReminder * > LeftoverReminders
Definition: MSCalibrator.h:259
Structure representing possible vehicle parameter.
SUMOVehicleParameter * vehicleParameter
Definition: MSCalibrator.h:147
const MSRouteProbe *const myProbe
the route probe to retrieve routes from
Definition: MSCalibrator.h:214
static void cleanup()
cleanup remaining data structures
OutputDevice * myOutput
The device for xml statistics.
Definition: MSCalibrator.h:233
virtual void updateMeanData()
aggregate lane values
virtual int passed() const
Definition: MSCalibrator.h:158
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
#define SUMOReal
Definition: config.h:215
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:218
bool isCurrentStateActive(SUMOTime time)
std::vector< VehicleRemover * > myVehicleRemovers
Definition: MSCalibrator.h:224
bool isActive() const
Definition: MSCalibrator.h:135
int clearedInJam() const
Definition: MSCalibrator.h:181
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:238
std::set< std::string > myToRemove
set of vehicle ids to remove
Definition: MSCalibrator.h:230
Parser and container for routes during their loading.
SUMOReal myDefaultSpeed
The default (maximum) speed on the segment.
Definition: MSCalibrator.h:250
const std::string & getID() const
Returns the name of the vehicle.