53 myCollector(collector), myPosition(crossSection.myPosition) {
59 #ifdef DEBUG_E3_NOTIFY_ENTER
60 if (
DEBUG_COND(myCollector) && DEBUG_COND_VEH(veh)) {
62 <<
" MSE3EntryReminder::notifyEnter() (" << getDescription() <<
"on lane '" << myLane->getID() <<
"')"
63 <<
" vehicle '" << veh.
getID() <<
"'"
64 <<
" enteredLane=" << enteredLane->
getID()
65 <<
" reason=" << reason
69 if (reason != NOTIFICATION_JUNCTION) {
71 if (myLane == enteredLane && posOnLane > myPosition) {
75 const auto& itVeh = myCollector.myEnteredContainer.find(&veh);
76 if (itVeh == myCollector.myEnteredContainer.end() ||
77 itVeh->second.entryReminder !=
this) {
78 #ifdef DEBUG_E3_NOTIFY_ENTER
79 if (
DEBUG_COND(myCollector) && DEBUG_COND_VEH(veh)) {
80 std::cout <<
" assume already known\n";
94 double newPos,
double newSpeed) {
95 #ifdef DEBUG_E3_NOTIFY_MOVE
96 if (
DEBUG_COND(myCollector) && DEBUG_COND_VEH(veh)) {
98 <<
" MSE3EntryReminder::notifyMove() (" << getDescription() <<
"on lane '" << myLane->getID() <<
"')"
99 <<
" vehicle '" << veh.
getID() <<
"'"
100 <<
" entered. oldPos=" << oldPos <<
" newPos=" << newPos <<
" newSpeed=" << newSpeed
101 <<
" myPosition=" << myPosition
108 if (myCollector.myEnteredContainer.find(&veh) == myCollector.myEnteredContainer.end() && newPos > myPosition) {
109 if (oldPos > myPosition) {
111 #ifdef DEBUG_E3_NOTIFY_MOVE
112 if (
DEBUG_COND(myCollector) && DEBUG_COND_VEH(veh)) {
113 std::cout <<
" already behind\n";
123 const double fractionTimeOnDet =
TS - timeBeforeEnter;
124 myCollector.enter(veh, entryTime - fractionTimeOnDet, fractionTimeOnDet,
this);
125 #ifdef DEBUG_E3_NOTIFY_MOVE
126 if (
DEBUG_COND(myCollector) && DEBUG_COND_VEH(veh)) {
127 std::cout <<
" enter\n";
138 #ifdef DEBUG_E3_NOTIFY_LEAVE
139 if (
DEBUG_COND(myCollector) && DEBUG_COND_VEH(veh)) {
141 <<
" MSE3EntryReminder::notifyLeave() (" << getDescription() <<
"on lane '" << myLane->getID() <<
"')"
142 <<
" vehicle '" << veh.
getID() <<
"'"
143 <<
" reason=" << reason
151 if (myCollector.myEnteredContainer.erase(&veh) > 0) {
166 myCollector(collector), myPosition(crossSection.myPosition) {}
171 #ifdef DEBUG_E3_NOTIFY_ENTER
172 if (
DEBUG_COND(myCollector) && DEBUG_COND_VEH(veh)) {
174 <<
" MSE3LeaveReminder::notifyEnter() (" << getDescription() <<
"on lane '" << myLane->getID() <<
"')"
175 <<
" vehicle '" << veh.
getID() <<
"'"
176 <<
" enteredLane=" << enteredLane->
getID()
177 <<
" reason=" << reason
182 if (reason != NOTIFICATION_JUNCTION) {
184 if (backPosOnLane > myPosition) {
187 #ifdef DEBUG_E3_NOTIFY_ENTER
188 if (
DEBUG_COND(myCollector) && DEBUG_COND_VEH(veh)) {
189 std::cout <<
" assume already known\n";
201 double newPos,
double newSpeed) {
202 #ifdef DEBUG_E3_NOTIFY_MOVE
203 if (
DEBUG_COND(myCollector) && DEBUG_COND_VEH(veh)) {
205 <<
" MSE3LeaveReminder::notifyMove() (" << getDescription() <<
" on lane '" << myLane->getID() <<
"')"
206 <<
" vehicle '" << veh.
getID() <<
"'"
207 <<
" entered. oldPos=" << oldPos <<
" newPos=" << newPos <<
" newSpeed=" << newSpeed
208 <<
" myPosition=" << myPosition
212 if (newPos < myPosition) {
220 if (oldPos < myPosition) {
224 const double leaveTimeFront =
SIMTIME -
TS + timeBeforeLeave;
225 myCollector.leaveFront(veh, leaveTimeFront);
226 #ifdef DEBUG_E3_NOTIFY_MOVE
227 if (
DEBUG_COND(myCollector) && DEBUG_COND_VEH(veh)) {
228 std::cout <<
" leaveFront\n";
233 if (backPos < myPosition) {
239 const double leaveStep =
SIMTIME;
241 const double timeBeforeLeave =
MSCFModel::passingTime(oldBackPos, myPosition, backPos, oldSpeed, newSpeed);
242 myCollector.leave(veh, leaveStep -
TS + timeBeforeLeave, timeBeforeLeave);
243 #ifdef DEBUG_E3_NOTIFY_MOVE
244 if (
DEBUG_COND(myCollector) && DEBUG_COND_VEH(veh)) {
245 std::cout <<
" leave\n";
254 #ifdef DEBUG_E3_NOTIFY_LEAVE
255 if (
DEBUG_COND(myCollector) && DEBUG_COND_VEH(veh)) {
257 <<
" MSE3LeaveReminder::notifyLeave() (" << getDescription() <<
"on lane '" << myLane->getID() <<
"')"
258 <<
" vehicle '" << veh.
getID() <<
"'"
259 <<
" reason=" << reason
265 #ifdef DEBUG_E3_NOTIFY_LEAVE
266 if (
DEBUG_COND(myCollector) && DEBUG_COND_VEH(veh)) {
267 std::cout <<
" remove reminder, keep in container\n";
277 myCollector.myEnteredContainer.erase(&veh);
281 if (myCollector.myEnteredContainer.erase(&veh) > 0) {
295 double haltingSpeedThreshold,
297 const std::string& vTypes,
340 const double speedFraction = veh.
getSpeed() * fractionTimeOnDet;
393 const double speedFraction = veh.
getSpeed() * (
TS - fractionTimeOnDet);
412 dev <<
" <interval begin=\"" <<
time2string(startTime) <<
"\" end=\"" <<
time2string(stopTime) <<
"\" " <<
"id=\"" <<
myID <<
"\" ";
415 double meanTravelTime = 0.;
416 double meanOverlapTravelTime = 0.;
417 double meanSpeed = 0.;
418 double meanHaltsPerVehicle = 0.;
419 double meanTimeLoss = 0.;
421 meanHaltsPerVehicle += (double)values.haltings;
422 meanTravelTime += values.frontLeaveTime - values.entryTime;
423 const double steps = values.backLeaveTime - values.entryTime;
424 meanOverlapTravelTime += steps;
425 meanSpeed += (values.speedSum / steps);
428 meanTravelTime = vehicleSum != 0 ? meanTravelTime / (double)vehicleSum : -1;
429 meanOverlapTravelTime = vehicleSum != 0 ? meanOverlapTravelTime / (double)vehicleSum : -1;
430 meanSpeed = vehicleSum != 0 ? meanSpeed / (double)vehicleSum : -1;
431 meanHaltsPerVehicle = vehicleSum != 0 ? meanHaltsPerVehicle / (double) vehicleSum : -1;
432 meanTimeLoss = vehicleSum != 0 ? meanTimeLoss / (double) vehicleSum : -1;
438 double meanSpeedWithin = 0.;
439 double meanDurationWithin = 0.;
440 double meanHaltsPerVehicleWithin = 0.;
441 double meanIntervalSpeedWithin = 0.;
442 double meanIntervalHaltsPerVehicleWithin = 0.;
443 double meanIntervalDurationWithin = 0.;
444 double meanTimeLossWithin = 0.;
446 meanHaltsPerVehicleWithin += (double)(*i).second.haltings;
447 meanIntervalHaltsPerVehicleWithin += (
double)(*i).second.intervalHaltings;
448 const double end = (*i).second.backLeaveTime == 0 ?
STEPS2TIME(stopTime) : (*i).second.backLeaveTime;
449 const double time = end - (*i).second.entryTime;
450 const double timeWithin =
MIN2(time, end -
STEPS2TIME(startTime));
451 if (i->second.speedSum > 0.) {
452 meanSpeedWithin += i->second.speedSum / time;
454 if (i->second.intervalSpeedSum > 0.) {
455 meanIntervalSpeedWithin += i->second.intervalSpeedSum / timeWithin;
457 meanDurationWithin += time;
458 meanIntervalDurationWithin += timeWithin;
460 (*i).second.intervalHaltings = 0;
461 (*i).second.intervalSpeedSum = 0;
464 const SUMOTime currentTimeLoss =
static_cast<const MSVehicle*
>(i->first)->getTimeLoss();
465 meanTimeLossWithin +=
STEPS2TIME(currentTimeLoss - (*i).second.intervalTimeLoss);
466 (*i).second.intervalTimeLoss = currentTimeLoss;
470 meanSpeedWithin = vehicleSumWithin != 0 ? meanSpeedWithin / (double) vehicleSumWithin : -1;
471 meanHaltsPerVehicleWithin = vehicleSumWithin != 0 ? meanHaltsPerVehicleWithin / (double) vehicleSumWithin : -1;
472 meanDurationWithin = vehicleSumWithin != 0 ? meanDurationWithin / (double) vehicleSumWithin : -1;
473 meanIntervalSpeedWithin = vehicleSumWithin != 0 ? meanIntervalSpeedWithin / (double) vehicleSumWithin : -1;
474 meanIntervalHaltsPerVehicleWithin = vehicleSumWithin != 0 ? meanIntervalHaltsPerVehicleWithin / (double) vehicleSumWithin : -1;
475 meanIntervalDurationWithin = vehicleSumWithin != 0 ? meanIntervalDurationWithin / (double) vehicleSumWithin : -1;
476 meanTimeLossWithin = vehicleSumWithin != 0 ? meanTimeLossWithin / (double) vehicleSumWithin : -1;
479 dev <<
"meanTravelTime=\"" << meanTravelTime
480 <<
"\" meanOverlapTravelTime=\"" << meanOverlapTravelTime
481 <<
"\" meanSpeed=\"" << meanSpeed
482 <<
"\" meanHaltsPerVehicle=\"" << meanHaltsPerVehicle
483 <<
"\" meanTimeLoss=\"" << meanTimeLoss
484 <<
"\" vehicleSum=\"" << vehicleSum
485 <<
"\" meanSpeedWithin=\"" << meanSpeedWithin
486 <<
"\" meanHaltsPerVehicleWithin=\"" << meanHaltsPerVehicleWithin
487 <<
"\" meanDurationWithin=\"" << meanDurationWithin
488 <<
"\" vehicleSumWithin=\"" << vehicleSumWithin
489 <<
"\" meanIntervalSpeedWithin=\"" << meanIntervalSpeedWithin
490 <<
"\" meanIntervalHaltsPerVehicleWithin=\"" << meanIntervalHaltsPerVehicleWithin
491 <<
"\" meanIntervalDurationWithin=\"" << meanIntervalDurationWithin
492 <<
"\" meanTimeLossWithin=\"" << meanTimeLossWithin
509 #ifdef DEBUG_E3_DETECTORUPDATE
512 std::cout <<
SIMTIME <<
" vehPtr=" << veh <<
"\n";
513 std::cout <<
" veh=" << veh->
getID() <<
"\n";
562 std::vector<std::string>
564 std::vector<std::string> ret;
566 ret.push_back((*pair).first->getID());
568 std::sort(ret.begin(), ret.end());
CrossSectionVector::const_iterator CrossSectionVectorConstIt
std::vector< MSCrossSection > CrossSectionVector
#define WRITE_WARNING(msg)
std::string time2string(SUMOTime t)
convert SUMOTime to string
@ SUMO_TAG_E3DETECTOR
an e3 detector
std::string toString(const T &t, std::streamsize accuracy=gPrecision)
A scoped lock which only triggers on condition.
static double passingTime(const double lastPos, const double passedPos, const double currentPos, const double lastSpeed, const double currentSpeed)
Calculates the time at which the position passedPosition has been passed In case of a ballistic updat...
A simple description of a position on a lane (crossing of a lane)
Base of value-generating classes (detectors)
bool vehicleApplies(const SUMOTrafficObject &veh) const
Checks whether the detector measures vehicles of the given type.
A place on the road net (at a certain lane and position on it) where the E3 area begins.
bool notifyMove(SUMOTrafficObject &veh, double, double newPos, double)
Checks whether the vehicle enters.
MSE3EntryReminder(const MSCrossSection &crossSection, MSE3Collector &collector)
Constructor.
bool notifyLeave(SUMOTrafficObject &veh, double lastPos, MSMoveReminder::Notification reason, const MSLane *enteredLane=0)
Processes state changes of a vehicle.
bool notifyEnter(SUMOTrafficObject &veh, Notification reason, const MSLane *enteredLane)
Checks whether the reminder is activated by a vehicle entering the lane.
A place on the road net (at a certain lane and position on it) where the E3 area ends.
MSE3LeaveReminder(const MSCrossSection &crossSection, MSE3Collector &collector)
Constructor.
bool notifyEnter(SUMOTrafficObject &veh, Notification reason, const MSLane *enteredLane)
Checks whether the reminder is activated by a vehicle entering the lane.
bool notifyMove(SUMOTrafficObject &veh, double oldPos, double newPos, double)
Checks whether the vehicle leaves.
bool notifyLeave(SUMOTrafficObject &veh, double lastPos, MSMoveReminder::Notification reason, const MSLane *enteredLane=0)
Processes state changes of a vehicle.
A detector of vehicles passing an area between entry/exit points.
std::vector< E3Values > myLeftContainer
Container for vehicles that have left the area.
std::map< const SUMOTrafficObject *, E3Values > myEnteredContainer
Container for vehicles that have entered the area.
double myHaltingSpeedThreshold
Speed-threshold to determine if a vehicle is halting.
double myCurrentMeanSpeed
The current mean speed of known vehicles (inside)
virtual void clearState()
Remove all vehicles before quick-loading state.
void reset()
Resets all generated values to allow computation of next interval.
CrossSectionVector myExits
The detector's exits.
int myCurrentHaltingsNumber
The current number of haltings (inside)
void enter(const SUMOTrafficObject &veh, const double entryTimestep, const double fractionTimeOnDet, MSE3EntryReminder *entryReminder)
Called if a vehicle touches an entry-cross-section.
SUMOTime myLastResetTime
Information when the last reset has been done.
int getVehiclesWithin() const
Returns the number of vehicles within the area.
std::vector< MSE3EntryReminder * > myEntryReminders
The detector's built entry reminder.
const bool myOpenEntry
whether this dector is declared as having incomplete entry detectors
void leave(const SUMOTrafficObject &veh, const double leaveTimestep, const double fractionTimeOnDet)
Called if a vehicle back passes a leave-cross-section.
std::vector< MSE3LeaveReminder * > myLeaveReminders
The detector's built exit reminder.
std::vector< std::string > getCurrentVehicleIDs() const
Returns the number of vehicles within the area.
virtual ~MSE3Collector()
Destructor.
void writeXMLDetectorProlog(OutputDevice &dev) const
Opens the XML-output using "e3Detector" as root element.
double getCurrentMeanSpeed() const
Returns the mean speed within the area.
int getCurrentHaltingNumber() const
Returns the number of current haltings within the area.
void detectorUpdate(const SUMOTime step)
Computes the detector values in each time step.
MSE3Collector(const std::string &id, const CrossSectionVector &entries, const CrossSectionVector &exits, double haltingSpeedThreshold, SUMOTime haltingTimeThreshold, const std::string &vTypes, bool openEntry)
Constructor.
SUMOTime myHaltingTimeThreshold
CrossSectionVector myEntries
The detector's entries.
void writeXMLOutput(OutputDevice &dev, SUMOTime startTime, SUMOTime stopTime)
Writes collected values into the given stream.
void leaveFront(const SUMOTrafficObject &veh, const double leaveTimestep)
Called if a vehicle front passes a leave-cross-section.
static bool gSemiImplicitEulerUpdate
static int gNumSimThreads
how many threads to use for simulation
Representation of a lane in the micro simulation.
MSEdge & getEdge() const
Returns the lane's edge.
Something on a lane to be noticed about vehicle movement.
Notification
Definition of a vehicle state.
@ NOTIFICATION_ARRIVED
The vehicle arrived at its destination (is deleted)
@ NOTIFICATION_LANE_CHANGE
The vehicle changes lanes (micro only)
@ NOTIFICATION_TELEPORT
The vehicle is being teleported.
static MSNet * getInstance()
Returns the pointer to the unique instance of MSNet (singleton).
Representation of a vehicle in the micro simulation.
double getLength() const
Get vehicle's length [m].
std::string myID
The name of the object.
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.
Representation of a vehicle, person, or container.
virtual double getPreviousSpeed() const =0
Returns the object's previous speed.
virtual double getSpeed() const =0
Returns the object's current speed.
virtual const MSVehicleType & getVehicleType() const =0
Returns the object's "vehicle" type.
virtual double getBackPositionOnLane(const MSLane *lane) const =0
Get the object's back position along the given lane.
Internal storage for values from a vehicle.
int intervalHaltings
The sum of haltings the vehicle has/had within the area during the current interval.
MSE3EntryReminder * entryReminder
the reminder on which the vehicle entered the detector
SUMOTime timeLoss
The timeLoss of the vehicle when entering. Updated to the actual time loss within the area when leavi...
double frontLeaveTime
The time the vehicle's front was crossing the leave line.
double entryTime
The vehicle's entry time.
SUMOTime intervalTimeLoss
The timeLoss of the vehicle when entering. Updated to the current timeLoss at interval write.
double speedSum
The sum of registered speeds the vehicle has/had inside the area.
bool hadUpdate
An internal information whether the update step was performed.
SUMOTime haltingBegin
Begin time of last halt begin.
double intervalSpeedSum
The sum of registered speeds the vehicle has/had inside the area during the current interval.
int haltings
The sum of haltings the vehicle has/had within the area.
double backLeaveTime
The time the vehicle's back was crossing the leave line.