ODMatrix Class Reference

#include <ODMatrix.h>


Detailed Description

An O/D (origin/destination) matrix.

This class is the internal representation of a loaded O/D-matrix. Beside being the storage for ODCells, the matrix also contains information about the numbers of loaded, discarded, and written vehicles.

The matrix has a reference to the container of districts stored. This allows to validate added cell descriptions in means that using existing origins/ destinations only is assured.

In addition of being a storage, the matrix is also responsible for writing the results and contains methods for splitting the entries over time.

Definition at line 70 of file ODMatrix.h.


Public Member Functions

void add (SUMOReal vehicleNumber, SUMOTime begin, SUMOTime end, const std::string &origin, const std::string &destination, const std::string &vehicleType) throw ()
 Builds a single cell from the given values, verifying them.
void applyCurve (const Distribution_Points &ps) throw ()
 Splits the stored cells dividing them on the given time line.
SUMOReal getNoDiscarded () const throw ()
 Returns the number of discarded vehicles.
SUMOReal getNoLoaded () const throw ()
 Returns the number of loaded vehicles.
SUMOReal getNoWritten () const throw ()
 Returns the number of written vehicles.
 ODMatrix (const ODDistrictCont &dc) throw ()
 Constructor.
void write (SUMOTime begin, SUMOTime end, OutputDevice &dev, bool uniform, bool noVtype, const std::string &prefix) throw ()
 Writes the vehicles stored in the matrix assigning the sources and sinks.
 ~ODMatrix () throw ()
 Destructor.

Protected Types

typedef std::vector< ODCell * > CellVector
 Definition of a container for cells.

Protected Member Functions

void applyCurve (const Distribution_Points &ps, ODCell *cell, CellVector &newCells) throw ()
 Splits the given cell dividing it on the given time line and storing the results in the given container.
SUMOReal computeEmissions (ODCell *cell, size_t &vehName, std::vector< ODVehicle > &into, bool uniform, const std::string &prefix) throw ()
 Computes the emissions stored in the given cell and saves them in "into".

Protected Attributes

CellVector myContainer
 The loaded cells.
const ODDistrictContmyDistricts
 The districts to retrieve sources/sinks from.
SUMOReal myNoDiscarded
 Number of discarded vehicles.
SUMOReal myNoLoaded
 Number of loaded vehicles.
SUMOReal myNoWritten
 Number of written vehicles.

Private Member Functions

 ODMatrix (const ODMatrix &s)
 invalid copy constructor
ODMatrixoperator= (const ODMatrix &s)
 invalid assignment operator

Data Structures

class  cell_by_begin_sorter
 Used for sorting the cells by the begin time they describe. More...
class  descending_departure_comperator
 Used for sorting vehicles by their departure (latest first). More...
struct  ODVehicle
 An internal representation of a single vehicle. More...

Member Typedef Documentation

typedef std::vector<ODCell*> ODMatrix::CellVector [protected]

Definition of a container for cells.

Definition at line 191 of file ODMatrix.h.


Constructor & Destructor Documentation

ODMatrix::ODMatrix ( const ODDistrictCont dc  )  throw ()

Constructor.

Parameters:
[in] dc The district container to obtain referenced distrivts from

Definition at line 49 of file ODMatrix.cpp.

00050         : myDistricts(dc), myNoLoaded(0), myNoWritten(0), myNoDiscarded(0) {}

ODMatrix::~ODMatrix (  )  throw ()

Destructor.

Definition at line 53 of file ODMatrix.cpp.

References myContainer.

00053                             {
00054     for (CellVector::iterator i=myContainer.begin(); i!=myContainer.end(); ++i) {
00055         delete *i;
00056     }
00057     myContainer.clear();
00058 }

ODMatrix::ODMatrix ( const ODMatrix s  )  [private]

invalid copy constructor


Member Function Documentation

void ODMatrix::add ( SUMOReal  vehicleNumber,
SUMOTime  begin,
SUMOTime  end,
const std::string &  origin,
const std::string &  destination,
const std::string &  vehicleType 
) throw ()

