65 MSLane*
const lane,
const double length,
const bool doAdd,
67 MSMoveReminder(
"meandata_" + (lane == 0 ?
"NULL" : lane->getID()), lane, doAdd),
71 travelledDistance(0) {}
80 #ifdef DEBUG_NOTIFY_ENTER 81 std::cout <<
"\n" <<
SIMTIME <<
" MSMeanData_Net::MSLaneMeanDataValues: veh '" << veh.
getID() <<
"' enters lane '" << enteredLane->
getID() <<
"'" << std::endl;
96 double leaveSpeed = newSpeed, leaveSpeedFront = newSpeed;
99 double timeOnLane =
TS;
104 double timeBeforeEnter = 0.;
105 double timeBeforeEnterBack = 0.;
107 double timeBeforeLeave =
TS;
110 if (oldPos < 0 && newPos >= 0) {
113 timeOnLane =
TS - timeBeforeEnter;
114 frontOnLane = timeOnLane;
122 if (oldBackPos < 0. && newBackPos > 0.) {
124 }
else if (newBackPos <= 0) {
125 timeBeforeEnterBack =
TS;
127 timeBeforeEnterBack = 0.;
136 const double timeAfterLeave =
TS - timeBeforeLeave;
137 timeOnLane -= timeAfterLeave;
151 const double timeAfterLeave =
TS - timeBeforeLeaveFront;
152 frontOnLane -= timeAfterLeave;
160 assert(frontOnLane <=
TS);
161 assert(timeOnLane <=
TS);
163 if (timeOnLane < 0) {
167 if (timeOnLane == 0) {
171 #ifdef DEBUG_NOTIFY_MOVE 172 std::stringstream ss;
175 <<
"\noldPos: " << oldPos
176 <<
"\nnewPos: " << newPos
177 <<
"\noldPosBack: " << oldBackPos
178 <<
"\nnewPosBack: " << newBackPos
179 <<
"\ntimeBeforeEnter: " << timeBeforeEnter
180 <<
"\ntimeBeforeEnterBack: " << timeBeforeEnterBack
181 <<
"\ntimeBeforeLeaveFront: " << timeBeforeLeaveFront
182 <<
"\ntimeBeforeLeave: " << timeBeforeLeave;
183 if (!(timeBeforeLeave >=
MAX2(timeBeforeEnterBack, timeBeforeLeaveFront))
184 || !(timeBeforeEnter <=
MIN2(timeBeforeEnterBack, timeBeforeLeaveFront))) {
187 std::cout << ss.str() << std::endl;
192 assert(timeBeforeEnter <=
MIN2(timeBeforeEnterBack, timeBeforeLeaveFront));
193 assert(timeBeforeLeave >=
MAX2(timeBeforeEnterBack, timeBeforeLeaveFront));
200 double integratedLengthOnLane = 0.;
201 if (timeBeforeEnterBack < timeBeforeLeaveFront) {
206 integratedLengthOnLane += (timeBeforeEnterBack - timeBeforeEnter) * (lengthOnLaneAtBackEnter + lengthOnLaneAtStepStart) * 0.5;
209 integratedLengthOnLane += (timeBeforeLeaveFront - timeBeforeEnterBack) * vehLength;
211 integratedLengthOnLane += (timeBeforeLeave - timeBeforeLeaveFront) * (vehLength + lengthOnLaneAtStepEnd) * 0.5;
212 }
else if (timeBeforeEnterBack >= timeBeforeLeaveFront) {
215 double lengthOnLaneAtLeaveFront;
216 if (timeBeforeLeaveFront == timeBeforeEnter) {
218 lengthOnLaneAtLeaveFront = lengthOnLaneAtStepStart;
219 }
else if (timeBeforeLeaveFront == timeBeforeLeave) {
221 lengthOnLaneAtLeaveFront = lengthOnLaneAtStepEnd;
225 #ifdef DEBUG_NOTIFY_MOVE 226 std::cout <<
"lengthOnLaneAtLeaveFront=" << lengthOnLaneAtLeaveFront << std::endl;
229 integratedLengthOnLane += (timeBeforeLeaveFront - timeBeforeEnter) * (lengthOnLaneAtLeaveFront + lengthOnLaneAtStepStart) * 0.5;
231 integratedLengthOnLane += (timeBeforeEnterBack - timeBeforeLeaveFront) * lengthOnLaneAtLeaveFront;
233 integratedLengthOnLane += (timeBeforeLeave - timeBeforeEnterBack) * (lengthOnLaneAtLeaveFront + lengthOnLaneAtStepEnd) * 0.5;
236 double meanLengthOnLane = integratedLengthOnLane /
TS;
237 #ifdef DEBUG_NOTIFY_MOVE 238 std::cout <<
"Calculated mean length on lane '" <<
myLane->
getID() <<
"' in last step as " << meanLengthOnLane
239 <<
"\nlengthOnLaneAtStepStart=" << lengthOnLaneAtStepStart <<
", lengthOnLaneAtStepEnd=" << lengthOnLaneAtStepEnd <<
", integratedLengthOnLane=" << integratedLengthOnLane
255 notifyMoveInternal(veh, frontOnLane, timeOnLane, (enterSpeed + leaveSpeedFront) / 2., (enterSpeed + leaveSpeed) / 2., travelledDistanceFrontOnLane, travelledDistanceVehicleOnLane, meanLengthOnLane);
298 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)) {
379 const double numLanes,
380 const double defaultTravelTime,
382 myCurrentData.front()->myValues->write(dev, period, numLanes,
392 if ((*it)->myNumVehicleEntered == (*it)->myNumVehicleLeft) {
413 const bool useLanes,
const bool withEmpty,
414 const bool printDefaults,
const bool withInternal,
const bool trackVehicles,
415 const double maxTravelTime,
416 const double minSamples,
417 const std::string& vTypes) :
434 for (MSEdgeVector::const_iterator e = edges.begin(); e != edges.end(); ++e) {
435 if ((
myDumpInternal || !(*e)->isInternal()) && !(*e)->isCrossing() && !(*e)->isWalkingArea()) {
437 myMeasures.push_back(std::vector<MeanDataValues*>());
438 const std::vector<MSLane*>& lanes = (*e)->getLanes();
461 for (std::vector<MSLane*>::const_iterator lane = lanes.begin(); lane != lanes.end(); ++lane) {
464 (*lane)->addMoveReminder(
myMeasures.back().back());
478 for (std::vector<std::vector<MeanDataValues*> >::const_iterator i =
myMeasures.begin(); i !=
myMeasures.end(); ++i) {
479 for (std::vector<MeanDataValues*>::const_iterator j = (*i).begin(); j != (*i).end(); ++j) {
490 MSEdgeVector::iterator edge =
myEdges.begin();
491 for (std::vector<std::vector<MeanDataValues*> >::const_iterator i =
myMeasures.begin(); i !=
myMeasures.end(); ++i, ++edge) {
502 for (std::vector<std::vector<MeanDataValues*> >::const_iterator i =
myMeasures.begin(); i !=
myMeasures.end(); ++i) {
503 for (std::vector<MeanDataValues*>::const_iterator j = (*i).begin(); j != (*i).end(); ++j) {
512 return edge->
getID();
518 const std::vector<MeanDataValues*>& edgeValues,
528 data->
write(dev, stopTime - startTime,
535 std::vector<MeanDataValues*>::const_iterator lane;
539 for (lane = edgeValues.begin(); lane != edgeValues.end(); ++lane) {
540 if (!(*lane)->isEmpty()) {
549 for (lane = edgeValues.begin(); lane != edgeValues.end(); ++lane) {
554 meanData.
reset(
true);
565 meanData.
reset(
true);
568 for (lane = edgeValues.begin(); lane != edgeValues.end(); ++lane) {
570 meanData.
addTo(*sumData);
607 for (std::vector<std::vector<MeanDataValues*> >::const_iterator i =
myMeasures.begin(); i !=
myMeasures.end(); ++i) {
608 for (std::vector<MeanDataValues*>::const_iterator j = (*i).begin(); j != (*i).end(); ++j) {
622 while (numReady-- > 0) {
629 MSEdgeVector::iterator edge =
myEdges.begin();
630 for (std::vector<std::vector<MeanDataValues*> >::const_iterator i =
myMeasures.begin(); i !=
myMeasures.end(); ++i, ++edge) {
631 writeEdge(dev, (*i), *edge, startTime, stopTime);
static double speedAfterTime(const double t, const double oldSpeed, const double dist)
Calculates the speed after a time t [0,TS] given the initial speed and the distance traveled in an i...
MESegment * getNextSegment() const
Returns the following segment on the same edge (0 if it is the last).
Data collector for edges/lanes.
virtual ~MeanDataValueTracker()
Destructor.
const MSLane * getLane() const
Returns the lane the reminder works on.
OutputDevice & writeAttr(const SumoXMLAttr attr, const T &val)
writes a named attribute
SumoXMLTag
Numbers representing SUMO-XML - element names.
MESegment * getSegmentForEdge(const MSEdge &e, double pos=0)
Get the segment for a given edge at a given position.
std::vector< std::vector< MeanDataValues * > > myMeasures
Value collectors; sorted by edge, then by lane.
begin/end of the description of a single lane
const bool myDumpInternal
Whether internal lanes/edges shall be written.
MeanDataValueTracker(MSLane *const lane, const double length, const MSMeanData *const parent)
Constructor.
virtual bool notifyEnter(SUMOVehicle &veh, MSMoveReminder::Notification reason, const MSLane *enteredLane=0)
Called if the vehicle enters the reminder's lane.
bool vehicleApplies(const SUMOVehicle &veh) const
Checks whether the detector measures vehicles of the given type.
double getSamples() const
Returns the number of collected sample seconds.
const double myMaxTravelTime
the maximum travel time to write
The vehicle arrived at a junction.
T MIN4(T a, T b, T c, T d)
MSLane *const myLane
Lane on which the reminder works.
bool isEmpty() const
Returns whether any data was collected.
Notification
Definition of a vehicle state.
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.
weights: time range begin
const std::vector< MSLane * > & getLanes() const
Returns this edge's lanes.
std::map< const SUMOVehicle *, TrackerEntry * > myTrackedData
The map of vehicles to data entries.
static MSNet * getInstance()
Returns the pointer to the unique instance of MSNet (singleton).
virtual bool isEmpty() const
Returns whether any data was collected.
double getLength() const
Returns the lane's length.
The vehicle changes the segment (meso only)
virtual void notifyMoveInternal(const SUMOVehicle &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.
const std::string & getID() const
Returns the id.
double getLength() const
return the length of the edge
void notifyMoveInternal(const SUMOVehicle &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.
double getSpeedLimit() const
Returns the speed limit of the edge The speed limit of the first lane is retured; should probably be...
#define UNUSED_PARAMETER(x)
std::list< TrackerEntry * > myCurrentData
The currently active meandata "intervals".
virtual MSMeanData::MeanDataValues * createValues(MSLane *const lane, const double length, const bool doAdd) const =0
Create an instance of MeanDataValues.
void addTo(MSMeanData::MeanDataValues &val) const
Add the values of this to the given one and store them there.
bool notifyMove(SUMOVehicle &veh, double oldPos, double newPos, double newSpeed)
Checks whether the reminder still has to be notified about the vehicle moves.
A road/street connecting two junctions.
bool notifyEnter(SUMOVehicle &veh, MSMoveReminder::Notification reason, const MSLane *enteredLane=0)
Computes current values and adds them to their sums.
const bool myPrintDefaults
Whether empty lanes/edges shall be written.
Representation of a vehicle.
bool notifyLeave(SUMOVehicle &veh, double lastPos, MSMoveReminder::Notification reason, const MSLane *enteredLane=0)
Called if the vehicle leaves the reminder's lane.
Data structure for mean (aggregated) edge/lane values.
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.
MSEdgeVector myEdges
The corresponding first edges.
const bool myAmEdgeBased
Information whether the output shall be edge-based (not lane-based)
double getSpeedLimit() const
Returns the lane's maximum allowed speed.
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 double minSamples, const double maxTravelTime, const std::string &vTypes)
Constructor.
void addDetector(MSMoveReminder *data)
Adds a data collector for a detector to this segment.
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)
const double myLaneLength
The length of the lane / edge the data collector is on.
virtual ~MSMeanData()
Destructor.
const double myMinSamples
the minimum sample seconds
virtual void addTo(MeanDataValues &val) const =0
Add the values of this to the given one and store them there.
begin/end of the description of an edge
virtual void openInterval(OutputDevice &dev, const SUMOTime startTime, const SUMOTime stopTime)
Writes the interval opener.
void setDescription(const std::string &description)
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...
virtual ~MeanDataValues()
Destructor.
std::string myID
The name of the object.
const MSMeanData *const myParent
The meandata parent.
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.
virtual void writeXMLDetectorProlog(OutputDevice &dev) const
Opens the XML-output using "netstats" as root element.
A single mesoscopic segment (cell)
virtual void update()
Called if a per timestep update is needed. Default does nothing.
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.
static MELoop * gMesoNet
mesoscopic simulation infrastructure
double getLength() const
Get vehicle's length [m].
const MSEdgeVector & getEdges() const
Returns loaded edges.
virtual void detectorUpdate(const SUMOTime step)
Updates the detector.
an aggreagated-output interval
Static storage of an output device and its base (abstract) implementation.
virtual double getSamples() const
Returns the number of collected sample seconds.
bool closeTag()
Closes the most recently opened tag.
static bool gSemiImplicitEulerUpdate
MSEdgeControl & getEdgeControl()
Returns the edge control.
void prepareDetectorForWriting(MSMoveReminder &data)
Updates data of a detector for all vehicle queues.
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.
MeanDataValues(MSLane *const lane, const double length, const bool doAdd, const MSMeanData *const parent)
Constructor.
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.
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.
void writeEdge(OutputDevice &dev, const std::vector< MeanDataValues *> &edgeValues, MSEdge *edge, SUMOTime startTime, SUMOTime stopTime)
Writes edge values into the given stream.
virtual double getPreviousSpeed() const =0
Returns the vehicle's previous speed.
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.
virtual bool notifyLeave(SUMOVehicle &veh, double lastPos, MSMoveReminder::Notification reason, const MSLane *enteredLane=0)
Called if the vehicle leaves the reminder's lane.
Base of value-generating classes (detectors)
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.