 |
Eclipse SUMO - Simulation of Urban MObility
|
Go to the documentation of this file.
51 : myDistricts(dc), myNumLoaded(0), myNumWritten(0), myNumDiscarded(0), myBegin(-1), myEnd(-1) {}
64 SUMOTime end,
const std::string& origin,
const std::string& destination,
65 const std::string& vehicleType,
const bool originIsEdge,
const bool destinationIsEdge) {
68 WRITE_WARNING(
"Missing origin '" + origin +
"' and destination '" + destination +
"' (" +
toString(vehicleNumber) +
" vehicles).");
73 }
else if (!originIsEdge &&
myDistricts.
get(origin) == 0 && vehicleNumber > 0) {
78 }
else if (!destinationIsEdge &&
myDistricts.
get(destination) == 0 && vehicleNumber > 0) {
79 WRITE_ERROR(
"Missing destination '" + destination +
"' (" +
toString(vehicleNumber) +
" vehicles).");
85 WRITE_ERROR(
"District '" + origin +
"' has no source.");
89 WRITE_ERROR(
"District '" + destination +
"' has no sink.");
109 const std::string& fromTaz,
const std::string& toTaz,
110 const std::string& vehicleType,
const bool originIsEdge,
const bool destinationIsEdge) {
117 std::vector<ODCell*>& odList =
myShortCut[std::make_pair(fromTaz, toTaz)];
119 for (std::vector<ODCell*>::const_reverse_iterator c = odList.rbegin(); c != odList.rend(); ++c) {
120 if ((*c)->begin <= depart && (*c)->end > depart && (*c)->vehicleType == vehicleType) {
125 if (cell ==
nullptr) {
127 const int intervalIdx = (int)(depart / interval);
128 if (
add(1., intervalIdx * interval, (intervalIdx + 1) * interval, fromTaz, toTaz, vehicleType, originIsEdge, destinationIsEdge)) {
130 odList.push_back(cell);
145 int& vehName, std::vector<ODVehicle>& into,
146 const bool uniform,
const bool differSourceSink,
147 const std::string& prefix) {
153 if (vehicles2insert == 0) {
157 const double offset = (double)(cell->
end - cell->
begin) / (double) vehicles2insert / (
double) 2.;
158 for (
int i = 0; i < vehicles2insert; ++i) {
171 }
while (canDiffer && differSourceSink && (veh.
to == veh.
from));
172 if (!canDiffer && differSourceSink && (veh.
to == veh.
from)) {
184 const ODCell*
const cell) {
190 if (oc.
isSet(
"departlane") && oc.
getString(
"departlane") !=
"default") {
193 if (oc.
isSet(
"departpos")) {
196 if (oc.
isSet(
"departspeed") && oc.
getString(
"departspeed") !=
"default") {
199 if (oc.
isSet(
"arrivallane")) {
202 if (oc.
isSet(
"arrivalpos")) {
205 if (oc.
isSet(
"arrivalspeed")) {
214 const bool differSourceSink,
const bool noVtype,
215 const std::string& prefix,
const bool stepLog,
216 bool pedestrians,
bool persontrips) {
220 std::map<std::pair<std::string, std::string>,
double> fractionLeft;
225 std::vector<ODCell*>::iterator next =
myContainer.begin();
226 std::vector<ODVehicle> vehicles;
229 for (
SUMOTime t = begin; t < end;) {
230 if (stepLog && t - lastOut >=
DELTA_T) {
231 std::cout <<
"Parsing time " +
time2string(t) <<
'\r';
235 bool changed =
false;
236 while (next !=
myContainer.end() && (*next)->begin <= t && (*next)->end > t) {
237 std::pair<std::string, std::string> odID = std::make_pair((*next)->origin, (*next)->destination);
239 if (fractionLeft.find(odID) != fractionLeft.end()) {
240 (*next)->vehicleNumber += fractionLeft[odID];
241 fractionLeft[odID] = 0;
244 const int oldSize = (int)vehicles.size();
245 const double fraction =
computeDeparts(*next, vehName, vehicles, uniform, differSourceSink, prefix);
246 if (oldSize != (
int)vehicles.size()) {
250 fractionLeft[odID] = fraction;
257 for (std::vector<ODVehicle>::reverse_iterator i = vehicles.rbegin(); i != vehicles.rend() && (*i).depart == t; ++i) {
268 }
else if (persontrips) {
284 while (vehicles.size() != 0 && vehicles.back().depart == t) {
287 if (!vehicles.empty()) {
288 t = vehicles.back().depart;
290 if (next !=
myContainer.end() && (t > (*next)->begin || vehicles.empty())) {
293 if (next ==
myContainer.end() && vehicles.empty()) {
303 const std::string& prefix,
304 bool asProbability,
bool pedestrians,
bool persontrips) {
312 const ODCell*
const c = *i;
313 if (c->
end > begin && c->
begin < end) {
315 if (probability <= 0) {
322 if (!asProbability) {
325 if (probability > 1) {
326 WRITE_WARNING(
"Flow density of " +
toString(probability) +
" vehicles per second, cannot be represented with a simple probability. Falling back to even spacing.");
339 }
else if (persontrips) {
342 if (!asProbability) {
345 if (probability > 1) {
346 WRITE_WARNING(
"Flow density of " +
toString(probability) +
" vehicles per second, cannot be represented with a simple probability. Falling back to even spacing.");
365 if (!asProbability) {
368 if (probability > 1) {
369 WRITE_WARNING(
"Flow density of " +
toString(probability) +
" vehicles per second, cannot be represented with a simple probability. Falling back to even spacing.");
388 const std::string line = lr.
readLine();
389 if (line[0] !=
'*') {
399 if (time.find(
'.') == std::string::npos) {
402 std::string hours = time.substr(0, time.find(
'.'));
403 std::string minutes = time.substr(time.find(
'.') + 1);
408 std::pair<SUMOTime, SUMOTime>
420 throw ProcessError(
"Broken period definition '" + line +
"'.");
422 throw ProcessError(
"Broken period definition '" + line +
"'.");
441 std::string vehType,
bool matrixHasVehType) {
445 if (matrixHasVehType) {
453 std::pair<SUMOTime, SUMOTime> times =
readTime(lr);
464 std::vector<std::string> names;
465 while ((
int)names.size() != numDistricts) {
469 names.push_back(st2.
next());
474 for (std::vector<std::string>::iterator si = names.begin(); si != names.end(); ++si) {
475 std::vector<std::string>::iterator di = names.begin();
479 if (line.length() == 0) {
485 assert(di != names.end());
487 if (vehNumber != 0) {
488 add(vehNumber, begin, end, *si, *di, vehType);
490 if (di == names.end()) {
491 throw ProcessError(
"More entries than districts found.");
496 throw ProcessError(
"Not numeric vehicle number in line '" + line +
"'.");
501 }
while (di != names.end());
509 std::string vehType,
bool matrixHasVehType) {
513 if (matrixHasVehType) {
522 std::pair<SUMOTime, SUMOTime> times =
readTime(lr);
532 if (line.length() == 0) {
536 if (st2.
size() == 0) {
540 std::string sourceD = st2.
next();
541 std::string destD = st2.
next();
543 if (vehNumber != 0) {
544 add(vehNumber, begin, end, sourceD, destD, vehType);
547 throw ProcessError(
"Missing at least one information in line '" + line +
"'.");
549 throw ProcessError(
"Not numeric vehicle number in line '" + line +
"'.");
577 const std::vector<double>& times = ps.
getVals();
578 for (
int i = 0; i < (int)times.size() - 1; ++i) {
586 newCells.push_back(ncell);
595 for (std::vector<ODCell*>::iterator i = oldCells.begin(); i != oldCells.end(); ++i) {
596 std::vector<ODCell*> newCells;
598 copy(newCells.begin(), newCells.end(), back_inserter(
myContainer));
606 std::vector<std::string> files = oc.
getStringVector(
"od-matrix-files");
607 for (std::vector<std::string>::iterator i = files.begin(); i != files.end(); ++i) {
614 if (type.find(
';') != std::string::npos) {
615 type = type.substr(0, type.find(
';'));
618 if (type.length() > 1 && type[1] ==
'V') {
620 if (type.find(
'N') != std::string::npos) {
621 throw ProcessError(
"'" + *i +
"' does not contain the needed information about the time described.");
624 }
else if (type.length() > 1 && type[1] ==
'O') {
626 if (type.find(
'N') != std::string::npos) {
627 throw ProcessError(
"'" + *i +
"' does not contain the needed information about the time described.");
631 throw ProcessError(
"'" + *i +
"' uses an unknown matrix type '" + type +
"'.");
634 std::vector<std::string> amitranFiles = oc.
getStringVector(
"od-amitran-files");
635 for (std::vector<std::string>::iterator i = amitranFiles.begin(); i != amitranFiles.end(); ++i) {
637 throw ProcessError(
"Could not access matrix file '" + *i +
"' to load.");
652 std::vector<std::string> routeFiles = oc.
getStringVector(
"route-files");
653 for (std::vector<std::string>::iterator i = routeFiles.begin(); i != routeFiles.end(); ++i) {
655 throw ProcessError(
"Could not access route file '" + *i +
"' to load.");
670 if (timelineDayInHours) {
671 if (def.size() != 24) {
672 throw ProcessError(
"Assuming 24 entries for a day timeline, but got " +
toString(def.size()) +
".");
674 for (
int chour = 0; chour < 24; ++chour) {
677 result.
add(24 * 3600., 0.);
679 for (
int i = 0; i < (int)def.size(); i++) {
681 if (st2.
size() != 2) {
682 throw ProcessError(
"Broken time line definition: missing a value in '" + def[i] +
"'.");
bool isSet(const std::string &name, bool failOnNonExistant=true) const
Returns the information whether the named option is set.
bool add(T val, double prob, bool checkDuplicates=true)
Adds a value with an assigned probability to the distribution.
Distribution_Points parseTimeLine(const std::vector< std::string > &def, bool timelineDayInHours)
split the given timeline
static bool runParser(GenericSAXHandler &handler, const std::string &file, const bool isNet=false)
Runs the given handler on the given file; returns if everything's ok.
bool originIsEdge
the origin "district" is an edge id
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.
#define WRITE_WARNING(msg)
ODMatrix(const ODDistrictCont &dc)
Constructor.
double vehicleNumber
The number of vehicles.
SAX-handler base for SUMO-files.
Static storage of an output device and its base (abstract) implementation.
bool readLine(LineHandler &lh)
Reads a single (the next) line from the file and reports it to the given LineHandler.
#define PROGRESS_FAILED_MESSAGE()
bool hasNext()
returns the information whether further substrings exist
static double toDouble(const std::string &sData)
converts a string into the double value described by it by calling the char-type converter
std::string getString(const std::string &name) const
Returns the string-value of the named option (only for Option_String)
void setPrecision(int precision=gPrecision)
Sets the precison or resets it to default.
const ODDistrictCont & myDistricts
The districts to retrieve sources/sinks from.
static OptionsCont & getOptions()
Retrieves the options.
std::string next()
returns the next substring when it exists. Otherwise the behaviour is undefined
static const int WHITECHARS
identifier for splitting the given string at all whitespace characters
std::string getRandomSourceFromDistrict(const std::string &name) const
Returns the id of a random source from the named district.
double myNumWritten
Number of written vehicles.
int sinkNumber() const
Returns the number of sinks.
void loadMatrix(OptionsCont &oc)
read a matrix in one of several formats
SUMOTime myBegin
parsed time bounds
bool closeTag(const std::string &comment="")
Closes the most recently opened tag and optionally adds a comment.
const StringVector & getStringVector(const std::string &name) const
Returns the list of string-value of the named option (only for Option_StringVector)
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".
weights: time range begin
SUMOTime parseSingleTime(const std::string &time)
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.
ODCell * cell
The cell of the ODMatrix which generated the vehicle.
OutputDevice & writeAttr(const SumoXMLAttr attr, const T &val)
writes a named attribute
void loadRoutes(OptionsCont &oc, SUMOSAXHandler &handler)
read SUMO routes
static double rand(std::mt19937 *rng=0)
Returns a random real number in [0, 1)
std::string id
The id of the vehicle.
a flow definitio nusing a from-to edges instead of a route (used by router)
A single O/D-matrix cell.
static std::string prune(const std::string &str)
Removes trailing and leading whitechars.
SUMOTime depart
The departure time of the vehicle.
An internal representation of a single vehicle.
std::string vehicleType
Name of the vehicle type.
std::string getFileName() const
Returns the name of the used file.
std::string destination
Name of the destination district.
std::string getRandomSinkFromDistrict(const std::string &name) const
Returns the id of a random sink from the named district.
std::map< const std::pair< const std::string, const std::string >, std::vector< ODCell * > > myShortCut
The loaded cells indexed by origin and destination.
Used for sorting vehicles by their departure (latest first)
std::string time2string(SUMOTime t)
A storage for options typed value containers)
std::vector< ODCell * > myContainer
The loaded cells.
int sourceNumber() const
Returns the number of sources.
const std::vector< double > & getProbs() const
Returns the probabilities assigned to the members of the distribution.
bool hasMore() const
Returns whether another line may be read (the file was not read completely)
double myNumDiscarded
Number of discarded vehicles.
Retrieves a file linewise and reports the lines to a handler.
SUMOTime string2time(const std::string &r)
int size() const
returns the number of existing substrings
bool good() const
Returns the information whether the stream is readable.
SUMOTime end
The end time this cell describes.
double readFactor(LineReader &lr, double scale)
An XML-Handler for districts.
A container for districts.
std::string to
The edge the vehicles shall end at.
double getFloat(const std::string &name) const
Returns the double-value of the named option (only for Option_Float)
OutputDevice & openTag(const std::string &xmlElement)
Opens an XML tag.
std::string toString(const T &t, std::streamsize accuracy=gPrecision)
static int toInt(const std::string &sData)
converts a string into the integer value described by it by calling the char-type converter,...
double getNumLoaded() const
Returns the number of loaded vehicles.
#define PROGRESS_BEGIN_MESSAGE(msg)
std::pair< SUMOTime, SUMOTime > readTime(LineReader &lr)
std::string origin
Name of the origin district.
double getNumWritten() const
Returns the number of written vehicles.
std::string getNextNonCommentLine(LineReader &lr)
T get(const std::string &id) const
Retrieves an item.
bool destinationIsEdge
the destination "district" is an edge id
#define PROGRESS_DONE_MESSAGE()
void readO(LineReader &lr, double scale, std::string vehType, bool matrixHasVehType)
read a VISUM-matrix with the O Format
static bool isReadable(std::string path)
Checks whether the given file is readable.
double getNumDiscarded() const
Returns the number of discarded vehicles.
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.
void applyCurve(const Distribution_Points &ps)
Splits the stored cells dividing them on the given time line.
void readV(LineReader &lr, double scale, std::string vehType, bool matrixHasVehType)
read a VISUM-matrix with the V Format
Used for sorting the cells by the begin time they describe.
SUMOTime begin
The begin time this cell describes.
double getOverallProb() const
Return the sum of the probabilites assigned to the members.
double myNumLoaded
Number of loaded vehicles.
std::map< SUMOTime, std::vector< std::string > > departures
mapping of departure times to departing vehicles, if already fixed
std::string from
The edge the vehicles shall start at.
a single trip definition (used by router)
const std::vector< T > & getVals() const
Returns the members of the distribution.
void writeDefaultAttrs(OutputDevice &dev, const bool noVtype, const ODCell *const cell)
Helper function for flow and trip output writing the depart and arrival attributes.
std::set< std::string > myMissingDistricts
The missing districts already warned about.