55#define HAS_NOT_LEFT_DETECTOR -1
59#define DEBUG_COND (true)
67 double positionInMeters,
68 double length, std::string name,
69 const std::string& vTypes,
70 const std::string& nextEdges,
72 const bool needLocking) :
76 myPosition(positionInMeters),
77 myEndPosition(myPosition + length),
78 myNeedLock(needLocking ||
MSGlobals::gNumSimThreads > 1),
80 myLastLeaveTime(-3600),
82 myOverrideEntryTime(-1),
85 myLastIntervalEnd(-1),
88 assert(
myPosition >= 0 && myEndPosition <= myLane->getLength());
124 assert(mesoveh !=
nullptr);
153 double newPos,
double newSpeed) {
162 keep =
notifyMove(*p, oldPos, newPos, newSpeed);
175#ifdef DEBUG_E1_NOTIFY_MOVE
177 std::cout <<
SIMTIME <<
" det=" <<
getID() <<
" enteredVeh=" << veh.
getID() <<
"\n";
188 const std::map<SUMOTrafficObject*, double>::iterator it =
myVehiclesOnDet.find(&veh);
190 const double entryTime = it->second;
193 assert(entryTime <= leaveTime);
196#ifdef DEBUG_E1_NOTIFY_MOVE
198 std::cout <<
SIMTIME <<
" det=" <<
getID() <<
" leftVeh=" << veh.
getID() <<
" oldBackPos=" << oldBackPos <<
" newBackPos=" << newBackPos <<
"\n";
202#ifdef DEBUG_E1_NOTIFY_MOVE
204 std::cout <<
SIMTIME <<
" det=" <<
getID() <<
" leftVeh=" << veh.
getID() <<
" oldBackPos=" << oldBackPos <<
" newBackPos=" << newBackPos <<
" (notFound)\n";
212#ifdef DEBUG_E1_NOTIFY_MOVE
214 std::cout <<
SIMTIME <<
" det=" <<
getID() <<
" leftVeh=" << veh.
getID() <<
" oldBackPos=" << oldBackPos <<
" newBackPos=" << newBackPos <<
" (unusual)\n";
233 assert(mesoveh !=
nullptr);
256 const std::map<SUMOTrafficObject*, double>::iterator it =
myVehiclesOnDet.find(&veh);
258 const double entryTime = it->second;
273 return d.empty() ? -1. : std::accumulate(d.begin(), d.end(), 0.0,
speedSum) / (double) d.size();
280 return d.empty() ? -1. : std::accumulate(d.begin(), d.end(), 0.0,
lengthSum) / (double)d.size();
290 double occupancy = 0;
291 const double csecond =
SIMTIME;
295 occupancy +=
MIN2(leaveTime - entryTime,
TS);
297 return occupancy /
TS * 100.;
310std::vector<std::string>
312 std::vector<std::string> ret;
314 ret.push_back(i.idM);
380 double minEntry = std::numeric_limits<double>::max();
382 minEntry =
MIN2(i.second, minEntry);
402 result =
MAX2(result, ad);
416 while (tq.size() > 0 && tq.top() < now) {
427 std::vector<SUMOTime> result;
432 while (!tq.empty()) {
433 result.push_back(tq.top());
467 double occupancy = 0;
476 occupancy +=
MIN2(leaveTime - entryTime, aggTime);
478 return occupancy / aggTime * 100.;
485 return d.empty() ? -1. : std::accumulate(d.begin(), d.end(), 0.0,
speedSum) / (double) d.size();
495std::vector<std::string>
497 std::vector<std::string> ret;
499 ret.push_back(i.idM);
511 const double entryTime =
MAX2(0.0,
SIMTIME - time);
533 const double t(
STEPS2TIME(stopTime - startTime));
534 double occupancy = 0.;
539 double inverseSpeedSum = 0.;
541 const double timeOnDetDuringInterval = vData.leaveTimeM -
MAX2(
STEPS2TIME(startTime), vData.entryTimeM);
542 occupancy +=
MIN2(timeOnDetDuringInterval, t);
543 if (!vData.leftEarlyM) {
545 assert(vData.speedM > 0.);
546 inverseSpeedSum += 1. / vData.speedM;
554 const double flow = (double)contrib / t * 3600.;
558 occupancy *= 100. / t;
559 const double meanSpeed = contrib != 0 ?
speedSum / (double)contrib : -1;
560 const double harmonicMeanSpeed = contrib != 0 ? (double)contrib / inverseSpeedSum : -1;
561 const double meanLength = contrib != 0 ?
lengthSum / (double)contrib : -1;
589 const double newSpeed = p->
getSpeed();
594 const double oldPos = newPos -
SPEED2DIST(newSpeed);
602std::vector<MSInductLoop::VehicleData>
608 std::vector<VehicleData> ret;
610 if ((includeEarly || !i.leftEarlyM) && (!lastInterval || i.entryTimeM < t)) {
611 if (i.entryTimeM >= t || (leaveTime && i.leaveTimeM >= t)) {
617 if (includeEarly || !i.leftEarlyM) {
618 if ((!lastInterval && (i.entryTimeM >= t || (leaveTime && i.leaveTimeM >= t)))
625 if ((!lastInterval && (i.second >= t || leaveTime || forOccupancy))
638 double leaveTimestep,
const bool leftEarly,
const double detLength)
639 : idM(v.getID()), lengthM(v.getVehicleType().getLength()), entryTimeM(entryTimestep), leaveTimeM(leaveTimestep),
640 speedM((v.getVehicleType().getLength() + detLength) /
MAX2(leaveTimestep - entryTimestep, NUMERICAL_EPS)), typeIDM(v.getVehicleType().getID()),
641 leftEarlyM(leftEarly) {}
#define HAS_NOT_LEFT_DETECTOR
constexpr SUMOTime TIME2STEPS(double x)
@ SUMO_TAG_INTERVAL
an aggreagated-output interval
@ SUMO_TAG_INDUCTION_LOOP
alternative tag for e1 detector
@ SUMO_ATTR_BEGIN
weights: time range begin
@ SUMO_ATTR_NEXT
succesor phase index
@ SUMO_ATTR_END
weights: time range end
@ SUMO_ATTR_TIME
trigger: the time of the step
const double INVALID_DOUBLE
invalid double
MESegment * getSegmentForEdge(const MSEdge &e, double pos=0)
Get the segment for a given edge at a given position.
A single mesoscopic segment (cell)
void addDetector(MSMoveReminder *data, int queueIndex=-1)
Adds a data collector for a detector to this segment.
double getLastHeadwaySeconds() const
get the last headway time in seconds
double getLength() const
Returns the length of the segment in meters.
SUMOTime getLastHeadway() const
get the last headway time
const std::vector< MEVehicle * > & getQueue(int index) const
Returns the cars in the queue with the given index for visualization.
int numQueues() const
return the number of queues
void setLastHeadway(SUMOTime headway)
restores the last headway time (when loading state)
int getIndex() const
Returns the running index of the segment in the edge (0 is the most upstream).
A vehicle from the mesoscopic point of view.
SUMOTime getLastEntryTime() const
Returns the time the vehicle entered the current segment.
MESegment * getSegment() const
Returns the current segment the vehicle is on.
int getQueIndex() const
Returns the index of the que the vehicle is in.
SUMOTime getEventTime() const
Returns the (planned) time at which the vehicle leaves its current segment.
The base class for microscopic and mesoscopic vehicles.
const std::vector< MSTransportable * > & getPersons() const
retrieve riding persons
double getLength() const
Returns the vehicle's length.
virtual double getStopArrivalDelay() const
Returns the estimated public transport stop arrival delay in seconds.
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.
static MELoop * gMesoNet
mesoscopic simulation infrastructure
void writeXMLDetectorProlog(OutputDevice &dev) const override
Opens the XML-output using "detector" as root element.
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.
std::priority_queue< SUMOTime, std::vector< SUMOTime >, std::greater< SUMOTime > > TimeQueue
helper function for managing meso timings
double getEnteredNumber(const int offset) const
Returns the number of vehicles that have passed the detector.
int getIntervalVehicleNumber(bool lastInterval=false) const
static double speedSum(double sumSoFar, const MSInductLoop::VehicleData &data)
Adds up VehicleData::speedM.
MESegment * mySegment
current segment (for actuated tls in meso)
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
void loadState(const SUMOSAXAttributes &attrs, const SUMOTime offset) override
Loads the detection state, shifting all times by the given offset.
bool notifyLeave(SUMOTrafficObject &veh, double lastPos, MSMoveReminder::Notification reason, const MSLane *enteredLane=0) override
Dismisses the vehicle if it is on the detector due to a lane change.
static std::vector< SUMOTime > getTimes(TimeQueue tq, SUMOTime now)
bool notifyEnter(SUMOTrafficObject &veh, Notification reason, const MSLane *enteredLane=0) override
Checks whether the reminder is activated by a vehicle entering the lane.
static void discardOldTimes(TimeQueue &tq, SUMOTime now)
TimeQueue myLastMesoLeaveTimes
void detectorUpdate(const SUMOTime step) override
Updates the detector (computes values) only used when detecting persons.
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
void writeXMLOutput(OutputDevice &dev, SUMOTime startTime, SUMOTime stopTime) override
Writes collected values into the given stream.
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.
bool notifyMove(SUMOTrafficObject &veh, double oldPos, double newPos, double newSpeed) override
Checks whether the vehicle shall be counted and/or shall still touch this MSMoveReminder.
void saveState(OutputDevice &out) const override
Saves the time of the last detection and the pending meso detections.
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 getArrivalDelay() const
Returns the maximum stop arrival delay of public transport vehicles that are on the detector or passe...
double getTimeSinceLastDetection() const
Returns the time since the last vehicle left the detector.
double myLastLeaveTime
Leave-time of the last vehicle detected [s].
TimeQueue myNextMesoLeaveTimes
extrapolated leave times for meso vehicle
const bool myNeedLock
whether internals need to be guarded against concurrent access (GUI or multi threading)
virtual void reset() override
Resets all generated values to allow computation of next interval.
double mySegmentPos
position relative to the current segment
double getIntervalMeanSpeed(bool lastInterval=false) const
virtual void clearState(SUMOTime time) override
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
Representation of a lane in the micro simulation.
double getSpeedLimit() const
Returns the lane's maximum allowed speed.
bool hasPedestrians() const
whether the lane has pedestrians on it
int getIndex() const
Returns the lane's index.
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_SEGMENT
The vehicle changes the segment (meso only)
@ 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.
MSVehicleControl & getVehicleControl()
Returns the vehicle control.
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.
The class responsible for building and deletion of vehicles.
SUMOVehicle * getVehicle(const std::string &id) const
Returns the vehicle with the given id.
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, const bool escape=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)
Encapsulated SAX-Attributes.
virtual std::string getString(int id, bool *isPresent=nullptr) const =0
Returns the string-value of the named (by its enum-value) attribute.
T get(int attr, const char *objectid, bool &ok, bool report=true) const
Tries to read given attribute assuming it is an int.
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.
Representation of a vehicle.
A scoped lock which only triggers on condition.
std::vector< std::string > getVector()
return vector of strings
static long long int toLong(const std::string &sData)
converts a string into the long value described by it by calling the char-type converter,...
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].