58 MSLane*
const lane,
const double length,
const bool doAdd,
60 MSMoveReminder(
"meandata_" + (lane == nullptr ?
"NULL" : lane->getID()), lane, doAdd),
64 travelledDistance(0) {}
73 #ifdef DEBUG_NOTIFY_ENTER
74 std::cout <<
"\n" <<
SIMTIME <<
" MSMeanData_Net::MSLaneMeanDataValues: veh '" << veh.
getID() <<
"' enters lane '" << enteredLane->
getID() <<
"'" << std::endl;
79 return myParent ==
nullptr || myParent->vehicleApplies(veh);
89 double leaveSpeed = newSpeed, leaveSpeedFront = newSpeed;
92 double timeOnLane =
TS;
93 double frontOnLane = oldPos > myLaneLength ? 0. :
TS;
97 double timeBeforeEnter = 0.;
98 double timeBeforeEnterBack = 0.;
99 double timeBeforeLeaveFront = newPos < myLaneLength ?
TS : 0.;
100 double timeBeforeLeave =
TS;
103 if (oldPos < 0 && newPos >= 0) {
106 timeOnLane =
TS - timeBeforeEnter;
107 frontOnLane = timeOnLane;
115 if (oldBackPos < 0. && newBackPos > 0.) {
117 }
else if (newBackPos <= 0) {
118 timeBeforeEnterBack =
TS;
120 timeBeforeEnterBack = 0.;
124 if (newBackPos > myLaneLength
125 && oldBackPos <= myLaneLength) {
129 const double timeAfterLeave =
TS - timeBeforeLeave;
130 timeOnLane -= timeAfterLeave;
133 if (fabs(timeOnLane) < NUMERICAL_EPS) {
140 if (newPos > myLaneLength && oldPos <= myLaneLength) {
144 const double timeAfterLeave =
TS - timeBeforeLeaveFront;
145 frontOnLane -= timeAfterLeave;
147 if (fabs(frontOnLane) < NUMERICAL_EPS) {
153 assert(frontOnLane <=
TS);
154 assert(timeOnLane <=
TS);
156 if (timeOnLane < 0) {
157 WRITE_ERROR(
"Negative vehicle step fraction for '" + veh.
getID() +
"' on lane '" + getLane()->
getID() +
"'.");
160 if (timeOnLane == 0) {
164 #ifdef DEBUG_NOTIFY_MOVE
165 std::stringstream ss;
167 <<
"lane length: " << myLaneLength
168 <<
"\noldPos: " << oldPos
169 <<
"\nnewPos: " << newPos
170 <<
"\noldPosBack: " << oldBackPos
171 <<
"\nnewPosBack: " << newBackPos
172 <<
"\ntimeBeforeEnter: " << timeBeforeEnter
173 <<
"\ntimeBeforeEnterBack: " << timeBeforeEnterBack
174 <<
"\ntimeBeforeLeaveFront: " << timeBeforeLeaveFront
175 <<
"\ntimeBeforeLeave: " << timeBeforeLeave;
176 if (!(timeBeforeLeave >=
MAX2(timeBeforeEnterBack, timeBeforeLeaveFront))
177 || !(timeBeforeEnter <=
MIN2(timeBeforeEnterBack, timeBeforeLeaveFront))) {
180 std::cout << ss.str() << std::endl;
185 assert(timeBeforeEnter <=
MIN2(timeBeforeEnterBack, timeBeforeLeaveFront));
186 assert(timeBeforeLeave >=
MAX2(timeBeforeEnterBack, timeBeforeLeaveFront));
190 double lengthOnLaneAtStepStart =
MAX2(0.,
MIN4(myLaneLength, vehLength, vehLength - (oldPos - myLaneLength), oldPos));
192 double lengthOnLaneAtStepEnd =
MAX2(0.,
MIN4(myLaneLength, vehLength, vehLength - (newPos - myLaneLength), newPos));
193 double integratedLengthOnLane = 0.;
194 if (timeBeforeEnterBack < timeBeforeLeaveFront) {
199 integratedLengthOnLane += (timeBeforeEnterBack - timeBeforeEnter) * (lengthOnLaneAtBackEnter + lengthOnLaneAtStepStart) * 0.5;
202 integratedLengthOnLane += (timeBeforeLeaveFront - timeBeforeEnterBack) * vehLength;
204 integratedLengthOnLane += (timeBeforeLeave - timeBeforeLeaveFront) * (vehLength + lengthOnLaneAtStepEnd) * 0.5;
205 }
else if (timeBeforeEnterBack >= timeBeforeLeaveFront) {
208 double lengthOnLaneAtLeaveFront;
209 if (timeBeforeLeaveFront == timeBeforeEnter) {
211 lengthOnLaneAtLeaveFront = lengthOnLaneAtStepStart;
212 }
else if (timeBeforeLeaveFront == timeBeforeLeave) {
214 lengthOnLaneAtLeaveFront = lengthOnLaneAtStepEnd;
216 lengthOnLaneAtLeaveFront = myLaneLength;
218 #ifdef DEBUG_NOTIFY_MOVE
219 std::cout <<
"lengthOnLaneAtLeaveFront=" << lengthOnLaneAtLeaveFront << std::endl;
222 integratedLengthOnLane += (timeBeforeLeaveFront - timeBeforeEnter) * (lengthOnLaneAtLeaveFront + lengthOnLaneAtStepStart) * 0.5;
224 integratedLengthOnLane += (timeBeforeEnterBack - timeBeforeLeaveFront) * lengthOnLaneAtLeaveFront;
226 integratedLengthOnLane += (timeBeforeLeave - timeBeforeEnterBack) * (lengthOnLaneAtLeaveFront + lengthOnLaneAtStepEnd) * 0.5;
229 double meanLengthOnLane = integratedLengthOnLane /
TS;
230 #ifdef DEBUG_NOTIFY_MOVE
231 std::cout <<
"Calculated mean length on lane '" << myLane->getID() <<
"' in last step as " << meanLengthOnLane
232 <<
"\nlengthOnLaneAtStepStart=" << lengthOnLaneAtStepStart <<
", lengthOnLaneAtStepEnd=" << lengthOnLaneAtStepEnd <<
", integratedLengthOnLane=" << integratedLengthOnLane
241 :
MAX2(0.,
MIN2(newPos, myLaneLength) -
MAX2(oldPos, 0.));
251 notifyMoveInternal(veh, frontOnLane, timeOnLane, (enterSpeed + leaveSpeedFront) / 2., (enterSpeed + leaveSpeed) / 2., travelledDistanceFrontOnLane, travelledDistanceVehicleOnLane, meanLengthOnLane);
267 return sampleSeconds == 0;
278 return sampleSeconds;
294 std::list<TrackerEntry*>::iterator i;
295 for (i = myCurrentData.begin(); i != myCurrentData.end(); i++) {
312 if (myCurrentData.begin() != myCurrentData.end()) {
313 myCurrentData.pop_front();
316 myCurrentData.push_back(
new TrackerEntry(myParent->createValues(myLane, myLaneLength,
false)));
323 myCurrentData.front()->myValues->addTo(val);
329 myTrackedData[&veh]->myValues->notifyMoveInternal(veh, frontOnLane, timeOnLane, meanSpeedFrontOnLane, meanSpeedVehicleOnLane, travelledDistanceFrontOnLane, travelledDistanceVehicleOnLane, meanLengthOnLane);
336 myTrackedData[&veh]->myNumVehicleLeft++;
338 return myTrackedData[&veh]->myValues->notifyLeave(veh, lastPos, reason);
344 #ifdef DEBUG_NOTIFY_ENTER
345 std::cout <<
"\n" <<
SIMTIME <<
" MSMeanData::MeanDataValueTracker: veh '" << veh.
getID() <<
"' enters lane '" << enteredLane->
getID() <<
"'" << std::endl;
352 if (myParent->vehicleApplies(veh) && myTrackedData.find(&veh) == myTrackedData.end()) {
353 myTrackedData[&veh] = myCurrentData.back();
354 myTrackedData[&veh]->myNumVehicleEntered++;
355 if (!myTrackedData[&veh]->myValues->notifyEnter(veh, reason)) {
356 myTrackedData[&veh]->myNumVehicleLeft++;
357 myTrackedData.erase(&veh);
368 return myCurrentData.front()->myValues->isEmpty();
374 long long int attributeMask,
376 const double numLanes,
377 const double defaultTravelTime,
379 myCurrentData.front()->myValues->write(dev, attributeMask, period, numLanes,
381 myCurrentData.front()->myNumVehicleEntered);
388 for (std::list<TrackerEntry*>::const_iterator it = myCurrentData.begin(); it != myCurrentData.end(); ++it) {
389 if ((*it)->myNumVehicleEntered == (*it)->myNumVehicleLeft) {
401 return myCurrentData.front()->myValues->getSamples();
410 const bool useLanes,
const bool withEmpty,
411 const bool printDefaults,
const bool withInternal,
412 const bool trackVehicles,
414 const double maxTravelTime,
415 const double minSamples,
416 const std::string& vTypes,
417 const std::string& writeAttributes) :
438 myMeasures.push_back(std::vector<MeanDataValues*>());
439 const std::vector<MSLane*>& lanes = edge->getLanes();
445 data =
createValues(
nullptr, lanes[0]->getLength(),
false);
450 while (s !=
nullptr) {
462 for (
MSLane*
const lane : lanes) {
465 lane->addMoveReminder(
myMeasures.back().back());
479 for (std::vector<std::vector<MeanDataValues*> >::const_iterator i =
myMeasures.begin(); i !=
myMeasures.end(); ++i) {
480 for (std::vector<MeanDataValues*>::const_iterator j = (*i).begin(); j != (*i).end(); ++j) {
491 MSEdgeVector::iterator edge =
myEdges.begin();
492 for (std::vector<std::vector<MeanDataValues*> >::const_iterator i =
myMeasures.begin(); i !=
myMeasures.end(); ++i, ++edge) {
495 while (s !=
nullptr) {
503 for (std::vector<std::vector<MeanDataValues*> >::const_iterator i =
myMeasures.begin(); i !=
myMeasures.end(); ++i) {
504 for (std::vector<MeanDataValues*>::const_iterator j = (*i).begin(); j != (*i).end(); ++j) {
513 return edge->
getID();
519 const std::vector<MeanDataValues*>& edgeValues,
524 while (s !=
nullptr) {
536 std::vector<MeanDataValues*>::const_iterator lane;
540 for (lane = edgeValues.begin(); lane != edgeValues.end(); ++lane) {
541 if (!(*lane)->isEmpty()) {
550 for (lane = edgeValues.begin(); lane != edgeValues.end(); ++lane) {
555 meanData.
reset(
true);
566 meanData.
reset(
true);
569 for (lane = edgeValues.begin(); lane != edgeValues.end(); ++lane) {
571 meanData.
addTo(*sumData);
610 for (std::vector<std::vector<MeanDataValues*> >::const_iterator i =
myMeasures.begin(); i !=
myMeasures.end(); ++i) {
611 for (std::vector<MeanDataValues*>::const_iterator j = (*i).begin(); j != (*i).end(); ++j) {
625 while (numReady-- > 0) {
632 MSEdgeVector::iterator edge =
myEdges.begin();
633 for (std::vector<std::vector<MeanDataValues*> >::const_iterator i =
myMeasures.begin(); i !=
myMeasures.end(); ++i, ++edge) {
634 writeEdge(dev, (*i), *edge, startTime, stopTime);
657 long long int result = 0;
658 for (std::string attrName :
StringTokenizer(writeAttributes).getVector()) {
660 WRITE_ERROR(
"Unknown attribute '" + attrName +
"' to write in meanData '" +
id +
"'.");
665 result |= ((
long long int)1 << attr);
std::string time2string(SUMOTime t)
convert SUMOTime to string
SumoXMLTag
Numbers representing SUMO-XML - element names.
@ SUMO_TAG_INTERVAL
an aggreagated-output interval
@ SUMO_TAG_LANE
begin/end of the description of a single lane
@ SUMO_TAG_EDGE
begin/end of the description of an edge
@ SUMO_ATTR_BEGIN
weights: time range begin
@ SUMO_ATTR_END
weights: time range end
@ SUMO_ATTR_SAMPLEDSECONDS
MSMeanData_Net.
T MIN4(T a, T b, T c, T d)
#define UNUSED_PARAMETER(x)
A scoped lock which only triggers on condition.
MESegment * getSegmentForEdge(const MSEdge &e, double pos=0)
Get the segment for a given edge at a given position.
A single mesoscopic segment (cell)
MESegment * getNextSegment() const
Returns the following segment on the same edge (0 if it is the last).
void prepareDetectorForWriting(MSMoveReminder &data)
Updates data of a detector for all vehicle queues.
void addDetector(MSMoveReminder *data)
Adds a data collector for a detector to this segment.
static double speedAfterTime(const double t, const double oldSpeed, const double dist)
Calculates the speed after a time t \in [0,TS] given the initial speed and the distance traveled in a...
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 detectPersons() const
A road/street connecting two junctions.
const std::vector< MSLane * > & getLanes() const
Returns this edge's lanes.
double getSpeedLimit() const
Returns the speed limit of the edge @caution The speed limit of the first lane is retured; should pro...
double getLength() const
return the length of the edge
static MELoop * gMesoNet
mesoscopic simulation infrastructure
static bool gSemiImplicitEulerUpdate
static int gNumSimThreads
how many threads to use for simulation
Representation of a lane in the micro simulation.
double getSpeedLimit() const
Returns the lane's maximum allowed speed.
double getLength() const
Returns the lane's length.
Data structure for mean (aggregated) edge/lane values for tracked vehicles.
void write(OutputDevice &dev, long long int attributeMask, const SUMOTime period, const double numLanes, const double defaultTravelTime, const int numVehicles=-1) const
Writes output values into the given stream.
double getSamples() const
Returns the number of collected sample seconds.
MeanDataValueTracker(MSLane *const lane, const double length, const MSMeanData *const parent)
Constructor.
bool notifyLeave(SUMOTrafficObject &veh, double lastPos, MSMoveReminder::Notification reason, const MSLane *enteredLane=0)
Called if the vehicle leaves the reminder's lane.
void addTo(MSMeanData::MeanDataValues &val) const
Add the values of this to the given one and store them there.
void notifyMoveInternal(const SUMOTrafficObject &veh, const double frontOnLane, const double timeOnLane, const double meanSpeedFrontOnLane, const double meanSpeedVehicleOnLane, const double travelledDistanceFrontOnLane, const double travelledDistanceVehicleOnLane, const double meanLengthOnLane)
Internal notification about the vehicle moves.
virtual ~MeanDataValueTracker()
Destructor.
bool notifyEnter(SUMOTrafficObject &veh, MSMoveReminder::Notification reason, const MSLane *enteredLane=0)
Computes current values and adds them to their sums.
std::list< TrackerEntry * > myCurrentData
The currently active meandata "intervals".
bool isEmpty() const
Returns whether any data was collected.
void reset(bool afterWrite)
Resets values so they may be used for the next interval.
Data structure for mean (aggregated) edge/lane values.
static void checkWriteAttribute(OutputDevice &dev, long long int attributeMask, const SumoXMLAttr attr, const T &val)
write attribute if it passed the attribute mask check
virtual void addTo(MeanDataValues &val) const =0
Add the values of this to the given one and store them there.
virtual bool notifyLeave(SUMOTrafficObject &veh, double lastPos, MSMoveReminder::Notification reason, const MSLane *enteredLane=0)
Called if the vehicle leaves the reminder's lane.
MeanDataValues(MSLane *const lane, const double length, const bool doAdd, const MSMeanData *const parent)
Constructor.
virtual void update()
Called if a per timestep update is needed. Default does nothing.
virtual bool isEmpty() const
Returns whether any data was collected.
virtual void write(OutputDevice &dev, long long int attributeMask, const SUMOTime period, const double numLanes, const double defaultTravelTime, const int numVehicles=-1) const =0
Writes output values into the given stream.
bool notifyMove(SUMOTrafficObject &veh, double oldPos, double newPos, double newSpeed)
Checks whether the reminder still has to be notified about the vehicle moves.
virtual ~MeanDataValues()
Destructor.
virtual void reset(bool afterWrite=false)=0
Resets values so they may be used for the next interval.
virtual bool notifyEnter(SUMOTrafficObject &veh, MSMoveReminder::Notification reason, const MSLane *enteredLane=0)
Called if the vehicle enters the reminder's lane.
virtual double getSamples() const
Returns the number of collected sample seconds.
Data collector for edges/lanes.
void writeXMLOutput(OutputDevice &dev, SUMOTime startTime, SUMOTime stopTime)
Writes collected values into the given stream.
void writeEdge(OutputDevice &dev, const std::vector< MeanDataValues * > &edgeValues, MSEdge *edge, SUMOTime startTime, SUMOTime stopTime)
Writes edge values into the given stream.
const bool myDumpInternal
Whether internal lanes/edges shall be written.
const SUMOTime myDumpBegin
The first and the last time step to write information (-1 indicates always)
virtual void detectorUpdate(const SUMOTime step)
Updates the detector.
virtual ~MSMeanData()
Destructor.
virtual MSMeanData::MeanDataValues * createValues(MSLane *const lane, const double length, const bool doAdd) const =0
Create an instance of MeanDataValues.
void init()
Adds the value collectors to all relevant edges.
const double myMinSamples
the minimum sample seconds
void resetOnly(SUMOTime stopTime)
Resets network value in order to allow processing of the next interval.
const long long int myWrittenAttributes
bit mask for checking attributes to be written
const bool myPrintDefaults
Whether empty lanes/edges shall be written.
const bool myAmEdgeBased
Information whether the output shall be edge-based (not lane-based)
const double myMaxTravelTime
the maximum travel time to write
std::list< std::pair< SUMOTime, SUMOTime > > myPendingIntervals
The intervals for which output still has to be generated (only in the tracking case)
virtual std::string getEdgeID(const MSEdge *const edge)
Return the relevant edge id.
static long long int initWrittenAttributes(const std::string writeAttributes, const std::string &id)
virtual void writeXMLDetectorProlog(OutputDevice &dev) const
Opens the XML-output using "netstats" as root element.
const bool myDumpEmpty
Whether empty lanes/edges shall be written.
MSEdgeVector myEdges
The corresponding first edges.
virtual void openInterval(OutputDevice &dev, const SUMOTime startTime, const SUMOTime stopTime)
Writes the interval opener.
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 int detectPersons, const double minSamples, const double maxTravelTime, const std::string &vTypes, const std::string &writeAttributes)
Constructor.
std::vector< std::vector< MeanDataValues * > > myMeasures
Value collectors; sorted by edge, then by lane.
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.
const bool myTrackVehicles
Whether vehicles are tracked.
Something on a lane to be noticed about vehicle movement.
const MSLane * getLane() const
Returns the lane the reminder works on.
void setDescription(const std::string &description)
Notification
Definition of a vehicle state.
@ NOTIFICATION_SEGMENT
The vehicle changes the segment (meso only)
@ NOTIFICATION_JUNCTION
The vehicle arrived at a junction.
static MSNet * getInstance()
Returns the pointer to the unique instance of MSNet (singleton).
double getLength() const
Get vehicle's length [m].
std::string myID
The name of the object.
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 const MSVehicleType & getVehicleType() const =0
Returns the object's "vehicle" type.
virtual bool hasArrived() const =0
Returns whether this object has arrived.
static StringBijection< int > Attrs
The names of SUMO-XML attributes for use in netbuild.
T get(const std::string &str) const