 |
Eclipse SUMO - Simulation of Urban MObility
|
Go to the documentation of this file.
61 const std::string& aXMLFilename,
62 const std::string& outputFilename,
63 const SUMOTime freq,
const double length,
65 const std::string& vTypes,
66 bool addLaneMeanData) :
72 myPos(pos), myProbe(probe),
73 myEdgeMeanData(nullptr, length, false, nullptr),
74 myMeanDataParent(id +
"_dummyMeanData", 0, 0, false, false, false, false, false, false, 1, 0, 0, vTypes),
75 myCurrentStateInterval(myIntervals.begin()),
76 myOutput(nullptr), myFrequency(freq), myRemoved(0),
77 myInserted(0), myClearedInJam(0),
78 mySpeedIsDefault(true), myDidSpeedAdaption(false), myDidInit(false),
79 myDefaultSpeed(myLane == nullptr ? myEdge->getSpeedLimit() : myLane->getSpeedLimit()),
80 myHaveWarnedAboutClearingJam(false),
82 myHaveInvalidJam(false) {
83 if (outputFilename !=
"") {
87 if (aXMLFilename !=
"") {
93 if (addLaneMeanData) {
154 if (state.
begin < lastEnd) {
155 WRITE_ERROR(
"Overlapping or unsorted intervals in calibrator '" +
getID() +
"'.");
172 }
else if (
myLane !=
nullptr && (
175 WRITE_WARNING(
"Insertion lane may differ from calibrator lane for calibrator '" +
getID() +
"'.");
182 WRITE_ERROR(
"Mandatory attribute missing in definition of calibrator '" +
getID() +
"'.");
184 WRITE_ERROR(
"Non-numeric value for numeric attribute in definition of calibrator '" +
getID() +
"'.");
186 if (state.
q < 0 && state.
v < 0) {
187 WRITE_ERROR(
"Either 'vehsPerHour' or 'speed' has to be given in flow definition of calibrator '" +
getID() +
"'.");
250 return passed() / totalHourFraction;
271 if (vehicle !=
nullptr) {
276 WRITE_WARNING(
"Calibrator '" +
getID() +
"' could not remove vehicle '" + *it +
"'.");
329 #ifdef MSCalibrator_DEBUG
332 <<
" totalWished=" << totalWishedNum
333 <<
" adapted=" << adaptedNum
343 if (calibrateFlow && adaptedNum < totalWishedNum && !hadRemovals) {
351 const int insertionSlack =
MAX2(0, adaptedNum + relaxedInsertion - totalWishedNum);
353 #ifdef MSCalibrator_DEBUG
355 <<
" wished:" << wishedNum
356 <<
" slack:" << insertionSlack
357 <<
" before:" << adaptedNum
360 while (wishedNum > adaptedNum + insertionSlack) {
363 if (route ==
nullptr) {
366 if (route ==
nullptr) {
374 const int routeIndex = (int)std::distance(route->
begin(),
377 assert(route != 0 && vtype != 0);
381 newPars->
depart = currentTime;
387 newPars, route, vtype,
true,
false));
397 #ifdef MSCalibrator_DEBUG
398 std::cout <<
" resetting route pos: " << routeIndex <<
"\n";
403 throw ProcessError(
"Emission of vehicle '" + vehicle->
getID() +
"' in calibrator '" +
getID() +
"'failed!");
407 #ifdef MSCalibrator_DEBUG
412 #ifdef MSCalibrator_DEBUG
439 for (
int i = 0; i < numLanes; ++i) {
463 for (
int i = 0; i < numLanes; ++i) {
475 if (last !=
nullptr) {
477 return MAX2(overallSpaceLeft, entrySpaceLeft);
479 return overallSpaceLeft;
501 for (std::vector<MSMeanData_Net::MSLaneMeanDataValues*>::iterator it =
myLaneMeanData.begin();
522 if (calibrateFlow && adaptedNum > totalWishedNum) {
523 #ifdef MSCalibrator_DEBUG
525 <<
" vaporizing " << vehicle->
getID() <<
" to reduce flow\n";
531 #ifdef MSCalibrator_DEBUG
533 <<
" vaporizing " << vehicle->
getID() <<
" to clear jam\n";
555 assert(discrepancy >= 0);
556 const std::string ds = (discrepancy > 0 ?
"\" vaporizedOnNextEdge=\"" +
toString(discrepancy) :
"");
557 const double durationSeconds =
STEPS2TIME(stopTime - startTime);
558 dev <<
" <interval begin=\"" <<
time2string(startTime) <<
560 "\" id=\"" <<
getID() <<
561 "\" nVehContrib=\"" << p <<
565 "\" flow=\"" << p * 3600.0 / durationSeconds <<
575 dev.
writeXMLHeader(
"calibratorstats",
"calibratorstats_file.xsd");
582 const int precision = beginS == int(beginS) ? 0 : 2;
int myRemoved
The number of vehicles that were removed in the current interval.
int myClearedInJam
The number of vehicles that were removed when clearin a jam.
bool scheduleRemoval(MSVehicle *veh)
try to schedule the givne vehicle for removal. return true if it isn't already scheduled
The car-following model and parameter.
SUMOVehicleParameter * vehicleParameter
Representation of a vehicle or person.
virtual int passed() const
const std::string & getID() const
static bool runParser(GenericSAXHandler &handler, const std::string &file, const bool isNet=false)
Runs the given handler on the given file; returns if everything's ok.
bool myHaveWarnedAboutClearingJam
The default (maximum) speed on the segment.
virtual void addEvent(Command *operation, SUMOTime execTimeStep=-1)
Adds an Event.
double getSpeedLimit() const
Returns the speed limit of the edge @caution The speed limit of the first lane is retured; should pro...
#define WRITE_WARNING(msg)
friend class VehicleRemover
Base of value-generating classes (detectors)
Representation of a lane in the micro simulation.
MSVehicleType * getVType(const std::string &id=DEFAULT_VTYPE_ID, std::mt19937 *rng=nullptr)
Returns the named vehicle type or a sample from the named distribution.
double currentFlow() const
flow in the current interval in veh/h
Static storage of an output device and its base (abstract) implementation.
int myInserted
The number of vehicles that were inserted in the current interval.
MSRouteIterator end() const
Returns the end of the list of edges to pass.
bool myHaveInvalidJam
whether the calibrator has registered an invalid jam in the last execution step
SUMOTime myFrequency
The frequeny with which to check for calibration.
OutputDevice * myOutput
The device for xml statistics.
Writes routes of vehicles passing a certain edge.
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 std::string &vTypes, bool addLaneMeanData=true)
double currentSpeed() const
measured speed in the current interval
std::string vtypeid
The vehicle's type id.
std::vector< AspiredState >::const_iterator myCurrentStateInterval
Iterator pointing to the current interval.
Data structure for mean (aggregated) edge/lane values.
int nVehArrived
The number of vehicles that finished on the lane.
double waitSeconds
The number of vehicle probes with small speed.
void onRemovalFromNet(const MSMoveReminder::Notification reason)
Called when the vehicle is removed from the network.
bool mySpeedIsDefault
The information whether the speed adaption has been reset.
int nVehLeft
The number of vehicles that left this lane within the sample interval.
Structure representing possible vehicle parameter.
MSMeanData_Net myMeanDataParent
dummy parent to retrieve vType filter
MSVehicle * getLastFullVehicle() const
returns the last vehicle for which this lane is responsible or 0
void scheduleVehicleRemoval(SUMOVehicle *veh, bool checkDuplicate=false)
Removes a vehicle after it has ended.
SUMOTime getSUMOTimeReporting(int attr, const char *objectid, bool &ok, bool report=true) const
Tries to read given attribute assuming it is a SUMOTime.
virtual void myEndElement(int element)
Called on the closing of a tag;.
void setMaxSpeed(double val)
Sets a new maximum speed for the lane (used by TraCI and MSCalibrator)
void resetRoutePosition(int index, DepartLaneDefinition departLaneProcedure)
reset index of edge within route
void reset(bool afterWrite=false)
Resets values so they may be used for the next interval.
double myDefaultSpeed
The default (maximum) speed on the segment.
@ NOTIFICATION_VAPORIZED
The vehicle got vaporized.
static SUMOVehicleParameter * parseVehicleAttributes(const SUMOSAXAttributes &attrs, const bool hardFail, const bool optionalID=false, const bool skipDepart=false, const bool isPerson=false)
Parses a vehicle's attributes.
@ SUMO_ATTR_BEGIN
weights: time range begin
int getVehicleNumber() const
Returns the number of vehicles on this lane (for which this lane is responsible)
@ DEPART_LANE_ALLOWED_FREE
The least occupied lane from lanes which allow the continuation.
MSLane *const myLane
the lane on which this calibrator lies (0 if the whole edge is covered at once)
virtual SUMOVehicle * buildVehicle(SUMOVehicleParameter *defs, const MSRoute *route, MSVehicleType *type, const bool ignoreStopErrors, const bool fromRouteFile=true)
Builds a vehicle, increases the number of built vehicles.
bool myDidInit
The information whether init was called.
SUMOVehicle * getVehicle(const std::string &id) const
Returns the vehicle with the given id.
@ SUMO_TAG_FLOW
a flow definitio nusing a from-to edges instead of a route (used by router)
double getPositionOnLane() const
Get the vehicle's position along the lane.
int nVehVaporized
The number of vehicles that left this lane within the sample interval.
const MSCFModel & getCarFollowModel() const
Returns the vehicle type's car following model definition (const version)
std::vector< MSMeanData_Net::MSLaneMeanDataValues * > myLaneMeanData
data collector for the calibrator
MSEventControl * getEndOfTimestepEvents()
Returns the event control for events executed at the end of a time step.
double getLengthWithGap() const
Get vehicle's length including the minimum gap [m].
const std::string DEFAULT_VTYPE_ID
bool myDidSpeedAdaption
The information whether speed was adapted in the current interval.
virtual void reset()
reset collected vehicle data
@ DEPART_LANE_GIVEN
The lane is given.
std::string id
The vehicle's id.
double getLength() const
Returns the lane's length.
virtual void myEndElement(int element)
Called when a closing tag occurs.
virtual void updateMeanData()
aggregate lane values
bool myAmActive
whether the calibrator was active when last checking
virtual void deleteVehicle(SUMOVehicle *v, bool discard=false)
Deletes the vehicle.
bool invalidJam(int laneIndex) const
double getMeanSpeed() const
Returns the mean speed on this lane.
double getTravelledDistance() const
Returns the total travelled distance.
int totalWished() const
number of vehicles expected to pass this interval
std::string time2string(SUMOTime t)
virtual MSVehicle * removeVehicle(MSVehicle *remVehicle, MSMoveReminder::Notification notification, bool notify=true)
A road/street connecting two junctions.
virtual void myStartElement(int element, const SUMOSAXAttributes &attrs)
Called on the opening of a tag;.
T getOpt(int attr, const char *objectid, bool &ok, T defaultValue, bool report=true) const
Tries to read given attribute assuming it is an int.
MSMeanData_Net::MSLaneMeanDataValues myEdgeMeanData
accumlated data for the whole edge
const MSRoute * getRoute() const
const MSRouteProbe *const myProbe
the route probe to retrieve routes from
static void cleanup()
cleanup remaining data structures
std::string routeid
The vehicle's route id.
std::vector< VehicleRemover * > myVehicleRemovers
An abstract device that changes the state of the micro simulation.
MSLane * getLane() const
Returns the lane the vehicle is on.
int remainingVehicleCapacity(int laneIndex) const
int departLane
(optional) The lane the vehicle shall depart from (index in edge)
bool removePending()
remove any vehicles which are scheduled for removal. return true if removals took place
std::string toString(const T &t, std::streamsize accuracy=gPrecision)
bool insertVehicle(SUMOVehicle &v, SUMOTime time, const bool checkOnly=false, const bool forceCheck=false) const
Tries to insert the given vehicle into the network.
virtual void myStartElement(int element, const SUMOSAXAttributes &attrs)
Called on the opening of a tag;.
DepartLaneDefinition departLaneProcedure
Information how the vehicle shall choose the lane to depart from.
virtual double getSamples() const
Returns the number of collected sample seconds.
void writeXMLOutput(OutputDevice &dev, SUMOTime startTime, SUMOTime stopTime)
Write the generated output to the given device.
static OutputDevice & getDevice(const std::string &name)
Returns the described OutputDevice.
static MSNet * getInstance()
Returns the pointer to the unique instance of MSNet (singleton).
SUMOTime getOptSUMOTimeReporting(int attr, const char *objectid, bool &ok, SUMOTime defaultValue, bool report=true) const
Tries to read given attribute assuming it is a SUMOTime.
std::set< std::string > myToRemove
set of vehicle ids to remove
virtual double getHeadwayTime() const
Get the driver's desired headway [s].
void writeXMLDetectorProlog(OutputDevice &dev) const
Open the XML-output.
void setMaxSpeed(double val) const
Sets a new maximum speed for all lanes (used by TraCI and MSCalibrator)
std::string getNewVehicleID()
determine id of new vehicle from calibrator state
bool isCurrentStateActive(SUMOTime time)
void setDescription(const std::string &description)
Parser and container for routes during their loading.
const std::string & getID() const
Returns the name of the vehicle.
const std::vector< MSLane * > & getLanes() const
Returns this edge's lanes.
@ DEPART_SPEED_MAX
The maximum safe speed is used.
@ DEPART_LANE_DEFAULT
No information given; use default.
MSRouteIterator begin() const
Returns the begin of the list of edges to pass.
bool vehicleApplies(const SUMOTrafficObject &veh) const
Checks whether the detector measures vehicles of the given type.
virtual bool notifyEnter(SUMOTrafficObject &veh, MSMoveReminder::Notification reason, const MSLane *enteredLane=0)
Checks whether the reminder is activated by a vehicle entering the lane.
static bool dictionary(const std::string &id, const MSRoute *route)
Adds a route to the dictionary.
The class responsible for building and deletion of vehicles.
static std::vector< MSMoveReminder * > LeftoverReminders
@ DEPART_SPEED_DEFAULT
No information given; use default.
static std::vector< SUMOVehicleParameter * > LeftoverVehicleParameters
@ SUMO_ATTR_END
weights: time range end
int nVehEntered
The number of vehicles that entered this lane within the sample interval.
bool writeXMLHeader(const std::string &rootElement, const std::string &schemaFile, std::map< SumoXMLAttr, std::string > attrs=std::map< SumoXMLAttr, std::string >())
Writes an XML header with optional configuration.
std::vector< AspiredState > myIntervals
List of adaptation intervals.
bool contains(const MSEdge *const edge) const
@ SUMO_TAG_CALIBRATOR
A calibrator placed over edge.
const MSEdge *const myEdge
the edge on which this calibrator lies
Encapsulated SAX-Attributes.
const std::string & getID() const
Returns the id.
Notification
Definition of a vehicle state.
int getIndex() const
Returns the lane's index.
@ DEPART_LANE_FIRST_ALLOWED
The rightmost lane the vehicle may use.
MSVehicleControl & getVehicleControl()
Returns the vehicle control.
DepartSpeedDefinition departSpeedProcedure
Information how the vehicle's initial speed shall be chosen.
virtual SUMOTime execute(SUMOTime currentTime)
Representation of a vehicle in the micro simulation.