RODFRouteCont Class Reference

#include <RODFRouteCont.h>


Detailed Description

A container for DFROUTER-routes.

The route id is (re)set as soon as the route is added.

As sometimes several routes can be used between two edges and have to be identified, the number of routes connecting them is stored for each edge pair "myConnectionOccurences" and the route is named using this information,

See also:
addRouteDesc.

RODFRouteDesc

Definition at line 61 of file RODFRouteCont.h.


Public Member Functions

void addAllEndFollower () throw ()
 All routes are replaced by their versions extended by follower edges.
void addRouteDesc (RODFRouteDesc &desc) throw ()
 Adds a route to the container.
std::vector< RODFRouteDesc > & get () throw ()
 Returns the container of stored routes.
void removeIllegal (const std::vector< std::vector< ROEdge * > > &illegals) throw ()
 Removes "illegal" routes.
bool removeRouteDesc (RODFRouteDesc &desc) throw ()
 Removes the given route description from the container.
 RODFRouteCont () throw ()
 Constructor.
bool save (std::vector< std::string > &saved, const std::string &prependix, OutputDevice &out) throw (IOError)
 Saves routes.
void sortByDistance () throw ()
 Sorts routes by their distance (length).
 ~RODFRouteCont () throw ()
 Destructor.

Protected Member Functions

void setID (RODFRouteDesc &desc) const throw ()
 Computes and sets the id of a route.

Protected Attributes

std::map< std::pair< ROEdge
*, ROEdge * >, int > 
myConnectionOccurences
 Counts how many routes connecting the key-edges were already stored.
std::vector< RODFRouteDescmyRoutes
 Stored route descriptions.

Data Structures

class  by_distance_sorter
 A class for sorting route descriptions by their length. More...
class  route_finder
 A class for finding a same route (one that passes the same edges). More...

Constructor & Destructor Documentation

RODFRouteCont::RODFRouteCont (  )  throw ()

Constructor.

Definition at line 47 of file RODFRouteCont.cpp.

00047 {}

RODFRouteCont::~RODFRouteCont (  )  throw ()

Destructor.

Definition at line 50 of file RODFRouteCont.cpp.

00050                                       {
00051 }


Member Function Documentation

void RODFRouteCont::addAllEndFollower (  )  throw ()

All routes are replaced by their versions extended by follower edges.

Definition at line 137 of file RODFRouteCont.cpp.

References RODFRouteDesc::edges2Pass, ROEdge::getFollower(), ROEdge::getNoFollowing(), myRoutes, and setID().

Referenced by RODFNet::buildRoutes().

00137                                          {
00138     std::vector<RODFRouteDesc> newRoutes;
00139     for (std::vector<RODFRouteDesc>::iterator i=myRoutes.begin(); i!=myRoutes.end(); ++i) {
00140         RODFRouteDesc &desc = *i;
00141         ROEdge *last = *(desc.edges2Pass.end()-1);
00142         if (last->getNoFollowing()==0) {
00143             newRoutes.push_back(desc);
00144             continue;
00145         }
00146         for (unsigned int j=0; j<last->getNoFollowing(); ++j) {
00147             RODFRouteDesc ndesc(desc);
00148             ndesc.edges2Pass.push_back(last->getFollower(j));
00149             setID(ndesc);
00150             newRoutes.push_back(ndesc);
00151         }
00152     }
00153     myRoutes = newRoutes;
00154 }

void RODFRouteCont::addRouteDesc ( RODFRouteDesc desc  )  throw ()

Adds a route to the container.

If the same route is already known, its "overallProb" is increased by the value stored in the given route.

An id for the route is generated if it is unset, yet. The id is computed and set via "setID".

Parameters:
[in] desc The route description to add
See also:
setID

Definition at line 55 of file RODFRouteCont.cpp.

References myRoutes, RODFRouteDesc::overallProb, and setID().

Referenced by RODFDetector::addRoute(), and RODFNet::computeRoutesFor().

00055                                                        {
00056     // routes may be duplicate as in-between routes may have different starting points
00057     if (find_if(myRoutes.begin(), myRoutes.end(), route_finder(desc))==myRoutes.end()) {
00058         // compute route id
00059         ROEdge *first = *(desc.edges2Pass.begin());
00060         ROEdge *last = *(desc.edges2Pass.end()-1);
00061         setID(desc);
00062         myRoutes.push_back(desc);
00063     } else {
00064         RODFRouteDesc &prev = *find_if(myRoutes.begin(), myRoutes.end(), route_finder(desc));
00065         prev.overallProb += desc.overallProb;
00066     }
00067 }

std::vector<RODFRouteDesc>& RODFRouteCont::get (  )  throw () [inline]

Returns the container of stored routes.

Returns:
The stored routes

Definition at line 111 of file RODFRouteCont.h.

References myRoutes.

Referenced by RODFDetector::buildDestinationDistribution(), RODFNet::buildRoutes(), RODFDetector::computeSplitProbabilities(), RODFDetector::getRouteVector(), RODFDetector::hasRoutes(), and RODFDetector::writeEmitterDefinition().

00111                                             {
00112         return myRoutes;
00113     }

void RODFRouteCont::removeIllegal ( const std::vector< std::vector< ROEdge * > > &  illegals  )  throw ()

Removes "illegal" routes.

"illegal" routes means edge combinations that shall not be passed.

Parameters:
[in] illegals List of edge combinations that shall not be passed
Todo:
Not used, yet

Definition at line 112 of file RODFRouteCont.cpp.

