59 myCollector(collector), myPosition(crossSection.myPosition) {
65 #ifdef DEBUG_E3_NOTIFY_ENTER
66 if (
DEBUG_COND(myCollector) && DEBUG_COND_VEH(veh)) {
68 <<
" MSE3EntryReminder::notifyEnter() (" << getDescription() <<
"on lane '" << myLane->getID() <<
"')"
69 <<
" vehicle '" << veh.
getID() <<
"'"
70 <<
" enteredLane=" << enteredLane->
getID()
71 <<
" reason=" << reason
75 if (reason != NOTIFICATION_JUNCTION) {
77 if (myLane == enteredLane && posOnLane > myPosition) {
81 const auto& itVeh = myCollector.myEnteredContainer.find(&veh);
82 if (itVeh == myCollector.myEnteredContainer.end() ||
83 itVeh->second.entryReminder !=
this) {
84 #ifdef DEBUG_E3_NOTIFY_ENTER
85 if (
DEBUG_COND(myCollector) && DEBUG_COND_VEH(veh)) {
86 std::cout <<
" assume already known\n";
100 double newPos,
double newSpeed) {
101 #ifdef DEBUG_E3_NOTIFY_MOVE
102 if (
DEBUG_COND(myCollector) && DEBUG_COND_VEH(veh)) {
104 <<
" MSE3EntryReminder::notifyMove() (" << getDescription() <<
"on lane '" << myLane->getID() <<
"')"
105 <<
" vehicle '" << veh.
getID() <<
"'"
106 <<
" entered. oldPos=" << oldPos <<
" newPos=" << newPos <<
" newSpeed=" << newSpeed
107 <<
" myPosition=" << myPosition
114 if ((myCollector.myEnteredContainer.find(&veh) == myCollector.myEnteredContainer.end() ||
116 && newPos > myPosition) {
117 if (oldPos > myPosition) {
119 #ifdef DEBUG_E3_NOTIFY_MOVE
120 if (
DEBUG_COND(myCollector) && DEBUG_COND_VEH(veh)) {
121 std::cout <<
" already behind\n";
131 const double fractionTimeOnDet =
TS - timeBeforeEnter;
132 myCollector.enter(veh, entryTime - fractionTimeOnDet, fractionTimeOnDet,
this);
133 #ifdef DEBUG_E3_NOTIFY_MOVE
134 if (
DEBUG_COND(myCollector) && DEBUG_COND_VEH(veh)) {
135 std::cout <<
" enter\n";
146 #ifdef DEBUG_E3_NOTIFY_LEAVE
147 if (
DEBUG_COND(myCollector) && DEBUG_COND_VEH(veh)) {
149 <<
" MSE3EntryReminder::notifyLeave() (" << getDescription() <<
"on lane '" << myLane->getID() <<
"')"
150 <<
" vehicle '" << veh.
getID() <<
"'"
151 <<
" reason=" << reason
159 if (myCollector.myEnteredContainer.erase(&veh) > 0) {
174 myCollector(collector), myPosition(crossSection.myPosition) {}
179 #ifdef DEBUG_E3_NOTIFY_ENTER
180 if (
DEBUG_COND(myCollector) && DEBUG_COND_VEH(veh)) {
182 <<
" MSE3LeaveReminder::notifyEnter() (" << getDescription() <<
"on lane '" << myLane->getID() <<
"')"
183 <<
" vehicle '" << veh.
getID() <<
"'"
184 <<
" enteredLane=" << enteredLane->
getID()
185 <<
" reason=" << reason
190 if (reason != NOTIFICATION_JUNCTION) {
192 if (backPosOnLane > myPosition) {
195 #ifdef DEBUG_E3_NOTIFY_ENTER
196 if (
DEBUG_COND(myCollector) && DEBUG_COND_VEH(veh)) {
197 std::cout <<
" assume already known\n";
209 double newPos,
double newSpeed) {
210 #ifdef DEBUG_E3_NOTIFY_MOVE
211 if (
DEBUG_COND(myCollector) && DEBUG_COND_VEH(veh)) {
213 <<
" MSE3LeaveReminder::notifyMove() (" << getDescription() <<
" on lane '" << myLane->getID() <<
"')"
214 <<
" vehicle '" << veh.
getID() <<
"'"
215 <<
" entered. oldPos=" << oldPos <<
" newPos=" << newPos <<
" newSpeed=" << newSpeed
216 <<
" myPosition=" << myPosition
220 if (newPos < myPosition) {
228 if (oldPos < myPosition) {
232 const double leaveTimeFront =
SIMTIME -
TS + timeBeforeLeave;
233 myCollector.leaveFront(veh, leaveTimeFront);
234 #ifdef DEBUG_E3_NOTIFY_MOVE
235 if (
DEBUG_COND(myCollector) && DEBUG_COND_VEH(veh)) {
236 std::cout <<
" leaveFront\n";
241 if (backPos < myPosition) {
247 const double leaveStep =
SIMTIME;
249 const double timeBeforeLeave =
MSCFModel::passingTime(oldBackPos, myPosition, backPos, oldSpeed, newSpeed);
250 myCollector.leave(veh, leaveStep -
TS + timeBeforeLeave, timeBeforeLeave);
251 #ifdef DEBUG_E3_NOTIFY_MOVE
252 if (
DEBUG_COND(myCollector) && DEBUG_COND_VEH(veh)) {
253 std::cout <<
" leave\n";
262 #ifdef DEBUG_E3_NOTIFY_LEAVE
263 if (
DEBUG_COND(myCollector) && DEBUG_COND_VEH(veh)) {
265 <<
" MSE3LeaveReminder::notifyLeave() (" << getDescription() <<
"on lane '" << myLane->getID() <<
"')"
266 <<
" vehicle '" << veh.
getID() <<
"'"
267 <<
" reason=" << reason
273 #ifdef DEBUG_E3_NOTIFY_LEAVE
274 if (
DEBUG_COND(myCollector) && DEBUG_COND_VEH(veh)) {
275 std::cout <<
" remove reminder, keep in container\n";
285 myCollector.myEnteredContainer.erase(&veh);
289 if (myCollector.myEnteredContainer.erase(&veh) > 0) {
303 double haltingSpeedThreshold,
305 const std::string& vTypes,
348 enter(*p, entryTimestep, fractionTimeOnDet, entryReminder);
358 leave(veh, entryTimestep, fractionTimeOnDet,
true);
365 #ifdef DEBUG_E3_NOTIFY_ENTER
366 std::cout << veh.
getID() <<
" enters\n";
368 const double speedFraction = veh.
getSpeed() * fractionTimeOnDet;
421 leave(*p, leaveTimestep, fractionTimeOnDet);
431 enter(veh, leaveTimestep, fractionTimeOnDet,
nullptr,
true);
441 const double speedFraction = veh.
getSpeed() * (
TS - fractionTimeOnDet);
464 dev <<
" <interval begin=\"" <<
time2string(startTime) <<
"\" end=\"" <<
time2string(stopTime) <<
"\" " <<
"id=\"" <<
myID <<
"\" ";
468 double meanOverlapTravelTime = 0.;
469 double meanSpeed = 0.;
475 const double steps = values.backLeaveTime - values.entryTime;
476 meanOverlapTravelTime += steps;
477 meanSpeed += (values.speedSum / steps);
490 double meanSpeedWithin = 0.;
491 double meanDurationWithin = 0.;
492 double meanHaltsPerVehicleWithin = 0.;
493 double meanIntervalSpeedWithin = 0.;
494 double meanIntervalHaltsPerVehicleWithin = 0.;
495 double meanIntervalDurationWithin = 0.;
496 double meanTimeLossWithin = 0.;
498 meanHaltsPerVehicleWithin += (double)(*i).second.haltings;
499 meanIntervalHaltsPerVehicleWithin += (
double)(*i).second.intervalHaltings;
500 const double end = (*i).second.backLeaveTime == 0 ?
STEPS2TIME(stopTime) : (*i).second.backLeaveTime;
501 const double time = end - (*i).second.entryTime;
502 const double timeWithin =
MIN2(time, end -
STEPS2TIME(startTime));
503 if (i->second.speedSum > 0.) {
504 meanSpeedWithin += i->second.speedSum / time;
506 if (i->second.intervalSpeedSum > 0.) {
507 meanIntervalSpeedWithin += i->second.intervalSpeedSum / timeWithin;
509 meanDurationWithin += time;
510 meanIntervalDurationWithin += timeWithin;
512 (*i).second.intervalHaltings = 0;
513 (*i).second.intervalSpeedSum = 0;
516 const SUMOTime currentTimeLoss =
dynamic_cast<const MSVehicle*
>(i->first)->getTimeLoss();
517 meanTimeLossWithin +=
STEPS2TIME(currentTimeLoss - (*i).second.intervalTimeLoss);
518 (*i).second.intervalTimeLoss = currentTimeLoss;
522 meanSpeedWithin = vehicleSumWithin != 0 ? meanSpeedWithin / (double) vehicleSumWithin : -1;
523 meanHaltsPerVehicleWithin = vehicleSumWithin != 0 ? meanHaltsPerVehicleWithin / (double) vehicleSumWithin : -1;
524 meanDurationWithin = vehicleSumWithin != 0 ? meanDurationWithin / (double) vehicleSumWithin : -1;
525 meanIntervalSpeedWithin = vehicleSumWithin != 0 ? meanIntervalSpeedWithin / (double) vehicleSumWithin : -1;
526 meanIntervalHaltsPerVehicleWithin = vehicleSumWithin != 0 ? meanIntervalHaltsPerVehicleWithin / (double) vehicleSumWithin : -1;
527 meanIntervalDurationWithin = vehicleSumWithin != 0 ? meanIntervalDurationWithin / (double) vehicleSumWithin : -1;
528 meanTimeLossWithin = vehicleSumWithin != 0 ? meanTimeLossWithin / (double) vehicleSumWithin : -1;
532 <<
"\" meanOverlapTravelTime=\"" << meanOverlapTravelTime
533 <<
"\" meanSpeed=\"" << meanSpeed
537 <<
"\" meanSpeedWithin=\"" << meanSpeedWithin
538 <<
"\" meanHaltsPerVehicleWithin=\"" << meanHaltsPerVehicleWithin
539 <<
"\" meanDurationWithin=\"" << meanDurationWithin
540 <<
"\" vehicleSumWithin=\"" << vehicleSumWithin
541 <<
"\" meanIntervalSpeedWithin=\"" << meanIntervalSpeedWithin
542 <<
"\" meanIntervalHaltsPerVehicleWithin=\"" << meanIntervalHaltsPerVehicleWithin
543 <<
"\" meanIntervalDurationWithin=\"" << meanIntervalDurationWithin
544 <<
"\" meanTimeLossWithin=\"" << meanTimeLossWithin
558 const double newSpeed = p->
getSpeed();
562 : detPos - (pos - detPos));
563 const double oldPos = newPos -
SPEED2DIST(newSpeed);
565 rem->
notifyMove(*p, oldPos, newPos, newSpeed);
576 const MSLane* lane = rem->getLane();
580 notifyMovePerson(p, rem, rem->getPosition(), p->getDirection(), p->getPositionOnLane());
586 const MSLane* lane = rem->getLane();
590 notifyMovePerson(p, rem, rem->getPosition(), p->getDirection(), p->getPositionOnLane());
601 #ifdef DEBUG_E3_DETECTORUPDATE
604 std::cout <<
SIMTIME <<
" vehPtr=" << veh <<
"\n";
605 std::cout <<
" veh=" << veh->
getID() <<
"\n";
654 std::vector<std::string>
656 std::vector<std::string> ret;
658 ret.push_back((*pair).first->getID());
660 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)
The base class for microscopic and mesoscopic vehicles.
const std::vector< MSTransportable * > & getPersons() const
retrieve riding persons
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 detectPersons() const
bool vehicleApplies(const SUMOTrafficObject &veh) const
Checks whether the detector measures vehicles of the given type.
const int myDetectPersons
Whether pedestrians shall be detected instead of vehicles.
bool personApplies(const MSTransportable &p, int dir) const
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.
double myLastMeanTravelTime
CrossSectionVector myExits
The detector's exits.
void enter(const SUMOTrafficObject &veh, const double entryTimestep, const double fractionTimeOnDet, MSE3EntryReminder *entryReminder, bool isBackward=false)
Called if a vehicle touches an entry-cross-section.
int myCurrentHaltingsNumber
The current number of haltings (inside)
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
std::vector< MSE3LeaveReminder * > myLeaveReminders
The detector's built exit reminder.
double myLastMeanHaltsPerVehicle
double myLastMeanTimeLoss
void notifyMovePerson(MSTransportable *p, MSMoveReminder *rem, double detPos, int dir, double pos)
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.
SUMOTime myHaltingTimeThreshold
MSE3Collector(const std::string &id, const CrossSectionVector &entries, const CrossSectionVector &exits, double haltingSpeedThreshold, SUMOTime haltingTimeThreshold, const std::string &vTypes, int detectPersons, bool openEntry)
Constructor.
CrossSectionVector myEntries
void writeXMLOutput(OutputDevice &dev, SUMOTime startTime, SUMOTime stopTime)
Writes collected values into the given stream.
void leave(const SUMOTrafficObject &veh, const double leaveTimestep, const double fractionTimeOnDet, bool isBackward=false)
Called if a vehicle back passes a leave-cross-section.
void leaveFront(const SUMOTrafficObject &veh, const double leaveTimestep)
Called if a vehicle front passes a leave-cross-section.
const std::set< MSTransportable * > & getPersons() const
Returns this edge's persons set.
static bool gSemiImplicitEulerUpdate
static int gNumSimThreads
how many threads to use for simulation
Representation of a lane in the micro simulation.
bool hasPedestrians() const
whether the lane has pedestrians on it
MSEdge & getEdge() const
Returns the lane's edge.
Something on a lane to be noticed about vehicle movement.
virtual bool notifyMove(SUMOTrafficObject &veh, double oldPos, double newPos, double newSpeed)
Checks whether the reminder still has to be notified about the vehicle moves.
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).
virtual double getSpeed() const
the current speed of the transportable
const MSVehicleType & getVehicleType() const
Returns the object's "vehicle" type.
virtual int getDirection() const
Return the movement directon on the edge.
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 >(), bool includeConfig=true)
Writes an XML header with optional configuration.
Representation of a vehicle, person, or container.
virtual bool isVehicle() const
Whether it is a vehicle.
virtual double getPreviousSpeed() const =0
Returns the object's previous speed.
virtual double getSpeed() const =0
Returns the object's current speed.
virtual bool isPerson() const
Whether it is a person.
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.
A scoped lock which only triggers on condition.
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.