Stride Reference Manual
1.0
|
Generate Populations. More...
#include <PopulationGenerator.h>
Public Member Functions | |
PopulationGenerator (const string &filename, const int &seed, bool output=true) | |
Constructor: Check if the xml is valid and set up the basic things like a random generator. More... | |
void | generate (const string &prefix) |
Generates a population, writes the result to the files found in the data directory Output files are respectively formatted according to the following template files: belgium_population.csv, pop_miami.csv, pop_miami_geo.csv. More... | |
Private Member Functions | |
void | writeCities (const string &target_cities) |
Writes the cities to the file, see PopulationGenerator::generate, recently, the villages have been added to this. More... | |
void | writePop (const string &target_pop) const |
Writes the population to the file, see PopulationGenerator::generate. More... | |
void | writeHouseholds (const string &target_households) const |
Writes the households to the file, see PopulationGenerator::generate. More... | |
void | writeClusters (const string &target_clusters) const |
Writes the clusters to the file (type, ID and coordinates), see PopulationGenerator::generate. More... | |
void | checkForValidXML () const |
Checks the xml on correctness, this includes only semantic errors, no syntax errors. More... | |
void | makeHouseholds () |
Generates all households (not yet their positions) More... | |
void | makeCities () |
Generate all cities (without inhabitants) More... | |
GeoCoordinate | getCityMiddle () const |
Gets the middle of all cities. More... | |
double | getCityRadius (const GeoCoordinate &coord) const |
Returns the distance between the given coordinate and the furthest city (in km) More... | |
double | getCityPopulation () const |
Get the population of all the cities combined (if they were on full capacity) More... | |
double | getVillagePopulation () const |
Get the population of all the villages combined (if they were on full capacity) More... | |
void | makeVillages () |
Generate all villages (without inhabitants) More... | |
template<typename T > | |
vector< pair< GeoCoordinate, map< double, vector< uint > > > > | makeDistanceMap (double radius, double factor, const vector< T > &clusters) const |
Precompute the distances between the locations of the clusters (given as an argument) and the districts (villages and cities) The distances measured will start at the radius given as an argument If not all clusters are within that radius, the radius will be mulktiplied with the given factor until all clusters have their distance computed The result is a vector of pairs, where each pair maps a coordinate of a city to another map This inner map has a radius as a key and a vector of indices as its value, these indices refer to the clusters passed as an argument assume ret_val is the return value: ret_val.at(x).second[10.0] = the indices of all clusters within a radius of 10.0 kilometres of a certain city ret_val.at(x).first = the coordinate of the "certain city" used above. More... | |
template<typename T > | |
vector< pair< GeoCoordinate, map< double, vector< uint > > > > | makeDistanceMap (double radius, double factor, const vector< vector< T >> &clusters) const |
Specialization of makeDistanceMap, except now the clusters aren't a vector of clusters anymore, instead, they are a vector of vectors This is because the schools are a cluster of clusters (and thus a vector of vectors) More... | |
vector< uint > | getClustersWithinRange (double radius, const vector< pair< GeoCoordinate, map< double, vector< uint >>>> &distance_map, GeoCoordinate coordinate) const |
Get the clusters that are within the range of a certain coordinate and radius (both given as an argument) The distances are precomputed by PopulationGenerator::makeDistanceMap and the result of that function has to be passed as an argument to this function. More... | |
void | placeHouseholds () |
Assign the households to a city/village. More... | |
template<typename C > | |
void | placeClusters (uint size, uint min_age, uint max_age, double fraction, C &clusters, string cluster_name, ClusterType cluster_type, bool add_location=true) |
Spreads the clusters of people with these constraints over the cities and villages size: the size of each cluster min_age and max_age: the category of people that belongs to these clusters (e.g. More... | |
void | makeSchools () |
Make the schools, place them in a village/city. More... | |
void | makeUniversities () |
Make the universities, place them in a city. More... | |
void | sortWorkplaces () |
Make sure workplaces are sorted: workplaces in bigger cities are in front of workplaces in smaller cities. More... | |
void | makeWork () |
Make workplaces Note: due to the fact that the cluster size of workplaces must be respected, the amount of working people will never be above a fixed certain percentage. More... | |
void | makeCommunities () |
Make the communities. More... | |
template<typename T > | |
vector< uint > | getClusters (GeoCoordinate coord, double radius, const vector< T > &clusters) const |
Get all clusters within a certain radius of the given point, choose those clusters from the given vector of clusters. More... | |
void | assignToSchools () |
Put children in mandatory schools. More... | |
void | assignToUniversities () |
Put students in universities. More... | |
void | removeFromUniMap (vector< pair< GeoCoordinate, map< double, vector< uint >>>> &distance_map, uint index) const |
Remove an element from the university map (the university map is special compared to other cluster maps, this is because a university is a cluster of clusters) More... | |
bool | removeFromMap (vector< pair< GeoCoordinate, map< double, vector< uint >>>> &distance_map, uint index) const |
Remove an element from the map (of regular clusters, not like universities, because they represent a cluster of clusters) Return true if the element is deleted, false if not. More... | |
void | assignCommutingStudent (SimplePerson &person, vector< pair< GeoCoordinate, map< double, vector< uint >>>> &distance_map) |
Put one student in a university according to the rules of commuting students. More... | |
void | assignCloseStudent (SimplePerson &person, double start_radius, vector< pair< GeoCoordinate, map< double, vector< uint >>>> &distance_map) |
Put one student in a university according to the rules of students that study close to their home. More... | |
void | assignToWork () |
Assign people to a workplace. More... | |
bool | assignCommutingEmployee (SimplePerson &person, vector< pair< GeoCoordinate, map< double, vector< uint >>>> &distance_map) |
Assign one person to a workplace according to the rule of commuting workers. More... | |
bool | assignCloseEmployee (SimplePerson &person, double start_radius, vector< pair< GeoCoordinate, map< double, vector< uint >>>> &distance_map) |
Assign one person to a workplace according to the rule of workers that work close to their home. More... | |
void | assignToCommunities (vector< pair< GeoCoordinate, map< double, vector< uint >>>> &distance_map, vector< SimpleCluster > &clusters, uint SimplePerson::*member, const string &name="") |
Assign entire households. More... | |
Private Attributes | |
boost::property_tree::ptree | m_props |
U | m_rng |
More... | |
uint | m_total |
More... | |
vector< SimplePerson > | m_people |
More... | |
vector< SimpleHousehold > | m_households |
More... | |
vector< SimpleCity > | m_cities |
More... | |
vector< SimpleCluster > | m_villages |
More... | |
vector< SimpleCluster > | m_workplaces |
More... | |
vector< SimpleCluster > | m_primary_communities |
More... | |
vector< SimpleCluster > | m_secondary_communities |
More... | |
vector< SimpleCluster > | m_mandatory_schools |
More... | |
vector< vector< SimpleCluster > > | m_optional_schools |
More... | |
bool | m_output |
More... | |
vector< vector< SimpleCluster > > | m_mandatory_schools_clusters |
TODO refactor this, it should be this structure from the beginning (see m_mandatory_schools) More... | |
uint | m_next_id |
More... | |
map< uint, uint > | m_age_distribution |
More... | |
map< uint, uint > | m_household_size |
More... | |
map< uint, uint > | m_work_size |
More... | |
map< pair< ClusterType, uint >, GeoCoordinate > | m_locations |
More... | |
Generate Populations.
Definition at line 33 of file PopulationGenerator.h.
PopulationGenerator::PopulationGenerator | ( | const string & | filename, |
const int & | seed, | ||
bool | output = true |
||
) |
Constructor: Check if the xml is valid and set up the basic things like a random generator.
Definition at line 18 of file PopulationGenerator.cpp.
References stride::util::InstallDirs::getDataDir().
void PopulationGenerator::generate | ( | const string & | prefix | ) |
Generates a population, writes the result to the files found in the data directory Output files are respectively formatted according to the following template files: belgium_population.csv, pop_miami.csv, pop_miami_geo.csv.
Definition at line 53 of file PopulationGenerator.cpp.
References stride::util::InstallDirs::getDataDir(), stride::popgen::SimplePerson::m_primary_community, and stride::popgen::SimplePerson::m_secondary_community.
|
private |
Writes the cities to the file, see PopulationGenerator::generate, recently, the villages have been added to this.
Definition at line 106 of file PopulationGenerator.cpp.
References stride::util::InstallDirs::getDataDir().
|
private |
Writes the population to the file, see PopulationGenerator::generate.
Definition at line 169 of file PopulationGenerator.cpp.
References stride::util::InstallDirs::getDataDir().
|
private |
Writes the households to the file, see PopulationGenerator::generate.
Definition at line 193 of file PopulationGenerator.cpp.
References stride::util::InstallDirs::getDataDir().
|
private |
Writes the clusters to the file (type, ID and coordinates), see PopulationGenerator::generate.
Definition at line 214 of file PopulationGenerator.cpp.
References stride::util::InstallDirs::getDataDir(), stride::Household, stride::Null, stride::PrimaryCommunity, stride::School, stride::SecondaryCommunity, stride::toString(), and stride::Work.
|
private |
Checks the xml on correctness, this includes only semantic errors, no syntax errors.
RNG is already valid at this point (made in constructor) Check for family tag must be done during parsing
Check for the provinces
Valid commuting data: the start radius is a positive double, and the factor is a double greater than 1
Cities: unique location
Check for valid villages
Check for valid Education Mandatory education
Optional education
Check for valid work
Check for valid communities
Definition at line 248 of file PopulationGenerator.cpp.
|
private |
Generates all households (not yet their positions)
Uniformly choose between the given family configurations
Get the family configuration
Make the configuration into reality
For visualisation purposes
For visualisation purposes
Definition at line 436 of file PopulationGenerator.cpp.
References stride::popgen::SimplePerson::m_household_id, stride::popgen::SimpleHousehold::m_id, stride::popgen::SimpleHousehold::m_indices, and stride::popgen::FamilyParser::parseFamilies().
|
private |
Generate all cities (without inhabitants)
Important, make sure the vector is sorted (biggest to smallest)!
Definition at line 480 of file PopulationGenerator.cpp.
References stride::popgen::SimpleCity::m_max_size.
|
private |
Gets the middle of all cities.
Definition at line 511 of file PopulationGenerator.cpp.
References stride::util::GeoCoordinate::m_latitude, and stride::util::GeoCoordinate::m_longitude.
|
private |
Returns the distance between the given coordinate and the furthest city (in km)
Definition at line 528 of file PopulationGenerator.cpp.
References stride::util::GeoCoordCalculator::getDistance(), and stride::util::GeoCoordCalculator::getInstance().
|
private |
Get the population of all the cities combined (if they were on full capacity)
Definition at line 543 of file PopulationGenerator.cpp.
|
private |
Get the population of all the villages combined (if they were on full capacity)
Definition at line 554 of file PopulationGenerator.cpp.
|
private |
Generate all villages (without inhabitants)
Get the configuration of the villages (relative occurrence, minimum and maximum population)
Depending on the relative occurrence of a village, choose this village
Make sure this isn't a duplicate coordinate
Definition at line 565 of file PopulationGenerator.cpp.
References stride::util::GeoCoordCalculator::generateRandomCoord(), stride::util::GeoCoordCalculator::getInstance(), stride::popgen::SimpleCluster::m_coord, stride::popgen::SimpleCluster::m_id, stride::popgen::SimpleCluster::m_max_size, stride::popgen::MinMax::max, and stride::popgen::MinMax::min.
|
inlineprivate |
Precompute the distances between the locations of the clusters (given as an argument) and the districts (villages and cities) The distances measured will start at the radius given as an argument If not all clusters are within that radius, the radius will be mulktiplied with the given factor until all clusters have their distance computed The result is a vector of pairs, where each pair maps a coordinate of a city to another map This inner map has a radius as a key and a vector of indices as its value, these indices refer to the clusters passed as an argument assume ret_val is the return value: ret_val.at(x).second[10.0] = the indices of all clusters within a radius of 10.0 kilometres of a certain city ret_val.at(x).first = the coordinate of the "certain city" used above.
Definition at line 90 of file PopulationGenerator.h.
References stride::util::GeoCoordCalculator::getDistance(), and stride::util::GeoCoordCalculator::getInstance().
|
inlineprivate |
Specialization of makeDistanceMap, except now the clusters aren't a vector of clusters anymore, instead, they are a vector of vectors This is because the schools are a cluster of clusters (and thus a vector of vectors)
Definition at line 164 of file PopulationGenerator.h.
References stride::util::GeoCoordCalculator::getDistance(), and stride::util::GeoCoordCalculator::getInstance().
|
inlineprivate |
Get the clusters that are within the range of a certain coordinate and radius (both given as an argument) The distances are precomputed by PopulationGenerator::makeDistanceMap and the result of that function has to be passed as an argument to this function.
Definition at line 225 of file PopulationGenerator.h.
|
private |
Assign the households to a city/village.
Note that this number may slightly differ from other "total pop" numbers
Get the relative occurrences of both the villages and cities => randomly choose an index in this vector based on that Note that the vector consists of 2 parts: the first one for the cities, the second one for the villages, keep this in mind when generating the random index
A city has been chosen
A village has been chosen
Definition at line 627 of file PopulationGenerator.cpp.
References stride::Household, stride::popgen::SimpleCluster::m_coord, stride::popgen::SimpleCity::m_coord, stride::popgen::SimpleCluster::m_current_size, and stride::popgen::SimpleCity::m_current_size.
|
inlineprivate |
Spreads the clusters of people with these constraints over the cities and villages size: the size of each cluster min_age and max_age: the category of people that belongs to these clusters (e.g.
schools an work have a minimum/maximum age)
Get the relative occurrences of both the villages and cities => randomly choose an index in this vector based on that Note that the vector consists of 2 parts: the first one for the cities, the second one for the villages, keep this in mind when generating the random index
Add to a city
Add to a village
Definition at line 251 of file PopulationGenerator.h.
References stride::popgen::SimpleCluster::m_coord, stride::popgen::SimpleCluster::m_id, and stride::popgen::SimpleCluster::m_max_size.
|
private |
Make the schools, place them in a village/city.
Note: schools are "assigned" to villages and cities
Definition at line 674 of file PopulationGenerator.cpp.
References stride::popgen::SimpleCluster::m_coord, stride::popgen::SimpleCluster::m_id, stride::popgen::SimpleCluster::m_max_size, and stride::School.
|
private |
Make the universities, place them in a city.
Note: not +1 as you cannot exceed a certain amount of students
Add a university to the list NOTE: a university is a vector of clusters
Because the last cluster might not fit in the university, this cluster is smaller
Definition at line 706 of file PopulationGenerator.cpp.
References stride::popgen::SimpleCluster::m_coord, stride::popgen::SimpleCluster::m_id, stride::popgen::SimpleCluster::m_max_size, and stride::School.
|
private |
Make sure workplaces are sorted: workplaces in bigger cities are in front of workplaces in smaller cities.
Sorts according to the cities (assumes they are sorted in a way that you might desire)
Definition at line 767 of file PopulationGenerator.cpp.
|
private |
Make workplaces Note: due to the fact that the cluster size of workplaces must be respected, the amount of working people will never be above a fixed certain percentage.
Make sure the work clusters are sorted from big city to smaller city
Definition at line 791 of file PopulationGenerator.cpp.
References stride::Work.
|
private |
Make the communities.
TODO? Currently not doing the thing with the average communities per person, right now, everyone gets two communities
Definition at line 831 of file PopulationGenerator.cpp.
References stride::PrimaryCommunity, and stride::SecondaryCommunity.
|
inlineprivate |
Get all clusters within a certain radius of the given point, choose those clusters from the given vector of clusters.
Definition at line 333 of file PopulationGenerator.h.
References stride::util::GeoCoordCalculator::getDistance(), and stride::util::GeoCoordCalculator::getInstance().
|
private |
Put children in mandatory schools.
Definition at line 843 of file PopulationGenerator.cpp.
|
private |
Put students in universities.
Commuting student
Non-commuting student
Definition at line 895 of file PopulationGenerator.cpp.
|
private |
Remove an element from the university map (the university map is special compared to other cluster maps, this is because a university is a cluster of clusters)
Remove the university from the map if it is full
Definition at line 936 of file PopulationGenerator.cpp.
|
private |
Remove an element from the map (of regular clusters, not like universities, because they represent a cluster of clusters) Return true if the element is deleted, false if not.
Definition at line 970 of file PopulationGenerator.cpp.
|
private |
Put one student in a university according to the rules of commuting students.
Definition at line 993 of file PopulationGenerator.cpp.
References stride::popgen::SimpleCluster::m_current_size, stride::popgen::SimpleCluster::m_id, stride::popgen::SimpleCluster::m_max_size, and stride::popgen::SimplePerson::m_school_id.
|
private |
Put one student in a university according to the rules of students that study close to their home.
Definition at line 1019 of file PopulationGenerator.cpp.
References stride::popgen::SimplePerson::m_coord, stride::popgen::SimpleCluster::m_current_size, stride::popgen::SimpleCluster::m_id, stride::popgen::SimpleCluster::m_max_size, and stride::popgen::SimplePerson::m_school_id.
|
private |
Assign people to a workplace.
Commuting employee
Non-commuting employee
Definition at line 1064 of file PopulationGenerator.cpp.
|
private |
Assign one person to a workplace according to the rule of commuting workers.
TODO ask question: it states that a full workplace has to be ignored but workplaces can be in cities and villages where commuting is only in cities => possible problems with over-employing in cities Behavior on that topic is currently as follows: do the thing that is requested, if all cities are full, it just adds to the first village in the list
Definition at line 1117 of file PopulationGenerator.cpp.
References stride::popgen::SimpleCluster::m_current_size, stride::popgen::SimpleCluster::m_id, stride::popgen::SimpleCluster::m_max_size, and stride::popgen::SimplePerson::m_work_id.
|
private |
Assign one person to a workplace according to the rule of workers that work close to their home.
Definition at line 1141 of file PopulationGenerator.cpp.
References stride::popgen::SimplePerson::m_coord, stride::popgen::SimpleCluster::m_current_size, stride::popgen::SimpleCluster::m_id, stride::popgen::SimpleCluster::m_max_size, and stride::popgen::SimplePerson::m_work_id.
|
private |
Assign entire households.
Remove the community if it is full
Definition at line 1172 of file PopulationGenerator.cpp.
References stride::popgen::SimpleCluster::m_current_size, stride::popgen::SimpleCluster::m_id, and stride::popgen::SimpleCluster::m_max_size.
|
private |
Definition at line 382 of file PopulationGenerator.h.
|
private |
The content of the xml file
Definition at line 383 of file PopulationGenerator.h.
|
private |
The random generator
Definition at line 384 of file PopulationGenerator.h.
|
private |
The total amount of people to be generated (according to the xml)
Definition at line 385 of file PopulationGenerator.h.
|
private |
All the people
Definition at line 386 of file PopulationGenerator.h.
|
private |
The households (a household is a vector of indices in the vector above)
Definition at line 387 of file PopulationGenerator.h.
|
private |
The cities
Definition at line 388 of file PopulationGenerator.h.
|
private |
The villages
Definition at line 389 of file PopulationGenerator.h.
|
private |
The workplaces
Definition at line 390 of file PopulationGenerator.h.
|
private |
The primary communities
Definition at line 391 of file PopulationGenerator.h.
|
private |
The secondary communities
Definition at line 392 of file PopulationGenerator.h.
|
private |
Mandatory schools (Not divided in clusters!!!)
Definition at line 393 of file PopulationGenerator.h.
|
private |
The universities: One univ is a vector of clusters, ordering is the same as the cities they belong to (using modulo of course)
Definition at line 395 of file PopulationGenerator.h.
|
private |
TODO refactor this, it should be this structure from the beginning (see m_mandatory_schools)
Definition at line 398 of file PopulationGenerator.h.
|
private |
The clusters of the mandatory schools, this should be refactored
Definition at line 400 of file PopulationGenerator.h.
|
private |
The next id for the nex cluster/school/... ID's are supposed to be unique
Data for visualisation
Definition at line 404 of file PopulationGenerator.h.
|
private |
The age distribution (histogram)
Definition at line 405 of file PopulationGenerator.h.
|
private |
The household size (histogram)
Definition at line 406 of file PopulationGenerator.h.
|
private |
The size of workplaces (histogram)
Definition at line 408 of file PopulationGenerator.h.