MSMeanData_Net Class Reference

#include <MSMeanData_Net.h>

Inheritance diagram for MSMeanData_Net:

MSMeanData MSDetectorFileOutput

Detailed Description

Network state mean data collector for edges/lanes.

This structure does not contain the data itself, it is stored within MSLaneMeanDataValues-MoveReminder objects. This class is used to build the output, optionally, in the case of edge-based dump, aggregated over the edge's lanes.

Todo:
check where mean data is stored in mesosim.
Todo:
consider error-handling on write (using IOError)

Definition at line 66 of file MSMeanData_Net.h.


Public Member Functions

void init (const std::vector< MSEdge * > &edges, const bool withInternal) throw ()
 Adds the value collectors to all relevant edges.
 MSMeanData_Net (const std::string &id, const SUMOTime dumpBegin, const SUMOTime dumpEnd, const bool useLanes, const bool withEmpty, const bool trackVehicles, const SUMOReal maxTravelTime, const SUMOReal minSamples, const SUMOReal haltSpeed, const std::set< std::string > vTypes) throw ()
 Constructor.
void update () throw ()
 Updates the detector.
virtual ~MSMeanData_Net () throw ()
 Destructor.
Virtual methods to implement by derived classes
virtual void reset ()
 Resets collected values.
Methods inherited from MSDetectorFileOutput.
void writeXMLDetectorProlog (OutputDevice &dev) const throw (IOError)
 Opens the XML-output using "netstats" as root element.
void writeXMLOutput (OutputDevice &dev, SUMOTime startTime, SUMOTime stopTime) throw (IOError)
 Writes collected values into the given stream.

Protected Member Functions

MSMeanData::MeanDataValuescreateValues (MSLane *const lane, const bool doAdd) const throw (IOError)
 Create an instance of MeanDataValues.
void resetOnly (SUMOTime stopTime) throw ()
 Resets network value in order to allow processing of the next interval.
virtual void writeEdge (OutputDevice &dev, const std::vector< MeanDataValues * > &edgeValues, MSEdge *edge, SUMOTime startTime, SUMOTime stopTime) throw (IOError)
 Writes edge values into the given stream.
void writeEdge (OutputDevice &dev, const std::vector< MSMeanData::MeanDataValues * > &edgeValues, MSEdge *edge, SUMOTime startTime, SUMOTime stopTime) throw (IOError)
 Writes edge values into the given stream.
bool writePrefix (OutputDevice &dev, const MeanDataValues &values, const std::string prefix) const throw (IOError)
 Checks for emptiness and writes prefix into the given stream.

Protected Attributes

const SUMOReal myMaxTravelTime
 the maximum travel time to write
const SUMOReal myMinSamples
 the minimum sample seconds
const std::set< std::string > myVehicleTypes
 The vehicle types to look for (empty means all).

Private Member Functions

 MSMeanData_Net (const MSMeanData_Net &)
 Invalidated copy constructor.
MSMeanData_Netoperator= (const MSMeanData_Net &)
 Invalidated assignment operator.

Private Attributes

const SUMOReal myHaltSpeed
 the minimum sample seconds

Data Structures

class  MSLaneMeanDataValues
 Data structure for mean (aggregated) edge/lane values. More...

Constructor & Destructor Documentation

MSMeanData_Net::MSMeanData_Net ( const std::string &  id,
const SUMOTime  dumpBegin,
const SUMOTime  dumpEnd,
const bool  useLanes,
const bool  withEmpty,
const bool  trackVehicles,
const SUMOReal  maxTravelTime,
const SUMOReal  minSamples,
const SUMOReal  haltSpeed,
const std::set< std::string >  vTypes 
) throw ()

Constructor.

Parameters:
[in] id The id of the detector
[in] dumpBegin Begin time of dump
[in] dumpEnd End time of dump
[in] useLanes Information whether lane-based or edge-based dump shall be generated
[in] withEmpty Information whether empty lanes/edges shall be written
[in] trackVehicles Information whether vehicles shall be tracked
[in] maxTravelTime the maximum travel time to output
[in] minSamples the minimum number of sample seconds before the values are valid
[in] haltSpeed the maximum speed to consider a vehicle waiting
[in] vTypes the set of vehicle types to consider

