 |
Eclipse SUMO - Simulation of Urban MObility
|
Go to the documentation of this file.
59 MSLane*
const lane,
const double length,
const bool doAdd,
61 MSMoveReminder(
"meandata_" + (lane == nullptr ?
"NULL" : lane->getID()), lane, doAdd),
65 travelledDistance(0) {}
74 #ifdef DEBUG_NOTIFY_ENTER
75 std::cout <<
"\n" <<
SIMTIME <<
" MSMeanData_Net::MSLaneMeanDataValues: veh '" << veh.
getID() <<
"' enters lane '" << enteredLane->
getID() <<
"'" << std::endl;
80 return myParent ==
nullptr || myParent->vehicleApplies(veh);
90 double leaveSpeed = newSpeed, leaveSpeedFront = newSpeed;
93 double timeOnLane =
TS;
94 double frontOnLane = oldPos > myLaneLength ? 0. :
TS;
98 double timeBeforeEnter = 0.;
99 double timeBeforeEnterBack = 0.;
100 double timeBeforeLeaveFront = newPos < myLaneLength ?
TS : 0.;
101 double timeBeforeLeave =
TS;
104 if (oldPos < 0 && newPos >= 0) {
107 timeOnLane =
TS - timeBeforeEnter;
108 frontOnLane = timeOnLane;
116 if (oldBackPos < 0. && newBackPos > 0.) {
118 }
else if (newBackPos <= 0) {
119 timeBeforeEnterBack =
TS;
121 timeBeforeEnterBack = 0.;
125 if (newBackPos > myLaneLength
126 && oldBackPos <= myLaneLength) {
130 const double timeAfterLeave =
TS - timeBeforeLeave;
131 timeOnLane -= timeAfterLeave;
141 if (newPos > myLaneLength && oldPos <= myLaneLength) {
145 const double timeAfterLeave =
TS - timeBeforeLeaveFront;
146 frontOnLane -= timeAfterLeave;
154 assert(frontOnLane <=
TS);
155 assert(timeOnLane <=
TS);
157 if (timeOnLane < 0) {
158 WRITE_ERROR(
"Negative vehicle step fraction for '" + veh.
getID() +
"' on lane '" + getLane()->getID() +
"'.");
161 if (timeOnLane == 0) {
165 #ifdef DEBUG_NOTIFY_MOVE
166 std::stringstream ss;
168 <<
"lane length: " << myLaneLength
169 <<
"\noldPos: " << oldPos
170 <<
"\nnewPos: " << newPos
171 <<
"\noldPosBack: " << oldBackPos
172 <<
"\nnewPosBack: " << newBackPos
173 <<
"\ntimeBeforeEnter: " << timeBeforeEnter
174 <<
"\ntimeBeforeEnterBack: " << timeBeforeEnterBack
175 <<
"\ntimeBeforeLeaveFront: " << timeBeforeLeaveFront
176 <<
"\ntimeBeforeLeave: " << timeBeforeLeave;
177 if (!(timeBeforeLeave >=
MAX2(timeBeforeEnterBack, timeBeforeLeaveFront))
178 || !(timeBeforeEnter <=
MIN2(timeBeforeEnterBack, timeBeforeLeaveFront))) {
181 std::cout << ss.str() << std::endl;
186 assert(timeBeforeEnter <=
MIN2(timeBeforeEnterBack, timeBeforeLeaveFront));
187 assert(timeBeforeLeave >=
MAX2(timeBeforeEnterBack, timeBeforeLeaveFront));
191 double lengthOnLaneAtStepStart =
MAX2(0.,
MIN4(myLaneLength, vehLength, vehLength - (oldPos - myLaneLength), oldPos));
193 double lengthOnLaneAtStepEnd =
MAX2(0.,
MIN4(myLaneLength, vehLength, vehLength - (newPos - myLaneLength), newPos));
194 double integratedLengthOnLane = 0.;
195 if (timeBeforeEnterBack < timeBeforeLeaveFront) {
200 integratedLengthOnLane += (timeBeforeEnterBack - timeBeforeEnter) * (lengthOnLaneAtBackEnter + lengthOnLaneAtStepStart) * 0.5;
203 integratedLengthOnLane += (timeBeforeLeaveFront - timeBeforeEnterBack) * vehLength;
205 integratedLengthOnLane += (timeBeforeLeave - timeBeforeLeaveFront) * (vehLength + lengthOnLaneAtStepEnd) * 0.5;
206 }
else if (timeBeforeEnterBack >= timeBeforeLeaveFront) {
209 double lengthOnLaneAtLeaveFront;
210 if (timeBeforeLeaveFront == timeBeforeEnter) {
212 lengthOnLaneAtLeaveFront = lengthOnLaneAtStepStart;
213 }
else if (timeBeforeLeaveFront == timeBeforeLeave) {
215 lengthOnLaneAtLeaveFront = lengthOnLaneAtStepEnd;
217 lengthOnLaneAtLeaveFront = myLaneLength;
219 #ifdef DEBUG_NOTIFY_MOVE
220 std::cout <<
"lengthOnLaneAtLeaveFront=" << lengthOnLaneAtLeaveFront << std::endl;
223 integratedLengthOnLane += (timeBeforeLeaveFront - timeBeforeEnter) * (lengthOnLaneAtLeaveFront + lengthOnLaneAtStepStart) * 0.5;
225 integratedLengthOnLane += (timeBeforeEnterBack - timeBeforeLeaveFront) * lengthOnLaneAtLeaveFront;
227 integratedLengthOnLane += (timeBeforeLeave - timeBeforeEnterBack) * (lengthOnLaneAtLeaveFront + lengthOnLaneAtStepEnd) * 0.5;
230 double meanLengthOnLane = integratedLengthOnLane /
TS;
231 #ifdef DEBUG_NOTIFY_MOVE
232 std::cout <<
"Calculated mean length on lane '" << myLane->getID() <<
"' in last step as " << meanLengthOnLane
233 <<
"\nlengthOnLaneAtStepStart=" << lengthOnLaneAtStepStart <<
", lengthOnLaneAtStepEnd=" << lengthOnLaneAtStepEnd <<
", integratedLengthOnLane=" << integratedLengthOnLane
242 :
MAX2(0.,
MIN2(newPos, myLaneLength) -
MAX2(oldPos, 0.));
249 notifyMoveInternal(veh, frontOnLane, timeOnLane, (enterSpeed + leaveSpeedFront) / 2., (enterSpeed + leaveSpeed) / 2., travelledDistanceFrontOnLane, travelledDistanceVehicleOnLane, meanLengthOnLane);
265 return sampleSeconds == 0;
276 return sampleSeconds;
292 std::list<TrackerEntry*>::iterator i;
293 for (i = myCurrentData.begin(); i != myCurrentData.end(); i++) {
310 if (myCurrentData.begin() != myCurrentData.end()) {
311 myCurrentData.pop_front();
314 myCurrentData.push_back(
new TrackerEntry(myParent->createValues(myLane, myLaneLength,
false)));
321 myCurrentData.front()->myValues->addTo(val);
327 myTrackedData[&veh]->myValues->notifyMoveInternal(veh, frontOnLane, timeOnLane, meanSpeedFrontOnLane, meanSpeedVehicleOnLane, travelledDistanceFrontOnLane, travelledDistanceVehicleOnLane, meanLengthOnLane);
334 myTrackedData[&veh]->myNumVehicleLeft++;
336 return myTrackedData[&veh]->myValues->notifyLeave(veh, lastPos, reason);
342 #ifdef DEBUG_NOTIFY_ENTER
343 std::cout <<
"\n" <<
SIMTIME <<
" MSMeanData::MeanDataValueTracker: veh '" << veh.
getID() <<
"' enters lane '" << enteredLane->
getID() <<
"'" << std::endl;
350 if (myParent->vehicleApplies(veh) && myTrackedData.find(&veh) == myTrackedData.end()) {
351 myTrackedData[&veh] = myCurrentData.back();
352 myTrackedData[&veh]->myNumVehicleEntered++;
353 if (!myTrackedData[&veh]->myValues->notifyEnter(veh, reason)) {
354 myTrackedData[&veh]->myNumVehicleLeft++;
355 myTrackedData.erase(&veh);
366 return myCurrentData.front()->myValues->isEmpty();
373 const double numLanes,
374 const double defaultTravelTime,
376 myCurrentData.front()->myValues->write(dev, period, numLanes,
378 myCurrentData.front()->myNumVehicleEntered);
385 for (std::list<TrackerEntry*>::const_iterator it = myCurrentData.begin(); it != myCurrentData.end(); ++it) {
386 if ((*it)->myNumVehicleEntered == (*it)->myNumVehicleLeft) {
398 return myCurrentData.front()->myValues->getSamples();
407 const bool useLanes,
const bool withEmpty,
408 const bool printDefaults,
const bool withInternal,
409 const bool trackVehicles,
411 const double maxTravelTime,
412 const double minSamples,
413 const std::string& vTypes) :
430 for (MSEdgeVector::const_iterator e = edges.begin(); e != edges.end(); ++e) {
434 myMeasures.push_back(std::vector<MeanDataValues*>());
435 const std::vector<MSLane*>& lanes = (*e)->getLanes();
441 data =
createValues(
nullptr, lanes[0]->getLength(),
false);
446 while (s !=
nullptr) {
458 for (std::vector<MSLane*>::const_iterator lane = lanes.begin(); lane != lanes.end(); ++lane) {
461 (*lane)->addMoveReminder(
myMeasures.back().back());
475 for (std::vector<std::vector<MeanDataValues*> >::const_iterator i =
myMeasures.begin(); i !=
myMeasures.end(); ++i) {
476 for (std::vector<MeanDataValues*>::const_iterator j = (*i).begin(); j != (*i).end(); ++j) {
487 MSEdgeVector::iterator edge =
myEdges.begin();
488 for (std::vector<std::vector<MeanDataValues*> >::const_iterator i =
myMeasures.begin(); i !=
myMeasures.end(); ++i, ++edge) {
491 while (s !=
nullptr) {
499 for (std::vector<std::vector<MeanDataValues*> >::const_iterator i =
myMeasures.begin(); i !=
myMeasures.end(); ++i) {
500 for (std::vector<MeanDataValues*>::const_iterator j = (*i).begin(); j != (*i).end(); ++j) {
509 return edge->
getID();
515 const std::vector<MeanDataValues*>& edgeValues,
520 while (s !=
nullptr) {
525 data->
write(dev, stopTime - startTime,
532 std::vector<MeanDataValues*>::const_iterator lane;
536 for (lane = edgeValues.begin(); lane != edgeValues.end(); ++lane) {
537 if (!(*lane)->isEmpty()) {
546 for (lane = edgeValues.begin(); lane != edgeValues.end(); ++lane) {
551 meanData.
reset(
true);
562 meanData.
reset(
true);
565 for (lane = edgeValues.begin(); lane != edgeValues.end(); ++lane) {
567 meanData.
addTo(*sumData);
604 for (std::vector<std::vector<MeanDataValues*> >::const_iterator i =
myMeasures.begin(); i !=
myMeasures.end(); ++i) {
605 for (std::vector<MeanDataValues*>::const_iterator j = (*i).begin(); j != (*i).end(); ++j) {
619 while (numReady-- > 0) {
626 MSEdgeVector::iterator edge =
myEdges.begin();
627 for (std::vector<std::vector<MeanDataValues*> >::const_iterator i =
myMeasures.begin(); i !=
myMeasures.end(); ++i, ++edge) {
628 writeEdge(dev, (*i), *edge, startTime, stopTime);
#define UNUSED_PARAMETER(x)
Representation of a vehicle or person.
void writeEdge(OutputDevice &dev, const std::vector< MeanDataValues * > &edgeValues, MSEdge *edge, SUMOTime startTime, SUMOTime stopTime)
Writes edge values into the given stream.
const bool myDumpEmpty
Whether empty lanes/edges shall be written.
double getSpeedLimit() const
Returns the speed limit of the edge @caution The speed limit of the first lane is retured; should pro...
Base of value-generating classes (detectors)
Representation of a lane in the micro simulation.
const bool myAmEdgeBased
Information whether the output shall be edge-based (not lane-based)
A single mesoscopic segment (cell)
Static storage of an output device and its base (abstract) implementation.
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)
Constructor.
virtual void writeXMLDetectorProlog(OutputDevice &dev) const
Opens the XML-output using "netstats" as root element.
virtual const MSVehicleType & getVehicleType() const =0
Returns the vehicle's type.
void addDetector(MSMoveReminder *data)
Adds a data collector for a detector to this segment.
virtual const std::string & getID() const =0
Get the vehicle's ID.
double getSamples() const
Returns the number of collected sample seconds.
begin/end of the description of a single lane
virtual bool notifyEnter(SUMOTrafficObject &veh, MSMoveReminder::Notification reason, const MSLane *enteredLane=0)
Called if the vehicle enters the reminder's lane.
virtual bool isEmpty() const
Returns whether any data was collected.
MeanDataValueTracker(MSLane *const lane, const double length, const MSMeanData *const parent)
Constructor.
std::vector< std::vector< MeanDataValues * > > myMeasures
Value collectors; sorted by edge, then by lane.
const bool myPrintDefaults
Whether empty lanes/edges shall be written.
virtual void write(OutputDevice &dev, const SUMOTime period, const double numLanes, const double defaultTravelTime, const int numVehicles=-1) const =0
Writes output values into the given stream.
void resetOnly(SUMOTime stopTime)
Resets network value in order to allow processing of the next interval.
double getLength() const
return the length of the edge
SumoXMLTag
Numbers representing SUMO-XML - element names.
void writeXMLOutput(OutputDevice &dev, SUMOTime startTime, SUMOTime stopTime)
Writes collected values into the given stream.
Something on a lane to be noticed about vehicle movement.
bool closeTag(const std::string &comment="")
Closes the most recently opened tag and optionally adds a comment.
MSEdgeVector myEdges
The corresponding first edges.
weights: time range begin
const bool myDumpInternal
Whether internal lanes/edges shall be written.
const double myMinSamples
the minimum sample seconds
OutputDevice & writeAttr(const SumoXMLAttr attr, const T &val)
writes a named attribute
bool notifyEnter(SUMOTrafficObject &veh, MSMoveReminder::Notification reason, const MSLane *enteredLane=0)
Computes current values and adds them to their sums.
Data collector for edges/lanes.
virtual ~MeanDataValueTracker()
Destructor.
virtual void openInterval(OutputDevice &dev, const SUMOTime startTime, const SUMOTime stopTime)
Writes the interval opener.
bool notifyMove(SUMOTrafficObject &veh, double oldPos, double newPos, double newSpeed)
Checks whether the reminder still has to be notified about the vehicle moves.
void prepareDetectorForWriting(MSMoveReminder &data)
Updates data of a detector for all vehicle queues.
void addTo(MSMeanData::MeanDataValues &val) const
Add the values of this to the given one and store them there.
std::list< std::pair< SUMOTime, SUMOTime > > myPendingIntervals
The intervals for which output still has to be generated (only in the tracking case)
virtual ~MSMeanData()
Destructor.
virtual bool notifyLeave(SUMOTrafficObject &veh, double lastPos, MSMoveReminder::Notification reason, const MSLane *enteredLane=0)
Called if the vehicle leaves the reminder's lane.
T MIN4(T a, T b, T c, T d)
double getLength() const
Returns the lane's length.
MESegment * getSegmentForEdge(const MSEdge &e, double pos=0)
Get the segment for a given edge at a given position.
begin/end of the description of an edge
const double myMaxTravelTime
the maximum travel time to write
std::string time2string(SUMOTime t)
MESegment * getNextSegment() const
Returns the following segment on the same edge (0 if it is the last).
A road/street connecting two junctions.
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...
bool isEmpty() const
Returns whether any data was collected.
void init()
Adds the value collectors to all relevant edges.
The vehicle changes the segment (meso only)
virtual void update()
Called if a per timestep update is needed. Default does nothing.
Data structure for mean (aggregated) edge/lane values.
bool detectPersons() const
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 ~MeanDataValues()
Destructor.
std::list< TrackerEntry * > myCurrentData
The currently active meandata "intervals".
const MSLane * getLane() const
Returns the lane the reminder works on.
OutputDevice & openTag(const std::string &xmlElement)
Opens an XML tag.
Data structure for mean (aggregated) edge/lane values for tracked vehicles.
const bool myTrackVehicles
Whether vehicles are tracked.
virtual double getSamples() const
Returns the number of collected sample seconds.
void reset(bool afterWrite)
Resets values so they may be used for the next interval.
static MSNet * getInstance()
Returns the pointer to the unique instance of MSNet (singleton).
static MELoop * gMesoNet
mesoscopic simulation infrastructure
virtual double getPreviousSpeed() const =0
Returns the vehicle's previous speed.
virtual bool hasArrived() const =0
Returns whether this vehicle has arrived.
double getLength() const
Get vehicle's length [m].
const SUMOTime myDumpBegin
The first and the last time step to write information (-1 indicates always)
std::vector< MSEdge * > MSEdgeVector
virtual void reset(bool afterWrite=false)=0
Resets values so they may be used for the next interval.
virtual MSMeanData::MeanDataValues * createValues(MSLane *const lane, const double length, const bool doAdd) const =0
Create an instance of MeanDataValues.
void setDescription(const std::string &description)
const std::vector< MSLane * > & getLanes() const
Returns this edge's lanes.
virtual void addTo(MeanDataValues &val) const =0
Add the values of this to the given one and store them there.
virtual std::string getEdgeID(const MSEdge *const edge)
Return the relevant edge id.
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...
void write(OutputDevice &dev, const SUMOTime period, const double numLanes, const double defaultTravelTime, const int numVehicles=-1) const
Writes output values into the given stream.
an aggreagated-output interval
bool notifyLeave(SUMOTrafficObject &veh, double lastPos, MSMoveReminder::Notification reason, const MSLane *enteredLane=0)
Called if the vehicle leaves the reminder's lane.
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.
double getSpeedLimit() const
Returns the lane's maximum allowed speed.
MSEdgeControl & getEdgeControl()
Returns the edge control.
static bool gSemiImplicitEulerUpdate
std::string myID
The name of the object.
const std::string & getID() const
Returns the id.
Notification
Definition of a vehicle state.
The vehicle arrived at a junction.
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.
MeanDataValues(MSLane *const lane, const double length, const bool doAdd, const MSMeanData *const parent)
Constructor.
const MSEdgeVector & getEdges() const
Returns loaded edges.
virtual void detectorUpdate(const SUMOTime step)
Updates the detector.