42 #define HAS_NOT_LEFT_DETECTOR -1
48 double positionInMeters,
49 const std::string& vTypes,
50 const bool needLocking) :
53 myPosition(positionInMeters),
54 myNeedLock(needLocking ||
MSGlobals::gNumSimThreads > 1),
58 assert(
myPosition >= 0 && myPosition <= myLane->getLength());
101 double newPos,
double newSpeed) {
123 const std::map<SUMOTrafficObject*, double>::iterator it =
myVehiclesOnDet.find(&veh);
125 const double entryTime = it->second;
128 assert(entryTime <= leaveTime);
150 const std::map<SUMOTrafficObject*, double>::iterator it =
myVehiclesOnDet.find(&veh);
152 const double entryTime = it->second;
167 return d.empty() ? -1. : std::accumulate(d.begin(), d.end(), 0.0,
speedSum) / (double) d.size();
174 return d.empty() ? -1. : std::accumulate(d.begin(), d.end(), 0.0,
lengthSum) / (double)d.size();
181 double occupancy = 0;
182 const double csecond =
SIMTIME;
186 occupancy +=
MIN2(leaveTime - entryTime,
TS);
188 return occupancy /
TS * 100.;
198 std::vector<std::string>
200 std::vector<std::string> ret;
202 ret.push_back(i.idM);
235 const double t(
STEPS2TIME(stopTime - startTime));
236 double occupancy = 0.;
241 double inverseSpeedSum = 0.;
243 const double timeOnDetDuringInterval = vData.leaveTimeM -
MAX2(
STEPS2TIME(startTime), vData.entryTimeM);
244 occupancy +=
MIN2(timeOnDetDuringInterval, t);
245 if (!vData.leftEarlyM) {
247 assert(vData.speedM > 0.);
248 inverseSpeedSum += 1. / vData.speedM;
253 const double flow = (double)contrib / t * 3600.;
257 occupancy *= 100. / t;
258 const double meanSpeed = contrib != 0 ?
speedSum / (double)contrib : -1;
259 const double harmonicMeanSpeed = contrib != 0 ? (double)contrib / inverseSpeedSum : -1;
260 const double meanLength = contrib != 0 ?
lengthSum / (double)contrib : -1;
269 std::vector<MSInductLoop::VehicleData>
275 std::vector<VehicleData> ret;
277 if (includeEarly || !i.leftEarlyM) {
278 if (i.entryTimeM >= t || (leaveTime && i.leaveTimeM >= t)) {
284 if (includeEarly || !i.leftEarlyM) {
285 if (i.entryTimeM >= t || (leaveTime && i.leaveTimeM >= t)) {
291 if (i.second >= t || leaveTime || forOccupancy) {
303 double leaveTimestep,
const bool leftEarly)
304 : idM(v.getID()), lengthM(v.getVehicleType().getLength()), entryTimeM(entryTimestep), leaveTimeM(leaveTimestep),
305 speedM(v.getVehicleType().getLength() /
MAX2(leaveTimestep - entryTimestep, NUMERICAL_EPS)), typeIDM(v.getVehicleType().getID()),
306 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
A scoped lock which only triggers on condition.
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.
static double lengthSum(double sumSoFar, const MSInductLoop::VehicleData &data)
Adds up VehicleData::lengthM.
double getOccupancy() const
Returns the current occupancy.
int myEnteredVehicleNumber
The number of entered vehicles.
double getEnteredNumber(const int offset) const
Returns the number of vehicles that have passed the detector.
MSInductLoop(const std::string &id, MSLane *const lane, double positionInMeters, const std::string &vTypes, const bool needLocking)
Constructor.
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.
VehicleDataCont myVehicleDataCont
Data of vehicles that have completely passed the detector.
double getSpeed(const int offset) const
Returns the speed of the vehicle on the detector.
virtual void clearState()
Remove all vehicles before quick-loading state.
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.
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.
~MSInductLoop()
Destructor.
void writeXMLDetectorProlog(OutputDevice &dev) const
Opens the XML-output using "detector" as root element.
bool notifyMove(SUMOTrafficObject &veh, double oldPos, double newPos, double newSpeed)
Checks whether the vehicle shall be counted and/or shall still touch this MSMoveReminder.
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)
bool notifyEnter(SUMOTrafficObject &veh, Notification reason, const MSLane *enteredLane=0)
Checks whether the reminder is activated by a vehicle entering the lane.
std::vector< VehicleData > collectVehiclesOnDet(SUMOTime t, bool includeEarly=false, bool leaveTime=false, bool forOccupancy=false) const
Returns vehicle data for vehicles that have been on the detector starting at the given time.
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.
Something on a lane to be noticed about vehicle movement.
MSLane *const myLane
Lane on which the reminder works.
Notification
Definition of a vehicle state.
@ NOTIFICATION_JUNCTION
The vehicle arrived at a junction.
static MSNet * getInstance()
Returns the pointer to the unique instance of MSNet (singleton).
SUMOTime getCurrentTimeStep() const
Returns the current simulation step.
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.
bool writeXMLHeader(const std::string &rootElement, const std::string &schemaFile, std::map< SumoXMLAttr, std::string > attrs=std::map< SumoXMLAttr, std::string >())
Writes an XML header with optional configuration.
OutputDevice & openTag(const std::string &xmlElement)
Opens an XML tag.
OutputDevice & writeAttr(const SumoXMLAttr attr, const T &val)
writes a named attribute
bool closeTag(const std::string &comment="")
Closes the most recently opened tag and optionally adds a comment.
Representation of a vehicle, person, or container.
virtual double getPreviousSpeed() const =0
Returns the object's previous speed.
virtual double getSpeed() const =0
Returns the object's current speed.
virtual const MSVehicleType & getVehicleType() const =0
Returns the object's "vehicle" type.
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.
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)
Constructor.
double speedM
Speed of the vehicle in [m/s].