RODFDetector Class Reference

#include <RODFDetector.h>


Detailed Description

Class representing a detector within the DFROUTER.

Definition at line 84 of file RODFDetector.h.


Public Member Functions

void addFollowingDetector (RODFDetector *det)
void addPriorDetector (RODFDetector *det)
void addRoute (RODFRouteDesc &nrd)
void addRoutes (RODFRouteCont *routes)
void buildDestinationDistribution (const RODFDetectorCon &detectors, const RODFDetectorFlows &flows, SUMOTime startTime, SUMOTime endTime, SUMOTime stepOffset, const RODFNet &net, std::map< size_t, RandomDistributor< size_t > * > &into, int maxFollower) const
void computeSplitProbabilities (const RODFNet *net, const RODFDetectorCon &detectors, const RODFDetectorFlows &flows, SUMOTime startTime, SUMOTime endTime, SUMOTime stepOffset)
const std::vector
< RODFDetector * > & 
getFollowerDetectors () const
const std::vector
< RODFDetector * > & 
getPriorDetectors () const
const std::vector
< RODFRouteDesc > & 
getRouteVector () const
const std::vector< std::map
< RODFEdge *, SUMOReal > > & 
getSplitProbabilities () const
bool hasRoutes () const
 RODFDetector (const std::string &id, const RODFDetector &f) throw ()
 Constructor.
 RODFDetector (const std::string &id, const std::string &laneID, SUMOReal pos, const RODFDetectorType type) throw ()
 Constructor.
void setType (RODFDetectorType type)
 ~RODFDetector () throw ()
 Destructor.
Atomar getter methods
std::string getEdgeID () const throw ()
 Returns the id of the edge this detector is placed on.
const std::string & getID () const throw ()
 Returns the ID of this detector.
const std::string & getLaneID () const throw ()
 Returns the id of the lane this detector is placed on.
SUMOReal getPos () const throw ()
 Returns the position at which the detector lies.
RODFDetectorType getType () const throw ()
 Returns the type of the detector.
Writing methods
bool writeEmitterDefinition (const std::string &file, const std::map< size_t, RandomDistributor< size_t > * > &dists, const RODFDetectorFlows &flows, SUMOTime startTime, SUMOTime endTime, SUMOTime stepOffset, bool includeUnusedRoutes, SUMOReal scale, bool emissionsOnly, SUMOReal defaultSpeed) const
void writeEndRerouterDetectors (const std::string &file)
bool writeRoutes (std::vector< std::string > &saved, OutputDevice &out)
void writeSingleSpeedTrigger (const std::string &file, const RODFDetectorFlows &flows, SUMOTime startTime, SUMOTime endTime, SUMOTime stepOffset, SUMOReal defaultSpeed)

Protected Member Functions

SUMOReal computeDistanceFactor (const RODFRouteDesc &rd) const
int getFlowFor (const ROEdge *edge, SUMOTime time) const

Protected Attributes

std::vector< RODFDetector * > myFollowingDetectors
std::string myID
std::string myLaneID
SUMOReal myPosition
std::vector< RODFDetector * > myPriorDetectors
std::map< std::string, RODFEdge * > myRoute2Edge
RODFRouteContmyRoutes
std::vector< std::map
< RODFEdge *, SUMOReal > > 
mySplitProbabilities
RODFDetectorType myType

Private Member Functions

RODFDetectoroperator= (const RODFDetector &src)
 Invalidated assignment operator.
 RODFDetector (const RODFDetector &src)
 Invalidated copy constructor.

Constructor & Destructor Documentation

RODFDetector::RODFDetector ( const std::string &  id,
const std::string &  laneID,
SUMOReal  pos,
const RODFDetectorType  type 
) throw ()

Constructor.

This constructor is used when detectors are read from a file

Parameters:
[in] id The id of the detector
[in] laneID The id of the lane the detector is placed at
[in] pos The position of the detector at the lane
[in] type The df-router type of the detector
See also:
RODFDetectorType

Definition at line 54 of file RODFDetector.cpp.

00056         : myID(id), myLaneID(laneID), myPosition(pos), myType(type), myRoutes(0) {}

RODFDetector::RODFDetector ( const std::string &  id,
const RODFDetector f 
) throw ()

Constructor.

This constructor is used when detectors shall be joined

