65 const MSEdge*
const edge,
const double pos,
66 const std::string& aXMLFilename,
67 const std::string& outputFilename,
68 const SUMOTime freq,
const double length,
70 const bool addLaneMeanData) :
73 myEdge(edge), myPos(pos), myProbe(probe),
74 myEdgeMeanData(0, length, false, 0),
75 myOutput(0), myFrequency(freq), myRemoved(0),
76 myInserted(0), myClearedInJam(0),
77 mySpeedIsDefault(true), myDidSpeedAdaption(false), myDidInit(false),
78 myDefaultSpeed(myEdge->getSpeedLimit()),
79 myHaveWarnedAboutClearingJam(false),
81 if (outputFilename !=
"") {
85 if (aXMLFilename !=
"") {
91 if (addLaneMeanData) {
149 if (state.
begin < lastEnd) {
150 WRITE_ERROR(
"Overlapping or unsorted intervals in calibrator '" +
myID +
"'.");
168 WRITE_ERROR(
"Mandatory attribute missing in definition of calibrator '" +
myID +
"'.");
170 WRITE_ERROR(
"Non-numeric value for numeric attribute in definition of calibrator '" +
myID +
"'.");
172 if (state.
q < 0 && state.
v < 0) {
173 WRITE_ERROR(
"Either 'vehsPerHour' or 'speed' has to be given in flow definition of calibrator '" +
myID +
"'.");
204 assert(discrepancy >= 0);
205 const std::string ds = (discrepancy > 0 ?
"\" vaporizedOnNextEdge=\"" +
toString(discrepancy) :
"");
209 "\" id=\"" <<
myID <<
210 "\" nVehContrib=\"" << p <<
214 "\" flow=\"" << p * 3600.0 / durationSeconds <<
264 WRITE_WARNING(
"Calibrator '" +
getID() +
"' could not remove vehicle '" + *it +
"'.");
308 #ifdef MSCalibrator_DEBUG 311 <<
" totalWished=" << totalWishedNum
312 <<
" adapted=" << adaptedNum
322 if (calibrateFlow && adaptedNum < totalWishedNum && !hadRemovals) {
330 const int insertionSlack =
MAX2(0, adaptedNum + relaxedInsertion - totalWishedNum);
332 #ifdef MSCalibrator_DEBUG 334 <<
" wished:" << wishedNum
335 <<
" slack:" << insertionSlack
336 <<
" before:" << adaptedNum
339 while (wishedNum > adaptedNum + insertionSlack) {
353 const int routeIndex = (int)std::distance(route->
begin(),
356 assert(route != 0 && vtype != 0);
360 newPars->
depart = currentTime;
363 newPars, route, vtype,
true,
false));
364 #ifdef MSCalibrator_DEBUG 365 std::cout <<
" resetting route pos: " << routeIndex <<
"\n";
370 throw ProcessError(
"Emission of vehicle '" + vehicle->
getID() +
"' in calibrator '" +
getID() +
"'failed!");
374 #ifdef MSCalibrator_DEBUG 379 #ifdef MSCalibrator_DEBUG 406 for (
int i = 0; i < numLanes; ++i) {
415 if (lane->getVehicleNumber() < 4) {
430 for (
int i = 0; i < numLanes; ++i) {
437 MSVehicle* last = lane->getLastFullVehicle();
467 for (std::vector<MSMeanData_Net::MSLaneMeanDataValues*>::iterator it =
myLaneMeanData.begin();
477 if (myParent->isActive()) {
478 myParent->updateMeanData();
479 const bool calibrateFlow = myParent->myCurrentStateInterval->q >= 0;
480 const int totalWishedNum = myParent->totalWished();
481 int adaptedNum = myParent->passed() + myParent->myClearedInJam;
483 if (calibrateFlow && adaptedNum > totalWishedNum) {
484 #ifdef MSCalibrator_DEBUG 486 <<
" vaporizing " << vehicle->
getID() <<
" to reduce flow\n";
488 if (myParent->scheduleRemoval(vehicle)) {
489 myParent->myRemoved++;
491 }
else if (myParent->invalidJam(myLaneIndex)) {
492 #ifdef MSCalibrator_DEBUG 494 <<
" vaporizing " << vehicle->
getID() <<
" to clear jam\n";
496 if (!myParent->myHaveWarnedAboutClearingJam) {
497 WRITE_WARNING(
"Clearing jam at calibrator '" + myParent->myID +
"' at time " 499 myParent->myHaveWarnedAboutClearingJam =
true;
501 if (myParent->scheduleRemoval(vehicle)) {
502 myParent->myClearedInJam++;
virtual bool notifyEnter(SUMOVehicle &veh, MSMoveReminder::Notification reason, const MSLane *enteredLane=0)
Checks whether the reminder is activated by a vehicle entering the lane.
double getLengthWithGap() const
Get vehicle's length including the minimum gap [m].
int nVehEntered
The number of vehicles that entered this lane within the sample interval.
bool insertVehicle(SUMOVehicle &v, SUMOTime time, const bool checkOnly=false, const bool forceCheck=false) const
Tries to insert the given vehicle into the network.
MSCalibrator(const std::string &id, const MSEdge *const edge, const double pos, const std::string &aXMLFilename, const std::string &outputFilename, const SUMOTime freq, const double length, const MSRouteProbe *probe, const bool addLaneMeanData=true)
Representation of a vehicle in the micro simulation.
virtual void deleteVehicle(SUMOVehicle *v, bool discard=false)
Deletes the vehicle.
std::string vtypeid
The vehicle's type id.
int nVehVaporized
The number of vehicles that left this lane within the sample interval.
const MSRoute * getRoute() const
a flow definition (used by router)
MSLane * getLane() const
Returns the lane the vehicle is on.
static std::vector< SUMOVehicleParameter * > LeftoverVehicleParameters
virtual int passed() const
virtual void myEndElement(int element)
Called on the closing of a tag;.
Writes routes of vehicles passing a certain edge.
DepartLaneDefinition departLaneProcedure
Information how the vehicle shall choose the lane to depart from.
bool myDidSpeedAdaption
The information whether speed was adapted in the current interval.
double getPositionOnLane() const
Get the vehicle's position along the lane.
static SUMOVehicleParameter * parseVehicleAttributes(const SUMOSAXAttributes &attrs, const bool optionalID=false, const bool skipDepart=false, const bool isPerson=false)
Parses a vehicle's attributes.
SUMOVehicle * getVehicle(const std::string &id) const
Returns the vehicle with the given id.
Notification
Definition of a vehicle state.
std::string time2string(SUMOTime t)
bool myAmActive
whether the calibrator was active when last checking
virtual MSVehicle * removeVehicle(MSVehicle *remVehicle, MSMoveReminder::Notification notification, bool notify=true)
weights: time range begin
const std::vector< MSLane * > & getLanes() const
Returns this edge's lanes.
bool myDidInit
The information whether init was called.
static MSNet * getInstance()
Returns the pointer to the unique instance of MSNet (singleton).
The vehicle got vaporized.
virtual bool addVehicle(const std::string &id, SUMOVehicle *v)
Tries to insert the vehicle into the internal vehicle container.
const std::string & getID() const
Returns the id.
SUMOTime myFrequency
The frequeny with which to check for calibration.
int myRemoved
The number of vehicles that were removed in the current interval.
friend class VehicleRemover
double getLength() const
return the length of the edge
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.
const std::string DEFAULT_VTYPE_ID
int myClearedInJam
The number of vehicles that were removed when clearin a jam.
double getSpeedLimit() const
Returns the speed limit of the edge The speed limit of the first lane is retured; should probably be...
SUMOTime getSUMOTimeReporting(int attr, const char *objectid, bool &ok, bool report=true) const
Tries to read given attribute assuming it is a SUMOTime.
const MSEdge *const myEdge
the edge on which this calibrator lies
virtual void myStartElement(int element, const SUMOSAXAttributes &attrs)
Called on the opening of a tag;.
Data structure for mean (aggregated) edge/lane values.
#define WRITE_WARNING(msg)
The car-following model and parameter.
int totalWished() const
number of vehicles expected to pass this interval
A road/street connecting two junctions.
DepartSpeedDefinition departSpeedProcedure
Information how the vehicle's initial speed shall be chosen.
const MSCFModel & getCarFollowModel() const
Returns the vehicle type's car following model definition (const version)
std::string toString(const T &t, std::streamsize accuracy=gPrecision)
std::vector< AspiredState >::const_iterator myCurrentStateInterval
Iterator pointing to the current interval.
An abstract device that changes the state of the micro simulation.
std::string routeid
The vehicle's route id.
Representation of a vehicle.
The least occupied lane from lanes which allow the continuation.
Encapsulated SAX-Attributes.
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.
MSVehicleControl & getVehicleControl()
Returns the vehicle control.
virtual SUMOVehicle * buildVehicle(SUMOVehicleParameter *defs, const MSRoute *route, const MSVehicleType *type, const bool ignoreStopErrors, const bool fromRouteFile=true)
Builds a vehicle, increases the number of built vehicles.
SUMOTime depart
The vehicle's departure time.
virtual void addEvent(Command *operation, SUMOTime execTimeStep=-1)
Adds an Event.
void resetRoutePosition(int index)
The maximum speed is used.
double myDefaultSpeed
The default (maximum) speed on the segment.
No information given; use default.
bool mySpeedIsDefault
The information whether the speed adaption has been reset.
void onRemovalFromNet(const MSMoveReminder::Notification reason)
Called when the vehicle is removed from the network.
std::vector< AspiredState > myIntervals
List of adaptation intervals.
virtual void reset()
reset collected vehicle data
virtual void myStartElement(int element, const SUMOSAXAttributes &attrs)
Called on the opening of a tag;.
bool myHaveWarnedAboutClearingJam
The default (maximum) speed on the segment.
void setDescription(const std::string &description)
MSEventControl * getEndOfTimestepEvents()
Returns the event control for events executed at the end of a time step.
double waitSeconds
The number of vehicle probes with small speed.
double getTravelledDistance() const
Returns the total travelled distance.
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.
bool invalidJam(int laneIndex) const
No information given; use default.
virtual void myEndElement(int element)
Called when a closing tag occurs.
std::vector< MSMeanData_Net::MSLaneMeanDataValues * > myLaneMeanData
data collector for the calibrator
static std::vector< MSMoveReminder * > LeftoverReminders
std::string myID
The name of the object.
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.
void scheduleVehicleRemoval(SUMOVehicle *veh)
Removes a vehicle after it has ended.
Structure representing possible vehicle parameter.
virtual double getHeadwayTime() const
Get the driver's reaction time [s].
static OutputDevice & getDevice(const std::string &name)
Returns the described OutputDevice.
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.
SUMOVehicleParameter * vehicleParameter
void setMaxSpeed(double val) const
Sets a new maximum speed for all lanes (used by TraCI and MSCalibrator)
const MSRouteProbe *const myProbe
the route probe to retrieve routes from
static void cleanup()
cleanup remaining data structures
OutputDevice * myOutput
The device for xml statistics.
virtual void updateMeanData()
aggregate lane values
virtual SUMOTime execute(SUMOTime currentTime)
virtual double getSamples() const
Returns the number of collected sample seconds.
bool removePending()
remove any vehicles which are scheduled for removal. return true if removals took place ...
void reset(bool afterWrite=false)
Resets values so they may be used for the next interval.
MSMeanData_Net::MSLaneMeanDataValues myEdgeMeanData
accumlated data for the whole edge
MSRouteIterator begin() const
Returns the begin of the list of edges to pass.
The class responsible for building and deletion of vehicles.
bool isCurrentStateActive(SUMOTime time)
std::vector< VehicleRemover * > myVehicleRemovers
int remainingVehicleCapacity(int laneIndex) const
MSVehicleType * getVType(const std::string &id=DEFAULT_VTYPE_ID, MTRand *rng=0)
Returns the named vehicle type or a sample from the named distribution.
const std::string & getID() const
Returns the name of the vehicle.
Representation of a lane in the micro simulation.
std::set< std::string > myToRemove
set of vehicle ids to remove
MSRouteIterator end() const
Returns the end of the list of edges to pass.
Parser and container for routes during their loading.
bool contains(const MSEdge *const edge) const
int myInserted
The number of vehicles that were inserted in the current interval.
std::string id
The vehicle's id.
static bool dictionary(const std::string &id, const MSRoute *route)
Adds a route to the dictionary.