Definition at line 248 of file MSMeanData_Net.cpp.

00254         : MSMeanData(id, dumpBegin, dumpEnd, useLanes, withEmpty, trackVehicles, maxTravelTime, minSamples, vTypes),
00255         myHaltSpeed(haltSpeed) {
00256 }

MSMeanData_Net::~MSMeanData_Net (  )  throw () [virtual]

Destructor.

Definition at line 259 of file MSMeanData_Net.cpp.

00259 {}

MSMeanData_Net::MSMeanData_Net ( const MSMeanData_Net  )  [private]

Invalidated copy constructor.


Member Function Documentation

MSMeanData::MeanDataValues * MSMeanData_Net::createValues ( MSLane *const   lane,
const bool  doAdd 
) const throw (IOError) [protected, virtual]

Create an instance of MeanDataValues.

Parameters:
[in] lane The lane to create for
[in] doAdd whether to add the values as reminder to the lane

Implements MSMeanData.

Definition at line 263 of file MSMeanData_Net.cpp.

References MSMeanData::myVehicleTypes.

Referenced by writeEdge().

00263                                                                                        {
00264     return new MSLaneMeanDataValues(lane, doAdd, &myVehicleTypes, this);
00265 }

void MSMeanData::init ( const std::vector< MSEdge * > &  edges,
const bool  withInternal 
) throw () [inherited]

Adds the value collectors to all relevant edges.

Parameters:
[in] edges the edges to use
[in] withInternal Information whether internal lanes/edges shall be written

Definition at line 204 of file MSMeanData.cpp.

References MSMeanData::createValues(), MSEdge::EDGEFUNCTION_INTERNAL, MSMeanData::MeanDataValueTracker::MeanDataValueTracker(), MSMeanData::myAmEdgeBased, MSMeanData::myEdges, MSMeanData::myMeasures, MSMeanData::myTrackVehicles, and MSMeanData::MeanDataValues::myVehicleTypes.

Referenced by NLDetectorBuilder::createEdgeLaneMeanData().

00204                                                                                  {
00205     for (std::vector<MSEdge*>::const_iterator e = edges.begin(); e != edges.end(); ++e) {
00206         if (withInternal || (*e)->getPurpose() != MSEdge::EDGEFUNCTION_INTERNAL) {
00207             myEdges.push_back(*e);
00208             myMeasures.push_back(std::vector<MeanDataValues*>());
00209 #ifdef HAVE_MESOSIM
00210             if (MSGlobals::gUseMesoSim) {
00211                 MESegment *s = MSGlobals::gMesoNet->getSegmentForEdge(**e);
00212                 while (s!=0) {
00213                     myMeasures.back().push_back(createValues(0, false));
00214                     s->addDetector(myMeasures.back().back());
00215                     s = s->getNextSegment();
00216                 }
00217                 continue;
00218             }
00219 #endif
00220             if (myAmEdgeBased && myTrackVehicles) {
00221                 myMeasures.back().push_back(new MeanDataValueTracker(0, &myVehicleTypes, this));
00222             }
00223             const std::vector<MSLane*> &lanes = (*e)->getLanes();
00224             for (std::vector<MSLane*>::const_iterator lane = lanes.begin(); lane != lanes.end(); ++lane) {
00225                 if (myTrackVehicles) {
00226                     if (myAmEdgeBased) {
00227                         (*lane)->addMoveReminder(myMeasures.back().back());
00228                     } else {
00229                         myMeasures.back().push_back(new MeanDataValueTracker(*lane, &myVehicleTypes, this));
00230                     }
00231                 } else {
00232                     myMeasures.back().push_back(createValues(*lane, true));
00233                 }
00234             }
00235         }
00236     }
00237 }

MSMeanData_Net& MSMeanData_Net::operator= ( const MSMeanData_Net  )  [private]

Invalidated assignment operator.

virtual void MSDetectorFileOutput::reset (  )  [inline, virtual, inherited]

Resets collected values.

Please note that this is only a "hack" for coupled-tls-outputs.

See also:
Command_SaveTLCoupledLaneDet
Todo:
Reckeck/refactor

Reimplemented in MSE2Collector, MSE3Collector, and MSInductLoop.

Definition at line 97 of file MSDetectorFileOutput.h.

Referenced by Command_SaveTLCoupledLaneDet::execute().