Parameters:
[in] id The id of the detector
[in] f A detector from which routes shall be copied

Definition at line 59 of file RODFDetector.cpp.

00060         : myID(id), myLaneID(f.myLaneID), myPosition(f.myPosition),
00061         myType(f.myType), myRoutes(0) {
00062     if (f.myRoutes!=0) {
00063         myRoutes = new RODFRouteCont(*(f.myRoutes));
00064     }
00065 }

RODFDetector::~RODFDetector (  )  throw ()

Destructor.

Definition at line 68 of file RODFDetector.cpp.

References myRoutes.

00068                                     {
00069     delete myRoutes;
00070 }

RODFDetector::RODFDetector ( const RODFDetector src  )  [private]

Invalidated copy constructor.


Member Function Documentation

void RODFDetector::addFollowingDetector ( RODFDetector det  ) 

Definition at line 200 of file RODFDetector.cpp.

References myFollowingDetectors.

00200                                                     {
00201     myFollowingDetectors.push_back(det);
00202 }

void RODFDetector::addPriorDetector ( RODFDetector det  ) 

Definition at line 194 of file RODFDetector.cpp.

References myPriorDetectors.

00194                                                 {
00195     myPriorDetectors.push_back(det);
00196 }

void RODFDetector::addRoute ( RODFRouteDesc nrd  ) 

Definition at line 226 of file RODFDetector.cpp.

References RODFRouteCont::addRouteDesc(), and myRoutes.

00226                                          {
00227     if (myRoutes==0) {
00228         myRoutes = new RODFRouteCont();
00229     }
00230     myRoutes->addRouteDesc(nrd);
00231 }

void RODFDetector::addRoutes ( RODFRouteCont routes  ) 

Definition at line 219 of file RODFDetector.cpp.

References myRoutes.

00219                                              {
00220     delete myRoutes;
00221     myRoutes = routes;
00222 }

void RODFDetector::buildDestinationDistribution ( const RODFDetectorCon detectors,
const RODFDetectorFlows flows,
SUMOTime  startTime,
SUMOTime  endTime,
SUMOTime  stepOffset,
const RODFNet net,
std::map< size_t, RandomDistributor< size_t > * > &  into,
int  maxFollower 
) const

Definition at line 139 of file RODFDetector.cpp.

References BETWEEN_DETECTOR, DISCARDED_DETECTOR, RODFRouteCont::get(), RODFDetectorCon::getAnyDetectorForEdge(), MsgHandler::getErrorInstance(), RODFDetectorFlows::getFlowDefs(), getSplitProbabilities(), RODFNet::hasDetector(), MsgHandler::inform(), myID, myRoutes, myType, and SUMOReal.

Referenced by RODFDetectorCon::writeEmitters().

00146                                {
00147     if (myRoutes==0) {
00148         if (myType!=DISCARDED_DETECTOR&&myType!=BETWEEN_DETECTOR) {
00149             MsgHandler::getErrorInstance()->inform("Missing routes for detector '" + myID + "'.");
00150         }
00151         return;
00152     }
00153     std::vector<RODFRouteDesc> &descs = myRoutes->get();
00154     const std::vector<FlowDef> &mflows = flows.getFlowDefs(myID);
00155     // iterate through time (in output interval steps)
00156     for (int time=startTime; time<endTime; time+=stepOffset) {
00157         into[time] = new RandomDistributor<size_t>();
00158         std::map<ROEdge*, SUMOReal> flowMap;
00159         // iterate through the routes
00160         size_t index = 0;
00161         for (std::vector<RODFRouteDesc>::iterator ri=descs.begin(); ri!=descs.end(); ++ri, index++) {
00162             SUMOReal prob = 1.;
00163             for (std::vector<ROEdge*>::iterator j=(*ri).edges2Pass.begin(); j!=(*ri).edges2Pass.end()&&prob>0; ++j) {
00164                 if (!net.hasDetector(*j)) {
00165                     continue;
00166                 }
00167                 const RODFDetector &det = detectors.getAnyDetectorForEdge(static_cast<RODFEdge*>(*j));
00168                 const std::vector<std::map<RODFEdge*, SUMOReal> > &probs = det.getSplitProbabilities();
00169                 if (probs.size()==0) {
00170                     prob = 0;
00171                     continue;
00172                 }
00173                 const std::map<RODFEdge*, SUMOReal> &tprobs = probs[time/stepOffset];
00174                 for (std::map<RODFEdge*, SUMOReal>::const_iterator k=tprobs.begin(); k!=tprobs.end(); ++k) {
00175                     if (find(j, (*ri).edges2Pass.end(), (*k).first)!=(*ri).edges2Pass.end()) {
00176                         prob *= (*k).second;
00177                     }
00178                 }
00179             }
00180             into[time]->add(prob, index);
00181             (*ri).overallProb = prob;
00182         }
00183     }
00184 }

