51 #ifdef CHECK_MEMORY_LEAKS
53 #endif // CHECK_MEMORY_LEAKS
55 #define HAS_NOT_LEFT_DETECTOR -1
61 SUMOReal positionInMeters,
bool splitByType) :
64 myPosition(positionInMeters), mySplitByType(splitByType),
65 myLastLeaveTime(
STEPS2TIME(
MSNet::getInstance()->getCurrentTimeStep())),
68 assert(
myPosition >= 0 && myPosition <= myLane->getLength());
155 for (std::vector< VehicleData >::const_iterator i = d.begin(); i != d.end(); ++i) {
158 timeOnDetDuringInterval =
MIN2(timeOnDetDuringInterval,
TS);
159 occupancy += timeOnDetDuringInterval;
168 return (
unsigned int) d.size();
172 std::vector<std::string>
175 std::vector<std::string> ret;
176 for (std::vector<VehicleData>::iterator i = d.begin(); i != d.end(); ++i) {
177 ret.push_back((*i).idM);
195 dev.
writeXMLHeader(
"detector",
"xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:noNamespaceSchemaLocation=\"http://sumo.dlr.de/xsd/det_e1_file.xsd\"");
205 std::map<std::string, std::pair<VehicleDataCont, VehicleMap> > types;
208 if (types.find((*i).typeIDM) == types.end()) {
211 types[(*i).typeIDM].first.push_back(*i);
214 const std::string& type = (*i).first->getVehicleType().getID();
215 if (types.find(type) == types.end()) {
218 types[type].second[(*i).first] = (*i).second;
221 for (std::map<std::string, std::pair<VehicleDataCont, VehicleMap> >::const_iterator i = types.begin(); i != types.end(); ++i) {
222 writeTypedXMLOutput(dev, startTime, stopTime, (*i).first, (*i).second.first, (*i).second.second);
225 dev <<
" </interval>\n";
236 unsigned nVehCrossed = (unsigned) vdc.size();
242 for (std::deque< VehicleData >::const_iterator i = vdc.begin(); i != vdc.end(); ++i) {
244 timeOnDetDuringInterval =
MIN2(timeOnDetDuringInterval, t);
245 occupancy += timeOnDetDuringInterval;
247 for (std::map< SUMOVehicle*, SUMOReal >::const_iterator i = vm.begin(); i != vm.end(); ++i) {
249 occupancy += timeOnDetDuringInterval;
251 occupancy = occupancy / t * (
SUMOReal) 100.;
252 SUMOReal meanSpeed = vdc.size() != 0
255 SUMOReal meanLength = vdc.size() != 0
259 dev <<
" <typedInterval type=\"" + type +
"\" ";
261 dev <<
" <interval ";
263 dev <<
"begin=\"" <<
time2string(startTime) <<
"\" end=\"" <<
265 dev <<
"nVehContrib=\"" << vdc.size() <<
"\" flow=\"" << flow <<
266 "\" occupancy=\"" << occupancy <<
"\" speed=\"" << meanSpeed <<
267 "\" length=\"" << meanLength <<
268 "\" nVehEntered=\"" << nVehCrossed <<
"\"";
284 SUMOReal entryTimestep = it->second;
286 assert(entryTimestep < leaveTimestep);
305 std::vector<MSInductLoop::VehicleData>
308 std::vector<VehicleData> ret;
310 if ((*i).leaveTimeM >= t) {
315 if ((*i).leaveTimeM >= t) {
void writeXMLOutput(OutputDevice &dev, SUMOTime startTime, SUMOTime stopTime)
Writes collected values into the given stream.
unsigned myDismissedVehicleNumber
The number of dismissed vehicles.
MSInductLoop(const std::string &id, MSLane *const lane, SUMOReal positionInMeters, bool splitByType)
Constructor.
The vehicle arrived at a junction.
virtual void reset()
Resets all generated values to allow computation of next interval.
static std::string escapeXML(const std::string &orig)
Replaces the standard escapes by their XML entities.
Notification
Definition of a vehicle state.
std::string time2string(SUMOTime t)
SUMOReal getLength() const
Get vehicle's length [m].
virtual std::vector< VehicleData > collectVehiclesOnDet(SUMOTime t) const
Returns vehicle data for vehicles that have been on the detector starting at the given time...
static MSNet * getInstance()
Returns the pointer to the unique instance of MSNet (singleton).
SUMOReal getCurrentOccupancy() const
Returns the current occupancy.
VehicleMap myVehiclesOnDet
Data for vehicles that have entered the detector (vehicle -> enter time)
SUMOTime getCurrentTimeStep() const
Returns the current simulation step.
VehicleDataCont myLastVehicleDataCont
Data of vehicles that have completely passed the detector in the last time interval.
const SUMOReal myPosition
Detector's position on lane [m].
The simulated network and simulation perfomer.
void writeXMLDetectorProlog(OutputDevice &dev) const
Opens the XML-output using "detector" as root element.
VehicleDataCont myVehicleDataCont
Data of vehicles that have completely passed the detector.
SUMOReal speedM
Speed of the vehicle in [m/s].
std::deque< VehicleData > VehicleDataCont
Type of myVehicleDataCont.
bool writeXMLHeader(const std::string &rootElement, const std::string &attrs="", const std::string &comment="")
Writes an XML header with optional configuration.
static SUMOReal lengthSum(SUMOReal sumSoFar, const MSInductLoop::VehicleData &data)
Adds up VehicleData::lengthM.
std::vector< std::string > getCurrentVehicleIDs() const
Returns the ids of vehicles that have passed the detector.
const std::string & getID() const
Returns the id.
Representation of a vehicle.
~MSInductLoop()
Destructor.
virtual void enterDetectorByMove(SUMOVehicle &veh, SUMOReal entryTimestep)
Introduces a vehicle to the detector's map myVehiclesOnDet.
static SUMOReal speedSum(SUMOReal sumSoFar, const MSInductLoop::VehicleData &data)
Adds up VehicleData::speedM.
bool mySplitByType
Whether additional information split by vehicle classes shall be generated.
Something on a lane to be noticed about vehicle movement.
SUMOReal getCurrentSpeed() const
Returns the speed of the vehicle on the detector.
unsigned int getCurrentPassedNumber() const
Returns the number of vehicles that have passed the detector.
#define HAS_NOT_LEFT_DETECTOR
SUMOReal myLastOccupancy
Occupancy by the last vehicle detected.
virtual SUMOReal getSpeed() const =0
Returns the vehicle's current speed.
Struct to store the data of the counted vehicle internally.
virtual void leaveDetectorByLaneChange(SUMOVehicle &veh, SUMOReal lastPos)
Removes a vehicle from the detector's map myVehiclesOnDet.
const std::string & getID() const
Returns the name of the vehicle type.
SUMOReal getTimestepsSinceLastDetection() const
Returns the time since the last vehicle left the detector.
Static storage of an output device and its base (abstract) implementation.
SUMOReal myLastLeaveTime
Leave-time of the last vehicle detected [s].
void writeTypedXMLOutput(OutputDevice &dev, SUMOTime startTime, SUMOTime stopTime, const std::string &type, const VehicleDataCont &vdc, const VehicleMap &vm)
SUMOReal getCurrentLength() const
Returns the length of the vehicle on the detector.
virtual void leaveDetectorByMove(SUMOVehicle &veh, SUMOReal leaveTimestep)
Processes a vehicle that leaves the detector.
Representation of a lane in the micro simulation.
virtual const std::string & getID() const =0
Get the vehicle's ID.
bool notifyLeave(SUMOVehicle &veh, SUMOReal lastPos, MSMoveReminder::Notification reason)
Dismisses the vehicle if it is on the detector due to a lane change.
std::map< SUMOVehicle *, SUMOReal > VehicleMap
Type of myVehiclesOnDet.
Base of value-generating classes (detectors)
bool notifyMove(SUMOVehicle &veh, SUMOReal oldPos, SUMOReal newPos, SUMOReal newSpeed)
Checks whether the vehicle shall be counted and/or shall still touch this MSMoveReminder.
virtual const MSVehicleType & getVehicleType() const =0
Returns the vehicle's type.