54 #ifdef CHECK_MEMORY_LEAKS 56 #endif // CHECK_MEMORY_LEAKS 63 : myDistricts(dc), myNumLoaded(0), myNumWritten(0), myNumDiscarded(0) {}
76 SUMOTime end,
const std::string& origin,
const std::string& destination,
77 const std::string& vehicleType) {
80 WRITE_WARNING(
"Missing origin '" + origin +
"' and destination '" + destination +
"' (" +
toString(vehicleNumber) +
" vehicles).");
89 }
else if (
myDistricts.
get(destination) == 0 && vehicleNumber > 0) {
90 WRITE_ERROR(
"Missing destination '" + destination +
"' (" +
toString(vehicleNumber) +
" vehicles).");
96 WRITE_ERROR(
"District '" + origin +
"' has no source.");
100 WRITE_ERROR(
"District '" + destination +
"' has no sink.");
118 const std::pair<const std::string, const std::string>& od,
119 const std::string& vehicleType) {
126 std::vector<ODCell*>& odList =
myShortCut[od];
128 for (std::vector<ODCell*>::const_reverse_iterator c = odList.rbegin(); c != odList.rend(); ++c) {
129 if ((*c)->begin <= depart && (*c)->end > depart && (*c)->vehicleType == vehicleType) {
136 const int intervalIdx = (int)(depart / interval);
137 if (
add(1., intervalIdx * interval, (intervalIdx + 1) * interval, od.first, od.second, vehicleType)) {
139 odList.push_back(cell);
154 int& vehName, std::vector<ODVehicle>& into,
155 const bool uniform,
const bool differSourceSink,
156 const std::string& prefix) {
162 if (vehicles2insert == 0) {
167 for (
int i = 0; i < vehicles2insert; ++i) {
180 }
while (canDiffer && differSourceSink && (veh.
to == veh.
from));
181 if (!canDiffer && differSourceSink && (veh.
to == veh.
from)) {
193 const ODCell*
const cell) {
199 if (oc.
isSet(
"departlane") && oc.
getString(
"departlane") !=
"default") {
202 if (oc.
isSet(
"departpos")) {
205 if (oc.
isSet(
"departspeed") && oc.
getString(
"departspeed") !=
"default") {
208 if (oc.
isSet(
"arrivallane")) {
211 if (oc.
isSet(
"arrivalpos")) {
214 if (oc.
isSet(
"arrivalspeed")) {
223 const bool differSourceSink,
const bool noVtype,
224 const std::string& prefix,
const bool stepLog) {
228 std::map<std::pair<std::string, std::string>,
SUMOReal> fractionLeft;
233 std::vector<ODCell*>::iterator next =
myContainer.begin();
234 std::vector<ODVehicle> vehicles;
237 for (
SUMOTime t = begin; t < end;) {
238 if (stepLog && t - lastOut >=
DELTA_T) {
239 std::cout <<
"Parsing time " +
time2string(t) <<
'\r';
243 bool changed =
false;
244 while (next !=
myContainer.end() && (*next)->begin <= t && (*next)->end > t) {
245 std::pair<std::string, std::string> odID = std::make_pair((*next)->origin, (*next)->destination);
247 if (fractionLeft.find(odID) != fractionLeft.end()) {
248 (*next)->vehicleNumber += fractionLeft[odID];
249 fractionLeft[odID] = 0;
252 const int oldSize = (int)vehicles.size();
254 if (oldSize != (
int)vehicles.size()) {
258 fractionLeft[odID] = fraction;
265 for (std::vector<ODVehicle>::reverse_iterator i = vehicles.rbegin(); i != vehicles.rend() && (*i).depart == t; ++i) {
274 while (vehicles.size() != 0 && vehicles.back().depart == t) {
277 if (!vehicles.empty()) {
278 t = vehicles.back().depart;
280 if (next !=
myContainer.end() && (t > (*next)->begin || vehicles.empty())) {
283 if (next ==
myContainer.end() && vehicles.empty()) {
293 const std::string& prefix) {
301 const ODCell*
const c = *i;
302 if (c->
end > begin && c->
begin < end) {
318 if (line[0] !=
'*') {
328 if (time.find(
'.') == std::string::npos) {
331 std::string hours = time.substr(0, time.find(
'.'));
332 std::string minutes = time.substr(time.find(
'.') + 1);
337 std::pair<SUMOTime, SUMOTime>
345 throw ProcessError(
"Begin time is larger than end time.");
347 return std::make_pair(begin, end);
349 throw ProcessError(
"Broken period definition '" + line +
"'.");
351 throw ProcessError(
"Broken period definition '" + line +
"'.");
369 std::string vehType,
bool matrixHasVehType) {
373 if (matrixHasVehType) {
381 std::pair<SUMOTime, SUMOTime> times =
readTime(lr);
392 std::vector<std::string> names;
397 names.push_back(st2.
next());
399 }
while ((
int) names.size() != districtNo);
402 for (std::vector<std::string>::iterator si = names.begin(); si != names.end(); ++si) {
403 std::vector<std::string>::iterator di = names.begin();
407 if (line.length() == 0) {
413 assert(di != names.end());
415 if (vehNumber != 0) {
416 add(vehNumber, begin, end, *si, *di, vehType);
418 if (di == names.end()) {
419 throw ProcessError(
"More entries than districts found.");
424 throw ProcessError(
"Not numeric vehicle number in line '" + line +
"'.");
429 }
while (di != names.end());
437 std::string vehType,
bool matrixHasVehType) {
441 if (matrixHasVehType) {
450 std::pair<SUMOTime, SUMOTime> times =
readTime(lr);
460 if (line.length() == 0) {
464 if (st2.
size() == 0) {
468 std::string sourceD = st2.
next();
469 std::string destD = st2.
next();
471 if (vehNumber != 0) {
472 add(vehNumber, begin, end, sourceD, destD, vehType);
475 throw ProcessError(
"Missing at least one information in line '" + line +
"'.");
477 throw ProcessError(
"Not numeric vehicle number in line '" + line +
"'.");
505 for (
int i = 0; i < ps.
getAreaNo(); ++i) {
513 newCells.push_back(ncell);
522 for (std::vector<ODCell*>::iterator i = oldCells.begin(); i != oldCells.end(); ++i) {
523 std::vector<ODCell*> newCells;
525 copy(newCells.begin(), newCells.end(), back_inserter(
myContainer));
533 std::vector<std::string> files = oc.
getStringVector(
"od-matrix-files");
534 for (std::vector<std::string>::iterator i = files.begin(); i != files.end(); ++i) {
541 if (type.find(
';') != std::string::npos) {
542 type = type.substr(0, type.find(
';'));
545 if (type.length() > 1 && type[1] ==
'V') {
547 if (type.find(
'N') != std::string::npos) {
548 throw ProcessError(
"'" + *i +
"' does not contain the needed information about the time described.");
551 }
else if (type.length() > 1 && type[1] ==
'O') {
553 if (type.find(
'N') != std::string::npos) {
554 throw ProcessError(
"'" + *i +
"' does not contain the needed information about the time described.");
558 throw ProcessError(
"'" + *i +
"' uses an unknown matrix type '" + type +
"'.");
561 std::vector<std::string> amitranFiles = oc.
getStringVector(
"od-amitran-files");
562 for (std::vector<std::string>::iterator i = amitranFiles.begin(); i != amitranFiles.end(); ++i) {
564 throw ProcessError(
"Could not access matrix file '" + *i +
"' to load.");
579 std::vector<std::string> routeFiles = oc.
getStringVector(
"route-files");
580 for (std::vector<std::string>::iterator i = routeFiles.begin(); i != routeFiles.end(); ++i) {
582 throw ProcessError(
"Could not access route file '" + *i +
"' to load.");
596 bool interpolating = !timelineDayInHours;
599 if (timelineDayInHours) {
600 if (def.size() != 24) {
601 throw ProcessError(
"Assuming 24 entries for a day timeline, but got " +
toString(def.size()) +
".");
603 for (
int chour = 0; chour < 24; ++chour) {
610 while (i < (
int)def.size()) {
612 if (st2.
size() != 2) {
613 throw ProcessError(
"Broken time line definition: missing a value in '" + def[i - 1] +
"'.");
617 points.push_back(
Position(time, prob));
SUMOReal myNumWritten
Number of written vehicles.
void writeDefaultAttrs(OutputDevice &dev, const bool noVtype, const ODCell *const cell)
Helper function for flow and trip output writing the depart and arrival attributes.
OutputDevice & writeAttr(const SumoXMLAttr attr, const T &val)
writes a named attribute
Used for sorting the cells by the begin time they describe.
std::vector< std::string > getStringVector(const std::string &name) const
Returns the list of string-vector-value of the named option (only for Option_String) ...
SUMOReal getNumLoaded() const
Returns the number of loaded vehicles.
static bool isReadable(std::string path)
Checks whether the given file is readable.
bool readLine(LineHandler &lh)
Reads a single (the next) line from the file and reports it to the given LineHandler.
static SUMOReal _2SUMOReal(const E *const data)
converts a char-type array into the SUMOReal value described by it
static const int WHITECHARS
Retrieves a file linewise and reports the lines to a handler.
int sinkNumber() const
Returns the number of sinks.
const ODDistrictCont & myDistricts
The districts to retrieve sources/sinks from.
An internal representation of a single vehicle.
static SUMOReal rand()
Returns a random real number in [0, 1)
std::string time2string(SUMOTime t)
SUMOReal getFloat(const std::string &name) const
Returns the SUMOReal-value of the named option (only for Option_Float)
SAX-handler base for SUMO-files.
std::string from
The edge the vehicles shall start at.
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.
SUMOTime parseSingleTime(const std::string &time)
#define WRITE_WARNING(msg)
static OptionsCont & getOptions()
Retrieves the options.
void loadMatrix(OptionsCont &oc)
read a matrix in one of several formats
T get(const std::string &id) const
Retrieves an item.
std::string getString(const std::string &name) const
Returns the string-value of the named option (only for Option_String)
#define PROGRESS_FAILED_MESSAGE()
SUMOReal myNumDiscarded
Number of discarded vehicles.
A single O/D-matrix cell.
void readV(LineReader &lr, SUMOReal scale, std::string vehType, bool matrixHasVehType)
read a VISUM-matrix with the V Format
std::string origin
Name of the origin district.
std::string getRandomSourceFromDistrict(const std::string &name) const
Returns the id of a random source from the named district.
A point in 2D or 3D with translation and scaling methods.
SUMOReal getAreaPerc(int index) const
SUMOReal getNumWritten() const
Returns the number of written vehicles.
void readO(LineReader &lr, SUMOReal scale, std::string vehType, bool matrixHasVehType)
read a VISUM-matrix with the O Format
ODCell * cell
The cell of the ODMatrix which generated the vehicle.
void loadRoutes(OptionsCont &oc, SUMOSAXHandler &handler)
read SUMO routes
SUMOTime string2time(const std::string &r)
A container for districts.
#define PROGRESS_BEGIN_MESSAGE(msg)
SUMOReal vehicleNumber
The number of vehicles.
Used for sorting vehicles by their departure (latest first)
std::map< SUMOTime, std::vector< std::string > > departures
mapping of departure times to departing vehicles, if already fixed
std::map< const std::pair< const std::string, const std::string >, std::vector< ODCell * > > myShortCut
The loaded cells indexed by origin and destination.
SUMOReal 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".
std::vector< ODCell * > myContainer
The loaded cells.
std::string toString(const T &t, std::streamsize accuracy=OUTPUT_ACCURACY)
SUMOTime begin
The begin time this cell describes.
bool good() const
Returns the information whether the stream is readable.
void writeFlows(const SUMOTime begin, const SUMOTime end, OutputDevice &dev, const bool noVtype, const std::string &prefix)
Writes the flows stored in the matrix.
SUMOReal readFactor(LineReader &lr, SUMOReal scale)
std::string getFileName() const
Returns the name of the used file.
std::pair< SUMOTime, SUMOTime > readTime(LineReader &lr)
static int _2int(const E *const data)
converts a char-type array into the integer value described by it
std::string getNextNonCommentLine(LineReader &lr)
SUMOTime depart
The departure time of the vehicle.
static std::string prune(const std::string &str)
Removes trailing and leading whitechars.
SUMOReal myNumLoaded
Number of loaded vehicles.
A storage for options typed value containers)
An XML-Handler for districts.
void applyCurve(const Distribution_Points &ps)
Splits the stored cells dividing them on the given time line.
std::string vehicleType
Name of the vehicle type.
Static storage of an output device and its base (abstract) implementation.
SUMOReal getAreaEnd(int index) const
std::string destination
Name of the destination district.
bool closeTag()
Closes the most recently opened tag.
SUMOReal getAreaBegin(int index) const
bool hasMore() const
Returns whether another line may be read (the file was not read completely)
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.
std::string getRandomSinkFromDistrict(const std::string &name) const
Returns the id of a random sink from the named district.
SUMOTime end
The end time this cell describes.
#define PROGRESS_DONE_MESSAGE()
std::string to
The edge the vehicles shall end at.
ODMatrix(const ODDistrictCont &dc)
Constructor.
std::set< std::string > myMissingDistricts
The missing districts already warned about.
std::string id
The id of the vehicle.
OutputDevice & openTag(const std::string &xmlElement)
Opens an XML tag.
int sourceNumber() const
Returns the number of sources.
SUMOReal getNumDiscarded() const
Returns the number of discarded vehicles.
Distribution_Points parseTimeLine(const std::vector< std::string > &def, bool timelineDayInHours)
split the given timeline
bool isSet(const std::string &name, bool failOnNonExistant=true) const
Returns the information whether the named option is set.
bool 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.