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 name,
const std::string& vTypes,
306 const std::string& nextEdges,
350 enter(*p, entryTimestep, fractionTimeOnDet, entryReminder);
360 leave(veh, entryTimestep, fractionTimeOnDet,
true);
367#ifdef DEBUG_E3_NOTIFY_ENTER
368 std::cout << veh.
getID() <<
" enters\n";
370 const double speedFraction = veh.
getSpeed() * fractionTimeOnDet;
423 leave(*p, leaveTimestep, fractionTimeOnDet);
433 enter(veh, leaveTimestep, fractionTimeOnDet,
nullptr,
true);
443 const double speedFraction = veh.
getSpeed() * (
TS - fractionTimeOnDet);
466 dev <<
" <interval begin=\"" <<
time2string(startTime) <<
"\" end=\"" <<
time2string(stopTime) <<
"\" " <<
"id=\"" <<
myID <<
"\" ";
470 double meanOverlapTravelTime = 0.;
471 double meanSpeed = 0.;
477 const double steps = values.backLeaveTime - values.entryTime;
478 meanOverlapTravelTime += steps;
479 meanSpeed += (values.speedSum / steps);
492 double meanSpeedWithin = 0.;
493 double meanDurationWithin = 0.;
494 double meanHaltsPerVehicleWithin = 0.;
495 double meanIntervalSpeedWithin = 0.;
496 double meanIntervalHaltsPerVehicleWithin = 0.;
497 double meanIntervalDurationWithin = 0.;
498 double meanTimeLossWithin = 0.;
500 meanHaltsPerVehicleWithin += (double)(*i).second.haltings;
501 meanIntervalHaltsPerVehicleWithin += (
double)(*i).second.intervalHaltings;
502 const double end = (*i).second.backLeaveTime == 0 ?
STEPS2TIME(stopTime) : (*i).second.backLeaveTime;
503 const double time = end - (*i).second.entryTime;
504 const double timeWithin =
MIN2(time, end -
STEPS2TIME(startTime));
505 if (i->second.speedSum > 0.) {
506 meanSpeedWithin += i->second.speedSum / time;
508 if (i->second.intervalSpeedSum > 0.) {
509 meanIntervalSpeedWithin += i->second.intervalSpeedSum / timeWithin;
511 meanDurationWithin += time;
512 meanIntervalDurationWithin += timeWithin;
514 (*i).second.intervalHaltings = 0;
515 (*i).second.intervalSpeedSum = 0;
518 const SUMOTime currentTimeLoss =
dynamic_cast<const MSVehicle*
>(i->first)->getTimeLoss();
519 meanTimeLossWithin +=
STEPS2TIME(currentTimeLoss - (*i).second.intervalTimeLoss);
520 (*i).second.intervalTimeLoss = currentTimeLoss;
524 meanSpeedWithin = vehicleSumWithin != 0 ? meanSpeedWithin / (double) vehicleSumWithin : -1;
525 meanHaltsPerVehicleWithin = vehicleSumWithin != 0 ? meanHaltsPerVehicleWithin / (double) vehicleSumWithin : -1;
526 meanDurationWithin = vehicleSumWithin != 0 ? meanDurationWithin / (double) vehicleSumWithin : -1;
527 meanIntervalSpeedWithin = vehicleSumWithin != 0 ? meanIntervalSpeedWithin / (double) vehicleSumWithin : -1;
528 meanIntervalHaltsPerVehicleWithin = vehicleSumWithin != 0 ? meanIntervalHaltsPerVehicleWithin / (double) vehicleSumWithin : -1;
529 meanIntervalDurationWithin = vehicleSumWithin != 0 ? meanIntervalDurationWithin / (double) vehicleSumWithin : -1;
530 meanTimeLossWithin = vehicleSumWithin != 0 ? meanTimeLossWithin / (double) vehicleSumWithin : -1;
534 <<
"\" meanOverlapTravelTime=\"" << meanOverlapTravelTime
535 <<
"\" meanSpeed=\"" << meanSpeed
539 <<
"\" meanSpeedWithin=\"" << meanSpeedWithin
540 <<
"\" meanHaltsPerVehicleWithin=\"" << meanHaltsPerVehicleWithin
541 <<
"\" meanDurationWithin=\"" << meanDurationWithin
542 <<
"\" vehicleSumWithin=\"" << vehicleSumWithin
543 <<
"\" meanIntervalSpeedWithin=\"" << meanIntervalSpeedWithin
544 <<
"\" meanIntervalHaltsPerVehicleWithin=\"" << meanIntervalHaltsPerVehicleWithin
545 <<
"\" meanIntervalDurationWithin=\"" << meanIntervalDurationWithin
546 <<
"\" meanTimeLossWithin=\"" << meanTimeLossWithin
560 const double newSpeed = p->
getSpeed();
564 : detPos - (pos - detPos));
565 const double oldPos = newPos -
SPEED2DIST(newSpeed);
567 rem->
notifyMove(*p, oldPos, newPos, newSpeed);
578 const MSLane* lane = rem->getLane();
582 notifyMovePerson(p, rem, rem->getPosition(), p->getDirection(), p->getPositionOnLane());
588 const MSLane* lane = rem->getLane();
592 notifyMovePerson(p, rem, rem->getPosition(), p->getDirection(), p->getPositionOnLane());
603#ifdef DEBUG_E3_DETECTORUPDATE
606 std::cout <<
SIMTIME <<
" vehPtr=" << veh <<
"\n";
607 std::cout <<
" veh=" << veh->
getID() <<
"\n";
668std::vector<std::string>
670 std::vector<std::string> ret;
672 ret.push_back((*pair).first->getID());
674 std::sort(ret.begin(), ret.end());
CrossSectionVector::const_iterator CrossSectionVectorConstIt
std::vector< MSCrossSection > CrossSectionVector
#define WRITE_WARNINGF(...)
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.
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.
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)
Constructor.
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.
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
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.