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-2013 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 /****************************************************************************/