pops-core  0.9
PoPS (Pest or Pathogen Spread) Model Core C++ library
switch_kernel.hpp
Go to the documentation of this file.
1 /*
2  * PoPS model - disperal kernels
3  *
4  * Copyright (C) 2019-2021 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_SWITCH_KERNEL_HPP
17 #define POPS_SWITCH_KERNEL_HPP
18 
19 #include "radial_kernel.hpp"
20 #include "deterministic_kernel.hpp"
21 #include "uniform_kernel.hpp"
22 #include "neighbor_kernel.hpp"
23 #include "network_kernel.hpp"
24 #include "kernel_types.hpp"
25 #include "utils.hpp"
26 
27 namespace pops {
28 
38 template<typename IntegerRaster, typename RasterIndex>
40 {
41 protected:
49 
50 public:
52  const DispersalKernelType& dispersal_kernel_type,
53  const RadialDispersalKernel<IntegerRaster>& radial_kernel,
54  const DeterministicDispersalKernel<IntegerRaster>& deterministic_kernel,
55  const UniformDispersalKernel& uniform_kernel,
56  const NetworkDispersalKernel<RasterIndex>& network_kernel,
57  const DeterministicNeighborDispersalKernel& deterministic_neighbor_kernel =
59  const bool deterministic = false)
60  : dispersal_kernel_type_(dispersal_kernel_type),
61  // Here we initialize all kernels,
62  // although we won't use all of them.
63  radial_kernel_(radial_kernel),
64  deterministic_kernel_(deterministic_kernel),
65  uniform_kernel_(uniform_kernel),
66  deterministic_neighbor_kernel_(deterministic_neighbor_kernel),
67  network_kernel_(network_kernel),
68  deterministic_(deterministic)
69  {}
70 
73  template<typename Generator>
74  std::tuple<int, int> operator()(Generator& generator, int row, int col)
75  {
76  // switch in between the supported kernels
78  return uniform_kernel_(generator, row, col);
79  }
81  return deterministic_neighbor_kernel_(generator, row, col);
82  }
84  return network_kernel_(generator, row, col);
85  }
86  else if (deterministic_) {
87  return deterministic_kernel_(generator, row, col);
88  }
89  else {
90  return radial_kernel_(generator, row, col);
91  }
92  }
93 
94  bool is_cell_eligible(int row, int col)
95  {
96  // switch in between the supported kernels
98  // TODO: Individual kernels should support this.
99  return true;
100  }
102  return true;
103  }
105  return network_kernel_.is_cell_eligible(row, col);
106  }
107  else if (deterministic_) {
108  return true;
109  }
110  else {
111  return true;
112  }
113  }
114 
117  static bool supports_kernel(const DispersalKernelType type)
118  {
119  if (type == DispersalKernelType::Uniform) {
120  return true;
121  }
123  return true;
124  }
125  // Radial and Deterministic support the same kernel types
126  else {
128  }
129  }
130 };
131 
132 } // namespace pops
133 
134 #endif // POPS_SWITCH_KERNEL_HPP
pops::SwitchDispersalKernel::supports_kernel
static bool supports_kernel(const DispersalKernelType type)
Returns true if the kernel class support a given kernel type.
Definition: switch_kernel.hpp:117
pops::SwitchDispersalKernel
Dispersal kernel providing all the radial kernels.
Definition: switch_kernel.hpp:39
utils.hpp
pops::SwitchDispersalKernel::deterministic_kernel_
DeterministicDispersalKernel< IntegerRaster > deterministic_kernel_
Definition: switch_kernel.hpp:44
neighbor_kernel.hpp
pops::DispersalKernelType::Uniform
@ Uniform
Random uniform dispersal kernel.
pops::SwitchDispersalKernel::deterministic_
bool deterministic_
Definition: switch_kernel.hpp:48
pops::RadialDispersalKernel::supports_kernel
static bool supports_kernel(const DispersalKernelType type)
Returns true if the kernel class support a given kernel type.
Definition: radial_kernel.hpp:212
radial_kernel.hpp
pops::DeterministicDispersalKernel
Dispersal kernel for deterministic spread to cell with highest probability of spread.
Definition: deterministic_kernel.hpp:59
pops::SwitchDispersalKernel::deterministic_neighbor_kernel_
DeterministicNeighborDispersalKernel deterministic_neighbor_kernel_
Definition: switch_kernel.hpp:46
pops::DispersalKernelType::Network
@ Network
Network spread.
network_kernel.hpp
pops::DispersalKernelType::DeterministicNeighbor
@ DeterministicNeighbor
Deterministic immediate neighbor dispersal kernel.
pops::NetworkDispersalKernel
Dispersal kernel for dispersal over a network.
Definition: network_kernel.hpp:725
pops::DispersalKernelType
DispersalKernelType
Type of dispersal kernel.
Definition: kernel_types.hpp:53
pops::SwitchDispersalKernel::dispersal_kernel_type_
DispersalKernelType dispersal_kernel_type_
Definition: switch_kernel.hpp:42
pops::SwitchDispersalKernel::SwitchDispersalKernel
SwitchDispersalKernel(const DispersalKernelType &dispersal_kernel_type, const RadialDispersalKernel< IntegerRaster > &radial_kernel, const DeterministicDispersalKernel< IntegerRaster > &deterministic_kernel, const UniformDispersalKernel &uniform_kernel, const NetworkDispersalKernel< RasterIndex > &network_kernel, const DeterministicNeighborDispersalKernel &deterministic_neighbor_kernel=DeterministicNeighborDispersalKernel(Direction::None), const bool deterministic=false)
Definition: switch_kernel.hpp:51
pops::SwitchDispersalKernel::is_cell_eligible
bool is_cell_eligible(int row, int col)
Definition: switch_kernel.hpp:94
pops
Definition: cauchy_kernel.hpp:25
pops::UniformDispersalKernel
Dispersal kernel for random uniform dispersal over the whole landscape.
Definition: uniform_kernel.hpp:34
deterministic_kernel.hpp
uniform_kernel.hpp
pops::SwitchDispersalKernel::radial_kernel_
RadialDispersalKernel< IntegerRaster > radial_kernel_
Definition: switch_kernel.hpp:43
pops::DeterministicNeighborDispersalKernel
Dispersal kernel for deterministic spread to a next cell.
Definition: neighbor_kernel.hpp:35
pops::SwitchDispersalKernel::operator()
std::tuple< int, int > operator()(Generator &generator, int row, int col)
Generates a new position for the spread.
Definition: switch_kernel.hpp:74
pops::SwitchDispersalKernel::uniform_kernel_
UniformDispersalKernel uniform_kernel_
Definition: switch_kernel.hpp:45
pops::RadialDispersalKernel
Dispersal kernel providing all the radial kernels.
Definition: radial_kernel.hpp:94
kernel_types.hpp
Kernel types enum and helper functions.
pops::SwitchDispersalKernel::network_kernel_
NetworkDispersalKernel< RasterIndex > network_kernel_
Definition: switch_kernel.hpp:47
Direction::None
@ None
No direction (non-directional)