61 myCollector(collector), myPosition(crossSection.myPosition) {
67#ifdef DEBUG_E3_NOTIFY_ENTER
68 if (
DEBUG_COND(myCollector) && DEBUG_COND_VEH(veh)) {
70 <<
" MSE3EntryReminder::notifyEnter() (" << getDescription() <<
" on lane '" << myLane->getID() <<
"')"
71 <<
" vehicle '" << veh.
getID() <<
"'"
72 <<
" enteredLane=" << enteredLane->
getID()
73 <<
" reason=" << reason
77 if (reason != NOTIFICATION_JUNCTION) {
79 if (myLane == enteredLane && posOnLane > myPosition) {
83 const auto& itVeh = myCollector.myEnteredContainer.find(&veh);
84 if (itVeh == myCollector.myEnteredContainer.end() ||
85 itVeh->second.entryReminder !=
this) {
86#ifdef DEBUG_E3_NOTIFY_ENTER
87 if (
DEBUG_COND(myCollector) && DEBUG_COND_VEH(veh)) {
88 std::cout <<
" assume already known\n";
102 double newPos,
double newSpeed) {
103#ifdef DEBUG_E3_NOTIFY_MOVE
104 if (
DEBUG_COND(myCollector) && DEBUG_COND_VEH(veh)) {
106 <<
" MSE3EntryReminder::notifyMove() (" << getDescription() <<
" on lane '" << myLane->getID() <<
"')"
107 <<
" vehicle '" << veh.
getID() <<
"'"
108 <<
" entered. oldPos=" << oldPos <<
" newPos=" << newPos <<
" newSpeed=" << newSpeed
109 <<
" myPosition=" << myPosition
116 if ((myCollector.myEnteredContainer.find(&veh) == myCollector.myEnteredContainer.end() ||
118 && newPos > myPosition) {
119 if (oldPos > myPosition) {
121#ifdef DEBUG_E3_NOTIFY_MOVE
122 if (
DEBUG_COND(myCollector) && DEBUG_COND_VEH(veh)) {
123 std::cout <<
" already behind, isPerson=" << veh.
isPerson() <<
"\n";
129#ifdef DEBUG_E3_NOTIFY_ENTER
130 std::cout << veh.
getID() <<
" is on the wrong lane\n";
139 const double fractionTimeOnDet =
TS - timeBeforeEnter;
140 myCollector.enter(veh, entryTime - fractionTimeOnDet, fractionTimeOnDet,
this);
141#ifdef DEBUG_E3_NOTIFY_MOVE
142 if (
DEBUG_COND(myCollector) && DEBUG_COND_VEH(veh)) {
143 std::cout <<
" enter\n";
154#ifdef DEBUG_E3_NOTIFY_LEAVE
155 if (
DEBUG_COND(myCollector) && DEBUG_COND_VEH(veh)) {
157 <<
" MSE3EntryReminder::notifyLeave() (" << getDescription() <<
" on lane '" << myLane->getID() <<
"')"
158 <<
" vehicle '" << veh.
getID() <<
"'"
159 <<
" reason=" << reason
167 if (myCollector.myEnteredContainer.erase(&veh) > 0) {
168 if (!myCollector.myExpectArrival) {
184 myCollector(collector), myPosition(crossSection.myPosition) {}
189#ifdef DEBUG_E3_NOTIFY_ENTER
190 if (
DEBUG_COND(myCollector) && DEBUG_COND_VEH(veh)) {
192 <<
" MSE3LeaveReminder::notifyEnter() (" << getDescription() <<
" on lane '" << myLane->getID() <<
"')"
193 <<
" vehicle '" << veh.
getID() <<
"'"
194 <<
" enteredLane=" << enteredLane->
getID()
195 <<
" reason=" << reason
200 if (reason != NOTIFICATION_JUNCTION) {
202 if (backPosOnLane > myPosition) {
205#ifdef DEBUG_E3_NOTIFY_ENTER
206 if (
DEBUG_COND(myCollector) && DEBUG_COND_VEH(veh)) {
207 std::cout <<
" assume already known\n";
219 double newPos,
double newSpeed) {
220#ifdef DEBUG_E3_NOTIFY_MOVE
221 if (
DEBUG_COND(myCollector) && DEBUG_COND_VEH(veh)) {
223 <<
" MSE3LeaveReminder::notifyMove() (" << getDescription() <<
" on lane '" << myLane->getID() <<
"')"
224 <<
" vehicle '" << veh.
getID() <<
"'"
225 <<
" entered. oldPos=" << oldPos <<
" newPos=" << newPos <<
" newSpeed=" << newSpeed
226 <<
" myPosition=" << myPosition
230 if (newPos < myPosition) {
238 if (oldPos < myPosition) {
242 const double leaveTimeFront =
SIMTIME -
TS + timeBeforeLeave;
243 myCollector.leaveFront(veh, leaveTimeFront);
244#ifdef DEBUG_E3_NOTIFY_MOVE
245 if (
DEBUG_COND(myCollector) && DEBUG_COND_VEH(veh)) {
246 std::cout <<
" leaveFront\n";
251 if (backPos < myPosition) {
257 const double leaveStep =
SIMTIME;
259 const double timeBeforeLeave =
MSCFModel::passingTime(oldBackPos, myPosition, backPos, oldSpeed, newSpeed);
260 myCollector.leave(veh, leaveStep -
TS + timeBeforeLeave, timeBeforeLeave);
261#ifdef DEBUG_E3_NOTIFY_MOVE
262 if (
DEBUG_COND(myCollector) && DEBUG_COND_VEH(veh)) {
263 std::cout <<
" leave\n";
272#ifdef DEBUG_E3_NOTIFY_LEAVE
273 if (
DEBUG_COND(myCollector) && DEBUG_COND_VEH(veh)) {
275 <<
" MSE3LeaveReminder::notifyLeave() (" << getDescription() <<
" on lane '" << myLane->getID() <<
"')"
276 <<
" vehicle '" << veh.
getID() <<
"'"
277 <<
" reason=" << reason
283#ifdef DEBUG_E3_NOTIFY_LEAVE
284 if (
DEBUG_COND(myCollector) && DEBUG_COND_VEH(veh)) {
285 std::cout <<
" remove reminder, keep in container\n";
295 myCollector.myEnteredContainer.erase(&veh);
299 if (myCollector.myEnteredContainer.erase(&veh) > 0) {
300 if (!myCollector.myExpectArrival) {
315 double haltingSpeedThreshold,
317 const std::string name,
const std::string& vTypes,
318 const std::string& nextEdges,
320 bool openEntry,
bool expectArrival) :
362 enter(*p, entryTimestep, fractionTimeOnDet, entryReminder);
372 leave(veh, entryTimestep, fractionTimeOnDet,
true);
379#ifdef DEBUG_E3_NOTIFY_ENTER
380 std::cout << veh.
getID() <<
" enters\n";
382 const double speedFraction = veh.
getSpeed() * fractionTimeOnDet;
435 leave(*p, leaveTimestep, fractionTimeOnDet);
445 enter(veh, leaveTimestep, fractionTimeOnDet,
nullptr,
true);
453#ifdef DEBUG_E3_NOTIFY_LEAVE
454 std::cout << veh.
getID() <<
" leaves\n";
458 const double speedFraction = veh.
getSpeed() * (
TS - fractionTimeOnDet);
486 double meanOverlapTravelTime = 0.;
487 double meanSpeed = 0.;
493 const double steps = values.backLeaveTime - values.entryTime;
494 meanOverlapTravelTime += steps;
495 meanSpeed += (values.speedSum / steps);
508 double meanSpeedWithin = 0.;
509 double meanDurationWithin = 0.;
510 double meanHaltsPerVehicleWithin = 0.;
511 double meanIntervalSpeedWithin = 0.;
512 double meanIntervalHaltsPerVehicleWithin = 0.;
513 double meanIntervalDurationWithin = 0.;
514 double meanTimeLossWithin = 0.;
516 meanHaltsPerVehicleWithin += (double)(*i).second.haltings;
517 meanIntervalHaltsPerVehicleWithin += (double)(*i).second.intervalHaltings;
518 const double end = (*i).second.backLeaveTime == 0 ?
STEPS2TIME(stopTime) : (*i).second.backLeaveTime;
519 const double time = end - (*i).second.entryTime;
520 const double timeWithin =
MIN2(time, end -
STEPS2TIME(startTime));
521 if (i->second.speedSum > 0.) {
522 meanSpeedWithin += i->second.speedSum / time;
524 if (i->second.intervalSpeedSum > 0.) {
525 meanIntervalSpeedWithin += i->second.intervalSpeedSum / timeWithin;
527 meanDurationWithin += time;
528 meanIntervalDurationWithin += timeWithin;
530 (*i).second.intervalHaltings = 0;
531 (*i).second.intervalSpeedSum = 0;
534 const SUMOTime currentTimeLoss =
dynamic_cast<const MSVehicle*
>(i->first)->getTimeLoss();
535 meanTimeLossWithin +=
STEPS2TIME(currentTimeLoss - (*i).second.intervalTimeLoss);
536 (*i).second.intervalTimeLoss = currentTimeLoss;
540 meanSpeedWithin = vehicleSumWithin != 0 ? meanSpeedWithin / (double) vehicleSumWithin : -1;
541 meanHaltsPerVehicleWithin = vehicleSumWithin != 0 ? meanHaltsPerVehicleWithin / (double) vehicleSumWithin : -1;
542 meanDurationWithin = vehicleSumWithin != 0 ? meanDurationWithin / (double) vehicleSumWithin : -1;
543 meanIntervalSpeedWithin = vehicleSumWithin != 0 ? meanIntervalSpeedWithin / (double) vehicleSumWithin : -1;
544 meanIntervalHaltsPerVehicleWithin = vehicleSumWithin != 0 ? meanIntervalHaltsPerVehicleWithin / (double) vehicleSumWithin : -1;
545 meanIntervalDurationWithin = vehicleSumWithin != 0 ? meanIntervalDurationWithin / (double) vehicleSumWithin : -1;
546 meanTimeLossWithin = vehicleSumWithin != 0 ? meanTimeLossWithin / (double) vehicleSumWithin : -1;
550 .
writeAttr(
"meanOverlapTravelTime", meanOverlapTravelTime)
555 .
writeAttr(
"meanSpeedWithin", meanSpeedWithin)
556 .
writeAttr(
"meanHaltsPerVehicleWithin", meanHaltsPerVehicleWithin)
557 .
writeAttr(
"meanDurationWithin", meanDurationWithin)
558 .
writeAttr(
"vehicleSumWithin", vehicleSumWithin)
559 .
writeAttr(
"meanIntervalSpeedWithin", meanIntervalSpeedWithin)
560 .
writeAttr(
"meanIntervalHaltsPerVehicleWithin", meanIntervalHaltsPerVehicleWithin)
561 .
writeAttr(
"meanIntervalDurationWithin", meanIntervalDurationWithin)
562 .
writeAttr(
"meanTimeLossWithin", meanTimeLossWithin)
576 const double newSpeed = p->
getSpeed();
580 : detPos - (pos - detPos));
581 const double oldPos = newPos -
SPEED2DIST(newSpeed);
583 rem->
notifyMove(*p, oldPos, newPos, newSpeed);
594 const MSLane* lane = rem->getLane();
598 notifyMovePerson(p, rem, rem->getPosition(), p->getDirection(), p->getPositionOnLane());
604 const MSLane* lane = rem->getLane();
608 notifyMovePerson(p, rem, rem->getPosition(), p->getDirection(), p->getPositionOnLane());
619#ifdef DEBUG_E3_DETECTORUPDATE
622 std::cout <<
SIMTIME <<
" vehPtr=" << veh <<
"\n";
623 std::cout <<
" veh=" << veh->
getID() <<
"\n";
684std::vector<std::string>
686 std::vector<std::string> ret;
688 ret.push_back((*pair).first->getID());
690 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_INTERVAL
an aggreagated-output interval
@ SUMO_TAG_E3DETECTOR
an e3 detector
@ SUMO_ATTR_BEGIN
weights: time range begin
@ SUMO_ATTR_END
weights: time range end
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 override
the current speed of the transportable
const MSVehicleType & getVehicleType() const override
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.
OutputDevice & openTag(const std::string &xmlElement)
Opens an XML tag.
OutputDevice & writeAttr(const ATTR_TYPE &attr, const T &val, const bool isNull=false)
writes a named attribute
bool closeTag(const std::string &comment="")
Closes the most recently opened tag and optionally adds a comment.
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.
OutputDevice & writeTime(const SumoXMLAttr attr, const SUMOTime val)
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.