48 #include <mesosim/MELoop.h>
49 #include <mesosim/MESegment.h>
52 #ifdef CHECK_MEMORY_LEAKS
54 #endif // CHECK_MEMORY_LEAKS
65 const std::set<std::string>*
const vTypes) :
66 MSMoveReminder(
"meandata_" + (lane == 0 ?
"NULL" : lane->getID()), lane, doAdd),
70 myVehicleTypes(vTypes) {}
80 return vehicleApplies(veh);
90 if (oldPos < 0 && newSpeed != 0) {
91 timeOnLane = newPos / newSpeed;
95 if (fabs(timeOnLane) < 0.001) {
100 if (timeOnLane < 0) {
101 WRITE_ERROR(
"Negative vehicle step fraction for '" + veh.
getID() +
"' on lane '" + getLane()->getID() +
"'.");
104 if (timeOnLane == 0) {
107 notifyMoveInternal(veh, timeOnLane, newSpeed);
132 return sampleSeconds == 0;
143 return sampleSeconds;
152 const std::set<std::string>*
const vTypes,
166 myCurrentData.pop_front();
168 myCurrentData.push_back(
new TrackerEntry(myParent->createValues(myLane, myLaneLength,
false)));
175 myCurrentData.front()->myValues->addTo(val);
181 myTrackedData[&veh]->myValues->notifyMoveInternal(veh, timeOnLane, speed);
188 myTrackedData[&veh]->myNumVehicleLeft++;
190 return myTrackedData[&veh]->myValues->notifyLeave(veh, lastPos, reason);
199 if (vehicleApplies(veh) && myTrackedData.find(&veh) == myTrackedData.end()) {
200 myTrackedData[&veh] = myCurrentData.back();
201 myTrackedData[&veh]->myNumVehicleEntered++;
202 if (!myTrackedData[&veh]->myValues->notifyEnter(veh, reason)) {
203 myTrackedData[&veh]->myNumVehicleLeft++;
204 myTrackedData.erase(&veh);
215 return myCurrentData.front()->myValues->isEmpty();
225 myCurrentData.front()->myValues->write(dev, period, numLanes,
227 myCurrentData.front()->myNumVehicleEntered);
234 for (std::list<TrackerEntry*>::const_iterator it = myCurrentData.begin(); it != myCurrentData.end(); ++it) {
235 if ((*it)->myNumVehicleEntered == (*it)->myNumVehicleLeft) {
247 return myCurrentData.front()->myValues->getSamples();
256 const bool useLanes,
const bool withEmpty,
257 const bool printDefaults,
const bool withInternal,
const bool trackVehicles,
260 const std::set<std::string> vTypes) :
278 for (MSEdgeVector::const_iterator e = edges.begin(); e != edges.end(); ++e) {
281 myMeasures.push_back(std::vector<MeanDataValues*>());
282 const std::vector<MSLane*>& lanes = (*e)->getLanes();
293 MESegment* s = MSGlobals::gMesoNet->getSegmentForEdge(**e);
295 s->addDetector(data);
296 s->prepareDetectorForWriting(*data);
297 s = s->getNextSegment();
307 for (std::vector<MSLane*>::const_iterator lane = lanes.begin(); lane != lanes.end(); ++lane) {
310 (*lane)->addMoveReminder(
myMeasures.back().back());
324 for (std::vector<std::vector<MeanDataValues*> >::const_iterator i =
myMeasures.begin(); i !=
myMeasures.end(); ++i) {
325 for (std::vector<MeanDataValues*>::const_iterator j = (*i).begin(); j != (*i).end(); ++j) {
337 MSEdgeVector::iterator edge =
myEdges.begin();
338 for (std::vector<std::vector<MeanDataValues*> >::const_iterator i =
myMeasures.begin(); i !=
myMeasures.end(); ++i, ++edge) {
339 MESegment* s = MSGlobals::gMesoNet->getSegmentForEdge(**edge);
342 s->prepareDetectorForWriting(*data);
343 s = s->getNextSegment();
350 for (std::vector<std::vector<MeanDataValues*> >::const_iterator i =
myMeasures.begin(); i !=
myMeasures.end(); ++i) {
351 for (std::vector<MeanDataValues*>::const_iterator j = (*i).begin(); j != (*i).end(); ++j) {
360 return edge->
getID();
366 const std::vector<MeanDataValues*>& edgeValues,
370 MESegment* s = MSGlobals::gMesoNet->getSegmentForEdge(*edge);
373 s->prepareDetectorForWriting(*data);
374 s = s->getNextSegment();
377 data->
write(dev, stopTime - startTime,
385 std::vector<MeanDataValues*>::const_iterator lane;
389 for (lane = edgeValues.begin(); lane != edgeValues.end(); ++lane) {
390 if (!(*lane)->isEmpty()) {
399 for (lane = edgeValues.begin(); lane != edgeValues.end(); ++lane) {
404 meanData.
reset(
true);
415 meanData.
reset(
true);
418 for (lane = edgeValues.begin(); lane != edgeValues.end(); ++lane) {
420 meanData.
addTo(*sumData);
457 for (std::vector<std::vector<MeanDataValues*> >::const_iterator i =
myMeasures.begin(); i !=
myMeasures.end(); ++i) {
458 for (std::vector<MeanDataValues*>::const_iterator j = (*i).begin(); j != (*i).end(); ++j) {
472 while (numReady-- > 0) {
479 MSEdgeVector::iterator edge =
myEdges.begin();
480 for (std::vector<std::vector<MeanDataValues*> >::const_iterator i =
myMeasures.begin(); i !=
myMeasures.end(); ++i, ++edge) {
481 writeEdge(dev, (*i), *edge, startTime, stopTime);
490 dev.
writeXMLHeader(
"meandata",
"xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:noNamespaceSchemaLocation=\"http://sumo.dlr.de/xsd/meandata_file.xsd\"");
Data collector for edges/lanes.
virtual ~MeanDataValueTracker()
Destructor.
OutputDevice & writeAttr(const SumoXMLAttr attr, const T &val)
writes a named attribute
virtual MSMeanData::MeanDataValues * createValues(MSLane *const lane, const SUMOReal length, const bool doAdd) const =0
Create an instance of MeanDataValues.
SumoXMLTag
Numbers representing SUMO-XML - element names.
std::vector< std::vector< MeanDataValues * > > myMeasures
Value collectors; sorted by edge, then by lane.
MeanDataValues(MSLane *const lane, const SUMOReal length, const bool doAdd, const std::set< std::string > *const vTypes=0)
Constructor.
const bool myDumpInternal
Whether internal lanes/edges shall be written.
const std::vector< MSLane * > & getLanes() const
Returns this edge's lanes.
The vehicle arrived at a junction.
SUMOReal getLength() const
Returns the lane's length.
const SUMOReal myMaxTravelTime
the maximum travel time to write
Notification
Definition of a vehicle state.
SUMOReal getLength() const
Get vehicle's length [m].
static MSNet * getInstance()
Returns the pointer to the unique instance of MSNet (singleton).
The vehicle changes the segment (meso only)
bool notifyEnter(SUMOVehicle &veh, MSMoveReminder::Notification reason)
Computes current values and adds them to their sums.
const std::set< std::string > myVehicleTypes
The vehicle types to look for (empty means all)
virtual bool writePrefix(OutputDevice &dev, const MeanDataValues &values, const SumoXMLTag tag, const std::string id) const
Checks for emptiness and writes prefix into the given stream.
#define UNUSED_PARAMETER(x)
const MSLane * getLane() const
Returns the lane the reminder works on.
std::list< TrackerEntry * > myCurrentData
The currently active meandata "intervals".
bool writeXMLHeader(const std::string &rootElement, const std::string &attrs="", const std::string &comment="")
Writes an XML header with optional configuration.
const std::string & getID() const
Returns the id.
A road/street connecting two junctions.
const bool myPrintDefaults
Whether empty lanes/edges shall be written.
MeanDataValueTracker(MSLane *const lane, const SUMOReal length, const std::set< std::string > *const vTypes=0, const MSMeanData *const parent=0)
Constructor.
SUMOReal getLength() const
return the length of the edge
virtual bool notifyLeave(SUMOVehicle &veh, SUMOReal lastPos, MSMoveReminder::Notification reason)
Called if the vehicle leaves the reminder's lane.
Representation of a vehicle.
Data structure for mean (aggregated) edge/lane values.
MSEdgeVector myEdges
The corresponding first edges.
const bool myAmEdgeBased
Information whether the output shall be edge-based (not lane-based)
virtual bool notifyEnter(SUMOVehicle &veh, MSMoveReminder::Notification reason)
Called if the vehicle enters the reminder's lane.
virtual bool isEmpty() const
Returns whether any data was collected.
virtual void writeXMLDetectorProlog(OutputDevice &dev) const
Opens the XML-output using "netstats" as root element.
SUMOReal getSpeedLimit() const
Returns the lane's maximum allowed speed.
virtual void write(OutputDevice &dev, const SUMOTime period, const SUMOReal numLanes, const SUMOReal defaultTravelTime, const int numVehicles=-1) const =0
Writes output values into the given stream.
Something on a lane to be noticed about vehicle movement.
const SUMOTime myDumpBegin
The first and the last time step to write information (-1 indicates always)
virtual ~MSMeanData()
Destructor.
SUMOReal getSpeedLimit() const
Returns the speed limit of the edge The speed limit of the first lane is retured; should probably be...
bool notifyMove(SUMOVehicle &veh, SUMOReal oldPos, SUMOReal newPos, SUMOReal newSpeed)
Checks whether the reminder still has to be notified about the vehicle moves.
const SUMOReal myMinSamples
the minimum sample seconds
void notifyMoveInternal(SUMOVehicle &veh, SUMOReal timeOnLane, SUMOReal speed)
Internal notification about the vehicle moves.
bool isEmpty() const
Returns whether any data was collected.
virtual void addTo(MeanDataValues &val) const =0
Add the values of this to the given one and store them there.
virtual void openInterval(OutputDevice &dev, const SUMOTime startTime, const SUMOTime stopTime)
Writes the interval opener.
void setDescription(const std::string &description)
MSMeanData(const std::string &id, const SUMOTime dumpBegin, const SUMOTime dumpEnd, const bool useLanes, const bool withEmpty, const bool printDefaults, const bool withInternal, const bool trackVehicles, const SUMOReal minSamples, const SUMOReal maxTravelTime, const std::set< std::string > vTypes)
Constructor.
void addTo(MSMeanData::MeanDataValues &val) const
Add the values of this to the given one and store them there.
virtual ~MeanDataValues()
Destructor.
std::string myID
The name of the object.
void writeXMLOutput(OutputDevice &dev, SUMOTime startTime, SUMOTime stopTime)
Writes collected values into the given stream.
virtual void reset(bool afterWrite=false)=0
Resets values so they may be used for the next interval.
std::list< std::pair< SUMOTime, SUMOTime > > myPendingIntervals
The intervals for which output still has to be generated (only in the tracking case) ...
virtual bool hasArrived() const =0
Returns whether this vehicle has arrived.
void writeEdge(OutputDevice &dev, const std::vector< MeanDataValues * > &edgeValues, MSEdge *edge, SUMOTime startTime, SUMOTime stopTime)
Writes edge values into the given stream.
virtual void update()
Called if a per timestep update is needed. Default does nothing.
const std::string & getID() const
Returns the name of the vehicle type.
void write(OutputDevice &dev, const SUMOTime period, const SUMOReal numLanes, const SUMOReal defaultTravelTime, const int numVehicles=-1) const
Writes output values into the given stream.
virtual void detectorUpdate(const SUMOTime step)
Updates the detector.
SUMOReal getSamples() const
Returns the number of collected sample seconds.
Static storage of an output device and its base (abstract) implementation.
bool closeTag()
Closes the most recently opened tag.
static const bool gUseMesoSim
virtual SUMOReal getSamples() const
Returns the number of collected sample seconds.
MSEdgeControl & getEdgeControl()
Returns the edge control.
bool vehicleApplies(const SUMOVehicle &veh) const
Tests whether the vehicles type is to be regarded.
std::vector< MSEdge * > MSEdgeVector
void resetOnly(SUMOTime stopTime)
Resets network value in order to allow processing of the next interval.
const bool myDumpEmpty
Whether empty lanes/edges shall be written.
The edge is an internal edge.
Data structure for mean (aggregated) edge/lane values for tracked vehicles.
const bool myTrackVehicles
Whether vehicles are tracked.
Representation of a lane in the micro simulation.
virtual const std::string & getID() const =0
Get the vehicle's ID.
OutputDevice & openTag(const std::string &xmlElement)
Opens an XML tag.
virtual std::string getEdgeID(const MSEdge *const edge)
Return the relevant edge id.
Base of value-generating classes (detectors)
bool notifyLeave(SUMOVehicle &veh, SUMOReal lastPos, MSMoveReminder::Notification reason)
Called if the vehicle leaves the reminder's lane.
const MSEdgeVector & getEdges() const
Returns loaded edges.
void init()
Adds the value collectors to all relevant edges.
virtual const MSVehicleType & getVehicleType() const =0
Returns the vehicle's type.
void reset(bool afterWrite)
Resets values so they may be used for the next interval.