pops-core  0.9
PoPS (Pest or Pathogen Spread) Model Core C++ library
natural_anthropogenic_kernel.hpp
Go to the documentation of this file.
1 /*
2  * PoPS model - disperal kernel combining natural and anthropogenic dispersals
3  *
4  * Copyright (C) 2015-2020 by the authors.
5  *
6  * Authors: Vaclav Petras (wenzeslaus gmail com)
7  *
8  * The code contained herein is licensed under the GNU General Public
9  * License. You may obtain a copy of the GNU General Public License
10  * Version 2 or later at the following locations:
11  *
12  * http://www.opensource.org/licenses/gpl-license.html
13  * http://www.gnu.org/copyleft/gpl.html
14  */
15 
16 #ifndef POPS_NATURAL_ANTHROPOGENIC_KERNEL_HPP
17 #define POPS_NATURAL_ANTHROPOGENIC_KERNEL_HPP
18 
19 #include "kernel_types.hpp"
20 
21 #include <tuple>
22 #include <random>
23 #include <type_traits>
24 
25 namespace pops {
26 
42 template<typename NaturalKernelType, typename AnthropogenicKernelType>
44 {
45 protected:
47  NaturalKernelType natural_kernel_;
48  AnthropogenicKernelType anthropogenic_kernel_;
49  std::bernoulli_distribution bernoulli_distribution;
50 
51 public:
53  const NaturalKernelType& natural_kernel,
54  const AnthropogenicKernelType& anthropogenic_kernel,
55  bool use_anthropogenic_kernel,
56  double percent_natural_dispersal)
57  : use_anthropogenic_kernel_(use_anthropogenic_kernel),
58  // Here we initialize all distributions,
59  // although we won't use all of them.
60  natural_kernel_(natural_kernel),
61  anthropogenic_kernel_(anthropogenic_kernel),
62  // use bernoulli distribution to act as the sampling with prob(gamma,1-gamma)
63  bernoulli_distribution(percent_natural_dispersal)
64  {}
65 
68  template<typename Generator>
69  std::tuple<int, int> operator()(Generator& generator, int row, int col)
70  {
71  // switch in between the supported kernels
73  || !anthropogenic_kernel_.is_cell_eligible(row, col)
74  || bernoulli_distribution(generator)) {
75  return natural_kernel_(generator, row, col);
76  }
77  return anthropogenic_kernel_(generator, row, col);
78  }
79 
91  static bool supports_kernel(const DispersalKernelType type)
92  {
93  if (std::is_same<NaturalKernelType, AnthropogenicKernelType>::value) {
94  return NaturalKernelType::supports_kernel(type);
95  }
96  else {
97  return NaturalKernelType::supports_kernel(type)
98  || AnthropogenicKernelType::supports_kernel(type);
99  }
100  }
101 };
102 
103 } // namespace pops
104 
105 #endif // POPS_NATURAL_ANTHROPOGENIC_KERNEL_HPP
pops::NaturalAnthropogenicDispersalKernel::use_anthropogenic_kernel_
bool use_anthropogenic_kernel_
Definition: natural_anthropogenic_kernel.hpp:46
pops::NaturalAnthropogenicDispersalKernel::anthropogenic_kernel_
AnthropogenicKernelType anthropogenic_kernel_
Definition: natural_anthropogenic_kernel.hpp:48
pops::DispersalKernelType
DispersalKernelType
Type of dispersal kernel.
Definition: kernel_types.hpp:53
pops::NaturalAnthropogenicDispersalKernel::bernoulli_distribution
std::bernoulli_distribution bernoulli_distribution
Definition: natural_anthropogenic_kernel.hpp:49
pops
Definition: cauchy_kernel.hpp:25
pops::NaturalAnthropogenicDispersalKernel::operator()
std::tuple< int, int > operator()(Generator &generator, int row, int col)
Generates a new position for the spread.
Definition: natural_anthropogenic_kernel.hpp:69
pops::NaturalAnthropogenicDispersalKernel
Dispersal kernel template for natural and anthropogenic distance dispersal.
Definition: natural_anthropogenic_kernel.hpp:43
pops::NaturalAnthropogenicDispersalKernel::natural_kernel_
NaturalKernelType natural_kernel_
Definition: natural_anthropogenic_kernel.hpp:47
pops::NaturalAnthropogenicDispersalKernel::supports_kernel
static bool supports_kernel(const DispersalKernelType type)
Returns true if the kernel class support a given kernel type.
Definition: natural_anthropogenic_kernel.hpp:91
pops::NaturalAnthropogenicDispersalKernel::NaturalAnthropogenicDispersalKernel
NaturalAnthropogenicDispersalKernel(const NaturalKernelType &natural_kernel, const AnthropogenicKernelType &anthropogenic_kernel, bool use_anthropogenic_kernel, double percent_natural_dispersal)
Definition: natural_anthropogenic_kernel.hpp:52
kernel_types.hpp
Kernel types enum and helper functions.