References RODFRouteDesc::edges2Pass, and myRoutes.

00112                                                                                    {
00113     for (std::vector<RODFRouteDesc>::iterator i=myRoutes.begin(); i!=myRoutes.end();) {
00114         RODFRouteDesc &desc = *i;
00115         bool remove = false;
00116         for (std::vector<std::vector<ROEdge*> >::const_iterator j=illegals.begin(); !remove&&j!=illegals.end(); ++j) {
00117             int noFound = 0;
00118             for (std::vector<ROEdge*>::const_iterator k=(*j).begin(); !remove&&k!=(*j).end(); ++k) {
00119                 if (find(desc.edges2Pass.begin(), desc.edges2Pass.end(), *k)!=desc.edges2Pass.end()) {
00120                     noFound++;
00121                     if (noFound>1) {
00122                         remove = true;
00123                     }
00124                 }
00125             }
00126         }
00127         if (remove) {
00128             i = myRoutes.erase(i);
00129         } else {
00130             ++i;
00131         }
00132     }
00133 }

bool RODFRouteCont::removeRouteDesc ( RODFRouteDesc desc  )  throw ()

Removes the given route description from the container.

All routes are regarded as being same if they pass the same edges. This is done via the "route_finder".

Parameters:
[in] desc The route description to remove
Returns:
Whether the route was removed (a similar was found)
See also:
RODFRouteCont::route_finder

Definition at line 71 of file RODFRouteCont.cpp.

References myRoutes.

Referenced by RODFNet::computeRoutesFor().

00071                                                           {
00072     std::vector<RODFRouteDesc>::const_iterator j = find_if(myRoutes.begin(), myRoutes.end(), route_finder(desc));
00073     if (j==myRoutes.end()) {
00074         return false;
00075     }
00076     return true;
00077 }

bool RODFRouteCont::save ( std::vector< std::string > &  saved,
const std::string &  prependix,
OutputDevice out 
) throw (IOError)

Saves routes.

Parameters:
[in,out] saved The list of ids of routes that shall not be saved (were saved before)
[in] prependix The prependix for route names
[out] out The device the routes shall written to
Returns:
Whether at least one route was saved
Exceptions:
IOError not yet implemented

Definition at line 81 of file RODFRouteCont.cpp.

References RODFRouteDesc::edges2Pass, myRoutes, and RODFRouteDesc::routename.

Referenced by RODFDetector::writeRoutes().

00082                                                                                   {
00083     bool haveSavedOneAtLeast = false;
00084     for (std::vector<RODFRouteDesc>::const_iterator j=myRoutes.begin(); j!=myRoutes.end(); ++j) {
00085         const RODFRouteDesc &desc = (*j);
00086         if (find(saved.begin(), saved.end(), desc.routename)!=saved.end()) {
00087             continue;
00088         }
00089         saved.push_back((*j).routename);
00090         assert(desc.edges2Pass.size()>=1);
00091         out << "   <route id=\"" << prependix << desc.routename << "\" edges=\"";
00092         for (std::vector<ROEdge*>::const_iterator k=desc.edges2Pass.begin(); k!=desc.edges2Pass.end(); k++) {
00093             if (k!=desc.edges2Pass.begin()) {
00094                 out << ' ';
00095             }
00096             out << (*k)->getID();
00097         }
00098         out << "\"/>\n";
00099         haveSavedOneAtLeast = true;
00100     }
00101     return haveSavedOneAtLeast;
00102 }

void RODFRouteCont::setID ( RODFRouteDesc desc  )  const throw () [protected]

Computes and sets the id of a route.

The id is <FIRST_EDGE>_to_<LAST_EDGE>_<RUNNING> where <RUNNING> is the number of routes which connect <FIRST_EDGE> and <LAST_EDGE>.

Parameters:
[in] desc The route description to add

Definition at line 158 of file RODFRouteCont.cpp.

References myConnectionOccurences, and toString().

Referenced by addAllEndFollower(), and addRouteDesc().

00158                                                       {
00159     std::pair<ROEdge*, ROEdge*> c(desc.edges2Pass[0], desc.edges2Pass.back());
00160     desc.routename = c.first->getID() + "_to_" + c.second->getID();
00161     if (myConnectionOccurences.find(c)==myConnectionOccurences.end()) {
00162         myConnectionOccurences[c] = 0;
00163     } else {
00164         myConnectionOccurences[c] = myConnectionOccurences[c] + 1;
00165         desc.routename = desc.routename + "_" + toString(myConnectionOccurences[c]);
00166     }
00167 }

void RODFRouteCont::sortByDistance (  )  throw ()

Sorts routes by their distance (length).

Done using by_distance_sorter.

See also:
RODFRouteCont::by_distance_sorter

Definition at line 106 of file RODFRouteCont.cpp.

References myRoutes.

00106                                       {
00107     sort(myRoutes.begin(), myRoutes.end(), by_distance_sorter());
00108 }


Field Documentation

std::map<std::pair<ROEdge*, ROEdge*>, int> RODFRouteCont::myConnectionOccurences [mutable, protected]

Counts how many routes connecting the key-edges were already stored.

Definition at line 187 of file RODFRouteCont.h.

Referenced by setID().

std::vector<RODFRouteDesc> RODFRouteCont::myRoutes [protected]

Stored route descriptions.

Definition at line 184 of file RODFRouteCont.h.

Referenced by addAllEndFollower(), addRouteDesc(), get(), removeIllegal(), removeRouteDesc(), save(), and sortByDistance().


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