Builds a single cell from the given values, verifying them.

At first, the number of loaded vehicles (myNoLoaded) is incremented by vehicleNumber.

It is checked whether both the origin and the destination exist within the assigned district container (myDistricts). If one of them is missing, an error is generated, if both, a warning, because in the later case the described flow may lay completely beside the processed area. In both cases the given number of vehicles (vehicleNumber) is added to myNoDiscarded.

If the origin/destination districts are known, a cell is built using the given values. This cell is added to the list of known cells (myContainer).

Parameters:
[in] vehicleNumber The number of vehicles to store within the cell
[in] begin The begin of the interval the cell is valid for
[in] end The end of the interval the cell is valid for
[in] origin The origin district to use for the cell's flows
[in] destination The destination district to use for the cell's flows
[in] vehicleType The vehicle type to use for the cell's flows

Definition at line 62 of file ODMatrix.cpp.

References ODCell::begin, ODCell::destination, ODCell::end, NamedObjectCont< T >::get(), MsgHandler::getErrorInstance(), MsgHandler::getWarningInstance(), MsgHandler::inform(), myContainer, myDistricts, myNoDiscarded, myNoLoaded, ODCell::origin, ODDistrict::sinkNumber(), ODDistrict::sourceNumber(), toString(), ODCell::vehicleNumber, and ODCell::vehicleType.

Referenced by readO(), and readV().

00064                                                     {
00065     myNoLoaded += vehicleNumber;
00066     if (myDistricts.get(origin)==0&&myDistricts.get(destination)==0) {
00067         MsgHandler::getWarningInstance()->inform("Missing origin '" + origin + "' and destination '" + destination + "' (" + toString(vehicleNumber) + " vehicles).");
00068     } else if (myDistricts.get(origin)==0&&vehicleNumber>0) {
00069         MsgHandler::getErrorInstance()->inform("Missing origin '" + origin + "' (" + toString(vehicleNumber) + " vehicles).");
00070         myNoDiscarded += vehicleNumber;
00071     } else if (myDistricts.get(destination)==0&&vehicleNumber>0) {
00072         MsgHandler::getErrorInstance()->inform("Missing destination '" + destination + "' (" + toString(vehicleNumber) + " vehicles).");
00073         myNoDiscarded += vehicleNumber;
00074     } else {
00075         if (myDistricts.get(origin)->sourceNumber()==0) {
00076             MsgHandler::getErrorInstance()->inform("District '" + origin + "' has no source.");
00077             myNoDiscarded += vehicleNumber;
00078         } else if (myDistricts.get(destination)->sinkNumber()==0) {
00079             MsgHandler::getErrorInstance()->inform("District '" + destination + "' has no sink.");
00080             myNoDiscarded += vehicleNumber;
00081         } else {
00082             ODCell *cell = new ODCell();
00083             cell->begin = begin;
00084             cell->end = end;
00085             cell->origin = origin;
00086             cell->destination = destination;
00087             cell->vehicleType = vehicleType;
00088             cell->vehicleNumber = vehicleNumber;
00089             myContainer.push_back(cell);
00090         }
00091     }
00092 }

void ODMatrix::applyCurve ( const Distribution_Points ps,
ODCell cell,
CellVector newCells 
) throw () [protected]

Splits the given cell dividing it on the given time line and storing the results in the given container.

For the given cell, a list of clones is generated. The number of these is equal to the number of "areas" within the given distribution description (time line in this case) and each clone's vehicleNumber is equal to the given cell's vehicle number multiplied with the area's probability. The clones are stored in the given cell vector.

See also:
Distribution_Points
Parameters:
[in] ps The time line to apply
[in] cell The cell to split
[out] newCells The storage to put generated cells into
Todo:
describe better!!!

Definition at line 236 of file ODMatrix.cpp.

References ODCell::begin, ODCell::destination, ODCell::end, ODCell::origin, ODCell::vehicleNumber, and ODCell::vehicleType.

