SUMO - Simulation of Urban MObility
ODMatrix Class Reference

An O/D (origin/destination) matrix. More...

#include <ODMatrix.h>

Collaboration diagram for ODMatrix:
Collaboration graph

Data Structures

class  cell_by_begin_comparator
 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...
 

Public Member Functions

void add (SUMOReal vehicleNumber, SUMOTime begin, SUMOTime end, const std::string &origin, const std::string &destination, const std::string &vehicleType)
 Builds a single cell from the given values, verifying them. More...
 
void add (const std::string &id, const SUMOTime depart, const std::pair< const std::string, const std::string > &od, const std::string &vehicleType)
 Adds a single vehicle with departure time. More...
 
void applyCurve (const Distribution_Points &ps)
 Splits the stored cells dividing them on the given time line. More...
 
const std::vector< ODCell * > & getCells ()
 
SUMOReal getNoDiscarded () const
 Returns the number of discarded vehicles. More...
 
SUMOReal getNoLoaded () const
 Returns the number of loaded vehicles. More...
 
SUMOReal getNoWritten () const
 Returns the number of written vehicles. More...
 
void loadMatrix (OptionsCont &oc)
 read a matrix in one of several formats More...
 
void loadRoutes (OptionsCont &oc, SUMOSAXHandler &handler)
 read SUMO routes More...
 
 ODMatrix (const ODDistrictCont &dc)
 Constructor. More...
 
Distribution_Points parseTimeLine (const std::vector< std::string > &def, bool timelineDayInHours)
 split the given timeline More...
 
void readO (LineReader &lr, SUMOReal scale, std::string vehType, bool matrixHasVehType)
 read a VISUM-matrix with the O Format More...
 
void readV (LineReader &lr, SUMOReal scale, std::string vehType, bool matrixHasVehType)
 read a VISUM-matrix with the V Format More...
 
void sortByBeginTime ()
 
void write (SUMOTime begin, const SUMOTime end, OutputDevice &dev, const bool uniform, const bool differSourceSink, const bool noVtype, const std::string &prefix, const bool stepLog)
 Writes the vehicles stored in the matrix assigning the sources and sinks. More...
 
void writeDefaultAttrs (OutputDevice &dev, const bool noVtype, const ODCell *const cell)
 Helper function for flow and trip output writing the depart and arrival attributes. More...
 
void writeFlows (const SUMOTime begin, const SUMOTime end, OutputDevice &dev, const bool noVtype, const std::string &prefix)
 Writes the flows stored in the matrix. More...
 
 ~ODMatrix ()
 Destructor. More...
 

Protected Member Functions

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

Protected Attributes

std::vector< ODCell * > myContainer
 The loaded cells. More...
 
const ODDistrictContmyDistricts
 The districts to retrieve sources/sinks from. More...
 
SUMOReal myNoDiscarded
 Number of discarded vehicles. More...
 
SUMOReal myNoLoaded
 Number of loaded vehicles. More...
 
SUMOReal myNoWritten
 Number of written vehicles. More...
 
std::map< const std::pair< const std::string, const std::string >, std::vector< ODCell * > > myShortCut
 The loaded cells indexed by origin and destination. More...
 

Private Member Functions

std::string getNextNonCommentLine (LineReader &lr)
 
 ODMatrix (const ODMatrix &s)
 invalid copy constructor More...
 
ODMatrixoperator= (const ODMatrix &s)
 invalid assignment operator More...
 
SUMOTime parseSingleTime (const std::string &time)
 
SUMOReal readFactor (LineReader &lr, SUMOReal scale)
 
std::pair< SUMOTime, SUMOTimereadTime (LineReader &lr)
 

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 75 of file ODMatrix.h.

Constructor & Destructor Documentation

ODMatrix::ODMatrix ( const ODDistrictCont dc)

Constructor.

Parameters
[in]dcThe district container to obtain referenced districts from

Definition at line 62 of file ODMatrix.cpp.

Referenced by ODMatrix::descending_departure_comperator::operator()().

ODMatrix::~ODMatrix ( )

Destructor.

Definition at line 66 of file ODMatrix.cpp.

References myContainer.

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 
)

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]vehicleNumberThe number of vehicles to store within the cell
[in]beginThe begin of the interval the cell is valid for
[in]endThe end of the interval the cell is valid for
[in]originThe origin district to use for the cell's flows
[in]destinationThe destination district to use for the cell's flows
[in]vehicleTypeThe vehicle type to use for the cell's flows

Definition at line 75 of file ODMatrix.cpp.

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

Referenced by add(), ROMARouteHandler::myStartElement(), ODAmitranHandler::myStartElement(), readO(), and readV().

void ODMatrix::add ( const std::string &  id,
const SUMOTime  depart,
const std::pair< const std::string, const std::string > &  od,
const std::string &  vehicleType 
)

Adds a single vehicle with departure time.

If there is no existing ODCell for the given parameters one is generated using add(...)

