Quetzal-CoaTL
The Coalescence Template Library
Loading...
Searching...
No Matches
bound_policy.hpp
1// Copyright 2021 Arnaud Becheler <abechele@umich.edu>
2
10
11#pragma once
12
13#include "concepts.hpp"
14#include <cassert>
15
16namespace quetzal::geography
17{
19class mirror
20{
21 public:
22 int constexpr inline num_extra_vertices() const { return 0; }
23
30 template <class Graph>
31 void operator()([[maybe_unused]] typename Graph::vertex_descriptor s, [[maybe_unused]] Graph &graph,
32 [[maybe_unused]] const two_dimensional auto &grid) const
33 {
34 // do nothing as by default bounding box is reflective
35 }
36};
37
39class sink
40{
41 public:
42
43 int constexpr inline num_extra_vertices() const { return 1; }
44
51 template <class Graph>
52 void operator()(typename Graph::vertex_descriptor s, Graph &graph, const two_dimensional auto &grid) const
53 {
54 using edge_property = typename Graph::edge_property;
55 int num_land_vertices = grid.width() * grid.height();
56 int sink = num_land_vertices;
57 assert( graph.num_vertices() == sink + 1 );
58 if ( s < sink )
60 }
61};
62
64class torus
65{
66 public:
67 int constexpr inline num_extra_vertices() const { return 0; }
68
75 template <class Graph>
76 void operator()(typename Graph::vertex_descriptor s, Graph &graph, const two_dimensional auto &grid) const
77 {
78 using edge_property = typename Graph::edge_property;
79 auto width = grid.width();
80 auto height = grid.height();
81 int symmetricIndex = 0;
82
83 // top border
84 if (s < width)
85 {
86 symmetricIndex = s + width * (height - 1);
87 }
88 // bottom border
89 else if (s >= (height - 1) * width)
90 {
91 symmetricIndex = s - (height - 1) * width;
92 }
93 // left border
94 else if (s % width == 0)
95 {
96 symmetricIndex = s + width - 1;
97 }
98 // right border
99 else if ((s + 1) % width == 0)
100 {
101 symmetricIndex = s - width + 1;
102 }
104 }
105};
106
107} // namespace quetzal::geography
Definition graph.hpp:262
Individuals can not escape the landscape's borders.
Definition bound_policy.hpp:20
void operator()(typename Graph::vertex_descriptor s, Graph &graph, const two_dimensional auto &grid) const
Does nothing as by default the bounding box is reflective.
Definition bound_policy.hpp:31
Individuals can migrate out of the landscape to a sink vertex, but can not come back.
Definition bound_policy.hpp:40
void operator()(typename Graph::vertex_descriptor s, Graph &graph, const two_dimensional auto &grid) const
Connect source vertex s to a sink vertex if on the border.
Definition bound_policy.hpp:52
The 2D landscape becomes a 3D torus connecting opposed borders.
Definition bound_policy.hpp:65
void operator()(typename Graph::vertex_descriptor s, Graph &graph, const two_dimensional auto &grid) const
Connect edges of source vertex s in a graph given a spatial grid.
Definition bound_policy.hpp:76
Concept to represent a 2D spatial grid.
Definition concepts.hpp:96
Geospatial data formatting and processing.
Definition geography.hpp:17