Eclipse SUMO - Simulation of Urban MObility
Loading...
Searching...
No Matches
MSCalibrator.h
Go to the documentation of this file.
1/****************************************************************************/
2// Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/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
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:
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)
CalibratorCommand(MSCalibrator *cali)
SUMOTime shiftTime(SUMOTime currentTime, SUMOTime execTime, SUMOTime newTime)
Reschedule or deschedule the command when quick-loading state.
SUMOTime execute(SUMOTime currentTime)
Executes the command.
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)
Calibrates the flow on a segment to a specified one.
static std::map< std::string, MSCalibrator * > myInstances
bool tryEmit(MSLane *lane, MSVehicle *vehicle)
OutputDevice * myOutput
The device for xml statistics.
double myInvalidJamThreshold
relative speed threshold for detecting and clearing invalid jam
int getInserted() const
double currentSpeed() const
measured speed in the current interval
const MSEdge *const myEdge
the edge on which this calibrator lies
MSMeanData_Net myMeanDataParent
dummy parent to retrieve vType filter
static void cleanup()
cleanup remaining data structures
bool isActive() const
bool mySpeedIsDefault
The information whether the speed adaption has been reset.
virtual void updateMeanData()
aggregate lane values
const MSRouteProbe * getRouteProbe() const
int myRemoved
The number of vehicles that were removed in the current interval.
virtual int passed() const
const MSRouteProbe *const myProbe
the route probe to retrieve routes from
bool myAmActive
whether the calibrator was active when last checking
std::set< std::string > myToRemove
set of vehicle ids to remove
const MSLane * getLane() const
static std::vector< MSMoveReminder * > myLeftoverReminders
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
std::vector< MSMeanData_Net::MSLaneMeanDataValues * > myLaneMeanData
data collector for the calibrator
std::vector< AspiredState >::const_iterator myCurrentStateInterval
Iterator pointing to the current interval.
int clearedInJam() const
double currentFlow() const
flow in the current interval in veh/h
static std::vector< SUMOVehicleParameter * > myLeftoverVehicleParameters
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.
bool myHaveWarnedAboutClearingJam
The default (maximum) speed on the segment.
std::vector< AspiredState > myIntervals
List of adaptation intervals.
const double myPos
the position on the edge where this calibrator lies
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
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
bool invalidJam(int laneIndex) const
int myClearedInJam
The number of vehicles that were removed when clearin a jam.
int getRemoved() const
void writeXMLDetectorProlog(OutputDevice &dev) const
Open the XML-output.
virtual ~MSCalibrator()
const MSEdge * getEdge() const
double myDefaultSpeed
The default (maximum) speed on the segment.
virtual SUMOTime execute(SUMOTime currentTime)
MSLane *const myLane
the lane on which this calibrator lies (0 if the whole edge is covered at once)
bool scheduleRemoval(SUMOTrafficObject *veh)
try to schedule the given vehicle for removal. return true if it isn't already scheduled
bool myDidInit
The information whether init was called.
int removed() const
int inserted() const
AspiredState getCurrentStateInterval() const
bool isCurrentStateActive(SUMOTime time)
static const std::map< std::string, MSCalibrator * > & getInstances()
return all calibrator instances
SUMOTime myFrequency
The frequeny with which to check for calibration.
virtual void reset()
reset collected vehicle data
int remainingVehicleCapacity(int laneIndex) const
bool myDidSpeedAdaption
The information whether speed was adapted in the current interval.
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.
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.
Encapsulated SAX-Attributes.
Representation of a vehicle, person, or container.
Structure representing possible vehicle parameter.
SUMOVehicleParameter * vehicleParameter