Stride Reference Manual  - generated for commit 9643b11
geopop::GeoGrid Class Reference

A Geographic grid of simulation region contains Locations that in turn contain an index to the ContactPools situated at that Location. More...

#include <GeoGrid.h>

Collaboration diagram for geopop::GeoGrid:
Collaboration graph

Public Types

using iterator = std::vector< std::shared_ptr< Location >>::iterator
 
using const_iterator = std::vector< std::shared_ptr< Location >>::const_iterator
 

Public Member Functions

 GeoGrid (stride::Population *population)
 GeoGrid and associated Population. More...
 
 GeoGrid (const GeoGrid &)=delete
 No copy constructor. More...
 
GeoGrid operator= (const GeoGrid &)=delete
 No copy assignment. More...
 
void AddLocation (std::shared_ptr< Location > location)
 Adds a location to this GeoGrid. More...
 
void Finalize ()
 Disables the addLocation method and builds the kdtree. More...
 
std::shared_ptr< LocationGetById (unsigned int id) const
 Gets a Location by Id and check if the Id exists. More...
 
stride::PopulationGetPopulation () const
 Get the Population associated with this GeoGrid. More...
 
std::vector< const Location * > LocationsInRadius (const Location &start, double radius) const
 Search for locations in radius (in km) around start. More...
 
std::vector< stride::ContactPool * > GetNearbyPools (stride::ContactType::Id id, const Location &start, double startRadius=10.0) const
 Find contactpools in startRadius (in km) around start and, if none are found, double the radius and search again until the radius gets infinite. More...
 
std::set< const Location * > LocationsInBox (double long1, double lat1, double long2, double lat2) const
 Gets the locations in a rectangle determined by the two coordinates (long1, lat1) and (long2, lat2). More...
 
std::set< const Location * > LocationsInBox (Location *loc1, Location *loc2) const
 Gets the location in a rectangle defined by the two Locations. More...
 
std::vector< Location * > TopK (size_t k) const
 Gets the K biggest (in population count) locations of this GeoGrid. More...
 
template<typename Policy , typename F >
GeoAggregator< Policy, F > BuildAggregator (F functor, typename Policy::Args &&args) const
 Build a GeoAggregator with a predefined functor and given args for the Policy. More...
 
template<typename Policy >
GeoAggregator< Policy > BuildAggregator (typename Policy::Args &&args) const
 Build a GeoAggregator that gets its functor when calling, with given args for the Policy. More...
 
iterator begin ()
 Iterator to first Location. More...
 
iterator end ()
 Iterator to the end of the Location storage. More...
 
const_iterator cbegin () const
 Const Iterator to first Location. More...
 
const_iterator cend () const
 Const iterator to the end of the Location storage. More...
 
std::shared_ptr< Location > & operator[] (size_t index)
 Gets a Location by index, doesn't performs a range check. More...
 
const std::shared_ptr< Location > & operator[] (size_t index) const
 Gets a Location by index, doesn't performs a range check. More...
 
size_t size () const
 Gets current size of Location storage. More...
 

Private Member Functions

void CheckFinalized (const std::string &functionName) const
 < Checks whether the GeoGrid is finalized i.e. certain operations can(not) be used. More...
 

Private Attributes

std::vector< std::shared_ptr< Location > > m_locations
 < Container for Locations in GeoGrid. More...
 
std::unordered_map< unsigned int, unsigned int > m_id_to_index
 Stores pointer to Popluation, but does not take ownership. More...
 
stride::Populationm_population
 Is the GeoGrid finalized (ready for use) yet? More...
 
bool m_finalized
 Internal KdTree for quick spatial lookup. More...
 
GeoGridKdTree m_tree
 

Detailed Description

A Geographic grid of simulation region contains Locations that in turn contain an index to the ContactPools situated at that Location.

Definition at line 41 of file GeoGrid.h.

Member Typedef Documentation

using geopop::GeoGrid::iterator = std::vector<std::shared_ptr<Location>>::iterator