00097 { }

void MSMeanData_Net::resetOnly ( SUMOTime  stopTime  )  throw () [protected]

Resets network value in order to allow processing of the next interval.

Goes through the lists of edges and starts "resetOnly" for each edge.

Parameters:
[in] edge The last time step that is reported

Reimplemented from MSMeanData.

void MSMeanData::update (  )  throw () [inherited]

Updates the detector.

Definition at line 381 of file MSMeanData.cpp.

References MSMeanData::myMeasures.

00381                            {
00382     for (std::vector<std::vector<MeanDataValues*> >::const_iterator i=myMeasures.begin(); i!=myMeasures.end(); ++i) {
00383         const std::vector<MeanDataValues*> &lm = *i;
00384         for (std::vector<MeanDataValues*>::const_iterator j=lm.begin(); j!=lm.end(); ++j) {
00385             (*j)->update();
00386         }
00387     }
00388 }

void MSMeanData::writeEdge ( OutputDevice dev,
const std::vector< MeanDataValues * > &  edgeValues,
MSEdge edge,
SUMOTime  startTime,
SUMOTime  stopTime 
) throw (IOError) [protected, virtual, inherited]

Writes edge values into the given stream.

microsim: It is checked whether the dump shall be generated edge- or lane-wise. In the first case, the lane-data are collected and aggregated and written directly. In the second case, "writeLane" is used to write each lane's state.

Parameters:
[in] dev The output device to write the data into
[in] edgeValues List of this edge's value collectors
[in] edge The edge to write the dump of
[in] startTime First time step the data were gathered
[in] stopTime Last time step the data were gathered
Exceptions:
IOError If an error on writing occurs (!!! not yet implemented)

Definition at line 268 of file MSMeanData.cpp.

References MSMeanData::MeanDataValues::addTo(), MSMeanData::createValues(), MSLane::getID(), MSMoveReminder::getLane(), MSLane::getLength(), MSMeanData::myAmEdgeBased, MSMeanData::myDumpEmpty, MSMeanData::myTrackVehicles, MSMeanData::MeanDataValues::reset(), SUMOReal, MSMeanData::MeanDataValues::write(), and MSMeanData::writePrefix().

Referenced by writeEdge(), and MSMeanData::writeXMLOutput().

00270                                                                                           {
00271     std::vector<MeanDataValues*>::const_iterator lane;
00272     if (!myAmEdgeBased) {
00273         bool writeCheck = myDumpEmpty;
00274         if (!writeCheck) {
00275             for (lane = edgeValues.begin(); lane != edgeValues.end(); ++lane) {
00276                 if (!(*lane)->isEmpty()) {
00277                     writeCheck = true;
00278                     break;
00279                 }
00280             }
00281         }
00282         if (writeCheck) {
00283             dev.openTag("edge")<<" id=\""<<edge->getID()<<"\">\n";
00284         }
00285         for (lane = edgeValues.begin(); lane != edgeValues.end(); ++lane) {
00286             MeanDataValues& meanData = **lane;
00287             if (writePrefix(dev, meanData, "<lane id=\""+meanData.getLane()->getID())) {
00288                 meanData.write(dev, stopTime - startTime,
00289                                1.f, meanData.getLane()->getLength());
00290             }
00291             if (myTrackVehicles) {
00292                 ((MeanDataValueTracker&)meanData).clearFirst();
00293             } else {
00294                 meanData.reset();
00295             }
00296         }
00297         if (writeCheck) {
00298             dev.closeTag();
00299         }
00300     } else {
00301         if (myTrackVehicles) {
00302             MeanDataValues& meanData = **edgeValues.begin();
00303             if (writePrefix(dev, meanData, "<edge id=\""+edge->getID())) {
00304                 meanData.write(dev, stopTime - startTime,
00305                                (SUMOReal)edge->getLanes().size(), edge->getLanes()[0]->getLength());
00306             }
00307         } else {
00308             MeanDataValues* sumData = createValues(0, false);
00309             for (lane = edgeValues.begin(); lane != edgeValues.end(); ++lane) {
00310                 MeanDataValues& meanData = **lane;
00311                 meanData.addTo(*sumData);
00312                 meanData.reset();
00313             }
00314             if (writePrefix(dev, *sumData, "<edge id=\""+edge->getID())) {
00315                 sumData->write(dev, stopTime - startTime,
00316                                (SUMOReal)edge->getLanes().size(), edge->getLanes()[0]->getLength());
00317             }
00318             delete sumData;
00319         }
00320     }
00321 }