SUMOReal RODFDetector::computeDistanceFactor ( const RODFRouteDesc rd  )  const [protected]

Definition at line 80 of file RODFDetector.cpp.

References RODFRouteDesc::edges2Pass, and SUMOReal.

00080                                                                  {
00081     SUMOReal distance = rd.edges2Pass[0]->getFromNode()->getPosition().distanceTo(rd.edges2Pass.back()->getToNode()->getPosition());
00082     SUMOReal length = 0;
00083     for (std::vector<ROEdge*>::const_iterator i=rd.edges2Pass.begin(); i!=rd.edges2Pass.end(); ++i) {
00084         length += (*i)->getLength();
00085     }
00086     return (distance/length);
00087 }

void RODFDetector::computeSplitProbabilities ( const RODFNet net,
const RODFDetectorCon detectors,
const RODFDetectorFlows flows,
SUMOTime  startTime,
SUMOTime  endTime,
SUMOTime  stepOffset 
)

Definition at line 91 of file RODFDetector.cpp.

References RODFRouteDesc::edges2Pass, RODFRouteCont::get(), RODFDetectorCon::getAggFlowFor(), RODFNet::hasDetector(), myRoute2Edge, myRoutes, mySplitProbabilities, RODFRouteDesc::routename, and SUMOReal.

00093                                                                                                    {
00094     if (myRoutes==0) {
00095         return;
00096     }
00097     // compute edges to determine split probabilities
00098     const std::vector<RODFRouteDesc> &routes = myRoutes->get();
00099     std::vector<RODFEdge*> nextDetEdges;
00100     for (std::vector<RODFRouteDesc>::const_iterator i=routes.begin(); i!=routes.end(); ++i) {
00101         const RODFRouteDesc &rd = *i;
00102         bool hadSplit = false;
00103         bool hadDetectorAfterSplit = false;
00104         for (std::vector<ROEdge*>::const_iterator j=rd.edges2Pass.begin(); !hadDetectorAfterSplit&&j!=rd.edges2Pass.end(); ++j) {
00105             if (hadSplit&&!hadDetectorAfterSplit&&net->hasDetector(*j)) {
00106                 hadDetectorAfterSplit = true;
00107                 if (find(nextDetEdges.begin(), nextDetEdges.end(), *j)==nextDetEdges.end()) {
00108                     nextDetEdges.push_back(static_cast<RODFEdge*>(*j));
00109                 }
00110                 myRoute2Edge[rd.routename] = static_cast<RODFEdge*>(*j);
00111             }
00112             if ((*j)->getNoFollowing()>1) {
00113                 hadSplit = true;
00114             }
00115         }
00116     }
00117     // compute the probabilities to use a certain direction
00118     int index = 0;
00119     for (int time=startTime; time<endTime; time+=stepOffset, ++index) {
00120         mySplitProbabilities.push_back(std::map<RODFEdge*, SUMOReal>());
00121         SUMOReal overallProb = 0;
00122         // retrieve the probabilities
00123         for (std::vector<RODFEdge*>::const_iterator i=nextDetEdges.begin(); i!=nextDetEdges.end(); ++i) {
00124             SUMOReal flow = detectors.getAggFlowFor(*i, time, 60, flows);
00125             overallProb += flow;
00126             mySplitProbabilities[index][*i] = flow;
00127         }
00128         // norm probabilities
00129         if (overallProb>0) {
00130             for (std::vector<RODFEdge*>::const_iterator i=nextDetEdges.begin(); i!=nextDetEdges.end(); ++i) {
00131                 mySplitProbabilities[index][*i] = mySplitProbabilities[index][*i] / overallProb;
00132             }
00133         }
00134     }
00135 }

