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-2024 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 MSEdge* const edge,
52 MSLane* const lane,
53 MSJunction* const node,
54 const double pos,
55 const std::string& aXMLFilename,
56 const std::string& outputFilename,
57 const SUMOTime freq, const double length,
58 const MSRouteProbe* probe,
59 const double invalidJamThreshold,
60 const std::string& vTypes,
61 const bool local,
62 const bool addLaneMeanData);
63
65 virtual ~MSCalibrator();
66
73 void writeXMLOutput(OutputDevice& dev, SUMOTime startTime, SUMOTime stopTime);
74
75
84 void writeXMLDetectorProlog(OutputDevice& dev) const;
85
88 virtual SUMOTime execute(SUMOTime currentTime);
89
91 static void cleanup();
92
94 static const std::map<std::string, MSCalibrator*>& getInstances() {
95 return myInstances;
96 }
97
106
108
109 const MSEdge* getEdge() const {
110 return myEdge;
111 }
112
113 const MSLane* getLane() const {
114 return myLane;
115 }
116
118 return myProbe;
119 }
120
121 inline virtual int passed() const {
122 // calibrator measures at start of segment
123 // vehicles drive to the end of an edge by default so they count as passed
124 // but vaporized vehicles do not count
125 // if the calibrator is located on a short edge, the vehicles are
126 // vaporized on the next edge so we cannot rely on myEdgeMeanData.nVehVaporized
128 }
129
130 int getInserted() const {
132 }
133
134 int getRemoved() const {
135 return myClearedInJam + myRemoved;
136 }
137
138 void setFlow(SUMOTime begin, SUMOTime end, double vehsPerHour, double speed, SUMOVehicleParameter vehicleParameter);
139
140protected:
141 class CalibratorCommand : public Command {
142 public:
145
146 SUMOTime execute(SUMOTime currentTime) {
147 return myCalibrator->execute(currentTime);
148 }
149
161 SUMOTime shiftTime(SUMOTime currentTime, SUMOTime execTime, SUMOTime newTime);
162
163 private:
165 };
166
167
169
170
178 virtual void myStartElement(int element,
179 const SUMOSAXAttributes& attrs);
180
187 virtual void myEndElement(int element);
189
190
191
193 public:
194 VehicleRemover(MSLane* const lane, MSCalibrator* const parent, const bool undo = false) :
195 MSMoveReminder(parent->getID(), lane, true), myParent(parent), myUndoCalibration(undo) {}
196
198
199
210 virtual bool notifyEnter(SUMOTrafficObject& veh, MSMoveReminder::Notification reason, const MSLane* enteredLane = nullptr);
211
221 virtual bool notifyLeave(SUMOTrafficObject& veh, double lastPos, Notification reason, const MSLane* enteredLane = nullptr);
222
223 void disable() {
224 myParent = nullptr;
225 }
226
227 private:
230 };
231 friend class GUICalibrator;
232
233 // @return whether the current state is active (GUI)
234 bool isActive() const {
235 return myAmActive;
236 }
237
238protected:
239
240 void intervalEnd();
241
243
244 bool tryEmit(MSLane* lane, MSVehicle* vehicle);
245
246 void init();
247
249 int totalWished() const;
250
252 double currentFlow() const;
253
255 double currentSpeed() const;
256
257 /* @brief returns whether the lane is jammed although it should not be
258 * @param[in] lane The lane to check or all for negative values
259 */
260 bool invalidJam(int laneIndex) const;
261
262 inline int inserted() const {
263 return myInserted;
264 }
265 inline int removed() const {
266 return myRemoved;
267 }
268 inline int clearedInJam() const {
269 return myClearedInJam;
270 }
271
272 /* @brief returns the number of vehicles (of the current type) that still
273 * fit on the given lane
274 * @param[in] lane The lane to check (return the maximum of all lanes for negative values)
275 */
276 int remainingVehicleCapacity(int laneIndex) const;
277
279 virtual void reset();
280
282 virtual void updateMeanData();
283
287 return myToRemove.insert(veh->getID()).second;
288 }
289
290
293 bool removePending();
294
296 std::string getNewVehicleID();
297
298protected:
306 const double myPos;
308 const MSRouteProbe* const myProbe;
312 std::vector<MSMeanData_Net::MSLaneMeanDataValues*> myLaneMeanData;
315
317 std::vector<AspiredState> myIntervals;
319 std::vector<AspiredState>::const_iterator myCurrentStateInterval;
320
321 std::vector<VehicleRemover*> myVehicleRemovers;
322
327 std::set<std::string> myToRemove;
328
331
350
353
356
359
362
363 /* @brief objects which need to live longer than the MSCalibrator
364 * instance which created them */
365 static std::vector<MSMoveReminder*> myLeftoverReminders;
366 static std::vector<SUMOVehicleParameter*> myLeftoverVehicleParameters;
367 static std::map<std::string, MSCalibrator*> myInstances;
368
369};
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.
VehicleRemover(MSLane *const lane, MSCalibrator *const parent, const bool undo=false)
virtual bool notifyLeave(SUMOTrafficObject &veh, double lastPos, Notification reason, const MSLane *enteredLane=nullptr)
Checks whether any calibrations need to be undone.
virtual bool notifyEnter(SUMOTrafficObject &veh, MSMoveReminder::Notification reason, const MSLane *enteredLane=nullptr)
Checks whether the reminder is activated by a vehicle entering the lane.
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
MSMeanData_Net myMeanDataParent
dummy parent to retrieve vType filter
MSEdge *const myEdge
the edge on which this calibrator lies
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 (nullptr 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
bool myAmLocal
whether the calibrator needs to undo the calibration after the edge / junction has been left
int inserted() const
AspiredState getCurrentStateInterval() const
bool isCurrentStateActive(SUMOTime time)
MSJunction *const myNode
the junction on which this calibrator lies (nullptr if is edge or lane specific)
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
The base class for an intersection.
Definition MSJunction.h:58
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