48 #define DEBUGCOND (getID() == DEBUGID)
49 #define DEBUGCOND2(id) ((id) == DEBUGID)
65 const std::string& aXMLFilename,
66 const std::string& outputFilename,
67 const SUMOTime freq,
const double length,
69 const double invalidJamThreshold,
70 const std::string& vTypes,
71 bool addLaneMeanData) :
77 myPos(pos), myProbe(probe),
78 myMeanDataParent(id +
"_dummyMeanData", 0, 0, false, false, false, false, false, false, 1, 0, 0, vTypes,
""),
79 myEdgeMeanData(nullptr, length, false, &myMeanDataParent),
80 myCurrentStateInterval(myIntervals.begin()),
81 myOutput(nullptr), myFrequency(freq), myRemoved(0),
82 myInserted(0), myClearedInJam(0),
83 mySpeedIsDefault(true), myDidSpeedAdaption(false), myDidInit(false),
84 myDefaultSpeed(myLane == nullptr ? myEdge->getSpeedLimit() : myLane->getSpeedLimit()),
85 myHaveWarnedAboutClearingJam(false),
87 myInvalidJamThreshold(invalidJamThreshold),
88 myHaveInvalidJam(false) {
90 if (outputFilename !=
"") {
94 if (aXMLFilename !=
"") {
100 if (addLaneMeanData) {
106 laneData->
setDescription(
"meandata_calibrator_" + eLane->getID());
146 throw ProcessError(
"Calibrator '" +
getID() +
"' has no active or upcoming interval");
168 if (state.
begin < lastEnd) {
169 WRITE_ERROR(
"Overlapping or unsorted intervals in calibrator '" +
getID() +
"'.");
186 }
else if (
myLane !=
nullptr && (
189 WRITE_WARNING(
"Insertion lane may differ from calibrator lane for calibrator '" +
getID() +
"'.");
196 WRITE_ERROR(
"Mandatory attribute missing in definition of calibrator '" +
getID() +
"'.");
198 WRITE_ERROR(
"Non-numeric value for numeric attribute in definition of calibrator '" +
getID() +
"'.");
201 WRITE_ERROR(
"Either 'vehsPerHour', 'speed' or 'type' has to be set in flow definition of calibrator '" +
getID() +
"'.");
204 WRITE_ERROR(
"Type calibration is not supported in meso for calibrator '" +
getID() +
"'.");
267 return passed() / totalHourFraction;
288 if (vehicle !=
nullptr) {
348 #ifdef MSCalibrator_DEBUG
352 <<
" totalWished=" << totalWishedNum
353 <<
" adapted=" << adaptedNum
364 if (calibrateFlow && adaptedNum < totalWishedNum && !hadRemovals) {
372 const int insertionSlack =
MAX2(0, adaptedNum + relaxedInsertion - totalWishedNum);
374 #ifdef MSCalibrator_DEBUG
376 std::cout <<
" wished:" << wishedNum
377 <<
" slack:" << insertionSlack
378 <<
" before:" << adaptedNum
382 while (wishedNum > adaptedNum + insertionSlack) {
385 if (route ==
nullptr) {
388 if (route ==
nullptr) {
396 const int routeIndex = (int)std::distance(route->
begin(),
399 assert(route != 0 && vtype != 0);
403 newPars->
depart = currentTime;
409 newPars, route, vtype,
true,
false));
419 #ifdef MSCalibrator_DEBUG
421 std::cout <<
" resetting route pos: " << routeIndex <<
"\n";
427 throw ProcessError(
"Emission of vehicle '" + vehicle->
getID() +
"' in calibrator '" +
getID() +
"'failed!");
431 #ifdef MSCalibrator_DEBUG
438 #ifdef MSCalibrator_DEBUG
467 for (
int i = 0; i < numLanes; ++i) {
491 for (
int i = 0; i < numLanes; ++i) {
503 if (last !=
nullptr) {
505 return MAX2(overallSpaceLeft, entrySpaceLeft);
507 return overallSpaceLeft;
530 for (std::vector<MSMeanData_Net::MSLaneMeanDataValues*>::iterator it =
myLaneMeanData.begin();
550 if (calibrateFlow && adaptedNum > totalWishedNum) {
551 #ifdef MSCalibrator_DEBUG
553 <<
" vaporizing " << vehicle->getID() <<
" to reduce flow\n";
559 #ifdef MSCalibrator_DEBUG
561 <<
" vaporizing " << vehicle->getID() <<
" to clear jam\n";
579 bool matchDistribution =
false;
580 if (oldDist !=
nullptr && newDist !=
nullptr && oldDist->
getVals().size() == newDist->
getVals().size()) {
582 if (it != oldDist->
getVals().end()) {
583 matchDistribution =
true;
584 const int distIndex = (int)(it - oldDist->
getVals().begin());
588 if (!matchDistribution) {
590 if (vehicleType ==
nullptr) {
608 const std::string ds = (discrepancy > 0 ?
"\" vaporizedOnNextEdge=\"" +
toString(discrepancy) :
"");
609 const double durationSeconds =
STEPS2TIME(stopTime - startTime);
618 dev.
writeAttr(
"flow", p * 3600.0 / durationSeconds);
623 if (discrepancy > 0) {
624 dev.
writeAttr(
"vaporizedOnNextEdge", discrepancy);
631 dev.
writeXMLHeader(
"calibratorstats",
"calibratorstats_file.xsd");
638 const int precision = beginS == int(beginS) ? 0 : 2;
646 if (it->begin > begin) {
648 }
else if (it->begin == begin && it->end == end) {
651 state.
q = vehsPerHour;
660 }
else if (begin < it->end) {
661 throw ProcessError(
"Cannot set flow for calibrator '" +
getID() +
"' with overlapping interval.");
662 }
else if (begin >= end) {
663 throw ProcessError(
"Cannot set flow for calibrator '" +
getID() +
"' with negative interval.");
672 state.
q = vehsPerHour;
#define WRITE_WARNING(msg)
std::string time2string(SUMOTime t)
convert SUMOTime to string
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 definitio nusing a from-to edges instead of a route (used by router)
@ SUMO_TAG_CALIBRATOR
A calibrator placed over edge.
@ SUMO_ATTR_BEGIN
weights: time range begin
@ SUMO_ATTR_END
weights: time range end
std::string toString(const T &t, std::streamsize accuracy=gPrecision)
void resetRoutePosition(int index, DepartLaneDefinition departLaneProcedure)
reset index of edge within route
virtual double getHeadwayTime() const
Get the driver's desired headway [s].
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 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
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
static std::vector< SUMOVehicleParameter * > LeftoverVehicleParameters
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
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
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
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;.
const std::string & getID() const
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.
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
static std::vector< MSMoveReminder * > LeftoverReminders
friend class VehicleRemover
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 (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.
AspiredState getCurrentStateInterval() const
bool isCurrentStateActive(SUMOTime time)
SUMOTime myFrequency
The frequeny with which to check for calibration.
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.
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.
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.
void setMaxSpeed(double val) const
Sets a new maximum speed for all lanes (used by TraCI and MSCalibrator)
virtual void addEvent(Command *operation, SUMOTime execTimeStep=-1)
Adds an Event.
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)
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 within the sample interval.
int nVehLeft
The number of vehicles that left this lane 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.
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).
MSVehicleControl & getVehicleControl()
Returns the vehicle control.
MSEventControl * getEndOfTimestepEvents()
Returns the event control for events executed at the end of a time step.
Parser and container for routes during their loading.
virtual void myStartElement(int element, const SUMOSAXAttributes &attrs)
Called on the opening of a tag;.
MSRouteIterator end() const
Returns the end of the list of edges to pass.
static bool dictionary(const std::string &id, const MSRoute *route)
Adds a route to the dictionary.
bool contains(const MSEdge *const edge) const
MSRouteIterator begin() const
Returns the begin of the list of edges to pass.
Writes routes of vehicles passing a certain edge.
const MSRoute * sampleRoute(bool last=true) const
An abstract device that changes the state of the micro simulation.
The class responsible for building and deletion of vehicles.
virtual void deleteVehicle(SUMOVehicle *v, bool discard=false)
Deletes the vehicle.
SUMOVehicle * getVehicle(const std::string &id) const
Returns the vehicle with the given id.
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.
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 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.
Representation of a vehicle in the micro simulation.
MSLane * getMutableLane() const
Returns the lane the vehicle is on Non const version indicates that something volatile is going on.
void onRemovalFromNet(const MSMoveReminder::Notification reason)
Called when the vehicle is removed from the network.
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.
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.
OutputDevice & openTag(const std::string &xmlElement)
Opens an XML tag.
OutputDevice & writeAttr(const SumoXMLAttr attr, const T &val)
writes a named attribute
bool closeTag(const std::string &comment="")
Closes the most recently opened tag and optionally adds a comment.
static OutputDevice & getDevice(const std::string &name)
Returns the described OutputDevice.
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, 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.
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)
Parses a vehicle's attributes.
static bool runParser(GenericSAXHandler &handler, const std::string &file, const bool isNet=false, const bool isRoute=false)
Runs the given handler on the given file; returns if everything's ok.
SUMOVehicleParameter * vehicleParameter