std::string RODFDetector::getEdgeID (  )  const throw () [inline]

Returns the id of the edge this detector is placed on.

Returns:
The id of the edge this detector is placed on

Definition at line 137 of file RODFDetector.h.

References myLaneID.

Referenced by RODFDetectorCon::writeEmitters(), and RODFDetectorCon::writeSpeedTrigger().

00137                                         {
00138         return myLaneID.substr(0, myLaneID.rfind('_'));
00139     }

int RODFDetector::getFlowFor ( const ROEdge edge,
SUMOTime  time 
) const [protected]

const std::vector< RODFDetector * > & RODFDetector::getFollowerDetectors (  )  const

Definition at line 212 of file RODFDetector.cpp.

References myFollowingDetectors.

Referenced by RODFDetectorCon::guessEmptyFlows().

00212                                          {
00213     return myFollowingDetectors;
00214 }

const std::string& RODFDetector::getID (  )  const throw () [inline]

const std::string& RODFDetector::getLaneID (  )  const throw () [inline]

Returns the id of the lane this detector is placed on.

Returns:
The id of the lane this detector is placed on

Definition at line 129 of file RODFDetector.h.

References myLaneID.

Referenced by RODFDetectorCon::addDetector(), RODFNet::getDetectorEdge(), RODFDetectorCon::writeEmitters(), RODFDetectorCon::writeEndRerouterDetectors(), RODFDetectorCon::writeSpeedTrigger(), and RODFDetectorCon::writeValidationDetectors().

00129                                                {
00130         return myLaneID;
00131     };

SUMOReal RODFDetector::getPos (  )  const throw () [inline]

Returns the position at which the detector lies.

Returns:
The position of the detector at the lane

Definition at line 145 of file RODFDetector.h.

References myPosition.

Referenced by RODFNet::buildEdgeFlowMap(), RODFNet::getAbsPos(), RODFNet::mesoJoin(), RODFDetectorCon::writeEmitters(), and RODFDetectorCon::writeValidationDetectors().

00145                                     {
00146         return myPosition;
00147     };

const std::vector< RODFDetector * > & RODFDetector::getPriorDetectors (  )  const

Definition at line 206 of file RODFDetector.cpp.

References myPriorDetectors.

Referenced by RODFDetectorCon::guessEmptyFlows().

00206                                       {
00207     return myPriorDetectors;
00208 }

const std::vector< RODFRouteDesc > & RODFDetector::getRouteVector (  )  const

Definition at line 188 of file RODFDetector.cpp.

References RODFRouteCont::get(), and myRoutes.

Referenced by RODFNet::buildDetectorDependencies().

00188                                    {
00189     return myRoutes->get();
00190 }

const std::vector<std::map<RODFEdge*, SUMOReal> >& RODFDetector::getSplitProbabilities (  )  const [inline]

Definition at line 200 of file RODFDetector.h.

References mySplitProbabilities.

Referenced by buildDestinationDistribution().

00200                                                                                  {
00201         return mySplitProbabilities;
00202     }

RODFDetectorType RODFDetector::getType (  )  const throw () [inline]

bool RODFDetector::hasRoutes (  )  const

Definition at line 235 of file RODFDetector.cpp.

References RODFRouteCont::get(), and myRoutes.

Referenced by RODFNet::buildDetectorDependencies().

00235                               {
00236     return myRoutes!=0&&myRoutes->get().size()!=0;
00237 }

RODFDetector& RODFDetector::operator= ( const RODFDetector src  )  [private]

Invalidated assignment operator.

void RODFDetector::setType ( RODFDetectorType  type  ) 

Definition at line 74 of file RODFDetector.cpp.

References myType.

00074                                            {
00075     myType = type;
00076 }

bool RODFDetector::writeEmitterDefinition ( const std::string &  file,
const std::map< size_t, RandomDistributor< size_t > * > &  dists,
const RODFDetectorFlows flows,
SUMOTime  startTime,
SUMOTime  endTime,
SUMOTime  stepOffset,
bool  includeUnusedRoutes,
SUMOReal  scale,
bool  emissionsOnly,
SUMOReal  defaultSpeed 
) const

!! type = lkwTypes[vehSpeedDist.get()];

!! type = pkwTypes[vehSpeedDist.get()];

