![]() |
Eclipse SUMO - Simulation of Urban MObility
|
An O/D (origin/destination) matrix. More...
#include <ODMatrix.h>
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 | |
bool | add (const std::string &id, const SUMOTime depart, const std::string &fromTaz, const std::string &toTaz, const std::string &vehicleType, const bool originIsEdge=false, const bool destinationIsEdge=false) |
Adds a single vehicle with departure time. More... | |
bool | add (double vehicleNumber, SUMOTime begin, SUMOTime end, const std::string &origin, const std::string &destination, const std::string &vehicleType, const bool originIsEdge=false, const bool destinationIsEdge=false) |
Builds a single cell from the given values, verifying them. More... | |
void | applyCurve (const Distribution_Points &ps) |
Splits the stored cells dividing them on the given time line. More... | |
SUMOTime | getBegin () const |
const std::vector< ODCell * > & | getCells () |
SUMOTime | getEnd () const |
double | getNumDiscarded () const |
Returns the number of discarded vehicles. More... | |
double | getNumLoaded () const |
Returns the number of loaded vehicles. More... | |
double | getNumWritten () 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, double scale, std::string vehType, bool matrixHasVehType) |
read a VISUM-matrix with the O Format More... | |
void | readV (LineReader &lr, double 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, bool pedestrians, bool persontrips) |
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, bool asProbability=false, bool pedestrians=false, bool persontrips=false) |
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... | |
double | computeDeparts (ODCell *cell, int &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... | |
Private Member Functions | |
std::string | getNextNonCommentLine (LineReader &lr) |
ODMatrix (const ODMatrix &s) | |
invalid copy constructor More... | |
ODMatrix & | operator= (const ODMatrix &s)=delete |
invalid assignment operator More... | |
SUMOTime | parseSingleTime (const std::string &time) |
double | readFactor (LineReader &lr, double scale) |
std::pair< SUMOTime, SUMOTime > | readTime (LineReader &lr) |
Private Attributes | |
SUMOTime | myBegin |
parsed time bounds More... | |
std::vector< ODCell * > | myContainer |
The loaded cells. More... | |
const ODDistrictCont & | myDistricts |
The districts to retrieve sources/sinks from. More... | |
SUMOTime | myEnd |
std::set< std::string > | myMissingDistricts |
The missing districts already warned about. More... | |
double | myNumDiscarded |
Number of discarded vehicles. More... | |
double | myNumLoaded |
Number of loaded vehicles. More... | |
double | myNumWritten |
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... | |
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 69 of file ODMatrix.h.
ODMatrix::ODMatrix | ( | const ODDistrictCont & | dc | ) |
Constructor.
[in] | dc | The district container to obtain referenced districts from |
Definition at line 50 of file ODMatrix.cpp.
ODMatrix::~ODMatrix | ( | ) |
|
private |
invalid copy constructor
bool ODMatrix::add | ( | const std::string & | id, |
const SUMOTime | depart, | ||
const std::string & | fromTaz, | ||
const std::string & | toTaz, | ||
const std::string & | vehicleType, | ||
const bool | originIsEdge = false , |
||
const bool | destinationIsEdge = false |
||
) |
Adds a single vehicle with departure time.
If there is no existing ODCell for the given parameters one is generated using add(...)
[in] | id | The id of the vehicle |
[in] | depart | The departure time of the vehicle |
[in] | od | The origin and destination district to use for the cell's flows |
[in] | vehicleType | The vehicle type to use for the cell's flows |
Definition at line 108 of file ODMatrix.cpp.
References add(), ODCell::departures, OptionsCont::getOptions(), myContainer, myMissingDistricts, myNumDiscarded, myNumLoaded, myShortCut, string2time(), and ODCell::vehicleNumber.
bool ODMatrix::add | ( | double | vehicleNumber, |
SUMOTime | begin, | ||
SUMOTime | end, | ||
const std::string & | origin, | ||
const std::string & | destination, | ||
const std::string & | vehicleType, | ||
const bool | originIsEdge = false , |
||
const bool | destinationIsEdge = false |
||
) |
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).
[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 63 of file ODMatrix.cpp.
References ODCell::begin, ODCell::destination, ODCell::destinationIsEdge, ODCell::end, NamedObjectCont< T >::get(), myContainer, myDistricts, myMissingDistricts, myNumDiscarded, myNumLoaded, ODCell::origin, ODCell::originIsEdge, ODDistrict::sinkNumber(), ODDistrict::sourceNumber(), toString(), ODCell::vehicleNumber, ODCell::vehicleType, WRITE_ERROR, and WRITE_WARNING.
Referenced by add(), ROMARouteHandler::myEndElement(), ODAmitranHandler::myStartElement(), readO(), and readV().
void ODMatrix::applyCurve | ( | const Distribution_Points & | ps | ) |
Splits the stored cells dividing them on the given time line.
Definition at line 592 of file ODMatrix.cpp.
References myContainer.
Referenced by computeRoutes(), and main().
|
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.
[in] | ps | The time line to apply |
[in] | cell | The cell to split |
[out] | newCells | The storage to put generated cells into |
Definition at line 576 of file ODMatrix.cpp.
References ODCell::begin, ODCell::destination, ODCell::end, RandomDistributor< T >::getOverallProb(), RandomDistributor< T >::getProbs(), RandomDistributor< T >::getVals(), ODCell::origin, TIME2STEPS, ODCell::vehicleNumber, and ODCell::vehicleType.
|
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.
[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] | differSourceSink | whether source and sink shall be different edges |
[in] | prefix | A prefix for the vehicle names |
Definition at line 144 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(), ODMatrix::ODVehicle::to, toString(), ODCell::vehicleNumber, and WRITE_WARNING.
Referenced by write().
|
inline |
|
inline |
Definition at line 246 of file ODMatrix.h.
References myContainer.
Referenced by computeRoutes(), ROMAAssignments::getKPaths(), ROMAAssignments::incremental(), ROMAAssignments::resetFlows(), and ROMAAssignments::sue().
|
inline |
|
private |
@used in the functions readV and readO
Definition at line 386 of file ODMatrix.cpp.
References LineReader::getFileName(), LineReader::good(), LineReader::hasMore(), StringUtils::prune(), and LineReader::readLine().
Referenced by readFactor(), readO(), readTime(), and readV().
double ODMatrix::getNumDiscarded | ( | ) | const |
Returns the number of discarded vehicles.
Returns the value of myNoDiscarded
Definition at line 570 of file ODMatrix.cpp.
References myNumDiscarded.
Referenced by main().
double ODMatrix::getNumLoaded | ( | ) | const |
Returns the number of loaded vehicles.
Returns the value of myNoLoaded
Definition at line 558 of file ODMatrix.cpp.
References myNumLoaded.
Referenced by main().
double ODMatrix::getNumWritten | ( | ) | const |
Returns the number of written vehicles.
Returns the value of myNoWritten
Definition at line 564 of file ODMatrix.cpp.
References myNumWritten.
Referenced by main().
void ODMatrix::loadMatrix | ( | OptionsCont & | oc | ) |
read a matrix in one of several formats
Definition at line 605 of file ODMatrix.cpp.
References OptionsCont::getFloat(), OptionsCont::getString(), OptionsCont::getStringVector(), LineReader::good(), FileHelpers::isReadable(), PROGRESS_BEGIN_MESSAGE, PROGRESS_DONE_MESSAGE, PROGRESS_FAILED_MESSAGE, LineReader::readLine(), readO(), readV(), and XMLSubSys::runParser().
Referenced by main().
void ODMatrix::loadRoutes | ( | OptionsCont & | oc, |
SUMOSAXHandler & | handler | ||
) |
read SUMO routes
Definition at line 651 of file ODMatrix.cpp.
References OptionsCont::getStringVector(), FileHelpers::isReadable(), PROGRESS_BEGIN_MESSAGE, PROGRESS_DONE_MESSAGE, PROGRESS_FAILED_MESSAGE, and XMLSubSys::runParser().
Referenced by main().
|
private |
@used in the functions readV and readO
Definition at line 398 of file ODMatrix.cpp.
References TIME2STEPS, and StringUtils::toInt().
Referenced by readTime().
Distribution_Points ODMatrix::parseTimeLine | ( | const std::vector< std::string > & | def, |
bool | timelineDayInHours | ||
) |
split the given timeline
Definition at line 668 of file ODMatrix.cpp.
References RandomDistributor< T >::add(), StringTokenizer::next(), StringTokenizer::size(), StringUtils::toDouble(), and toString().
Referenced by computeRoutes(), and main().
|
private |
@used in the functions readV and readO
Definition at line 428 of file ODMatrix.cpp.
References getNextNonCommentLine(), and StringUtils::toDouble().
void ODMatrix::readO | ( | LineReader & | lr, |
double | scale, | ||
std::string | vehType, | ||
bool | matrixHasVehType | ||
) |
read a VISUM-matrix with the O Format
Definition at line 508 of file ODMatrix.cpp.
References add(), LineReader::getFileName(), getNextNonCommentLine(), LineReader::hasMore(), StringTokenizer::next(), PROGRESS_BEGIN_MESSAGE, PROGRESS_DONE_MESSAGE, StringUtils::prune(), readFactor(), readTime(), StringTokenizer::size(), StringUtils::toDouble(), StringUtils::toInt(), toString(), and StringTokenizer::WHITECHARS.
Referenced by loadMatrix().
|
private |
@used in the functions readV and readO
Definition at line 409 of file ODMatrix.cpp.
References getNextNonCommentLine(), myBegin, myEnd, StringTokenizer::next(), parseSingleTime(), time2string(), and StringTokenizer::WHITECHARS.
void ODMatrix::readV | ( | LineReader & | lr, |
double | scale, | ||
std::string | vehType, | ||
bool | matrixHasVehType | ||
) |
read a VISUM-matrix with the V Format
Definition at line 440 of file ODMatrix.cpp.
References add(), LineReader::getFileName(), getNextNonCommentLine(), LineReader::hasMore(), StringTokenizer::hasNext(), StringTokenizer::next(), PROGRESS_BEGIN_MESSAGE, PROGRESS_DONE_MESSAGE, StringUtils::prune(), readFactor(), readTime(), StringUtils::toDouble(), StringUtils::toInt(), and StringTokenizer::WHITECHARS.
Referenced by loadMatrix().
void ODMatrix::sortByBeginTime | ( | ) |
Definition at line 693 of file ODMatrix.cpp.
References myContainer.
Referenced by computeRoutes(), 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, | ||
bool | pedestrians, | ||
bool | persontrips | ||
) |
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.
[in] | begin | The begin time to generate vehicles for |
[in] | end | The end time to generate vehicles for |
[in] | dev | The stream to write the generated vehicle trips to |
[in] | uniform | Information whether departure times shallbe uniformly spread or random |
[in] | differSourceSink | whether source and sink shall be different edges |
[in] | noVtype | Whether vtype information shall not be written |
[in] | prefix | A prefix for the vehicle names |
[in] | stepLog | Whether processed time shall be written |
[in] | pedestrians | Writes trips for pedestrians |
[in] | persontrips | Writes trips for persontrips |
Definition at line 212 of file ODMatrix.cpp.
References OutputDevice::closeTag(), computeDeparts(), DELTA_T, MAX2(), myContainer, myNumWritten, OutputDevice::openTag(), sortByBeginTime(), SUMO_ATTR_ARRIVALPOS, SUMO_ATTR_DEPART, SUMO_ATTR_DEPARTPOS, SUMO_ATTR_FROM, SUMO_ATTR_ID, SUMO_ATTR_TO, SUMO_TAG_PERSON, SUMO_TAG_PERSONTRIP, SUMO_TAG_TRIP, SUMO_TAG_WALK, 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.
[in] | dev | The stream to write the generated vehicle trips to |
[in] | noVtype | Whether vtype information shall not be written |
[in] | cell | The OD cell containing the vtype |
Definition at line 183 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, | ||
bool | asProbability = false , |
||
bool | pedestrians = false , |
||
bool | persontrips = false |
||
) |
Writes the flows stored in the matrix.
[in] | begin | The begin time to generate vehicles for |
[in] | end | The end time to generate vehicles for |
[in] | dev | The stream to write the generated vehicle trips to |
[in] | noVtype | Whether vtype information shall not be written |
[in] | prefix | A prefix for the flow names |
[in] | asProbability | Write probability to spawn per second instead of number of vehicles |
[in] | pedestrians | Writes flows for pedestrians |
[in] | persontrips | Writes flows for persontrips |
Definition at line 301 of file ODMatrix.cpp.
References ODCell::begin, OutputDevice::closeTag(), ODCell::destination, ODCell::end, myContainer, OutputDevice::openTag(), ODCell::origin, OutputDevice::setPrecision(), sortByBeginTime(), STEPS2TIME, SUMO_ATTR_ARRIVALPOS, SUMO_ATTR_BEGIN, SUMO_ATTR_END, SUMO_ATTR_FROM, SUMO_ATTR_ID, SUMO_ATTR_NUMBER, SUMO_ATTR_PROB, SUMO_ATTR_TO, SUMO_TAG_FLOW, SUMO_TAG_PERSONFLOW, SUMO_TAG_PERSONTRIP, SUMO_TAG_WALK, time2string(), toString(), ODCell::vehicleNumber, WRITE_WARNING, OutputDevice::writeAttr(), and writeDefaultAttrs().
Referenced by main().
|
private |
parsed time bounds
Definition at line 375 of file ODMatrix.h.
Referenced by getBegin(), and readTime().
|
private |
The loaded cells.
Definition at line 354 of file ODMatrix.h.
Referenced by add(), applyCurve(), getCells(), sortByBeginTime(), write(), writeFlows(), and ~ODMatrix().
|
private |
The districts to retrieve sources/sinks from.
Definition at line 360 of file ODMatrix.h.
Referenced by add(), and computeDeparts().
|
private |
Definition at line 375 of file ODMatrix.h.
Referenced by getEnd(), and readTime().
|
private |
The missing districts already warned about.
Definition at line 363 of file ODMatrix.h.
Referenced by add().
|
private |
Number of discarded vehicles.
Definition at line 372 of file ODMatrix.h.
Referenced by add(), and getNumDiscarded().
|
private |
Number of loaded vehicles.
Definition at line 366 of file ODMatrix.h.
Referenced by add(), and getNumLoaded().
|
private |
Number of written vehicles.
Definition at line 369 of file ODMatrix.h.
Referenced by getNumWritten(), and write().
|
private |
The loaded cells indexed by origin and destination.
Definition at line 357 of file ODMatrix.h.
Referenced by add().