std::string ODMatrix::getNextNonCommentLine(LineReader& lr) { while (lr.good() && lr.hasMore()) { const std::string line = lr.readLine(); if (line[0] != '*') { return StringUtils::prune(line); } } throw ProcessError("End of file while reading " + lr.getFileName() + "."); }
void ODMatrix::readO(LineReader& lr, double scale, std::string vehType, bool matrixHasVehType) { PROGRESS_BEGIN_MESSAGE("Reading matrix '" + lr.getFileName() + "' stored as OR"); // parse first defs std::string line; if (matrixHasVehType) { line = getNextNonCommentLine(lr); int type = TplConvert::_2int(StringUtils::prune(line).c_str()); if (vehType == "") { vehType = toString(type); } } // parse time std::pair<SUMOTime, SUMOTime> times = readTime(lr); SUMOTime begin = times.first; SUMOTime end = times.second; // factor double factor = readFactor(lr, scale); // parse the cells while (lr.hasMore()) { line = getNextNonCommentLine(lr); if (line.length() == 0) { continue; } StringTokenizer st2(line, StringTokenizer::WHITECHARS); if (st2.size() == 0) { continue; } try { std::string sourceD = st2.next(); std::string destD = st2.next(); double vehNumber = TplConvert::_2double(st2.next().c_str()) * factor; if (vehNumber != 0) { add(vehNumber, begin, end, sourceD, destD, vehType); } } catch (OutOfBoundsException&) { throw ProcessError("Missing at least one information in line '" + line + "'."); } catch (NumberFormatException&) { throw ProcessError("Not numeric vehicle number in line '" + line + "'."); } } PROGRESS_DONE_MESSAGE(); }
void ODMatrix::readV(LineReader& lr, double scale, std::string vehType, bool matrixHasVehType) { PROGRESS_BEGIN_MESSAGE("Reading matrix '" + lr.getFileName() + "' stored as VMR"); // parse first defs std::string line; if (matrixHasVehType) { line = getNextNonCommentLine(lr); if (vehType == "") { vehType = StringUtils::prune(line); } } // parse time std::pair<SUMOTime, SUMOTime> times = readTime(lr); SUMOTime begin = times.first; SUMOTime end = times.second; // factor double factor = readFactor(lr, scale); // districts line = getNextNonCommentLine(lr); const int numDistricts = TplConvert::_2int(StringUtils::prune(line).c_str()); // parse district names (normally ints) std::vector<std::string> names; while ((int)names.size() != numDistricts) { line = getNextNonCommentLine(lr); StringTokenizer st2(line, StringTokenizer::WHITECHARS); while (st2.hasNext()) { names.push_back(st2.next()); } } // parse the cells for (std::vector<std::string>::iterator si = names.begin(); si != names.end(); ++si) { std::vector<std::string>::iterator di = names.begin(); // do { line = getNextNonCommentLine(lr); if (line.length() == 0) { continue; } try { StringTokenizer st2(line, StringTokenizer::WHITECHARS); while (st2.hasNext()) { assert(di != names.end()); double vehNumber = TplConvert::_2double(st2.next().c_str()) * factor; if (vehNumber != 0) { add(vehNumber, begin, end, *si, *di, vehType); } if (di == names.end()) { throw ProcessError("More entries than districts found."); } ++di; } } catch (NumberFormatException&) { throw ProcessError("Not numeric vehicle number in line '" + line + "'."); } if (!lr.hasMore()) { break; } } while (di != names.end()); } PROGRESS_DONE_MESSAGE(); }