49#define DEBUGCOND (getID() == DEBUGID)
50#define DEBUGCOND2(id) ((id) == DEBUGID)
81 const std::string& aXMLFilename,
82 const std::string& outputFilename,
83 const SUMOTime freq,
const double length,
85 const double invalidJamThreshold,
86 const std::string& vTypes,
88 const bool addLaneMeanData) :
95 myMeanDataParent(id +
"_dummyMeanData", 0, 0, false, false, false, false, false, false, 1, 0, 0, vTypes,
"",
110 if (outputFilename !=
"") {
114 if (aXMLFilename !=
"") {
120 if (addLaneMeanData &&
myEdge !=
nullptr) {
126 laneData->
setDescription(
"meandata_calibrator_" + eLane->getID());
135 if (node !=
nullptr) {
137 for (
MSLane*
const eLane : inEdge->getLanes()) {
145 for (
MSLane*
const eLane : outEdge->getLanes()) {
210 if (state.
begin < lastEnd) {
212 }
else if (state.
begin <= lastBegin) {
231 }
else if (
myLane !=
nullptr && (
243 WRITE_ERRORF(
TL(
"Non-numeric value for numeric attribute in definition of calibrator '%'."),
getID());
246 WRITE_ERRORF(
TL(
"Either 'vehsPerHour', 'speed' or 'type' has to be set in flow definition of calibrator '%'."),
getID());
249 WRITE_ERRORF(
TL(
"Type calibration is not supported in meso for calibrator '%'."),
getID());
315 return passed() / totalHourFraction;
337 if (vehicle !=
nullptr) {
397#ifdef MSCalibrator_DEBUG
401 <<
" totalWished=" << totalWishedNum
402 <<
" adapted=" << adaptedNum
413 if (calibrateFlow && adaptedNum < totalWishedNum && !hadRemovals) {
421 const int insertionSlack =
MAX2(0, adaptedNum + relaxedInsertion - totalWishedNum);
423#ifdef MSCalibrator_DEBUG
425 std::cout <<
" wished:" << wishedNum
426 <<
" slack:" << insertionSlack
427 <<
" before:" << adaptedNum
432 while (wishedNum > adaptedNum + insertionSlack) {
435 if (route ==
nullptr) {
438 if (route ==
nullptr) {
442 if (!route->contains(
myEdge)) {
446 const int routeIndex = (int)std::distance(route->begin(),
447 std::find(route->begin(), route->end(),
myEdge));
449 assert(route != 0 && vtype != 0);
459 newPars->
depart = currentTime;
460 newPars->
routeid = route->getID();
474#ifdef MSCalibrator_DEBUG
476 std::cout <<
" resetting route pos: " << routeIndex <<
"\n";
480 bool success =
false;
489 throw ProcessError(
"Emission of vehicle '" + vehicle->
getID() +
"' in calibrator '" +
getID() +
"'failed!");
493#ifdef MSCalibrator_DEBUG
500#ifdef MSCalibrator_DEBUG
530 for (
int i = 0; i < numLanes; ++i) {
554 for (
int i = 0; i < numLanes; ++i) {
566 if (last !=
nullptr) {
568 return MAX2(overallSpaceLeft, entrySpaceLeft);
570 return overallSpaceLeft;
594 for (std::vector<MSMeanData_Net::MSLaneMeanDataValues*>::iterator it =
myLaneMeanData.begin();
614 if (calibrateFlow && adaptedNum > totalWishedNum) {
615#ifdef MSCalibrator_DEBUG
617 <<
" vaporizing " << vehicle->getID() <<
" to reduce flow\n";
623#ifdef MSCalibrator_DEBUG
625 <<
" vaporizing " << vehicle->getID() <<
" to clear jam\n";
642 bool matchDistribution =
false;
643 if (oldDist !=
nullptr && newDist !=
nullptr && oldDist->
getVals().size() == newDist->
getVals().size()) {
645 if (it != oldDist->
getVals().end()) {
646 matchDistribution =
true;
647 const int distIndex = (int)(it - oldDist->
getVals().begin());
651 if (!matchDistribution) {
653 if (vehicleType ==
nullptr) {
666 if (myUndoCalibration && reason != NOTIFICATION_LANE_CHANGE) {
681 const std::string ds = (discrepancy > 0 ?
"\" vaporizedOnNextEdge=\"" +
toString(discrepancy) :
"");
682 const double durationSeconds =
STEPS2TIME(stopTime - startTime);
691 dev.
writeAttr(
"flow", p * 3600.0 / durationSeconds);
696 if (discrepancy > 0) {
697 dev.
writeAttr(
"vaporizedOnNextEdge", discrepancy);
704 dev.
writeXMLHeader(
"calibratorstats",
"calibratorstats_file.xsd");
711 const int precision = beginS == int(beginS) ? 0 : 2;
719 if (it->begin > begin) {
721 }
else if (it->begin == begin && it->end == end) {
724 state.
q = vehsPerHour;
733 }
else if (begin < it->end) {
734 throw ProcessError(
TLF(
"Cannot set flow for calibrator '%' with overlapping interval.",
getID()));
735 }
else if (begin >= end) {
745 state.
q = vehsPerHour;
#define WRITE_WARNINGF(...)
#define WRITE_ERRORF(...)
#define WRITE_WARNING(msg)
std::shared_ptr< const MSRoute > ConstMSRoutePtr
std::string time2string(SUMOTime t, bool humanReadable)
convert SUMOTime to string (independently of global format setting)
const std::string DEFAULT_VTYPE_ID
@ GIVEN
The lane is given.
@ ALLOWED_FREE
The least occupied lane from lanes which allow the continuation.
@ DEFAULT
No information given; use default.
@ FIRST_ALLOWED
The rightmost lane the vehicle may use.
@ MAX
The maximum safe speed is used.
@ DEFAULT
No information given; use default.
@ SUMO_TAG_INTERVAL
an aggreagated-output interval
@ SUMO_TAG_FLOW
a flow definition using from and to edges or a route
@ SUMO_TAG_CALIBRATOR
A calibrator placed over edge.
PersonMode
travel modes for persons
@ SUMO_ATTR_BEGIN
weights: time range begin
@ SUMO_ATTR_END
weights: time range end
#define UNUSED_PARAMETER(x)
std::string toString(const T &t, std::streamsize accuracy=gPrecision)
void callParentEnd(int element)
signal endElement to the parent handler (special case for MSCalibrator)
void resetRoutePosition(int index, DepartLaneDefinition departLaneProcedure)
reset index of edge within route
virtual double getHeadwayTime() const
Get the driver's desired headway [s].
SUMOTime shiftTime(SUMOTime currentTime, SUMOTime execTime, SUMOTime newTime)
Reschedule or deschedule the command when quick-loading state.
MSCalibrator * myCalibrator
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.
static std::map< std::string, MSCalibrator * > myInstances
OutputDevice * myOutput
The device for xml statistics.
double myInvalidJamThreshold
relative speed threshold for detecting and clearing invalid jam
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 mySpeedIsDefault
The information whether the speed adaption has been reset.
virtual void updateMeanData()
aggregate lane values
int myRemoved
The number of vehicles that were removed in the current interval.
virtual int passed() const
MSCalibrator(const std::string &id, MSEdge *const edge, MSLane *const lane, MSJunction *const node, 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, const bool local, const bool addLaneMeanData)
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
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.
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.
void writeXMLDetectorProlog(OutputDevice &dev) const
Open the XML-output.
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.
bool myAmLocal
whether the calibrator needs to undo the calibration after the edge / junction has been left
AspiredState getCurrentStateInterval() const
bool isCurrentStateActive(SUMOTime time)
MSJunction *const myNode
the junction on which this calibrator lies (nullptr if is edge or lane specific)
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)
bool vehicleApplies(const SUMOTrafficObject &veh) const
Checks whether the detector measures vehicles of the given type.
A road/street connecting two junctions.
const std::vector< MSLane * > & getLanes() const
Returns this edge's lanes.
void setMaxSpeed(double val, double jamThreshold=-1)
Sets a new maximum speed for all lanes (used by TraCI and MSCalibrator)
double getSpeedLimit() const
Returns the speed limit of the edge @caution The speed limit of the first lane is retured; should pro...
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 addEvent(Command *operation, SUMOTime execTimeStep=-1)
Adds an Event.
The base class for an intersection.
const ConstMSEdgeVector & getOutgoing() const
const ConstMSEdgeVector & getIncoming() const
Representation of a lane in the micro simulation.
virtual MSVehicle * removeVehicle(MSVehicle *remVehicle, MSMoveReminder::Notification notification, bool notify=true)
int getVehicleNumber() const
Returns the number of vehicles on this lane (for which this lane is responsible)
MSVehicle * getLastFullVehicle() const
returns the last vehicle for which this lane is responsible or 0
double getLength() const
Returns the lane's length.
int getIndex() const
Returns the lane's index.
void setMaxSpeed(double val, bool byVSS=false, bool byTraCI=false, double jamThreshold=-1)
Sets a new maximum speed for the lane (used by TraCI and MSCalibrator)
double getMeanSpeed() const
Returns the mean speed on this lane.
double getTravelledDistance() const
Returns the total travelled distance.
virtual double getSamples() const
Returns the number of collected sample seconds.
Data structure for mean (aggregated) edge/lane values.
int nVehVaporized
The number of vehicles that left this lane via vaporization within the sample interval.
int nVehLeft
The number of vehicles that left this lane within the sample interval.
int nVehTeleported
The number of vehicles that left this lane via teleporting within the sample interval.
int nVehArrived
The number of vehicles that finished on the lane.
double waitSeconds
The number of vehicle probes with small speed.
int nVehEntered
The number of vehicles that entered this lane within the sample interval.
void reset(bool afterWrite=false)
Resets values so they may be used for the next interval.
Something on a lane to be noticed about vehicle movement.
void setDescription(const std::string &description)
Notification
Definition of a vehicle state.
@ NOTIFICATION_VAPORIZED_CALIBRATOR
The vehicle got removed by a calibrator.
static MSNet * getInstance()
Returns the pointer to the unique instance of MSNet (singleton).
MSEventControl * getEndOfTimestepEvents()
Returns the event control for events executed at the end of a time step.
MSVehicleControl & getVehicleControl()
Returns the vehicle control.
Parser and container for routes during their loading.
virtual void myStartElement(int element, const SUMOSAXAttributes &attrs) override
Called on the opening of a tag;.
static bool dictionary(const std::string &id, ConstMSRoutePtr route)
Adds a route to the dictionary.
Writes routes of vehicles passing a certain edge.
ConstMSRoutePtr sampleRoute(bool last=true) const
The class responsible for building and deletion of vehicles.
SUMOVehicle * getVehicle(const std::string &id) const
Returns the vehicle with the given id.
MSVehicleType * getVType(const std::string &id=DEFAULT_VTYPE_ID, SumoRNG *rng=nullptr, bool readOnly=false)
Returns the named vehicle type or a sample from the named distribution.
virtual SUMOVehicle * buildVehicle(SUMOVehicleParameter *defs, ConstMSRoutePtr route, MSVehicleType *type, const bool ignoreStopErrors, const VehicleDefinitionSource source=ROUTEFILE, bool addRouteStops=true)
Builds a vehicle, increases the number of built vehicles.
const RandomDistributor< MSVehicleType * > * getVTypeDistribution(const std::string &typeDistID) const
return the vehicle type distribution with the given id
void scheduleVehicleRemoval(SUMOVehicle *veh, bool checkDuplicate=false)
Removes a vehicle after it has ended.
virtual void deleteVehicle(SUMOVehicle *v, bool discard=false, bool wasKept=false)
Deletes the vehicle.
Representation of a vehicle in the micro simulation.
void onRemovalFromNet(const MSMoveReminder::Notification reason)
Called when the vehicle is removed from the network.
MSLane * getMutableLane() const
Returns the lane the vehicle is on Non const version indicates that something volatile is going on.
double getPositionOnLane() const
Get the vehicle's position along the lane.
The car-following model and parameter.
double getLengthWithGap() const
Get vehicle's length including the minimum gap [m].
const MSCFModel & getCarFollowModel() const
Returns the vehicle type's car following model definition (const version)
const std::string & getID() const
Returns the id.
Static storage of an output device and its base (abstract) implementation.
OutputDevice & writeAttr(const SumoXMLAttr attr, const T &val)
writes a named attribute
OutputDevice & openTag(const std::string &xmlElement)
Opens an XML tag.
bool closeTag(const std::string &comment="")
Closes the most recently opened tag and optionally adds a comment.
static OutputDevice & getDevice(const std::string &name, bool usePrefix=true)
Returns the described OutputDevice.
bool writeXMLHeader(const std::string &rootElement, const std::string &schemaFile, std::map< SumoXMLAttr, std::string > attrs=std::map< SumoXMLAttr, std::string >(), bool includeConfig=true)
Writes an XML header with optional configuration.
Represents a generic random distribution.
const std::vector< T > & getVals() const
Returns the members of the distribution.
virtual void myEndElement(int element)
Called when a closing tag occurs.
Encapsulated SAX-Attributes.
T getOpt(int attr, const char *objectid, bool &ok, T defaultValue=T(), bool report=true) const
Tries to read given attribute assuming it is an int.
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.
SUMOTime getSUMOTimeReporting(int attr, const char *objectid, bool &ok, bool report=true) const
Tries to read given attribute assuming it is a SUMOTime.
Representation of a vehicle, person, or container.
virtual const MSVehicleType & getVehicleType() const =0
Returns the object's "vehicle" type.
virtual const SUMOVehicleParameter & getParameter() const =0
Returns the vehicle's parameter (including departure definition)
virtual void replaceVehicleType(MSVehicleType *type)=0
Replaces the current vehicle type by the one given.
Structure representing possible vehicle parameter.
int departLane
(optional) The lane the vehicle shall depart from (index in edge)
double departSpeed
(optional) The initial speed of the vehicle
std::string vtypeid
The vehicle's type id.
long long int parametersSet
Information for the router which parameter were set, TraCI may modify this (when changing color)
DepartLaneDefinition departLaneProcedure
Information how the vehicle shall choose the lane to depart from.
DepartSpeedDefinition departSpeedProcedure
Information how the vehicle's initial speed shall be chosen.
std::string routeid
The vehicle's route id.
std::string id
The vehicle's id.
static SUMOVehicleParameter * parseVehicleAttributes(int element, const SUMOSAXAttributes &attrs, const bool hardFail, const bool optionalID=false, const bool skipDepart=false, const bool allowInternalRoutes=false)
Parses a vehicle's attributes.
static bool runParser(GenericSAXHandler &handler, const std::string &file, const bool isNet=false, const bool isRoute=false, const bool isExternal=false, const bool catchExceptions=true)
Runs the given handler on the given file; returns if everything's ok.
SUMOVehicleParameter * vehicleParameter