Definition at line 241 of file RODFDetector.cpp.

References OutputDevice::close(), FlowDef::fLKW, RandomDistributor< T >::get(), RODFRouteCont::get(), OutputDevice::getDevice(), MsgHandler::getErrorInstance(), RODFDetectorFlows::getFlowDefs(), getID(), RandomDistributor< T >::getOverallProb(), getType(), MsgHandler::inform(), FlowDef::isLKW, RODFDetectorFlows::knows(), myID, myRoutes, FlowDef::qLKW, FlowDef::qPKW, SOURCE_DETECTOR, SUMOReal, FlowDef::vLKW, FlowDef::vPKW, and OutputDevice::writeXMLHeader().

Referenced by RODFDetectorCon::writeEmitters().

00249                                                                   {
00250     OutputDevice& out = OutputDevice::getDevice(file);
00251     if (getType()==SOURCE_DETECTOR) {
00252         out.writeXMLHeader("triggeredsource");
00253     } else {
00254         out.writeXMLHeader("calibrator");
00255     }
00256     // routes
00257     if (!emissionsOnly) {
00258         if (myRoutes!=0&&myRoutes->get().size()!=0) {
00259             const std::vector<RODFRouteDesc> &routes = myRoutes->get();
00260             std::vector<RODFRouteDesc>::const_iterator i;
00261             // compute the overall routes sum
00262             SUMOReal overallSum = 0;
00263             for (i=routes.begin(); i!=routes.end(); ++i) {
00264                 overallSum += (*i).overallProb;
00265             }
00266 
00267             int writtenRoutes = 0;
00268             if (overallSum!=0) {
00269                 // !!! check things about intervals
00270                 // !!! optional
00271                 for (i=routes.begin(); i!=routes.end(); ++i) {
00272                     if ((*i).overallProb>0||includeUnusedRoutes) {
00273                         out << "   <routedistelem id=\"" << (*i).routename << "\" probability=\"" << ((*i).overallProb/overallSum) << "\"/>\n"; // !!!
00274                         writtenRoutes++;
00275                     }
00276                 }
00277             }
00278             // hmmmm - all routes seem to have a probability of zero...
00279             //  let's save them all (should maybe be done optional)
00280             if (writtenRoutes==0) {
00281                 for (i=routes.begin(); i!=routes.end(); ++i) {
00282                     out << "   <routedistelem id=\"" << (*i).routename << "\" probability=\"1\"/>\n"; // !!!
00283                 }
00284             }
00285         } else {
00286             MsgHandler::getErrorInstance()->inform("Detector '" + getID() + "' has no routes!?");
00287             return false;
00288         }
00289     }
00290     // emissions
00291     if (emissionsOnly||flows.knows(myID)) {
00292         // get the flows for this detector
00293 
00294         const std::vector<FlowDef> &mflows = flows.getFlowDefs(myID);
00295         // go through the simulation seconds
00296         for (SUMOTime time=startTime; time<endTime; time+=stepOffset) {
00297             // get own (departure flow)
00298             if ((int) mflows.size()<=(int)((time/stepOffset) - startTime)) {
00299                 std::cout << mflows.size() << ":" << (int)(time/stepOffset) - startTime << std::endl;
00300                 throw 1;
00301             }
00302             const FlowDef &srcFD = mflows[(int)(time/stepOffset) - startTime];  // !!! check stepOffset
00303             // get flows at end
00304             RandomDistributor<size_t> *destDist = dists.size()>time ? dists.find(time)->second : 0;
00305             // go through the cars
00306             size_t carNo = (size_t)((srcFD.qPKW + srcFD.qLKW) * scale);
00307             for (size_t car=0; car<carNo; ++car) {
00308                 // get the vehicle parameter
00309                 std::string type = "test";
00310                 SUMOReal v = -1;
00311                 int destIndex = destDist!=0 && destDist->getOverallProb()>0 ? (int) destDist->get() : -1;
00312                 if (srcFD.isLKW>=1) {
00313                     srcFD.isLKW = srcFD.isLKW - (SUMOReal) 1.;
00315                     v = srcFD.vLKW;
00316                 } else {
00318                     v = srcFD.vPKW;
00319                 }
00320                 // compute emission speed
00321                 if (v<0||v>250) {
00322                     v = defaultSpeed;
00323                 } else {
00324                     v = (SUMOReal)(v/3.6);
00325                 }
00326                 // compute the departure time
00327                 int ctime = (int)(time + ((SUMOReal) stepOffset * (SUMOReal) car / (SUMOReal) carNo));
00328 
00329                 // write
00330                 out << "   <emit id=\"";
00331                 if (getType()==SOURCE_DETECTOR) {
00332                     out << "emitter_" << myID;
00333                 } else {
00334                     out << "calibrator_" << myID;
00335                 }
00336                 out << "_" << ctime  << "\"" // !!! running
00337                 << " time=\"" << ctime << "\""
00338                 << " speed=\"" << v << "\"";
00339                 if (!emissionsOnly&&destIndex>=0) {
00340                     out << " route=\"" << myRoutes->get()[destIndex].routename << "\""; // !!! optional
00341                 }
00342                 out  << "/>\n";
00343                 srcFD.isLKW += srcFD.fLKW;
00344             }
00345         }
00346     }
00347 //    cout << "a5" << endl;
00348     out.close();
00349     return true;
00350 }

