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());
149 for (std::vector< VehicleData >::const_iterator i = d.begin(); i != d.end(); ++i) {
151 timeOnDetDuringInterval =
MIN2(timeOnDetDuringInterval,
TS);
152 occupancy += timeOnDetDuringInterval;
161 return (
unsigned int) d.size();
165 std::vector<std::string>
168 std::vector<std::string> ret;
169 for (std::vector<VehicleData>::iterator i = d.begin(); i != d.end(); ++i) {
170 ret.push_back((*i).idM);
188 dev.
writeXMLHeader(
"detector",
"xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:noNamespaceSchemaLocation=\"http://sumo-sim.org/xsd/det_e1_file.xsd\"");
198 std::map<std::string, std::pair<VehicleDataCont, VehicleMap> > types;
201 if (types.find((*i).typeIDM) == types.end()) {
204 types[(*i).typeIDM].first.push_back(*i);
207 const std::string& type = (*i).first->getVehicleType().getID();
208 if (types.find(type) == types.end()) {
211 types[type].second[(*i).first] = (*i).second;
214 for (std::map<std::string, std::pair<VehicleDataCont, VehicleMap> >::const_iterator i = types.begin(); i != types.end(); ++i) {
215 writeTypedXMLOutput(dev, startTime, stopTime, (*i).first, (*i).second.first, (*i).second.second);
218 dev <<
" </interval>\n";
229 unsigned nVehCrossed = (unsigned) vdc.size();
235 for (std::deque< VehicleData >::const_iterator i = vdc.begin(); i != vdc.end(); ++i) {
237 timeOnDetDuringInterval =
MIN2(timeOnDetDuringInterval, t);
238 occupancy += timeOnDetDuringInterval;
240 for (std::map< SUMOVehicle*, SUMOReal >::const_iterator i = vm.begin(); i != vm.end(); ++i) {
242 occupancy += timeOnDetDuringInterval;
244 occupancy = occupancy / t * (
SUMOReal) 100.;
245 SUMOReal meanSpeed = vdc.size() != 0
248 SUMOReal meanLength = vdc.size() != 0
252 dev <<
" <typedInterval type=\"" + type +
"\" ";
254 dev <<
" <interval ";
256 dev <<
"begin=\"" <<
time2string(startTime) <<
"\" end=\"" <<
258 dev <<
"nVehContrib=\"" << vdc.size() <<
"\" flow=\"" << flow <<
259 "\" occupancy=\"" << occupancy <<
"\" speed=\"" << meanSpeed <<
260 "\" length=\"" << meanLength <<
261 "\" nVehEntered=\"" << nVehCrossed <<
"\"";
277 SUMOReal entryTimestep = it->second;
279 assert(entryTimestep < leaveTimestep);
298 std::vector<MSInductLoop::VehicleData>
301 std::vector<VehicleData> ret;
303 if ((*i).leaveTimeM >= t) {
308 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.