61 MSLane*
const lane,
const double length,
const bool doAdd,
63 MSMoveReminder(
"meandata_" + (parent == nullptr ?
"" : parent->
getID() +
"|") + (lane == nullptr ?
"NULL" : lane->
getID()), lane, doAdd),
76#ifdef DEBUG_NOTIFY_ENTER
77 std::cout <<
"\n" <<
SIMTIME <<
" MSMeanData_Net::MSLaneMeanDataValues: veh '" << veh.
getID() <<
"' enters lane '" << enteredLane->
getID() <<
"'" << std::endl;
92 double leaveSpeed = newSpeed, leaveSpeedFront = newSpeed;
95 double timeOnLane =
TS;
100 double timeBeforeEnter = 0.;
101 double timeBeforeEnterBack = 0.;
103 double timeBeforeLeave =
TS;
106 if (oldPos < 0 && newPos >= 0) {
109 timeOnLane =
TS - timeBeforeEnter;
110 frontOnLane = timeOnLane;
118 if (oldBackPos < 0. && newBackPos > 0.) {
120 }
else if (newBackPos <= 0) {
121 timeBeforeEnterBack =
TS;
123 timeBeforeEnterBack = 0.;
132 const double timeAfterLeave =
TS - timeBeforeLeave;
133 timeOnLane -= timeAfterLeave;
136 if (fabs(timeOnLane) < NUMERICAL_EPS) {
147 const double timeAfterLeave =
TS - timeBeforeLeaveFront;
148 frontOnLane -= timeAfterLeave;
150 if (fabs(frontOnLane) < NUMERICAL_EPS) {
156 assert(frontOnLane <=
TS);
157 assert(timeOnLane <=
TS);
159 if (timeOnLane < 0) {
163 if (timeOnLane == 0) {
167#ifdef DEBUG_NOTIFY_MOVE
168 std::stringstream ss;
171 <<
"\noldPos: " << oldPos
172 <<
"\nnewPos: " << newPos
173 <<
"\noldPosBack: " << oldBackPos
174 <<
"\nnewPosBack: " << newBackPos
175 <<
"\ntimeBeforeEnter: " << timeBeforeEnter
176 <<
"\ntimeBeforeEnterBack: " << timeBeforeEnterBack
177 <<
"\ntimeBeforeLeaveFront: " << timeBeforeLeaveFront
178 <<
"\ntimeBeforeLeave: " << timeBeforeLeave;
179 if (!(timeBeforeLeave >=
MAX2(timeBeforeEnterBack, timeBeforeLeaveFront))
180 || !(timeBeforeEnter <=
MIN2(timeBeforeEnterBack, timeBeforeLeaveFront))) {
183 std::cout << ss.str() << std::endl;
188 assert(timeBeforeEnter <=
MIN2(timeBeforeEnterBack, timeBeforeLeaveFront));
189 assert(timeBeforeLeave >=
MAX2(timeBeforeEnterBack, timeBeforeLeaveFront));
196 double integratedLengthOnLane = 0.;
197 if (timeBeforeEnterBack < timeBeforeLeaveFront) {
202 integratedLengthOnLane += (timeBeforeEnterBack - timeBeforeEnter) * (lengthOnLaneAtBackEnter + lengthOnLaneAtStepStart) * 0.5;
205 integratedLengthOnLane += (timeBeforeLeaveFront - timeBeforeEnterBack) * vehLength;
207 integratedLengthOnLane += (timeBeforeLeave - timeBeforeLeaveFront) * (vehLength + lengthOnLaneAtStepEnd) * 0.5;
208 }
else if (timeBeforeEnterBack >= timeBeforeLeaveFront) {
211 double lengthOnLaneAtLeaveFront;
212 if (timeBeforeLeaveFront == timeBeforeEnter) {
214 lengthOnLaneAtLeaveFront = lengthOnLaneAtStepStart;
215 }
else if (timeBeforeLeaveFront == timeBeforeLeave) {
217 lengthOnLaneAtLeaveFront = lengthOnLaneAtStepEnd;
221#ifdef DEBUG_NOTIFY_MOVE
222 std::cout <<
"lengthOnLaneAtLeaveFront=" << lengthOnLaneAtLeaveFront << std::endl;
225 integratedLengthOnLane += (timeBeforeLeaveFront - timeBeforeEnter) * (lengthOnLaneAtLeaveFront + lengthOnLaneAtStepStart) * 0.5;
227 integratedLengthOnLane += (timeBeforeEnterBack - timeBeforeLeaveFront) * lengthOnLaneAtLeaveFront;
229 integratedLengthOnLane += (timeBeforeLeave - timeBeforeEnterBack) * (lengthOnLaneAtLeaveFront + lengthOnLaneAtStepEnd) * 0.5;
232 double meanLengthOnLane = integratedLengthOnLane /
TS;
233#ifdef DEBUG_NOTIFY_MOVE
234 std::cout <<
"Calculated mean length on lane '" <<
myLane->getID() <<
"' in last step as " << meanLengthOnLane
235 <<
"\nlengthOnLaneAtStepStart=" << lengthOnLaneAtStepStart <<
", lengthOnLaneAtStepEnd=" << lengthOnLaneAtStepEnd <<
", integratedLengthOnLane=" << integratedLengthOnLane
254 notifyMoveInternal(veh, frontOnLane, timeOnLane, (enterSpeed + leaveSpeedFront) / 2., (enterSpeed + leaveSpeed) / 2., travelledDistanceFrontOnLane, travelledDistanceVehicleOnLane, meanLengthOnLane);
297 std::list<TrackerEntry*>::iterator i;
333 myTrackedData[&veh]->myValues->notifyMoveInternal(veh, frontOnLane, timeOnLane, meanSpeedFrontOnLane, meanSpeedVehicleOnLane, travelledDistanceFrontOnLane, travelledDistanceVehicleOnLane, meanLengthOnLane);
342 return myTrackedData[&veh]->myValues->notifyLeave(veh, lastPos, reason);
348#ifdef DEBUG_NOTIFY_ENTER
349 std::cout <<
"\n" <<
SIMTIME <<
" MSMeanData::MeanDataValueTracker: veh '" << veh.
getID() <<
"' enters lane '" << enteredLane->
getID() <<
"'" << std::endl;
359 if (!
myTrackedData[&veh]->myValues->notifyEnter(veh, reason)) {
381 const double speedLimit,
382 const double defaultTravelTime,
384 myCurrentData.front()->myValues->write(dev, attributeMask, period, numLanes, speedLimit,
394 if ((*it)->myNumVehicleEntered == (*it)->myNumVehicleLeft) {
415 const bool useLanes,
const bool withEmpty,
416 const bool printDefaults,
const bool withInternal,
417 const bool trackVehicles,
418 const int detectPersons,
419 const double maxTravelTime,
420 const double minSamples,
421 const std::string& vTypes,
422 const std::string& writeAttributes,
423 const std::vector<MSEdge*>& edges,
456 myMeasures.push_back(std::vector<MeanDataValues*>());
458 const std::vector<MSLane*>& lanes = edge->getLanes();
462 for (
MSLane*
const lane : lanes) {
463 data =
createValues(lane, lanes[0]->getLength(),
false);
466 while (s !=
nullptr) {
478 data =
createValues(
nullptr, lanes[0]->getLength(),
false);
483 while (s !=
nullptr) {
496 for (
MSLane*
const lane : lanes) {
499 lane->addMoveReminder(
myMeasures.back().back());
512 for (std::vector<std::vector<MeanDataValues*> >::const_iterator i =
myMeasures.begin(); i !=
myMeasures.end(); ++i) {
513 for (std::vector<MeanDataValues*>::const_iterator j = (*i).begin(); j != (*i).end(); ++j) {
524 MSEdgeVector::iterator edge =
myEdges.begin();
525 for (std::vector<std::vector<MeanDataValues*> >::const_iterator i =
myMeasures.begin(); i !=
myMeasures.end(); ++i, ++edge) {
528 while (s !=
nullptr) {
537 for (std::vector<std::vector<MeanDataValues*> >::const_iterator i =
myMeasures.begin(); i !=
myMeasures.end(); ++i) {
538 for (std::vector<MeanDataValues*>::const_iterator j = (*i).begin(); j != (*i).end(); ++j) {
547 return edge->
getID();
554 throw ProcessError(
TL(
"aggregated meanData output not yet implemented for trackVehicles"));
557 double edgeLengthSum = 0;
562 edgeLengthSum += edge->getLength();
563 laneNumber += edge->getNumDrivingLanes();
564 speedSum += edge->getSpeedLimit();
565 totalTT += edge->getLength() / edge->getSpeedLimit();
568 for (
const std::vector<MeanDataValues*>& edgeValues :
myMeasures) {
570 meanData->addTo(*sumData);
577 for (
int i = 0; i < (int)
myEdges.size(); i++) {
579 std::vector<MeanDataValues*>& edgeValues =
myMeasures[i];
581 while (s !=
nullptr) {
584 meanData->addTo(*sumData);
605 const std::vector<MeanDataValues*>& edgeValues,
611 while (s !=
nullptr) {
631 std::vector<MeanDataValues*>::const_iterator lane;
635 for (lane = edgeValues.begin(); lane != edgeValues.end(); ++lane) {
636 if (!(*lane)->isEmpty()) {
645 for (lane = edgeValues.begin(); lane != edgeValues.end(); ++lane) {
652 meanData.
reset(
true);
666 meanData.
reset(
true);
670 for (lane = edgeValues.begin(); lane != edgeValues.end(); ++lane) {
672 meanData.
addTo(*sumData);
714 for (std::vector<std::vector<MeanDataValues*> >::const_iterator i =
myMeasures.begin(); i !=
myMeasures.end(); ++i) {
715 for (std::vector<MeanDataValues*>::const_iterator j = (*i).begin(); j != (*i).end(); ++j) {
726 const bool partialInterval = startTime <
myInitTime;
730 if (partialInterval) {
733 while (numReady-- > 0) {
743 MSEdgeVector::const_iterator edge =
myEdges.begin();
744 for (
const std::vector<MeanDataValues*>& measures :
myMeasures) {
745 writeEdge(dev, measures, *edge, startTime, stopTime);
769const std::vector<MSMeanData::MeanDataValues*>*
780const std::vector<MSMoveReminder*>
782 std::vector<MSMoveReminder*> result;
784 result.insert(result.end(), vec.begin(), vec.end());
#define WRITE_ERRORF(...)
std::string time2string(SUMOTime t, bool humanReadable)
convert SUMOTime to string (independently of global format setting)
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
std::bitset< 96 > SumoXMLAttrMask
@ 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)
A single mesoscopic segment (cell).
void addDetector(MSMoveReminder *data, int queueIndex=-1)
Adds a data collector for a detector to this segment.
void prepareDetectorForWriting(MSMoveReminder &data, int queueIndex=-1)
Removes a data collector for a detector from this segment.
MESegment * getNextSegment() const
Returns the following segment on the same edge (0 if it is the last).
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...
bool detectsPersons() const
MSDetectorFileOutput(const std::string &id, const std::string &vTypes, const std::string &nextEdges="", const int detectPersons=false)
Constructor.
A road/street connecting two junctions.
int getNumDrivingLanes() const
return the number of lanes that permit non-weak modes if the edge allows non weak modes and the numbe...
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.
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.
void write(OutputDevice &dev, const SumoXMLAttrMask &attributeMask, const SUMOTime period, const int numLanes, const double speedLimit, const double defaultTravelTime, const int numVehicles=-1) const
Writes output values into the given stream.
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.
std::map< const SUMOTrafficObject *, TrackerEntry * > myTrackedData
The map of vehicles to data entries.
Data structure for mean (aggregated) edge/lane values.
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 write(OutputDevice &dev, const SumoXMLAttrMask &attributeMask, const SUMOTime period, const int numLanes, const double speedLimit, const double defaultTravelTime, const int numVehicles=-1) const =0
Writes output values into the given stream.
virtual void update()
Called if a per timestep update is needed. Default does nothing.
double travelledDistance
The sum of the distances the vehicles travelled.
virtual bool isEmpty() const
Returns whether any data was collected.
bool notifyMove(SUMOTrafficObject &veh, double oldPos, double newPos, double newSpeed)
Checks whether the reminder still has to be notified about the vehicle moves.
const double myLaneLength
The length of the lane / edge the data collector is on.
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.
const MSMeanData *const myParent
The meandata parent.
virtual double getSamples() const
Returns the number of collected sample seconds.
virtual MSMeanData::MeanDataValues * createValues(MSLane *const lane, const double length, const bool doAdd) const =0
Create an instance of MeanDataValues.
const bool myAggregate
whether the data for all edges shall be aggregated
void writeXMLOutput(OutputDevice &dev, SUMOTime startTime, SUMOTime stopTime)
Writes collected 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.
void writeAggregated(OutputDevice &dev, SUMOTime startTime, SUMOTime stopTime)
Writes aggregate of all edge values into the given stream.
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 bool myPrintDefaults
Whether empty lanes/edges shall be written.
std::map< const MSEdge *, int > myEdgeIndex
The index in myEdges / myMeasures.
const SumoXMLAttrMask myWrittenAttributes
bit mask for checking attributes to be written
const bool myAmEdgeBased
Information whether the output shall be edge-based (not lane-based).
SUMOTime myInitTime
time at which init was called();
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).
const std::vector< MeanDataValues * > * getEdgeValues(const MSEdge *edge) const
void writeEdge(OutputDevice &dev, const std::vector< MeanDataValues * > &edgeValues, const MSEdge *const edge, SUMOTime startTime, SUMOTime stopTime)
Writes edge values into the given stream.
virtual std::string getEdgeID(const MSEdge *const edge)
Return the relevant edge 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.
const std::vector< MSMoveReminder * > getReminders() const
retrieve all MeanDataValues
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, const std::vector< MSEdge * > &edges, bool aggregate)
Constructor.
virtual void openInterval(OutputDevice &dev, const SUMOTime startTime, const SUMOTime stopTime)
Writes the interval opener.
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.
virtual 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.
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.
MSMoveReminder(const std::string &description, MSLane *const lane=nullptr, const bool doAdd=true)
Constructor.
MSLane * myLane
Lane on which the reminder works.
const MSLane * getLane() const
Returns the lane the reminder works on.
static MSNet * getInstance()
Returns the pointer to the unique instance of MSNet (singleton).
SUMOTime getCurrentTimeStep() const
Returns the current simulation step.
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.
OutputDevice & writeAttr(const SumoXMLAttr attr, const T &val)
writes a named attribute
OutputDevice & openTag(const std::string &xmlElement)
Opens an XML tag.
bool closeTag(const std::string &comment="")
Closes the most recently opened tag and optionally adds a comment.
bool writeXMLHeader(const std::string &rootElement, const std::string &schemaFile, std::map< SumoXMLAttr, std::string > attrs=std::map< SumoXMLAttr, std::string >(), bool includeConfig=true)
Writes an XML header with optional configuration.
OutputDevice & writeOptionalAttr(const SumoXMLAttr attr, const T &val, const SumoXMLAttrMask &attributeMask, const bool isNull=false)
writes a named attribute unless filtered
Representation of a vehicle, person, or container.
virtual const MSVehicleType & getVehicleType() const =0
Returns the object's "vehicle" type.
virtual double getPreviousSpeed() const =0
Returns the object's previous speed.
virtual bool hasArrived() const =0
Returns whether this object has arrived.
A scoped lock which only triggers on condition.
#define UNUSED_PARAMETER(x)