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) {
160 if (!myCollector.myExpectArrival) {
176 myCollector(collector), myPosition(crossSection.myPosition) {}
181#ifdef DEBUG_E3_NOTIFY_ENTER
182 if (
DEBUG_COND(myCollector) && DEBUG_COND_VEH(veh)) {
184 <<
" MSE3LeaveReminder::notifyEnter() (" << getDescription() <<
"on lane '" << myLane->getID() <<
"')"
185 <<
" vehicle '" << veh.
getID() <<
"'"
186 <<
" enteredLane=" << enteredLane->
getID()
187 <<
" reason=" << reason
192 if (reason != NOTIFICATION_JUNCTION) {
194 if (backPosOnLane > myPosition) {
197#ifdef DEBUG_E3_NOTIFY_ENTER
198 if (
DEBUG_COND(myCollector) && DEBUG_COND_VEH(veh)) {
199 std::cout <<
" assume already known\n";
211 double newPos,
double newSpeed) {
212#ifdef DEBUG_E3_NOTIFY_MOVE
213 if (
DEBUG_COND(myCollector) && DEBUG_COND_VEH(veh)) {
215 <<
" MSE3LeaveReminder::notifyMove() (" << getDescription() <<
" on lane '" << myLane->getID() <<
"')"
216 <<
" vehicle '" << veh.
getID() <<
"'"
217 <<
" entered. oldPos=" << oldPos <<
" newPos=" << newPos <<
" newSpeed=" << newSpeed
218 <<
" myPosition=" << myPosition
222 if (newPos < myPosition) {
230 if (oldPos < myPosition) {
234 const double leaveTimeFront =
SIMTIME -
TS + timeBeforeLeave;
235 myCollector.leaveFront(veh, leaveTimeFront);
236#ifdef DEBUG_E3_NOTIFY_MOVE
237 if (
DEBUG_COND(myCollector) && DEBUG_COND_VEH(veh)) {
238 std::cout <<
" leaveFront\n";
243 if (backPos < myPosition) {
249 const double leaveStep =
SIMTIME;
251 const double timeBeforeLeave =
MSCFModel::passingTime(oldBackPos, myPosition, backPos, oldSpeed, newSpeed);
252 myCollector.leave(veh, leaveStep -
TS + timeBeforeLeave, timeBeforeLeave);
253#ifdef DEBUG_E3_NOTIFY_MOVE
254 if (
DEBUG_COND(myCollector) && DEBUG_COND_VEH(veh)) {
255 std::cout <<
" leave\n";
264#ifdef DEBUG_E3_NOTIFY_LEAVE
265 if (
DEBUG_COND(myCollector) && DEBUG_COND_VEH(veh)) {
267 <<
" MSE3LeaveReminder::notifyLeave() (" << getDescription() <<
"on lane '" << myLane->getID() <<
"')"
268 <<
" vehicle '" << veh.
getID() <<
"'"
269 <<
" reason=" << reason
275#ifdef DEBUG_E3_NOTIFY_LEAVE
276 if (
DEBUG_COND(myCollector) && DEBUG_COND_VEH(veh)) {
277 std::cout <<
" remove reminder, keep in container\n";
287 myCollector.myEnteredContainer.erase(&veh);
291 if (myCollector.myEnteredContainer.erase(&veh) > 0) {
292 if (!myCollector.myExpectArrival) {
307 double haltingSpeedThreshold,
309 const std::string name,
const std::string& vTypes,
310 const std::string& nextEdges,
312 bool openEntry,
bool expectArrival) :
354 enter(*p, entryTimestep, fractionTimeOnDet, entryReminder);
364 leave(veh, entryTimestep, fractionTimeOnDet,
true);
371#ifdef DEBUG_E3_NOTIFY_ENTER
372 std::cout << veh.
getID() <<
" enters\n";
374 const double speedFraction = veh.
getSpeed() * fractionTimeOnDet;
427 leave(*p, leaveTimestep, fractionTimeOnDet);
437 enter(veh, leaveTimestep, fractionTimeOnDet,
nullptr,
true);
445#ifdef DEBUG_E3_NOTIFY_LEAVE
446 std::cout << veh.
getID() <<
" leaves\n";
450 const double speedFraction = veh.
getSpeed() * (
TS - fractionTimeOnDet);
473 dev <<
" <interval begin=\"" <<
time2string(startTime) <<
"\" end=\"" <<
time2string(stopTime) <<
"\" " <<
"id=\"" <<
myID <<
"\" ";
477 double meanOverlapTravelTime = 0.;
478 double meanSpeed = 0.;
484 const double steps = values.backLeaveTime - values.entryTime;
485 meanOverlapTravelTime += steps;
486 meanSpeed += (values.speedSum / steps);
499 double meanSpeedWithin = 0.;
500 double meanDurationWithin = 0.;
501 double meanHaltsPerVehicleWithin = 0.;
502 double meanIntervalSpeedWithin = 0.;
503 double meanIntervalHaltsPerVehicleWithin = 0.;
504 double meanIntervalDurationWithin = 0.;
505 double meanTimeLossWithin = 0.;
507 meanHaltsPerVehicleWithin += (double)(*i).second.haltings;
508 meanIntervalHaltsPerVehicleWithin += (double)(*i).second.intervalHaltings;
509 const double end = (*i).second.backLeaveTime == 0 ?
STEPS2TIME(stopTime) : (*i).second.backLeaveTime;
510 const double time = end - (*i).second.entryTime;
511 const double timeWithin =
MIN2(time, end -
STEPS2TIME(startTime));
512 if (i->second.speedSum > 0.) {
513 meanSpeedWithin += i->second.speedSum / time;
515 if (i->second.intervalSpeedSum > 0.) {
516 meanIntervalSpeedWithin += i->second.intervalSpeedSum / timeWithin;
518 meanDurationWithin += time;
519 meanIntervalDurationWithin += timeWithin;
521 (*i).second.intervalHaltings = 0;
522 (*i).second.intervalSpeedSum = 0;
525 const SUMOTime currentTimeLoss =
dynamic_cast<const MSVehicle*
>(i->first)->getTimeLoss();
526 meanTimeLossWithin +=
STEPS2TIME(currentTimeLoss - (*i).second.intervalTimeLoss);
527 (*i).second.intervalTimeLoss = currentTimeLoss;
531 meanSpeedWithin = vehicleSumWithin != 0 ? meanSpeedWithin / (double) vehicleSumWithin : -1;
532 meanHaltsPerVehicleWithin = vehicleSumWithin != 0 ? meanHaltsPerVehicleWithin / (double) vehicleSumWithin : -1;
533 meanDurationWithin = vehicleSumWithin != 0 ? meanDurationWithin / (double) vehicleSumWithin : -1;
534 meanIntervalSpeedWithin = vehicleSumWithin != 0 ? meanIntervalSpeedWithin / (double) vehicleSumWithin : -1;
535 meanIntervalHaltsPerVehicleWithin = vehicleSumWithin != 0 ? meanIntervalHaltsPerVehicleWithin / (double) vehicleSumWithin : -1;
536 meanIntervalDurationWithin = vehicleSumWithin != 0 ? meanIntervalDurationWithin / (double) vehicleSumWithin : -1;
537 meanTimeLossWithin = vehicleSumWithin != 0 ? meanTimeLossWithin / (double) vehicleSumWithin : -1;
541 <<
"\" meanOverlapTravelTime=\"" << meanOverlapTravelTime
542 <<
"\" meanSpeed=\"" << meanSpeed
546 <<
"\" meanSpeedWithin=\"" << meanSpeedWithin
547 <<
"\" meanHaltsPerVehicleWithin=\"" << meanHaltsPerVehicleWithin
548 <<
"\" meanDurationWithin=\"" << meanDurationWithin
549 <<
"\" vehicleSumWithin=\"" << vehicleSumWithin
550 <<
"\" meanIntervalSpeedWithin=\"" << meanIntervalSpeedWithin
551 <<
"\" meanIntervalHaltsPerVehicleWithin=\"" << meanIntervalHaltsPerVehicleWithin
552 <<
"\" meanIntervalDurationWithin=\"" << meanIntervalDurationWithin
553 <<
"\" meanTimeLossWithin=\"" << meanTimeLossWithin
567 const double newSpeed = p->
getSpeed();
571 : detPos - (pos - detPos));
572 const double oldPos = newPos -
SPEED2DIST(newSpeed);
574 rem->
notifyMove(*p, oldPos, newPos, newSpeed);
585 const MSLane* lane = rem->getLane();
589 notifyMovePerson(p, rem, rem->getPosition(), p->getDirection(), p->getPositionOnLane());
595 const MSLane* lane = rem->getLane();
599 notifyMovePerson(p, rem, rem->getPosition(), p->getDirection(), p->getPositionOnLane());
610#ifdef DEBUG_E3_DETECTORUPDATE
613 std::cout <<
SIMTIME <<
" vehPtr=" << veh <<
"\n";
614 std::cout <<
" veh=" << veh->
getID() <<
"\n";
675std::vector<std::string>
677 std::vector<std::string> ret;
679 ret.push_back((*pair).first->getID());
681 std::sort(ret.begin(), ret.end());
CrossSectionVector::const_iterator CrossSectionVectorConstIt
std::vector< MSCrossSection > CrossSectionVector
#define WRITE_WARNINGF(...)
std::string time2string(SUMOTime t, bool humanReadable)
convert SUMOTime to string (independently of global format setting)
@ 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.
const CrossSectionVector & getEntries() const
Returns the entry cross sections.
virtual void clearState(SUMOTime step)
Remove all vehicles before quick-loading state.
double myCurrentMeanSpeed
The current mean speed of known vehicles (inside)
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
const CrossSectionVector & getExits() const
Returns the exit cross sections.
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.
const bool myExpectArrival
Whether the detector expects vehicles to arrive inside (and doesn't issue a warning in this case)
virtual ~MSE3Collector()
Destructor.
MSE3Collector(const std::string &id, const CrossSectionVector &entries, const CrossSectionVector &exits, double haltingSpeedThreshold, SUMOTime haltingTimeThreshold, const std::string name, const std::string &vTypes, const std::string &nextEdges, int detectPersons, bool openEntry, bool expectArrival)
Constructor.
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
CrossSectionVector myEntries
The detector's entrys.
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 *, ComparatorNumericalIdLess > & 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 const MSVehicleType & getVehicleType() const =0
Returns the object's "vehicle" type.
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 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.