00236                                                                                               {
00237     for (size_t i=0; i<ps.getAreaNo(); ++i) {
00238         ODCell *ncell = new ODCell();
00239         ncell->begin = (SUMOTime) ps.getAreaBegin(i);
00240         ncell->end = (SUMOTime) ps.getAreaEnd(i);
00241         ncell->origin = cell->origin;
00242         ncell->destination = cell->destination;
00243         ncell->vehicleType = cell->vehicleType;
00244         ncell->vehicleNumber = cell->vehicleNumber * ps.getAreaPerc(i);
00245         newCells.push_back(ncell);
00246     }
00247 }

void ODMatrix::applyCurve ( const Distribution_Points ps  )  throw ()

Splits the stored cells dividing them on the given time line.

Todo:
Describe

Definition at line 251 of file ODMatrix.cpp.

References myContainer.

Referenced by main().

00251                                                           {
00252     CellVector oldCells = myContainer;
00253     myContainer.clear();
00254     for (CellVector::iterator i=oldCells.begin(); i!=oldCells.end(); ++i) {
00255         CellVector newCells;
00256         applyCurve(ps, *i, newCells);
00257         copy(newCells.begin(), newCells.end(), back_inserter(myContainer));
00258         delete *i;
00259     }
00260 }

SUMOReal ODMatrix::computeEmissions ( ODCell cell,
size_t vehName,
std::vector< ODVehicle > &  into,
bool  uniform,
const std::string &  prefix 
) throw () [protected]

Computes the emissions stored in the given cell and saves them in "into".

At first, the number of vehicles to emit is computed using the integer value of the vehicleNumber information from the given cell. In the case vehicleNumber has a fraction, an additional vehicle may be added in the case a chosen random number is lower than this fraction.

If uniform is true, the departure times of the generated vehicles are spread uniformly, otherwise the departure time are chosen randomly from the interval.

The vehicle names are generated by putting the value of vehName after the given prefix. The value of vehName is incremented with each generated vehicle.

The number of left vehicles (the fraction if no additional vehicle was generated) is returned.

Parameters:
[in] cell The cell to use
[in,out] vehName An incremented index of the generated vehicle
[out] into The storage to put generated vehicles into
[in] uniform Information whether departure times shallbe uniformly spread or random
[in] prefix A prefix for the vehicle names
Returns:
The number of left vehicles to emit

Definition at line 96 of file ODMatrix.cpp.

References ODMatrix::ODVehicle::cell, ODMatrix::ODVehicle::depart, ODMatrix::ODVehicle::from, ODDistrictCont::getRandomSinkFromDistrict(), ODDistrictCont::getRandomSourceFromDistrict(), ODMatrix::ODVehicle::id, myDistricts, RandHelper::rand(), SUMOReal, ODMatrix::ODVehicle::to, toString(), and ODCell::vehicleNumber.

Referenced by write().

00098                                                                           {
00099     int vehicles2emit = (int) cell->vehicleNumber;
00100     // compute whether the fraction forces an additional vehicle emission
00101     SUMOReal mrand = RandHelper::rand();
00102     SUMOReal mprob = (SUMOReal) cell->vehicleNumber - (SUMOReal) vehicles2emit;
00103     if (mrand<mprob) {
00104         vehicles2emit++;
00105     }
00106 
00107     SUMOReal offset = (SUMOReal)(cell->end - cell->begin) / (SUMOReal) vehicles2emit / (SUMOReal) 2.;
00108     for (int i=0; i<vehicles2emit; ++i) {
00109         ODVehicle veh;
00110         veh.id = prefix + toString(vehName++);
00111 
00112         if (uniform) {
00113             veh.depart = (unsigned int)(offset + cell->begin + ((SUMOReal)(cell->end - cell->begin) * (SUMOReal) i / (SUMOReal) vehicles2emit));
00114         } else {
00115             veh.depart = (unsigned int) RandHelper::rand((int) cell->begin, (int) cell->end);
00116         }
00117 
00118         veh.from = myDistricts.getRandomSourceFromDistrict(cell->origin);
00119         veh.to = myDistricts.getRandomSinkFromDistrict(cell->destination);
00120         veh.cell = cell;
00121         into.push_back(veh);
00122     }
00123     return cell->vehicleNumber - vehicles2emit;
00124 }

SUMOReal ODMatrix::getNoDiscarded (  )  const throw ()

Returns the number of discarded vehicles.

Returns the value of myNoDiscarded

Returns:
The number of discarded vehicles

Definition at line 230 of file ODMatrix.cpp.

References myNoDiscarded.

Referenced by main().

00230                                        {
00231     return myNoDiscarded;
00232 }

SUMOReal ODMatrix::getNoLoaded (  )  const throw ()

Returns the number of loaded vehicles.

Returns the value of myNoLoaded

Returns:
The number of loaded vehicles

Definition at line 218 of file ODMatrix.cpp.

References myNoLoaded.

Referenced by main().

00218                                     {
00219     return myNoLoaded;
00220 }

SUMOReal ODMatrix::getNoWritten (  )  const throw ()

Returns the number of written vehicles.

Returns the value of myNoWritten

Returns:
The number of written vehicles

Definition at line 224 of file ODMatrix.cpp.

References myNoWritten.

Referenced by main().

00224                                      {
00225     return myNoWritten;
00226 }

ODMatrix& ODMatrix::operator= ( const ODMatrix s  )  [private]

invalid assignment operator

void ODMatrix::write ( SUMOTime  begin,
SUMOTime  end,
OutputDevice dev,
bool  uniform,
bool  noVtype,
const std::string &  prefix 
) throw ()

Writes the vehicles stored in the matrix assigning the sources and sinks.

The cells stored in myContainer are sorted, first. Then, for each time step to generate vehicles for, it is checked whether the topmost cell is valid for this time step. If so, vehicles are generated from this cell's description using computeEmission and stored in an internal vector. The pointer is moved and the check is repeated until the current cell is not valid for the current time or no further cells exist.

Then, for the current time step, the internal list of vehicles is sorted and all vehicles that start within this time step are written.

The left fraction of vehicles to emit is saved for each O/D-dependency over time and the number of vehicles to generate is increased as soon as this value is larger than 1, decrementing it.

Parameters:
[in] begin The begin time to generate vehicles for
[in] end The end time to generate vehicles for
[out] strm The stream to write the generated vehicle trips to
[in] uniform Information whether departure times shallbe uniformly spread or random
[in] noVtype Whether vtype information shall not be written
[in] prefix A prefix for the vehicle names

Definition at line 128 of file ODMatrix.cpp.

References computeEmissions(), OptionsCont::getBool(), MsgHandler::getMessageInstance(), OptionsCont::getOptions(), OptionsCont::getString(), OptionsCont::isSet(), MAX2(), myContainer, myNoWritten, MsgHandler::progressMsg(), SUMOReal, and toString().

Referenced by main().

00130                                                  {
00131     if (myContainer.size()==0) {
00132         return;
00133     }
00134     OptionsCont &oc = OptionsCont::getOptions();
00135     std::map<std::pair<std::string, std::string>, SUMOReal> fractionLeft;
00136     size_t vehName = 0;
00137     sort(myContainer.begin(), myContainer.end(), cell_by_begin_sorter());
00138     // recheck begin time
00139     ODCell *first = *myContainer.begin();
00140     begin = MAX2(begin, first->begin);
00141     CellVector::iterator next = myContainer.begin();
00142     std::vector<ODVehicle> vehicles;
00143     // go through the time steps
00144     for (SUMOTime t=begin; t!=end; t++) {
00145         MsgHandler::getMessageInstance()->progressMsg("Parsing time " + toString(t));
00146         // recheck whether a new cell got valid
00147         bool changed = false;
00148         while (next!=myContainer.end()&&(*next)->begin<=t&&(*next)->end>t) {
00149             std::pair<std::string, std::string> odID = std::make_pair((*next)->origin, (*next)->destination);
00150             // check whether the current cell must be extended by the last fraction
00151             if (fractionLeft.find(odID)!=fractionLeft.end()) {
00152                 (*next)->vehicleNumber += fractionLeft[odID];
00153                 fractionLeft[odID] = 0;
00154             }
00155             // get the new emissions (into tmp)
00156             std::vector<ODVehicle> tmp;
00157             SUMOReal fraction = computeEmissions(*next, vehName, tmp, uniform, prefix);
00158             // copy new emissions if any
00159             if (tmp.size()!=0) {
00160                 copy(tmp.begin(), tmp.end(), back_inserter(vehicles));
00161                 changed = true;
00162             }
00163             // save the fraction
00164             if (fraction!=0) {
00165                 if (fractionLeft.find(odID)==fractionLeft.end()) {
00166                     fractionLeft[odID] = fraction;
00167                 } else {
00168                     fractionLeft[odID] += fraction;
00169                 }
00170             }
00171             //
00172             ++next;
00173         }
00174         if (changed) {
00175             sort(vehicles.begin(), vehicles.end(), descending_departure_comperator());
00176         }
00177         std::vector<ODVehicle>::reverse_iterator i = vehicles.rbegin();
00178         for (; i!=vehicles.rend()&&(*i).depart==t; ++i) {
00179             myNoWritten++;
00180             dev.openTag("tripdef") << " id=\"" << (*i).id << "\" depart=\"" << t << ".00\" "
00181             << "from=\"" << (*i).from << "\" "
00182             << "to=\"" << (*i).to << "\"";
00183             if (!noVtype&&(*i).cell->vehicleType.length()!=0) {
00184                 dev << " type=\"" << (*i).cell->vehicleType << "\"";
00185             }
00186             if (oc.getBool("with-taz")) {
00187                 dev << " fromtaz=\"" << (*i).cell->origin << "\"";
00188                 dev << " totaz=\"" << (*i).cell->destination << "\"";
00189             }
00190             if (oc.isSet("departlane") && oc.getString("departlane")!="default") {
00191                 dev << " departlane=\"" << oc.getString("departlane") << "\"";
00192             }
00193             if (oc.isSet("departpos")) {
00194                 dev << " departpos=\"" << oc.getString("departpos") << "\"";
00195             }
00196             if (oc.isSet("departspeed") && oc.getString("departspeed")!="default") {
00197                 dev << " departspeed=\"" << oc.getString("departspeed") << "\"";
00198             }
00199             if (oc.isSet("arrivallane")) {
00200                 dev << " arrivallane=\"" << oc.getString("arrivallane") << "\"";
00201             }
00202             if (oc.isSet("arrivalpos")) {
00203                 dev << " arrivalpos=\"" << oc.getString("arrivalpos") << "\"";
00204             }
00205             if (oc.isSet("arrivalspeed")) {
00206                 dev << " arrivalspeed=\"" << oc.getString("arrivalspeed") << "\"";
00207             }
00208             dev.closeTag(true);
00209         }
00210         while (vehicles.size()!=0&&(*vehicles.rbegin()).depart==t) {
00211             vehicles.pop_back();
00212         }
00213     }
00214 }


Field Documentation

The loaded cells.

Definition at line 244 of file ODMatrix.h.

Referenced by add(), applyCurve(), write(), and ~ODMatrix().

The districts to retrieve sources/sinks from.

Definition at line 247 of file ODMatrix.h.

Referenced by add(), and computeEmissions().

SUMOReal ODMatrix::myNoDiscarded [protected]

Number of discarded vehicles.

Definition at line 256 of file ODMatrix.h.

Referenced by add(), and getNoDiscarded().

SUMOReal ODMatrix::myNoLoaded [protected]

Number of loaded vehicles.

Definition at line 250 of file ODMatrix.h.

Referenced by add(), and getNoLoaded().

SUMOReal ODMatrix::myNoWritten [protected]

Number of written vehicles.

Definition at line 253 of file ODMatrix.h.

Referenced by getNoWritten(), and write().


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

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