49#define HAS_NOT_LEFT_DETECTOR -1
53#define DEBUG_COND (true)
61 double positionInMeters,
62 double length, std::string name,
63 const std::string& vTypes,
64 const std::string& nextEdges,
66 const bool needLocking) :
70 myPosition(positionInMeters),
71 myEndPosition(myPosition + length),
72 myNeedLock(needLocking ||
MSGlobals::gNumSimThreads > 1),
74 myLastLeaveTime(-3600),
76 myOverrideEntryTime(-1),
79 myLastIntervalEnd(-1) {
81 assert(
myPosition >= 0 && myEndPosition <= myLane->getLength());
127 double newPos,
double newSpeed) {
136 keep =
notifyMove(*p, oldPos, newPos, newSpeed);
149#ifdef DEBUG_E1_NOTIFY_MOVE
151 std::cout <<
SIMTIME <<
" det=" <<
getID() <<
" enteredVeh=" << veh.
getID() <<
"\n";
162 const std::map<SUMOTrafficObject*, double>::iterator it =
myVehiclesOnDet.find(&veh);
164 const double entryTime = it->second;
167 assert(entryTime <= leaveTime);
170#ifdef DEBUG_E1_NOTIFY_MOVE
172 std::cout <<
SIMTIME <<
" det=" <<
getID() <<
" leftVeh=" << veh.
getID() <<
" oldBackPos=" << oldBackPos <<
" newBackPos=" << newBackPos <<
"\n";
176#ifdef DEBUG_E1_NOTIFY_MOVE
178 std::cout <<
SIMTIME <<
" det=" <<
getID() <<
" leftVeh=" << veh.
getID() <<
" oldBackPos=" << oldBackPos <<
" newBackPos=" << newBackPos <<
" (notFound)\n";
186#ifdef DEBUG_E1_NOTIFY_MOVE
188 std::cout <<
SIMTIME <<
" det=" <<
getID() <<
" leftVeh=" << veh.
getID() <<
" oldBackPos=" << oldBackPos <<
" newBackPos=" << newBackPos <<
" (unusual)\n";
209 const std::map<SUMOTrafficObject*, double>::iterator it =
myVehiclesOnDet.find(&veh);
211 const double entryTime = it->second;
226 return d.empty() ? -1. : std::accumulate(d.begin(), d.end(), 0.0,
speedSum) / (double) d.size();
233 return d.empty() ? -1. : std::accumulate(d.begin(), d.end(), 0.0,
lengthSum) / (double)d.size();
243 double occupancy = 0;
244 const double csecond =
SIMTIME;
248 occupancy +=
MIN2(leaveTime - entryTime,
TS);
250 return occupancy /
TS * 100.;
263std::vector<std::string>
265 std::vector<std::string> ret;
267 ret.push_back(i.idM);
304 double minEntry = std::numeric_limits<double>::max();
306 minEntry =
MIN2(i.second, minEntry);
328 double occupancy = 0;
337 occupancy +=
MIN2(leaveTime - entryTime, aggTime);
339 return occupancy / aggTime * 100.;
346 return d.empty() ? -1. : std::accumulate(d.begin(), d.end(), 0.0,
speedSum) / (double) d.size();
356std::vector<std::string>
358 std::vector<std::string> ret;
360 ret.push_back(i.idM);
372 const double entryTime =
MAX2(0.0,
SIMTIME - time);
394 const double t(
STEPS2TIME(stopTime - startTime));
395 double occupancy = 0.;
400 double inverseSpeedSum = 0.;
402 const double timeOnDetDuringInterval = vData.leaveTimeM -
MAX2(
STEPS2TIME(startTime), vData.entryTimeM);
403 occupancy +=
MIN2(timeOnDetDuringInterval, t);
404 if (!vData.leftEarlyM) {
406 assert(vData.speedM > 0.);
407 inverseSpeedSum += 1. / vData.speedM;
412 const double flow = (double)contrib / t * 3600.;
416 occupancy *= 100. / t;
417 const double meanSpeed = contrib != 0 ?
speedSum / (double)contrib : -1;
418 const double harmonicMeanSpeed = contrib != 0 ? (double)contrib / inverseSpeedSum : -1;
419 const double meanLength = contrib != 0 ?
lengthSum / (double)contrib : -1;
447 const double newSpeed = p->
getSpeed();
452 const double oldPos = newPos -
SPEED2DIST(newSpeed);
460std::vector<MSInductLoop::VehicleData>
466 std::vector<VehicleData> ret;
468 if ((includeEarly || !i.leftEarlyM) && (!lastInterval || i.entryTimeM < t)) {
469 if (i.entryTimeM >= t || (leaveTime && i.leaveTimeM >= t)) {
475 if (includeEarly || !i.leftEarlyM) {
476 if ((!lastInterval && (i.entryTimeM >= t || (leaveTime && i.leaveTimeM >= t)))
483 if ((!lastInterval && (i.second >= t || leaveTime || forOccupancy))
496 double leaveTimestep,
const bool leftEarly,
const double detLength)
497 : idM(v.getID()), lengthM(v.getVehicleType().getLength()), entryTimeM(entryTimestep), leaveTimeM(leaveTimestep),
498 speedM((v.getVehicleType().getLength() + detLength) /
MAX2(leaveTimestep - entryTimestep, NUMERICAL_EPS)), typeIDM(v.getVehicleType().getID()),
499 leftEarlyM(leftEarly) {}
#define HAS_NOT_LEFT_DETECTOR
@ SUMO_TAG_INTERVAL
an aggreagated-output interval
@ SUMO_ATTR_BEGIN
weights: time range begin
@ SUMO_ATTR_END
weights: time range end
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...
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
const std::set< MSTransportable *, ComparatorNumericalIdLess > & getPersons() const
Returns this edge's persons set.
double getOccupancyTime() const
Returns the time of continous occupation by the same vehicle in seconds or 0 if there is no vehicle o...
static double lengthSum(double sumSoFar, const MSInductLoop::VehicleData &data)
Adds up VehicleData::lengthM.
double getOccupancy() const
Returns the current occupancy.
double getIntervalOccupancy(bool lastInterval=false) const
std::vector< std::string > getIntervalVehicleIDs(bool lastInterval=false) const
int myEnteredVehicleNumber
The number of entered vehicles.
double getEnteredNumber(const int offset) const
Returns the number of vehicles that have passed the detector.
int getIntervalVehicleNumber(bool lastInterval=false) const
void writeXMLOutput(OutputDevice &dev, SUMOTime startTime, SUMOTime stopTime)
Writes collected values into the given stream.
static double speedSum(double sumSoFar, const MSInductLoop::VehicleData &data)
Adds up VehicleData::speedM.
std::vector< VehicleData > collectVehiclesOnDet(SUMOTime t, bool includeEarly=false, bool leaveTime=false, bool forOccupancy=false, bool lastInterval=false) const
Returns vehicle data for vehicles that have been on the detector starting at the given time.
VehicleDataCont myVehicleDataCont
Data of vehicles that have completely passed the detector.
void overrideTimeSinceDetection(double time)
double myOverrideEntryTime
records the time at which overrideTimeSinceDetection was activated
double getSpeed(const int offset) const
Returns the speed of the vehicle on the detector.
SUMOTime myLastIntervalEnd
std::vector< std::string > getVehicleIDs(const int offset) const
Returns the ids of vehicles that have passed the detector.
double getVehicleLength(const int offset) const
Returns the length of the vehicle on the detector.
SUMOTime myLastIntervalBegin
virtual void reset()
Resets all generated values to allow computation of next interval.
const double myPosition
Detector's position on lane [m].
VehicleDataCont myLastVehicleDataCont
Data of vehicles that have completely passed the detector in the last time interval.
const double myEndPosition
Detector's end position (defaults to myPosition)
~MSInductLoop()
Destructor.
void loadTimeSinceLastDetection(double time)
void writeXMLDetectorProlog(OutputDevice &dev) const
Opens the XML-output using "detector" as root element.
void detectorUpdate(const SUMOTime step)
Updates the detector (computes values) only used when detecting persons.
bool notifyMove(SUMOTrafficObject &veh, double oldPos, double newPos, double newSpeed)
Checks whether the vehicle shall be counted and/or shall still touch this MSMoveReminder.
void notifyMovePerson(MSTransportable *p, int dir, double pos)
helper function for mapping person movement
double myOverrideTime
overrides the time since last detection
MSInductLoop(const std::string &id, MSLane *const lane, double positionInMeters, double length, std::string name, const std::string &vTypes, const std::string &nextEdges, int detectPersons, const bool needLocking)
Constructor.
double getTimeSinceLastDetection() const
Returns the time since the last vehicle left the detector.
double myLastLeaveTime
Leave-time of the last vehicle detected [s].
const bool myNeedLock
whether internals need to be guarded against concurrent access (GUI or multi threading)
double getIntervalMeanSpeed(bool lastInterval=false) const
bool notifyEnter(SUMOTrafficObject &veh, Notification reason, const MSLane *enteredLane=0)
Checks whether the reminder is activated by a vehicle entering the lane.
virtual void clearState(SUMOTime time)
Remove all vehicles before quick-loading state.
std::map< SUMOTrafficObject *, double > myVehiclesOnDet
Data for vehicles that have entered the detector (vehicle -> enter time)
SUMOTime getLastDetectionTime() const
return last time a vehicle was on the detector
bool notifyLeave(SUMOTrafficObject &veh, double lastPos, MSMoveReminder::Notification reason, const MSLane *enteredLane=0)
Dismisses the vehicle if it is on the detector due to a lane change.
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.
Notification
Definition of a vehicle state.
@ NOTIFICATION_JUNCTION
The vehicle arrived at a junction.
MSLane * myLane
Lane on which the reminder works.
static MSNet * getInstance()
Returns the pointer to the unique instance of MSNet (singleton).
SUMOTime getCurrentTimeStep() const
Returns the current simulation step.
static const int BACKWARD
virtual double getSpeed() const override
the current speed of the transportable
const MSVehicleType & getVehicleType() const override
Returns the object's "vehicle" type.
double getLength() const
Get vehicle's length [m].
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
virtual bool isNull()
returns the information whether the device will discard all output
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 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.
virtual double getPositionOnLane() const =0
Get the object's position along the lane.
A scoped lock which only triggers on condition.
static std::string escapeXML(const std::string &orig, const bool maskDoubleHyphen=false)
Replaces the standard escapes by their XML entities.
Struct to store the data of the counted vehicle internally.
VehicleData(const SUMOTrafficObject &v, double entryTimestep, double leaveTimestep, const bool leftEarly, const double detLength=0)
Constructor.
double speedM
Speed of the vehicle in [m/s].