void MSMeanData_Net::writeEdge ( OutputDevice dev,
const std::vector< MSMeanData::MeanDataValues * > &  edgeValues,
MSEdge edge,
SUMOTime  startTime,
SUMOTime  stopTime 
) throw (IOError) [protected]

Writes edge values into the given stream.

microsim: It is checked whether the dump shall be generated edge- or lane-wise. In the first case, the lane-data are collected and aggregated and written directly. In the second case, "writeLane" is used to write each lane's state.

Parameters:
[in] dev The output device to write the data into
[in] edgeValues List of this edge's value collectors
[in] edge The edge to write the dump of
[in] startTime First time step the data were gathered
[in] stopTime Last time step the data were gathered
Exceptions:
IOError If an error on writing occurs (!!! not yet implemented)

Definition at line 269 of file MSMeanData_Net.cpp.

References MSMeanData_Net::MSLaneMeanDataValues::addTo(), createValues(), MSMeanData_Net::MSLaneMeanDataValues::nVehEntered, MSMeanData_Net::MSLaneMeanDataValues::nVehLeft, MSMeanData_Net::MSLaneMeanDataValues::reset(), SUMOReal, MSMeanData_Net::MSLaneMeanDataValues::write(), MSMeanData::writeEdge(), and MSMeanData::writePrefix().

00271                                                                                               {
00272 #ifdef HAVE_MESOSIM
00273     if (MSGlobals::gUseMesoSim) {
00274         MSLaneMeanDataValues* sumData = (MSLaneMeanDataValues*)createValues(0, false);
00275         unsigned entered;
00276         bool isFirst = true;
00277         MESegment *s = MSGlobals::gMesoNet->getSegmentForEdge(*edge);
00278         std::vector<MeanDataValues*>::const_iterator data;
00279         for (data = edgeValues.begin(); data != edgeValues.end(); ++data) {
00280             MSLaneMeanDataValues& meanData = (MSLaneMeanDataValues&)**data;
00281             s->prepareMeanDataForWriting(meanData, stopTime);
00282             meanData.addTo(*sumData);
00283             if (isFirst) {
00284                 entered = meanData.nVehEntered;
00285                 isFirst = false;
00286             }
00287             sumData->nVehLeft = meanData.nVehLeft;
00288             meanData.reset();
00289             s = s->getNextSegment();
00290         }
00291         sumData->nVehEntered = entered;
00292         if (writePrefix(dev, *sumData, "<edge id=\""+edge->getID())) {
00293             sumData->write(dev, stopTime - startTime,
00294                            (SUMOReal)edge->getLanes().size(), edge->getLanes()[0]->getLength());
00295         }
00296         delete sumData;
00297         return;
00298     }
00299 #endif
00300     MSMeanData::writeEdge(dev, edgeValues, edge, startTime, stopTime);
00301 }

bool MSMeanData::writePrefix ( OutputDevice dev,
const MeanDataValues values,
const std::string  prefix 
) const throw (IOError) [protected, inherited]

Checks for emptiness and writes prefix into the given stream.

Parameters:
[in] dev The output device to write the data into
[in] values The values to check for emptiness
[in] prefix The xml prefix to write (mostly the lane / edge id)
Returns:
whether further output should be generated
Exceptions:
IOError If an error on writing occurs (!!! not yet implemented)

Definition at line 325 of file MSMeanData.cpp.

References MSMeanData::myDumpEmpty.

Referenced by writeEdge(), and MSMeanData::writeEdge().

00325                                                                                                                     {
00326     if (myDumpEmpty || !values.isEmpty()) {
00327         dev.indent() << prefix << "\" sampledSeconds=\"" << values.getSamples();
00328         return true;
00329     }
00330     return false;
00331 }

void MSMeanData::writeXMLDetectorProlog ( OutputDevice dev  )  const throw (IOError) [virtual, inherited]

Opens the XML-output using "netstats" as root element.

