Eclipse SUMO - Simulation of Urban MObility
MSCalibrator.h
Go to the documentation of this file.
1/****************************************************************************/
2// Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.org/sumo
3// Copyright (C) 2005-2023 German Aerospace Center (DLR) and others.
4// This program and the accompanying materials are made available under the
5// terms of the Eclipse Public License 2.0 which is available at
6// https://www.eclipse.org/legal/epl-2.0/
7// This Source Code may also be made available under the following Secondary
8// Licenses when the conditions for such availability set forth in the Eclipse
9// Public License 2.0 are satisfied: GNU General Public License, version 2
10// or later which is available at
11// https://www.gnu.org/licenses/old-licenses/gpl-2.0-standalone.html
12// SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-or-later
13/****************************************************************************/
20// Calibrates the flow on an edge by removing an inserting vehicles
21/****************************************************************************/
22#pragma once
23#include <config.h>
24
25#include <string>
26#include <vector>
31
32
33// ===========================================================================
34// class declarations
35// ===========================================================================
36class OutputDevice;
37class MSRouteProbe;
38
39
40// ===========================================================================
41// class definitions
42// ===========================================================================
48public:
50 MSCalibrator(const std::string& id,
51 const MSEdge* const edge,
52 MSLane* lane,
53 const double pos,
54 const std::string& aXMLFilename,
55 const std::string& outputFilename,
56 const SUMOTime freq, const double length,
57 const MSRouteProbe* probe,
58 const double invalidJamThreshold,
59 const std::string& vTypes,
60 bool addLaneMeanData = true);
61
63 virtual ~MSCalibrator();
64
71 void writeXMLOutput(OutputDevice& dev, SUMOTime startTime, SUMOTime stopTime);
72
73
82 void writeXMLDetectorProlog(OutputDevice& dev) const;
83
86 virtual SUMOTime execute(SUMOTime currentTime);
87
89 static void cleanup();
90
92 static const std::map<std::string, MSCalibrator*>& getInstances() {
93 return myInstances;
94 }
95
96 struct AspiredState {
97 AspiredState() : begin(-1), end(-1), q(-1.), v(-1.), vehicleParameter(0) {}
100 double q;
101 double v;
103 };
104
106
107 const MSEdge* getEdge() const {
108 return myEdge;
109 }
110
111 const MSLane* getLane() const {
112 return myLane;
113 }
114
116 return myProbe;
117 }
118
119 inline virtual int passed() const {
120 // calibrator measures at start of segment
121 // vehicles drive to the end of an edge by default so they count as passed
122 // but vaporized vehicles do not count
123 // if the calibrator is located on a short edge, the vehicles are
124 // vaporized on the next edge so we cannot rely on myEdgeMeanData.nVehVaporized
126 }
127
128 int getInserted() const {
130 }
131
132 int getRemoved() const {
133 return myClearedInJam + myRemoved;
134 }
135
136 void setFlow(SUMOTime begin, SUMOTime end, double vehsPerHour, double speed, SUMOVehicleParameter vehicleParameter);
137
138protected:
139 class CalibratorCommand : public Command {
140 public:
142 myCalibrator(cali) {}
143
144 SUMOTime execute(SUMOTime currentTime) {
145 return myCalibrator->execute(currentTime);
146 }
147
159 SUMOTime shiftTime(SUMOTime currentTime, SUMOTime execTime, SUMOTime newTime);
160
161 private:
163 };
164
165
167
168
176 virtual void myStartElement(int element,
177 const SUMOSAXAttributes& attrs);
178
185 virtual void myEndElement(int element);
187
188
189
191 public:
193 MSMoveReminder(parent->getID(), lane, true), myParent(parent) {}
194
196
197
208 virtual bool notifyEnter(SUMOTrafficObject& veh, MSMoveReminder::Notification reason, const MSLane* enteredLane = 0);
209
210 void disable() {
211 myParent = 0;
212 }
213
214 private:
216 };
217 friend class VehicleRemover;
218 friend class GUICalibrator;
219
220 // @return whether the current state is active (GUI)
221 bool isActive() const {
222 return myAmActive;
223 }
224
225protected:
226
227 void intervalEnd();
228
230
231 bool tryEmit(MSLane* lane, MSVehicle* vehicle);
232
233 void init();
234
236 int totalWished() const;
237
239 double currentFlow() const;
240
242 double currentSpeed() const;
243
244 /* @brief returns whether the lane is jammed although it should not be
245 * @param[in] lane The lane to check or all for negative values
246 */
247 bool invalidJam(int laneIndex) const;
248
249 inline int inserted() const {
250 return myInserted;
251 }
252 inline int removed() const {
253 return myRemoved;
254 }
255 inline int clearedInJam() const {
256 return myClearedInJam;
257 }
258
259 /* @brief returns the number of vehicles (of the current type) that still
260 * fit on the given lane
261 * @param[in] lane The lane to check (return the maximum of all lanes for negative values)
262 */
263 int remainingVehicleCapacity(int laneIndex) const;
264
266 virtual void reset();
267
269 virtual void updateMeanData();
270
274 return myToRemove.insert(veh->getID()).second;
275 }
276
277
280 bool removePending();
281
283 std::string getNewVehicleID();
284
285protected:
287 const MSEdge* const myEdge;
291 const double myPos;
293 const MSRouteProbe* const myProbe;
297 std::vector<MSMeanData_Net::MSLaneMeanDataValues*> myLaneMeanData;
300
302 std::vector<AspiredState> myIntervals;
304 std::vector<AspiredState>::const_iterator myCurrentStateInterval;
305
306 std::vector<VehicleRemover*> myVehicleRemovers;
307
312 std::set<std::string> myToRemove;
313
316
335
338
341
344
345 /* @brief objects which need to live longer than the MSCalibrator
346 * instance which created them */
347 static std::vector<MSMoveReminder*> myLeftoverReminders;
348 static std::vector<SUMOVehicleParameter*> myLeftoverVehicleParameters;
349 static std::map<std::string, MSCalibrator*> myInstances;
350
351};
long long int SUMOTime
Definition: GUI.h:36
Base (microsim) event class.
Definition: Command.h:50
Changes the speed allowed on a set of lanes (gui version)
Definition: GUICalibrator.h:42
CalibratorCommand(MSCalibrator *cali)
Definition: MSCalibrator.h:141
SUMOTime shiftTime(SUMOTime currentTime, SUMOTime execTime, SUMOTime newTime)
Reschedule or deschedule the command when quick-loading state.
SUMOTime execute(SUMOTime currentTime)
Executes the command.
Definition: MSCalibrator.h:144
virtual bool notifyEnter(SUMOTrafficObject &veh, MSMoveReminder::Notification reason, const MSLane *enteredLane=0)
Checks whether the reminder is activated by a vehicle entering the lane.
VehicleRemover(MSLane *lane, MSCalibrator *parent)
Definition: MSCalibrator.h:192
Calibrates the flow on a segment to a specified one.
Definition: MSCalibrator.h:47
static std::map< std::string, MSCalibrator * > myInstances
Definition: MSCalibrator.h:349
bool tryEmit(MSLane *lane, MSVehicle *vehicle)
OutputDevice * myOutput
The device for xml statistics.
Definition: MSCalibrator.h:315
double myInvalidJamThreshold
relative speed threshold for detecting and clearing invalid jam
Definition: MSCalibrator.h:340
int getInserted() const
Definition: MSCalibrator.h:128
double currentSpeed() const
measured speed in the current interval
const MSEdge *const myEdge
the edge on which this calibrator lies
Definition: MSCalibrator.h:287
MSMeanData_Net myMeanDataParent
dummy parent to retrieve vType filter
Definition: MSCalibrator.h:295
static void cleanup()
cleanup remaining data structures
bool isActive() const
Definition: MSCalibrator.h:221
bool mySpeedIsDefault
The information whether the speed adaption has been reset.
Definition: MSCalibrator.h:326
virtual void updateMeanData()
aggregate lane values
const MSRouteProbe * getRouteProbe() const
Definition: MSCalibrator.h:115
int myRemoved
The number of vehicles that were removed in the current interval.
Definition: MSCalibrator.h:320
virtual int passed() const
Definition: MSCalibrator.h:119
const MSRouteProbe *const myProbe
the route probe to retrieve routes from
Definition: MSCalibrator.h:293
bool myAmActive
whether the calibrator was active when last checking
Definition: MSCalibrator.h:337
std::set< std::string > myToRemove
set of vehicle ids to remove
Definition: MSCalibrator.h:312
const MSLane * getLane() const
Definition: MSCalibrator.h:111
static std::vector< MSMoveReminder * > myLeftoverReminders
Definition: MSCalibrator.h:347
void setFlow(SUMOTime begin, SUMOTime end, double vehsPerHour, double speed, SUMOVehicleParameter vehicleParameter)
bool myHaveInvalidJam
whether the calibrator has registered an invalid jam in the last execution step
Definition: MSCalibrator.h:343
std::vector< MSMeanData_Net::MSLaneMeanDataValues * > myLaneMeanData
data collector for the calibrator
Definition: MSCalibrator.h:297
std::vector< AspiredState >::const_iterator myCurrentStateInterval
Iterator pointing to the current interval.
Definition: MSCalibrator.h:304
int clearedInJam() const
Definition: MSCalibrator.h:255
double currentFlow() const
flow in the current interval in veh/h
static std::vector< SUMOVehicleParameter * > myLeftoverVehicleParameters
Definition: MSCalibrator.h:348
bool removePending()
remove any vehicles which are scheduled for removal. return true if removals took place
virtual void myStartElement(int element, const SUMOSAXAttributes &attrs)
Called on the opening of a tag;.
int myInserted
The number of vehicles that were inserted in the current interval.
Definition: MSCalibrator.h:322
bool myHaveWarnedAboutClearingJam
The default (maximum) speed on the segment.
Definition: MSCalibrator.h:334
std::vector< AspiredState > myIntervals
List of adaptation intervals.
Definition: MSCalibrator.h:302
const double myPos
the position on the edge where this calibrator lies
Definition: MSCalibrator.h:291
virtual void myEndElement(int element)
Called on the closing of a tag;.
int totalWished() const
number of vehicles expected to pass this interval
std::vector< VehicleRemover * > myVehicleRemovers
Definition: MSCalibrator.h:306
void writeXMLOutput(OutputDevice &dev, SUMOTime startTime, SUMOTime stopTime)
Write the generated output to the given device.
std::string getNewVehicleID()
determine id of new vehicle from calibrator state
MSMeanData_Net::MSLaneMeanDataValues myEdgeMeanData
accumlated data for the whole edge
Definition: MSCalibrator.h:299
bool invalidJam(int laneIndex) const
int myClearedInJam
The number of vehicles that were removed when clearin a jam.
Definition: MSCalibrator.h:324
int getRemoved() const
Definition: MSCalibrator.h:132
void writeXMLDetectorProlog(OutputDevice &dev) const
Open the XML-output.
virtual ~MSCalibrator()
const MSEdge * getEdge() const
Definition: MSCalibrator.h:107
double myDefaultSpeed
The default (maximum) speed on the segment.
Definition: MSCalibrator.h:332
virtual SUMOTime execute(SUMOTime currentTime)
MSLane *const myLane
the lane on which this calibrator lies (0 if the whole edge is covered at once)
Definition: MSCalibrator.h:289
bool scheduleRemoval(SUMOTrafficObject *veh)
try to schedule the given vehicle for removal. return true if it isn't already scheduled
Definition: MSCalibrator.h:273
bool myDidInit
The information whether init was called.
Definition: MSCalibrator.h:330
int removed() const
Definition: MSCalibrator.h:252
void intervalEnd()
int inserted() const
Definition: MSCalibrator.h:249
AspiredState getCurrentStateInterval() const
bool isCurrentStateActive(SUMOTime time)
static const std::map< std::string, MSCalibrator * > & getInstances()
return all calibrator instances
Definition: MSCalibrator.h:92
SUMOTime myFrequency
The frequeny with which to check for calibration.
Definition: MSCalibrator.h:318
MSCalibrator(const std::string &id, const MSEdge *const edge, MSLane *lane, const double pos, const std::string &aXMLFilename, const std::string &outputFilename, const SUMOTime freq, const double length, const MSRouteProbe *probe, const double invalidJamThreshold, const std::string &vTypes, bool addLaneMeanData=true)
virtual void reset()
reset collected vehicle data
int remainingVehicleCapacity(int laneIndex) const
bool myDidSpeedAdaption
The information whether speed was adapted in the current interval.
Definition: MSCalibrator.h:328
Base of value-generating classes (detectors)
A road/street connecting two junctions.
Definition: MSEdge.h:77
Representation of a lane in the micro simulation.
Definition: MSLane.h:84
Data structure for mean (aggregated) edge/lane values.
int nVehEntered
The number of vehicles that entered this lane within the sample interval.
Network state mean data collector for edges/lanes.
Something on a lane to be noticed about vehicle movement.
Notification
Definition of a vehicle state.
Parser and container for routes during their loading.
Writes routes of vehicles passing a certain edge.
Definition: MSRouteProbe.h:58
Representation of a vehicle in the micro simulation.
Definition: MSVehicle.h:77
const std::string & getID() const
Returns the id.
Definition: Named.h:74
Static storage of an output device and its base (abstract) implementation.
Definition: OutputDevice.h:61
Encapsulated SAX-Attributes.
Representation of a vehicle, person, or container.
Structure representing possible vehicle parameter.
SUMOVehicleParameter * vehicleParameter
Definition: MSCalibrator.h:102