52 #ifdef CHECK_MEMORY_LEAKS
54 #endif // CHECK_MEMORY_LEAKS
69 const std::string& aXMLFilename,
70 const std::string& outputFilename,
73 const bool addLaneMeanData) :
76 myEdge(edge), myPos(pos), myProbe(probe),
77 myEdgeMeanData(0, length, false),
78 myOutput(0), myFrequency(freq), myRemoved(0),
79 myInserted(0), myClearedInJam(0),
80 mySpeedIsDefault(true), myDidSpeedAdaption(false), myDidInit(false),
81 myDefaultSpeed(myEdge->getSpeedLimit()),
82 myHaveWarnedAboutClearingJam(false),
84 if (outputFilename !=
"") {
88 if (aXMLFilename !=
"") {
94 if (addLaneMeanData) {
154 if (state.
begin < lastEnd) {
155 WRITE_ERROR(
"Overlapping or unsorted intervals in calibrator '" +
myID +
"'.");
173 WRITE_ERROR(
"Mandatory attribute missing in definition of calibrator '" +
myID +
"'.");
175 WRITE_ERROR(
"Non-numeric value for numeric attribute in definition of calibrator '" +
myID +
"'.");
177 if (state.
q < 0 && state.
v < 0) {
178 WRITE_ERROR(
"Either 'vehsPerHour' or 'speed' has to be given in flow definition of calibrator '" +
myID +
"'.");
209 assert(discrepancy >= 0);
210 const std::string ds = (discrepancy > 0 ?
"\" vaporizedOnNextEdge=\"" +
toString(discrepancy) :
"");
214 "\" id=\"" <<
myID <<
215 "\" nVehContrib=\"" << p <<
219 "\" flow=\"" << p * 3600.0 / durationSeconds <<
317 #ifdef MSCalibrator_DEBUG
320 <<
" totalWished=" << totalWishedNum
321 <<
" adapted=" << adaptedNum
331 if (calibrateFlow && adaptedNum < totalWishedNum && !hadRemovals) {
339 const int insertionSlack =
MAX2(0, adaptedNum + relaxedInsertion - totalWishedNum);
341 #ifdef MSCalibrator_DEBUG
343 <<
" wished:" << wishedNum
344 <<
" slack:" << insertionSlack
345 <<
" before:" << adaptedNum
348 while (wishedNum > adaptedNum + insertionSlack) {
362 const unsigned int routeIndex = (
unsigned int)std::distance(route->
begin(),
365 assert(route != 0 && vtype != 0);
369 newPars->
depart = currentTime;
372 newPars, route, vtype));
373 #ifdef MSCalibrator_DEBUG
374 std::cout <<
" resetting route pos: " << routeIndex <<
"\n";
380 throw ProcessError(
"Emission of vehicle '" + vehicle->
getID() +
"' in calibrator '" +
getID() +
"'failed!");
384 #ifdef MSCalibrator_DEBUG
389 #ifdef MSCalibrator_DEBUG
416 for (
int i = 0; i < numLanes; ++i) {
425 if (lane->getVehicleNumber() < 4) {
440 for (
int i = 0; i < numLanes; ++i) {
447 MSVehicle* last = lane->getLastVehicle();
477 for (std::vector<MSMeanData_Net::MSLaneMeanDataValues*>::iterator it =
myLaneMeanData.begin();
493 if (calibrateFlow && adaptedNum > totalWishedNum) {
494 #ifdef MSCalibrator_DEBUG
496 <<
" vaporizing " << vehicle->
getID() <<
" to reduce flow\n";
502 #ifdef MSCalibrator_DEBUG
504 <<
" vaporizing " << vehicle->
getID() <<
" to clear jam\n";
void resetRoutePosition(unsigned int index)
MSCalibrator(const std::string &id, const MSEdge *const edge, const SUMOReal pos, const std::string &aXMLFilename, const std::string &outputFilename, const SUMOTime freq, const SUMOReal length, const MSRouteProbe *probe, const bool addLaneMeanData=true)
static SUMOVehicleParameter * parseVehicleAttributes(const SUMOSAXAttributes &attrs, bool optionalID=false, bool skipDepart=false)
Parses a vehicle's attributes.
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.
unsigned nVehVaporized
The number of vehicles that left this lane within the sample interval.
const std::vector< MSLane * > & getLanes() const
Returns this edge's lanes.
MSEventControl & getEndOfTimestepEvents()
Returns the event control for events executed at the end of a time step.
SUMOReal getLengthWithGap() const
Get vehicle's length including the minimum gap [m].
static std::vector< SUMOVehicleParameter * > LeftoverVehicleParameters
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.
unsigned int myClearedInJam
The number of vehicles that were removed when clearin a jam.
bool myDidSpeedAdaption
The information whether speed was adapted in the current interval.
SUMOReal travelledDistance
The sum of the distances the vehicles travelled.
MSVehicleType * getVType(const std::string &id=DEFAULT_VTYPE_ID)
Returns the named vehicle type or a sample from the named distribution.
virtual bool notifyEnter(SUMOVehicle &veh, Notification reason)
Checks whether the reminder is activated by a vehicle entering the lane.
Notification
Definition of a vehicle state.
std::string time2string(SUMOTime t)
bool myAmActive
whether the calibrator was active when last checking
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.
SUMOReal getPositionOnLane() const
Get the vehicle's position along the lane.
SUMOTime myFrequency
The frequeny with which to check for calibration.
static bool runParser(GenericSAXHandler &handler, const std::string &file)
Runs the given handler on the given file; returns if everything's ok.
friend class VehicleRemover
const std::string DEFAULT_VTYPE_ID
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.
const MSCFModel & getCarFollowModel() const
Returns the vehicle type's car following model definition (const version)
SUMOReal waitSeconds
The number of vehicle probes with small speed.
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.
bool writeXMLHeader(const std::string &rootElement, const std::string &attrs="", const std::string &comment="")
Writes an XML header with optional configuration.
virtual SUMOVehicle * buildVehicle(SUMOVehicleParameter *defs, const MSRoute *route, const MSVehicleType *type)
Builds a vehicle, increases the number of built vehicles.
int remainingVehicleCapacity(int laneIndex) const
const std::string & getID() const
Returns the id.
A road/street connecting two junctions.
SUMOReal getLength() const
return the length of the edge
DepartSpeedDefinition departSpeedProcedure
Information how the vehicle's initial speed shall be chosen.
unsigned int myInserted
The number of vehicles that were inserted in the current interval.
virtual MSVehicle * removeVehicle(MSVehicle *remVehicle, MSMoveReminder::Notification notification)
remove the vehicle from this lane
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.
unsigned nVehArrived
The number of vehicles that finished on the lane.
MSVehicleControl & getVehicleControl()
Returns the vehicle control.
bool invalidJam(int laneIndex) const
unsigned nVehEntered
The number of vehicles that entered this lane within the sample interval.
bool contains(const MSEdge *const edge) const
SUMOTime depart
The vehicle's departure time.
The maximum speed is used.
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.
bool scheduleRemoval(MSVehicle *veh)
try to schedule the givne vehicle for removal. return true if it isn't already scheduled ...
std::vector< AspiredState > myIntervals
List of adaptation intervals.
std::string toString(const T &t, std::streamsize accuracy=OUTPUT_ACCURACY)
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 reset()
reset collected vehicle data
SUMOReal getSpeedLimit() const
Returns the speed limit of the edge The speed limit of the first lane is retured; should probably be...
virtual void myStartElement(int element, const SUMOSAXAttributes &attrs)
Called on the opening of a tag;.
virtual SUMOReal getHeadwayTime() const
Get the driver's reaction time [s].
virtual SUMOTime addEvent(Command *operation, SUMOTime execTimeStep, AdaptType type)
Adds an Event.
bool myHaveWarnedAboutClearingJam
The default (maximum) speed on the segment.
void setDescription(const std::string &description)
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
const MSRoute * getRoute() const
static std::vector< MSMoveReminder * > LeftoverReminders
std::string myID
The name of the object.
void scheduleVehicleRemoval(SUMOVehicle *veh)
Removes a vehicle after it has ended.
Structure representing possible vehicle parameter.
MSRouteIterator end() const
Returns the end of the list of edges to pass.
static OutputDevice & getDevice(const std::string &name)
Returns the described OutputDevice.
void onDepart()
Called when the vehicle is inserted into the network.
SUMOVehicleParameter * vehicleParameter
unsigned nVehLeft
The number of vehicles that left this lane within the sample interval.
const MSRouteProbe *const myProbe
the route probe to retrieve routes from
static void cleanup()
cleanup remaining data structures
SUMOVehicle * getVehicle(const std::string &id) const
Returns the vehicle with the given id.
OutputDevice * myOutput
The device for xml statistics.
virtual void updateMeanData()
aggregate lane values
virtual int passed() const
virtual SUMOTime execute(SUMOTime currentTime)
Patch the time in a way that it is at least as high as the simulation begin time. ...
virtual SUMOReal 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.
int totalWished() const
number of vehicles expected to pass this interval
MSMeanData_Net::MSLaneMeanDataValues myEdgeMeanData
accumlated data for the whole edge
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.
The class responsible for building and deletion of vehicles.
bool isCurrentStateActive(SUMOTime time)
std::vector< VehicleRemover * > myVehicleRemovers
bool insertVehicle(SUMOVehicle &v, SUMOTime time) const
Tries to insert the given vehicle into the network.
MSLane * getLane() const
Returns the lane the vehicle is on.
Representation of a lane in the micro simulation.
unsigned int myRemoved
The number of vehicles that were removed in the current interval.
std::set< std::string > myToRemove
set of vehicle ids to remove
Parser and container for routes during their loading.
SUMOReal myDefaultSpeed
The default (maximum) speed on the segment.
MSRouteIterator begin() const
Returns the begin of the list of edges to pass.
std::string id
The vehicle's id.
const std::string & getID() const
Returns the name of the vehicle.
static bool dictionary(const std::string &id, const MSRoute *route)
Adds a route to the dictionary.