Parameters:
[in] dev The output device to write the root into
See also:
MSDetectorFileOutput::writeXMLDetectorProlog
Exceptions:
IOError If an error on writing occurs (!!! not yet implemented)

Implements MSDetectorFileOutput.

Definition at line 375 of file MSMeanData.cpp.

00375                                                                          {
00376     dev.writeXMLHeader("netstats");
00377 }

void MSMeanData::writeXMLOutput ( OutputDevice dev,
SUMOTime  startTime,
SUMOTime  stopTime 
) throw (IOError) [virtual, inherited]

Writes collected values into the given stream.

At first, it is checked whether the values for the current interval shall be written. If not, a reset is performed, only, using "resetOnly". Otherwise, both the list of single-lane edges and the list of multi-lane edges are gone through and each edge is written using "writeEdge".

Parameters:
[in] dev The output device to write the data into
[in] startTime First time step the data were gathered
[in] stopTime Last time step the data were gathered
See also:
MSDetectorFileOutput::writeXMLOutput

write

Exceptions:
IOError If an error on writing occurs (!!! not yet implemented)

Implements MSDetectorFileOutput.

Definition at line 335 of file MSMeanData.cpp.

References DELTA_T, MIN2(), MSMeanData::myDumpBegin, MSMeanData::myDumpEnd, MSMeanData::myEdges, MSMeanData::myID, MSMeanData::myMeasures, MSMeanData::myPendingIntervals, MSMeanData::myTrackVehicles, MSMeanData::resetOnly(), time2string(), and MSMeanData::writeEdge().

00336                                                                                  {
00337     // check whether this dump shall be written for the current time
00338     size_t numReady = myDumpBegin < stopTime && myDumpEnd-DELTA_T >= startTime;
00339     if (myTrackVehicles && myDumpBegin < stopTime) {
00340         myPendingIntervals.push_back(std::make_pair(startTime, stopTime));
00341         numReady = myPendingIntervals.size();
00342         for (std::vector<std::vector<MeanDataValues*> >::const_iterator i=myMeasures.begin(); i!=myMeasures.end(); ++i) {
00343             for (std::vector<MeanDataValues*>::const_iterator j=(*i).begin(); j!=(*i).end(); ++j) {
00344                 numReady = MIN2(numReady, ((MeanDataValueTracker*)*j)->getNumReady());
00345                 if (numReady == 0) {
00346                     break;
00347                 }
00348             }
00349             if (numReady == 0) {
00350                 break;
00351             }
00352         }
00353     }
00354     if (numReady == 0) {
00355         resetOnly(stopTime);
00356     }
00357     while (numReady-- > 0) {
00358         if (!myPendingIntervals.empty()) {
00359             startTime = myPendingIntervals.front().first;
00360             stopTime = myPendingIntervals.front().second;
00361             myPendingIntervals.pop_front();
00362         }
00363         dev.openTag("interval")<<" begin=\""<<time2string(startTime)<<"\" end=\""<<
00364         time2string(stopTime)<<"\" "<<"id=\""<<myID<<"\">\n";
00365         std::vector<MSEdge*>::iterator edge = myEdges.begin();
00366         for (std::vector<std::vector<MeanDataValues*> >::const_iterator i=myMeasures.begin(); i!=myMeasures.end(); ++i, ++edge) {
00367             writeEdge(dev, (*i), *edge, startTime, stopTime);
00368         }
00369         dev.closeTag();
00370     }
00371 }


Field Documentation

const SUMOReal MSMeanData_Net::myHaltSpeed [private]

the minimum sample seconds

Definition at line 259 of file MSMeanData_Net.h.

Referenced by MSMeanData_Net::MSLaneMeanDataValues::isStillActive().

const SUMOReal MSMeanData::myMaxTravelTime [protected, inherited]

const SUMOReal MSMeanData::myMinSamples [protected, inherited]

const std::set<std::string> MSMeanData::myVehicleTypes [protected, inherited]

The vehicle types to look for (empty means all).

Definition at line 386 of file MSMeanData.h.

Referenced by createValues(), MSMeanData_HBEFA::createValues(), and MSMeanData_Harmonoise::createValues().


The documentation for this class was generated from the following files:

Generated on Wed May 5 00:06:49 2010 for Sumo - Simulation of Urban MObility by  doxygen 1.5.6