pops-core  0.9
PoPS (Pest or Pathogen Spread) Model Core C++ library
uniform_kernel.hpp
Go to the documentation of this file.
1 /*
2  * PoPS model - random uniform dispersal kernel
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_UNIFORM_KERNEL_HPP
17 #define POPS_UNIFORM_KERNEL_HPP
18 
19 #include "kernel_types.hpp"
20 
21 #include <random>
22 
23 namespace pops {
24 
35 {
36 protected:
37  int row_max_;
38  int col_max_;
39  std::uniform_int_distribution<> row_distribution;
40  std::uniform_int_distribution<> col_distribution;
41 
42 public:
43  UniformDispersalKernel(int row_max, int col_max)
44  : row_max_(row_max),
45  col_max_(col_max),
46  row_distribution(0, row_max),
47  col_distribution(0, col_max)
48  {}
49 
56  template<typename Generator>
57  std::tuple<int, int> operator()(Generator& generator, int row, int col)
58  {
59  row = row_distribution(generator);
60  col = col_distribution(generator);
61 
62  return std::make_tuple(row, col);
63  }
64 
67  static bool supports_kernel(const DispersalKernelType type)
68  {
69  return type == DispersalKernelType::Uniform;
70  }
71 };
72 
73 } // namespace pops
74 
75 #endif // POPS_UNIFORM_KERNEL_HPP
pops::DispersalKernelType::Uniform
@ Uniform
Random uniform dispersal kernel.
pops::UniformDispersalKernel::row_max_
int row_max_
Definition: uniform_kernel.hpp:37
pops::UniformDispersalKernel::col_distribution
std::uniform_int_distribution col_distribution
Definition: uniform_kernel.hpp:40
pops::DispersalKernelType
DispersalKernelType
Type of dispersal kernel.
Definition: kernel_types.hpp:53
pops::UniformDispersalKernel::row_distribution
std::uniform_int_distribution row_distribution
Definition: uniform_kernel.hpp:39
pops
Definition: cauchy_kernel.hpp:25
pops::UniformDispersalKernel
Dispersal kernel for random uniform dispersal over the whole landscape.
Definition: uniform_kernel.hpp:34
pops::UniformDispersalKernel::UniformDispersalKernel
UniformDispersalKernel(int row_max, int col_max)
Definition: uniform_kernel.hpp:43
pops::UniformDispersalKernel::supports_kernel
static bool supports_kernel(const DispersalKernelType type)
Returns true if the kernel class support a given kernel type.
Definition: uniform_kernel.hpp:67
pops::UniformDispersalKernel::col_max_
int col_max_
Definition: uniform_kernel.hpp:38
kernel_types.hpp
Kernel types enum and helper functions.
pops::UniformDispersalKernel::operator()
std::tuple< int, int > operator()(Generator &generator, int row, int col)
Generates a new position for the spread.
Definition: uniform_kernel.hpp:57