40 vector<unsigned int> header;
42 for (
const string& label : reader.
GetLabels()) {
43 header.push_back(static_cast<unsigned int>(stoi(label.substr(3))));
46 const auto columnCount =
static_cast<unsigned int>(reader.
GetColumnCount());
47 map<unsigned int, unsigned int> sizes;
51 for (
const CSVRow& row : reader) {
52 for (
unsigned int columnIndex = 0; columnIndex < columnCount; columnIndex++) {
53 sizes[columnIndex] += row.GetValue<
int>(columnIndex);
58 for (
const CSVRow& row : reader) {
59 for (
auto columnIndex = 0U; columnIndex < columnCount; columnIndex++) {
60 auto abs = row.GetValue<
double>(columnIndex);
61 if (abs != 0 && columnIndex != rowIndex) {
62 const auto& locFrom = geoGrid.
GetById(header[columnIndex]);
63 const auto& locTo = geoGrid.
GetById(header[rowIndex]);
64 const auto& total = sizes[columnIndex];
65 double proportion = abs / total;
67 if (proportion < 0 || proportion > 1) {
68 throw Exception(
"Proportion of commutes from " + to_string(locFrom->GetID()) +
69 " to " + to_string(locTo->GetID()) +
70 " is invalid (0 <= proportion <= 1)");
72 locFrom->AddOutgoingCommute(locTo, proportion);
73 locTo->AddIncomingCommute(locFrom, proportion);
const std::vector< std::string > & GetLabels() const
Utilities for the project.
size_t GetColumnCount() const
Number of columns in the CSV.
CommutesCSVReader(std::unique_ptr< std::istream > istream)
Construct the CommutesCSVReader with an istream containing the CSV data.
A Geographic grid of simulation region contains Locations that in turn contain an index to the Contac...
Basic exception class: needed to prevent clang-tidy warning "thrown exception type is not nothrow cop...
void FillGeoGrid(GeoGrid &geoGrid) const override
Add the found Commutes to the provided GeoGrid.
Namespace for the geographic and demograhic classes.
std::shared_ptr< Location > GetById(unsigned int id) const
Gets a Location by Id and check if the Id exists.
A collection of CSVRow elements.
Header file of base class for config that needs to be read from a file.
Create an abstract Reader that fills a GeoGrid with the commute info from file.
std::unique_ptr< std::istream > m_inputStream
The istream with the file content.