51 #ifdef CHECK_MEMORY_LEAKS
53 #endif // CHECK_MEMORY_LEAKS
60 SUMOReal positionInMeters,
bool splitByType) :
63 myPosition(positionInMeters), mySplitByType(splitByType),
64 myLastLeaveTime(
STEPS2TIME(
MSNet::getInstance()->getCurrentTimeStep())),
67 assert(
myPosition >= 0 && myPosition <= myLane->getLength());
153 for (std::vector< VehicleData >::const_iterator i = d.begin(); i != d.end(); ++i) {
155 timeOnDetDuringInterval =
MIN2(timeOnDetDuringInterval,
TS);
156 occupancy += timeOnDetDuringInterval;
165 return (
unsigned int) d.size();
169 std::vector<std::string>
172 std::vector<std::string> ret;
173 for (std::vector<VehicleData>::iterator i = d.begin(); i != d.end(); ++i) {
174 ret.push_back((*i).idM);
192 dev.
writeXMLHeader(
"detector",
"xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:noNamespaceSchemaLocation=\"http://sumo-sim.org/xsd/det_e1_file.xsd\"");
202 std::map<std::string, std::pair<VehicleDataCont, VehicleMap> > types;
205 if (types.find((*i).typeIDM) == types.end()) {
208 types[(*i).typeIDM].first.push_back(*i);
211 const std::string& type = (*i).first->getVehicleType().getID();
212 if (types.find(type) == types.end()) {
215 types[type].second[(*i).first] = (*i).second;
218 for (std::map<std::string, std::pair<VehicleDataCont, VehicleMap> >::const_iterator i = types.begin(); i != types.end(); ++i) {
219 writeTypedXMLOutput(dev, startTime, stopTime, (*i).first, (*i).second.first, (*i).second.second);
222 dev <<
" </interval>\n";
233 unsigned nVehCrossed = (unsigned) vdc.size();
239 for (std::deque< VehicleData >::const_iterator i = vdc.begin(); i != vdc.end(); ++i) {
241 timeOnDetDuringInterval =
MIN2(timeOnDetDuringInterval, t);
242 occupancy += timeOnDetDuringInterval;
244 for (std::map< SUMOVehicle*, SUMOReal >::const_iterator i = vm.begin(); i != vm.end(); ++i) {
246 occupancy += timeOnDetDuringInterval;
248 occupancy = occupancy / t * (
SUMOReal) 100.;
249 SUMOReal meanSpeed = vdc.size() != 0
252 SUMOReal meanLength = vdc.size() != 0
256 dev <<
" <typedInterval type=\"" + type +
"\" ";
258 dev <<
" <interval ";
260 dev <<
"begin=\"" <<
time2string(startTime) <<
"\" end=\"" <<
262 dev <<
"nVehContrib=\"" << vdc.size() <<
"\" flow=\"" << flow <<
263 "\" occupancy=\"" << occupancy <<
"\" speed=\"" << meanSpeed <<
264 "\" length=\"" << meanLength <<
265 "\" nVehEntered=\"" << nVehCrossed <<
"\"";
281 SUMOReal entryTimestep = it->second;
283 assert(entryTimestep < leaveTimestep);
302 std::vector<MSInductLoop::VehicleData>
305 std::vector<VehicleData> ret;
307 if ((*i).leaveTimeM >= t) {
312 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.
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.