Parameters
[in]idThe id of the vehicle
[in]departThe departure time of the vehicle
[in]odThe origin and destination district to use for the cell's flows
[in]vehicleTypeThe vehicle type to use for the cell's flows

Definition at line 109 of file ODMatrix.cpp.

References add(), ODCell::departures, OptionsCont::getOptions(), myContainer, myShortCut, string2time(), SUMOReal, and ODCell::vehicleNumber.

void ODMatrix::applyCurve ( const Distribution_Points ps)

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

Todo:
Describe

Definition at line 501 of file ODMatrix.cpp.

References myContainer.

Referenced by computeRoutes(), and main().

void ODMatrix::applyCurve ( const Distribution_Points ps,
ODCell cell,
std::vector< ODCell * > &  newCells 
)
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]psThe time line to apply
[in]cellThe cell to split
[out]newCellsThe storage to put generated cells into
Todo:
describe better!!!

Definition at line 486 of file ODMatrix.cpp.

References ODCell::begin, ODCell::destination, ODCell::end, Distribution_Points::getAreaBegin(), Distribution_Points::getAreaEnd(), Distribution_Points::getAreaNo(), Distribution_Points::getAreaPerc(), ODCell::origin, TIME2STEPS, ODCell::vehicleNumber, and ODCell::vehicleType.

SUMOReal ODMatrix::computeDeparts ( ODCell cell,
size_t &  vehName,
std::vector< ODVehicle > &  into,
const bool  uniform,
const bool  differSourceSink,
const std::string &  prefix 
)
protected

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

At first, the number of vehicles to insert 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]cellThe cell to use
[in,out]vehNameAn incremented index of the generated vehicle
[out]intoThe storage to put generated vehicles into
[in]uniformInformation whether departure times shallbe uniformly spread or random
[in]differSourceSinkwhether source and sink shall be different edges
[in]prefixA prefix for the vehicle names
Returns
The number of left vehicles to insert

Definition at line 135 of file ODMatrix.cpp.

References ODCell::begin, ODMatrix::ODVehicle::cell, ODMatrix::ODVehicle::depart, ODCell::destination, ODCell::end, ODMatrix::ODVehicle::from, NamedObjectCont< T >::get(), ODDistrictCont::getRandomSinkFromDistrict(), ODDistrictCont::getRandomSourceFromDistrict(), ODMatrix::ODVehicle::id, myDistricts, ODCell::origin, RandHelper::rand(), ODDistrict::sinkNumber(), ODDistrict::sourceNumber(), SUMOReal, ODMatrix::ODVehicle::to, toString(), ODCell::vehicleNumber, and WRITE_WARNING.

Referenced by write().

const std::vector<ODCell*>& ODMatrix::getCells ( )
inline
std::string ODMatrix::getNextNonCommentLine ( LineReader lr)
private

in the functions readV and readO

Todo:
Describe

Definition at line 296 of file ODMatrix.cpp.

References LineReader::good(), LineReader::hasMore(), StringUtils::prune(), and LineReader::readLine().

Referenced by readFactor(), readO(), readTime(), and readV().

SUMOReal ODMatrix::getNoDiscarded ( ) const

Returns the number of discarded vehicles.

Returns the value of myNoDiscarded

Returns
The number of discarded vehicles

Definition at line 480 of file ODMatrix.cpp.

References myNoDiscarded.

Referenced by main().

SUMOReal ODMatrix::getNoLoaded ( ) const

Returns the number of loaded vehicles.

Returns the value of myNoLoaded

Returns
The number of loaded vehicles

Definition at line 468 of file ODMatrix.cpp.

References myNoLoaded, and SUMOReal.

Referenced by main().

SUMOReal ODMatrix::getNoWritten ( ) const

Returns the number of written vehicles.

Returns the value of myNoWritten

Returns
The number of written vehicles

Definition at line 474 of file ODMatrix.cpp.

References myNoWritten, and SUMOReal.

Referenced by main().

void ODMatrix::loadRoutes ( OptionsCont oc,
SUMOSAXHandler handler 
)
ODMatrix& ODMatrix::operator= ( const ODMatrix s)
private

invalid assignment operator

Referenced by ODMatrix::descending_departure_comperator::operator()().

SUMOTime ODMatrix::parseSingleTime ( const std::string &  time)
private

in the functions readV and readO

Todo:
Describe

Definition at line 309 of file ODMatrix.cpp.

References TplConvert::_2int(), and TIME2STEPS.

Referenced by readTime().

Distribution_Points ODMatrix::parseTimeLine ( const std::vector< std::string > &  def,
bool  timelineDayInHours 
)

split the given timeline

Todo:
Describe

Definition at line 577 of file ODMatrix.cpp.

References TplConvert::_2int(), TplConvert::_2SUMOReal(), StringTokenizer::next(), StringTokenizer::size(), SUMOReal, and toString().

Referenced by computeRoutes(), and main().

SUMOReal ODMatrix::readFactor ( LineReader lr,
SUMOReal  scale 
)
private

in the functions readV and readO

Todo:
Describe

Definition at line 338 of file ODMatrix.cpp.

