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.sourceforge.net/
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(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 private:
127 
128  struct AspiredState {
134  };
135 
136  void writeXMLOutput();
137 
138  bool isCurrentStateActive(SUMOTime time);
139 
140  bool tryEmit(MSLane* lane, MSVehicle* vehicle);
141 
142  void init();
143 
144  inline int passed() const {
145  // calibrator measures at start of segment
147  }
148 
149  /* @brief returns whether the lane is jammed although it should not be
150  * @param[in] lane The lane to check or all for negative values
151  */
152  bool invalidJam(int laneIndex = -1) const;
153 
154 
155  /* @brief returns the number of vehicles (of the current type) that still
156  * fit on the given lane
157  * @param[in] lane The lane to check (return the maximum of all lanes for negative values)
158  */
159  int remainingVehicleCapacity(int laneIndex = -1) const;
160 
162  void reset();
163 
165  void updateMeanData();
166 
168  myToRemove.push_back(veh);
169  };
170 
171 private:
173  MSEdge* myEdge;
175  std::vector<MSMeanData_Net::MSLaneMeanDataValues*> myLaneMeanData;
179  std::vector<AspiredState> myIntervals;
181  std::vector<AspiredState>::const_iterator myCurrentStateInterval;
182 
183  std::vector<VehicleRemover*> myVehicleRemovers;
184 
185  std::vector<MSVehicle*> myToRemove;
186 
189 
193  unsigned int myRemoved;
195  unsigned int myInserted;
197  unsigned int myClearedInJam;
203  bool myDidInit;
208 
209  /* @brief objects which need to live longer than the MSCalibrator
210  * instance which created them */
211  static std::vector<MSMoveReminder*> LeftoverReminders;
212  static std::vector<SUMOVehicleParameter*> LeftoverVehicleParameters;
213 
214 };
215 
216 #endif
217 
218 /****************************************************************************/