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, isPerson=" << veh.
isPerson() <<
"\n";
127#ifdef DEBUG_E3_NOTIFY_ENTER
128 std::cout << veh.
getID() <<
" is on the wrong lane\n";
137 const double fractionTimeOnDet =
TS - timeBeforeEnter;
138 myCollector.enter(veh, entryTime - fractionTimeOnDet, fractionTimeOnDet,
this);
139#ifdef DEBUG_E3_NOTIFY_MOVE
140 if (
DEBUG_COND(myCollector) && DEBUG_COND_VEH(veh)) {
141 std::cout <<
" enter\n";
152#ifdef DEBUG_E3_NOTIFY_LEAVE
153 if (
DEBUG_COND(myCollector) && DEBUG_COND_VEH(veh)) {
155 <<
" MSE3EntryReminder::notifyLeave() (" << getDescription() <<
" on lane '" << myLane->getID() <<
"')"
156 <<
" vehicle '" << veh.
getID() <<
"'"
157 <<
" reason=" << reason
165 if (myCollector.myEnteredContainer.erase(&veh) > 0) {
166 if (!myCollector.myExpectArrival) {
182 myCollector(collector), myPosition(crossSection.myPosition) {}
187#ifdef DEBUG_E3_NOTIFY_ENTER
188 if (
DEBUG_COND(myCollector) && DEBUG_COND_VEH(veh)) {
190 <<
" MSE3LeaveReminder::notifyEnter() (" << getDescription() <<
" on lane '" << myLane->getID() <<
"')"
191 <<
" vehicle '" << veh.
getID() <<
"'"
192 <<
" enteredLane=" << enteredLane->
getID()
193 <<
" reason=" << reason
198 if (reason != NOTIFICATION_JUNCTION) {
200 if (backPosOnLane > myPosition) {
203#ifdef DEBUG_E3_NOTIFY_ENTER
204 if (
DEBUG_COND(myCollector) && DEBUG_COND_VEH(veh)) {
205 std::cout <<
" assume already known\n";
217 double newPos,
double newSpeed) {
218#ifdef DEBUG_E3_NOTIFY_MOVE
219 if (
DEBUG_COND(myCollector) && DEBUG_COND_VEH(veh)) {
221 <<
" MSE3LeaveReminder::notifyMove() (" << getDescription() <<
" on lane '" << myLane->getID() <<
"')"
222 <<
" vehicle '" << veh.
getID() <<
"'"
223 <<
" entered. oldPos=" << oldPos <<
" newPos=" << newPos <<
" newSpeed=" << newSpeed
224 <<
" myPosition=" << myPosition
228 if (newPos < myPosition) {
236 if (oldPos < myPosition) {
240 const double leaveTimeFront =
SIMTIME -
TS + timeBeforeLeave;
241 myCollector.leaveFront(veh, leaveTimeFront);
242#ifdef DEBUG_E3_NOTIFY_MOVE
243 if (
DEBUG_COND(myCollector) && DEBUG_COND_VEH(veh)) {
244 std::cout <<
" leaveFront\n";
249 if (backPos < myPosition) {
255 const double leaveStep =
SIMTIME;
257 const double timeBeforeLeave =
MSCFModel::passingTime(oldBackPos, myPosition, backPos, oldSpeed, newSpeed);
258 myCollector.leave(veh, leaveStep -
TS + timeBeforeLeave, timeBeforeLeave);
259#ifdef DEBUG_E3_NOTIFY_MOVE
260 if (
DEBUG_COND(myCollector) && DEBUG_COND_VEH(veh)) {
261 std::cout <<
" leave\n";
270#ifdef DEBUG_E3_NOTIFY_LEAVE
271 if (
DEBUG_COND(myCollector) && DEBUG_COND_VEH(veh)) {
273 <<
" MSE3LeaveReminder::notifyLeave() (" << getDescription() <<
" on lane '" << myLane->getID() <<
"')"
274 <<
" vehicle '" << veh.
getID() <<
"'"
275 <<
" reason=" << reason
281#ifdef DEBUG_E3_NOTIFY_LEAVE
282 if (
DEBUG_COND(myCollector) && DEBUG_COND_VEH(veh)) {
283 std::cout <<
" remove reminder, keep in container\n";
293 myCollector.myEnteredContainer.erase(&veh);
297 if (myCollector.myEnteredContainer.erase(&veh) > 0) {
298 if (!myCollector.myExpectArrival) {
313 double haltingSpeedThreshold,
315 const std::string name,
const std::string& vTypes,
316 const std::string& nextEdges,
318 bool openEntry,
bool expectArrival) :
360 enter(*p, entryTimestep, fractionTimeOnDet, entryReminder);
370 leave(veh, entryTimestep, fractionTimeOnDet,
true);
377#ifdef DEBUG_E3_NOTIFY_ENTER
378 std::cout << veh.
getID() <<
" enters\n";
380 const double speedFraction = veh.
getSpeed() * fractionTimeOnDet;
433 leave(*p, leaveTimestep, fractionTimeOnDet);
443 enter(veh, leaveTimestep, fractionTimeOnDet,
nullptr,
true);
451#ifdef DEBUG_E3_NOTIFY_LEAVE
452 std::cout << veh.
getID() <<
" leaves\n";
456 const double speedFraction = veh.
getSpeed() * (
TS - fractionTimeOnDet);
479 dev <<
" <interval begin=\"" <<
time2string(startTime) <<
"\" end=\"" <<
time2string(stopTime) <<
"\" " <<
"id=\"" <<
myID <<
"\" ";
483 double meanOverlapTravelTime = 0.;
484 double meanSpeed = 0.;
490 const double steps = values.backLeaveTime - values.entryTime;
491 meanOverlapTravelTime += steps;
492 meanSpeed += (values.speedSum / steps);
505 double meanSpeedWithin = 0.;
506 double meanDurationWithin = 0.;
507 double meanHaltsPerVehicleWithin = 0.;
508 double meanIntervalSpeedWithin = 0.;
509 double meanIntervalHaltsPerVehicleWithin = 0.;
510 double meanIntervalDurationWithin = 0.;
511 double meanTimeLossWithin = 0.;
513 meanHaltsPerVehicleWithin += (double)(*i).second.haltings;
514 meanIntervalHaltsPerVehicleWithin += (double)(*i).second.intervalHaltings;
515 const double end = (*i).second.backLeaveTime == 0 ?
STEPS2TIME(stopTime) : (*i).second.backLeaveTime;
516 const double time = end - (*i).second.entryTime;
517 const double timeWithin =
MIN2(time, end -
STEPS2TIME(startTime));
518 if (i->second.speedSum > 0.) {
519 meanSpeedWithin += i->second.speedSum / time;
521 if (i->second.intervalSpeedSum > 0.) {
522 meanIntervalSpeedWithin += i->second.intervalSpeedSum / timeWithin;
524 meanDurationWithin += time;
525 meanIntervalDurationWithin += timeWithin;
527 (*i).second.intervalHaltings = 0;
528 (*i).second.intervalSpeedSum = 0;
531 const SUMOTime currentTimeLoss =
dynamic_cast<const MSVehicle*
>(i->first)->getTimeLoss();
532 meanTimeLossWithin +=
STEPS2TIME(currentTimeLoss - (*i).second.intervalTimeLoss);
533 (*i).second.intervalTimeLoss = currentTimeLoss;
537 meanSpeedWithin = vehicleSumWithin != 0 ? meanSpeedWithin / (double) vehicleSumWithin : -1;
538 meanHaltsPerVehicleWithin = vehicleSumWithin != 0 ? meanHaltsPerVehicleWithin / (double) vehicleSumWithin : -1;
539 meanDurationWithin = vehicleSumWithin != 0 ? meanDurationWithin / (double) vehicleSumWithin : -1;
540 meanIntervalSpeedWithin = vehicleSumWithin != 0 ? meanIntervalSpeedWithin / (double) vehicleSumWithin : -1;
541 meanIntervalHaltsPerVehicleWithin = vehicleSumWithin != 0 ? meanIntervalHaltsPerVehicleWithin / (double) vehicleSumWithin : -1;
542 meanIntervalDurationWithin = vehicleSumWithin != 0 ? meanIntervalDurationWithin / (double) vehicleSumWithin : -1;
543 meanTimeLossWithin = vehicleSumWithin != 0 ? meanTimeLossWithin / (double) vehicleSumWithin : -1;
547 <<
"\" meanOverlapTravelTime=\"" << meanOverlapTravelTime
548 <<
"\" meanSpeed=\"" << meanSpeed
552 <<
"\" meanSpeedWithin=\"" << meanSpeedWithin
553 <<
"\" meanHaltsPerVehicleWithin=\"" << meanHaltsPerVehicleWithin
554 <<
"\" meanDurationWithin=\"" << meanDurationWithin
555 <<
"\" vehicleSumWithin=\"" << vehicleSumWithin
556 <<
"\" meanIntervalSpeedWithin=\"" << meanIntervalSpeedWithin
557 <<
"\" meanIntervalHaltsPerVehicleWithin=\"" << meanIntervalHaltsPerVehicleWithin
558 <<
"\" meanIntervalDurationWithin=\"" << meanIntervalDurationWithin
559 <<
"\" meanTimeLossWithin=\"" << meanTimeLossWithin
573 const double newSpeed = p->
getSpeed();
577 : detPos - (pos - detPos));
578 const double oldPos = newPos -
SPEED2DIST(newSpeed);
580 rem->
notifyMove(*p, oldPos, newPos, newSpeed);
591 const MSLane* lane = rem->getLane();
595 notifyMovePerson(p, rem, rem->getPosition(), p->getDirection(), p->getPositionOnLane());
601 const MSLane* lane = rem->getLane();
605 notifyMovePerson(p, rem, rem->getPosition(), p->getDirection(), p->getPositionOnLane());
616#ifdef DEBUG_E3_DETECTORUPDATE
619 std::cout <<
SIMTIME <<
" vehPtr=" << veh <<
"\n";
620 std::cout <<
" veh=" << veh->
getID() <<
"\n";
681std::vector<std::string>
683 std::vector<std::string> ret;
685 ret.push_back((*pair).first->getID());
687 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 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 const MSLane * getLane() const =0
Returns the lane the object is currently at.
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.