void RODFDetector::writeEndRerouterDetectors ( const std::string &  file  ) 

bool RODFDetector::writeRoutes ( std::vector< std::string > &  saved,
OutputDevice out 
)

Definition at line 354 of file RODFDetector.cpp.

References myRoutes, and RODFRouteCont::save().

00355                                              {
00356     if (myRoutes!=0) {
00357         return myRoutes->save(saved, "", out);
00358     }
00359     return false;
00360 }

void RODFDetector::writeSingleSpeedTrigger ( const std::string &  file,
const RODFDetectorFlows flows,
SUMOTime  startTime,
SUMOTime  endTime,
SUMOTime  stepOffset,
SUMOReal  defaultSpeed 
)

Definition at line 364 of file RODFDetector.cpp.

References OutputDevice::close(), OutputDevice::getDevice(), RODFDetectorFlows::getFlowDefs(), MAX2(), myID, SUMOReal, FlowDef::vLKW, FlowDef::vPKW, and OutputDevice::writeXMLHeader().

Referenced by RODFDetectorCon::writeSpeedTrigger().

00367                                                                                   {
00368     OutputDevice& out = OutputDevice::getDevice(file);
00369     out.writeXMLHeader("vss");
00370     const std::vector<FlowDef> &mflows = flows.getFlowDefs(myID);
00371     for (SUMOTime t=startTime; t<endTime; t+=stepOffset) {
00372         const FlowDef &srcFD = mflows[(int)(t/stepOffset) - startTime]; // !!! check stepOffset
00373         SUMOReal speed = MAX2(srcFD.vLKW, srcFD.vPKW);
00374         if (speed<=0||speed>250) {
00375             speed = defaultSpeed;
00376         } else {
00377             speed = (SUMOReal)(speed / 3.6);
00378         }
00379         out << "   <step time=\"" << t << "\" speed=\"" << speed << "\"/>\n";
00380     }
00381     out.close();
00382 }


Field Documentation

Definition at line 215 of file RODFDetector.h.

Referenced by addFollowingDetector(), and getFollowerDetectors().

std::string RODFDetector::myID [protected]

std::string RODFDetector::myLaneID [protected]

Definition at line 211 of file RODFDetector.h.

Referenced by getEdgeID(), and getLaneID().

SUMOReal RODFDetector::myPosition [protected]

Definition at line 212 of file RODFDetector.h.

Referenced by getPos().

std::vector<RODFDetector*> RODFDetector::myPriorDetectors [protected]

Definition at line 215 of file RODFDetector.h.

Referenced by addPriorDetector(), and getPriorDetectors().

std::map<std::string, RODFEdge*> RODFDetector::myRoute2Edge [protected]

Definition at line 217 of file RODFDetector.h.

Referenced by computeSplitProbabilities().

std::vector<std::map<RODFEdge*, SUMOReal> > RODFDetector::mySplitProbabilities [protected]

Definition at line 216 of file RODFDetector.h.

Referenced by computeSplitProbabilities(), and getSplitProbabilities().

Definition at line 213 of file RODFDetector.h.

Referenced by buildDestinationDistribution(), getType(), and setType().


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

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