Definition at line 102 of file GeoGrid.h.

using geopop::GeoGrid::const_iterator = std::vector<std::shared_ptr<Location>>::const_iterator

Definition at line 103 of file GeoGrid.h.

Constructor & Destructor Documentation

geopop::GeoGrid::GeoGrid ( stride::Population population)
explicit

GeoGrid and associated Population.

Definition at line 34 of file GeoGrid.cpp.

geopop::GeoGrid::GeoGrid ( const GeoGrid )
delete

No copy constructor.

Member Function Documentation

GeoGrid geopop::GeoGrid::operator= ( const GeoGrid )
delete

No copy assignment.

void geopop::GeoGrid::AddLocation ( std::shared_ptr< Location location)

Adds a location to this GeoGrid.

Definition at line 39 of file GeoGrid.cpp.

References m_finalized, m_id_to_index, and m_locations.

Referenced by geopop::LocationsCSVReader::FillGeoGrid().

Here is the caller graph for this function:

void geopop::GeoGrid::Finalize ( )

Disables the addLocation method and builds the kdtree.

Definition at line 67 of file GeoGrid.cpp.

References geopop::KdTree< geogrid_detail::KdTree2DPoint >::Build(), m_finalized, m_locations, and m_tree.

Here is the call graph for this function:

std::shared_ptr<Location> geopop::GeoGrid::GetById ( unsigned int  id) const
inline

Gets a Location by Id and check if the Id exists.

Definition at line 60 of file GeoGrid.h.

References m_id_to_index, and m_locations.

Referenced by geopop::GeoGridReader::AddCommutes(), and geopop::CommutesCSVReader::FillGeoGrid().

Here is the caller graph for this function:

stride::Population* geopop::GeoGrid::GetPopulation ( ) const
inline

Get the Population associated with this GeoGrid.

Definition at line 63 of file GeoGrid.h.

References BuildAggregator(), GetNearbyPools(), LocationsInBox(), LocationsInRadius(), m_population, and TopK().

Referenced by geopop::Generator< ID >::Apply(), and geopop::Populator< ID >::Apply().

Here is the call graph for this function:

Here is the caller graph for this function:

vector< const Location * > geopop::GeoGrid::LocationsInRadius ( const Location start,
double  radius 
) const

Search for locations in radius (in km) around start.

Definition at line 98 of file GeoGrid.cpp.

References CheckFinalized(), and geopop::MakeCollector().

Referenced by GetNearbyPools(), and GetPopulation().

Here is the call graph for this function:

Here is the caller graph for this function:

vector< ContactPool * > geopop::GeoGrid::GetNearbyPools ( stride::ContactType::Id  id,
const Location start,
double  startRadius = 10.0 
) const

Find contactpools in startRadius (in km) around start and, if none are found, double the radius and search again until the radius gets infinite.

May return an empty vector when there are really no pools to be found (empty grid).

Definition at line 111 of file GeoGrid.cpp.

References LocationsInRadius().

Referenced by GetPopulation().

Here is the call graph for this function:

Here is the caller graph for this function:

set< const Location * > geopop::GeoGrid::LocationsInBox ( double  long1,
double  lat1,
double  long2,
double  lat2 
) const

Gets the locations in a rectangle determined by the two coordinates (long1, lat1) and (long2, lat2).

The coordinates must be positioned on the diagonal, i.e:

p1 --—+ +----—p1 | | | | | | or | | | | | | +----—p2 p2---—+

Definition at line 77 of file GeoGrid.cpp.

References CheckFinalized(), and geopop::MakeCollector().

Referenced by GetPopulation(), and LocationsInBox().

Here is the call graph for this function:

Here is the caller graph for this function:

set< const Location * > geopop::GeoGrid::LocationsInBox ( Location loc1,
Location loc2 
) const

Gets the location in a rectangle defined by the two Locations.

Definition at line 91 of file GeoGrid.cpp.

References geopop::Location::GetCoordinate(), and LocationsInBox().

Here is the call graph for this function:

vector< Location * > geopop::GeoGrid::TopK ( size_t  k) const

Gets the K biggest (in population count) locations of this GeoGrid.

Definition at line 129 of file GeoGrid.cpp.

References geopop::Location::GetPopCount(), and m_locations.

Referenced by geopop::Generator< ID >::Apply(), and GetPopulation().

Here is the call graph for this function:

Here is the caller graph for this function:

template<typename Policy , typename F >
GeoAggregator< Policy, F > geopop::GeoGrid::BuildAggregator ( functor,
typename Policy::Args &&  args 
) const

Build a GeoAggregator with a predefined functor and given args for the Policy.

Definition at line 49 of file GeoGrid.cpp.

References m_tree.

Referenced by GetPopulation().

Here is the caller graph for this function:

template<typename Policy >
GeoAggregator< Policy > geopop::GeoGrid::BuildAggregator ( typename Policy::Args &&  args) const

Build a GeoAggregator that gets its functor when calling, with given args for the Policy.

Definition at line 55 of file GeoGrid.cpp.

References m_tree.

iterator geopop::GeoGrid::begin ( )
inline

Iterator to first Location.

Definition at line 106 of file GeoGrid.h.

References m_locations.

iterator geopop::GeoGrid::end ( )
inline

Iterator to the end of the Location storage.

Definition at line 109 of file GeoGrid.h.

References m_locations.

const_iterator geopop::GeoGrid::cbegin ( ) const
inline

Const Iterator to first Location.

Definition at line 112 of file GeoGrid.h.

References m_locations.

const_iterator geopop::GeoGrid::cend ( ) const
inline

Const iterator to the end of the Location storage.

Definition at line 115 of file GeoGrid.h.

References m_locations.

std::shared_ptr<Location>& geopop::GeoGrid::operator[] ( size_t  index)
inline

Gets a Location by index, doesn't performs a range check.

Definition at line 118 of file GeoGrid.h.

References m_locations.

const std::shared_ptr<Location>& geopop::GeoGrid::operator[] ( size_t  index) const
inline

Gets a Location by index, doesn't performs a range check.

Definition at line 121 of file GeoGrid.h.

References m_locations.

size_t geopop::GeoGrid::size ( ) const
inline

Gets current size of Location storage.

Definition at line 124 of file GeoGrid.h.

References CheckFinalized(), and m_locations.

Here is the call graph for this function:

void geopop::GeoGrid::CheckFinalized ( const std::string &  functionName) const
private

< Checks whether the GeoGrid is finalized i.e. certain operations can(not) be used.

Definition at line 60 of file GeoGrid.cpp.

References m_finalized.

Referenced by LocationsInBox(), LocationsInRadius(), and size().

Here is the caller graph for this function:

Member Data Documentation

std::vector<std::shared_ptr<Location> > geopop::GeoGrid::m_locations
private

< Container for Locations in GeoGrid.

Associative container maps Location Id to index in m_locations.

Definition at line 132 of file GeoGrid.h.

Referenced by AddLocation(), begin(), cbegin(), cend(), end(), Finalize(), GetById(), operator[](), size(), and TopK().

std::unordered_map<unsigned int, unsigned int> geopop::GeoGrid::m_id_to_index
private

Stores pointer to Popluation, but does not take ownership.

Definition at line 135 of file GeoGrid.h.

Referenced by AddLocation(), and GetById().

stride::Population* geopop::GeoGrid::m_population
private

Is the GeoGrid finalized (ready for use) yet?

Definition at line 138 of file GeoGrid.h.

Referenced by GetPopulation().

bool geopop::GeoGrid::m_finalized
private

Internal KdTree for quick spatial lookup.

Definition at line 141 of file GeoGrid.h.

Referenced by AddLocation(), CheckFinalized(), and Finalize().

GeoGridKdTree geopop::GeoGrid::m_tree
private

Definition at line 144 of file GeoGrid.h.

Referenced by BuildAggregator(), and Finalize().


The documentation for this class was generated from the following files: