Stride Reference Manual  - generated for commit 9643b11
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Generator.h
Go to the documentation of this file.
1 /*
2  * This is free software: you can redistribute it and/or modify it
3  * under the terms of the GNU General Public License as published by
4  * the Free Software Foundation, either version 3 of the License, or
5  * any later version.
6  * The software is distributed in the hope that it will be useful,
7  * but WITHOUT ANY WARRANTY; without even the implied warranty of
8  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
9  * GNU General Public License for more details.
10  * You should have received a copy of the GNU General Public License
11  * along with the software. If not, see <http://www.gnu.org/licenses/>.
12  *
13  * Copyright 2018, 2019, Jan Broeckhove and Bistromatics group.
14  */
15 
16 #pragma once
17 
18 #include "contact/ContactType.h"
19 
20 #include "geopop/GeoGridConfig.h"
21 #include "geopop/Location.h"
22 #include "pop/Population.h"
23 #include "util/RnMan.h"
24 #include "util/LogUtils.h"
25 
26 #include <spdlog/logger.h>
27 
28 namespace geopop {
29 
30 class GeoGrid;
31 
32 
36 template <typename stride::ContactType::Id ID>
37 class Generator
38 {
39 public:
41  explicit Generator(stride::util::RnMan rnMan, std::shared_ptr<spdlog::logger> logger = nullptr)
42  : m_rn_man(std::move(rnMan)), m_logger(std::move(logger))
43  {
44  if (!m_logger)
46  }
47 
49  ~Generator() = default;
50 
52  void Apply(GeoGrid&, const GeoGridConfig&) {}
53 
55  void AddPools(Location& loc, stride::Population* pop, const GeoGridConfig& ggConfig)
56  {
57  auto& poolSys = pop->RefPoolSys();
58  for (auto i = 0U; i < ggConfig.pools[ID]; ++i) {
59  const auto p = poolSys.CreateContactPool(ID);
60  loc.RegisterPool<ID>(p);
61  }
62  }
63 
64 protected:
66  std::shared_ptr<spdlog::logger> m_logger;
67 };
68 
69 // ---------------------------------------------------------------
70 // Declare specializations (implemntation in separate .cpp files).
71 // ---------------------------------------------------------------
72 template<>
74 
75 template<>
77 
78 template<>
80 
81 template<>
83 
84 template<>
86 
87 template<>
89 
90 // ---------------------------------------------------------------
91 // Shorthand definitions.
92 // ---------------------------------------------------------------
99 
100 } // namespace geopop
Configuration data mostly for generating a population, but also for computing the required number of ...
Definition: GeoGridConfig.h:35
~Generator()=default
Default is OK.
void RegisterPool(stride::ContactPool *p, stride::ContactType::Id typeId)
Register a ContactPool pointer in this Location&#39;s pool system.
Definition: Location.h:132
STL namespace.
A Geographic grid of simulation region contains Locations that in turn contain an index to the Contac...
Definition: GeoGrid.h:41
ContactPoolSys & RefPoolSys()
Reference the ContactPoolSys of the Population.
Definition: Population.h:80
std::shared_ptr< spdlog::logger > m_logger
Logger used by generators.
Definition: Generator.h:66
Interface of RnMan.
Key Data structure: container for (a) all individuals in the population (b) the ContactPoolSys wchich...
Definition: Population.h:47
Definition of ContactPool Id Type.
Logging (spdlog) utilities.
Namespace for the geographic and demograhic classes.
Definition: Coordinate.h:21
void Apply(GeoGrid &, const GeoGridConfig &)
Generate ContactPools for ContactType::Id as sepcified by data in GeoGridConfig.
Definition: Generator.h:52
stride::util::RnMan m_rn_man
RnManager used by generators.
Definition: Generator.h:65
Header file for the core Population class.
Generator uses geo & pop data to construct ContactPools in the GeoGrid.
Definition: Generator.h:37
ContactPool * CreateContactPool(ContactType::Id typeId)
Create a new contact pool of a given type.
Generator(stride::util::RnMan rnMan, std::shared_ptr< spdlog::logger > logger=nullptr)
Constructor with random number manager and logger.
Definition: Generator.h:41
Location for use within the GeoGrid, contains Coordinate and index to ContactPools.
Definition: Location.h:41
void AddPools(Location &loc, stride::Population *pop, const GeoGridConfig &ggConfig)
Create a given number ContactPools in the GeoGrid.
Definition: Generator.h:55
stride::ContactType::IdSubscriptArray< unsigned int > pools
Pools per unit (= Household, K12School, College, etc.) for each of the ContactTypes.
Definition: GeoGridConfig.h:52
static std::shared_ptr< spdlog::logger > CreateNullLogger(const std::string &logger_name="null_logger")
Return a (not-yet-registered) null logger, without registering it.
Definition: LogUtils.cpp:71