References TplConvert::_2SUMOReal(), getNextNonCommentLine(), and SUMOReal.

Referenced by readO(), and readV().

void ODMatrix::readO ( LineReader lr,
SUMOReal  scale,
std::string  vehType,
bool  matrixHasVehType 
)
std::pair< SUMOTime, SUMOTime > ODMatrix::readTime ( LineReader lr)
private

in the functions readV and readO

Todo:
Describe

Definition at line 320 of file ODMatrix.cpp.

References getNextNonCommentLine(), StringTokenizer::next(), parseSingleTime(), SUMOReal, and StringTokenizer::WHITECHARS.

Referenced by readO(), and readV().

void ODMatrix::readV ( LineReader lr,
SUMOReal  scale,
std::string  vehType,
bool  matrixHasVehType 
)
void ODMatrix::sortByBeginTime ( )

Definition at line 607 of file ODMatrix.cpp.

References myContainer.

Referenced by computeRoutes(), getCells(), write(), and writeFlows().

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

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 "computeDeparts" 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 insert 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]beginThe begin time to generate vehicles for
[in]endThe end time to generate vehicles for
[in]devThe stream to write the generated vehicle trips to
[in]uniformInformation whether departure times shallbe uniformly spread or random
[in]differSourceSinkwhether source and sink shall be different edges
[in]noVtypeWhether vtype information shall not be written
[in]prefixA prefix for the vehicle names
[in]stepLogWhether processed time shall be written

Definition at line 203 of file ODMatrix.cpp.

References OutputDevice::closeTag(), computeDeparts(), DELTA_T, MAX2(), myContainer, myNoWritten, OutputDevice::openTag(), sortByBeginTime(), SUMO_ATTR_DEPART, SUMO_ATTR_FROM, SUMO_ATTR_ID, SUMO_ATTR_TO, SUMO_TAG_TRIP, SUMOReal, time2string(), OutputDevice::writeAttr(), and writeDefaultAttrs().

Referenced by main().

void ODMatrix::writeDefaultAttrs ( OutputDevice dev,
const bool  noVtype,
const ODCell *const  cell 
)

Helper function for flow and trip output writing the depart and arrival attributes.

Parameters
[in]devThe stream to write the generated vehicle trips to
[in]noVtypeWhether vtype information shall not be written
[in]cellThe OD cell containing the vtype

Definition at line 174 of file ODMatrix.cpp.

References ODCell::destination, OptionsCont::getOptions(), OptionsCont::getString(), OptionsCont::isSet(), ODCell::origin, SUMO_ATTR_ARRIVALLANE, SUMO_ATTR_ARRIVALPOS, SUMO_ATTR_ARRIVALSPEED, SUMO_ATTR_DEPARTLANE, SUMO_ATTR_DEPARTPOS, SUMO_ATTR_DEPARTSPEED, SUMO_ATTR_FROM_TAZ, SUMO_ATTR_TO_TAZ, SUMO_ATTR_TYPE, ODCell::vehicleType, and OutputDevice::writeAttr().

Referenced by write(), and writeFlows().

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

Writes the flows stored in the matrix.

Parameters
[in]beginThe begin time to generate vehicles for
[in]endThe end time to generate vehicles for
[in]devThe stream to write the generated vehicle trips to
[in]noVtypeWhether vtype information shall not be written
[in]prefixA prefix for the flow names

Definition at line 273 of file ODMatrix.cpp.

References ODCell::begin, OutputDevice::closeTag(), ODCell::end, myContainer, OutputDevice::openTag(), sortByBeginTime(), SUMO_ATTR_BEGIN, SUMO_ATTR_END, SUMO_ATTR_ID, SUMO_ATTR_NUMBER, SUMO_TAG_FLOW, time2string(), toString(), ODCell::vehicleNumber, OutputDevice::writeAttr(), and writeDefaultAttrs().

Referenced by main().

Field Documentation

std::vector<ODCell*> ODMatrix::myContainer
protected

The loaded cells.

Definition at line 341 of file ODMatrix.h.

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

const ODDistrictCont& ODMatrix::myDistricts
protected

The districts to retrieve sources/sinks from.

Definition at line 347 of file ODMatrix.h.

Referenced by add(), and computeDeparts().

SUMOReal ODMatrix::myNoDiscarded
protected

Number of discarded vehicles.

Definition at line 356 of file ODMatrix.h.

Referenced by add(), and getNoDiscarded().

SUMOReal ODMatrix::myNoLoaded
protected

Number of loaded vehicles.

Definition at line 350 of file ODMatrix.h.

Referenced by add(), and getNoLoaded().

SUMOReal ODMatrix::myNoWritten
protected

Number of written vehicles.

Definition at line 353 of file ODMatrix.h.

Referenced by getNoWritten(), and write().

std::map<const std::pair<const std::string, const std::string>, std::vector<ODCell*> > ODMatrix::myShortCut
protected

The loaded cells indexed by origin and destination.

Definition at line 344 of file ODMatrix.h.

Referenced by add().


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