Skip to content

Commit

Permalink
Merge pull request #39 from Quetzal-framework/revert-38-develop
Browse files Browse the repository at this point in the history
Revert "doc: updating local and dispersal processes"
  • Loading branch information
Becheler authored Jul 1, 2024
2 parents 9a552bd + f7c2f40 commit 1f67e4b
Show file tree
Hide file tree
Showing 8 changed files with 166 additions and 283 deletions.
410 changes: 152 additions & 258 deletions docs/4-tutorials.md

Large diffs are not rendered by default.

File renamed without changes.
2 changes: 1 addition & 1 deletion example/expressive_2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ int main()

// We need to make choices here concerning how NA are handled
auto f1 = raster.to_view(); // lightweight functor returning empty optionals for NA
auto f2 = [&](location_type x, time_type t) {
auto f2 = [f1](location_type x, time_type t) {
return f1(x, t).value_or(0.0);
}; // remap empty optionals (NA) to 0.0 suitability value
auto f3 = expressive::use(f2); // f3 has now access to math operators
Expand Down
8 changes: 4 additions & 4 deletions example/expressive_3.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,20 +29,20 @@ int main()
auto e_view = landscape["DEM"].to_view();

// We need to make choices here concerning how NA are handled
auto suit = expressive::use([&](location_type x, time_type t) { return s_view(x, t).value_or(0.0); });
auto elev = expressive::use([&](location_type x, time_type t) { return e_view(x, t).value_or(0.0); });
auto suit = expressive::use([s_view](location_type x, time_type t) { return s_view(x, t).value_or(0.0); });
auto elev = expressive::use([e_view](location_type x, time_type t) { return e_view(x, t).value_or(0.0); });

std::random_device rd; // a seed source for the random number engine
std::mt19937 gen(rd()); // mersenne_twister_engine seeded with rd()

// 1) hostile environment above an isoline: particularly useful if 123.0 is a randomly sampled parameter to be
// estimated
auto isoline_suitability = [&](location_type x, time_type t) {
auto isoline_suitability = [suit, elev](location_type x, time_type t) {
return (elev(x, t) >= 123.0) ? 0.0 : suit(x, t);
};

// 2) small-scale suitable ice-free shelters randomly popping above the snow cover at high-altitude
auto nunatak_suitability = [&](location_type x, time_type t) {
auto nunatak_suitability = [suit, elev, &gen](location_type x, time_type t) {
std::bernoulli_distribution d(0.1); // give "false" 9/10 of the time
bool is_nunatak = d(gen);
return (elev(x, t) >= 123.0) ? static_cast<double>(is_nunatak) * suit(x, t) : suit(x, t);
Expand Down
8 changes: 4 additions & 4 deletions example/expressive_4.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,13 @@ int main()
auto e_view = landscape["DEM"].to_view();

// We need to make choices here concerning how NA are handled
auto suit = expressive::use([&](location_type x, time_type t) { return s_view(x, t).value_or(0.0); });
auto elev = expressive::use([&](location_type x, time_type t) { return s_view(x, t).value_or(0.0); });
auto suit = expressive::use([s_view](location_type x, time_type t) { return s_view(x, t).value_or(0.0); });
auto elev = expressive::use([s_view](location_type x, time_type t) { return s_view(x, t).value_or(0.0); });

std::random_device rd; // a seed source for the random number engine
std::mt19937 gen(rd()); // mersenne_twister_engine seeded with rd()

auto rafting_capacity = [&](location_type x, time_type t) {
auto rafting_capacity = [suit, elev, &gen](location_type x, time_type t) {
std::bernoulli_distribution d(0.1); // give "false" 9/10 of the time
if (suit(x, t) == 0.0 and elev(x, t) == 0.0) // ocean cell case
return static_cast<double>(d(gen)) * 2; // will (rarely) allow 2 individuals to survive in the ocean cell
Expand All @@ -45,7 +45,7 @@ int main()
return 100. * suit(x, 0); // simple rescaling by the max number of individuals in a cell
};

auto rafting_friction = [&](location_type x, time_type t) {
auto rafting_friction = [suit, elev](location_type x, time_type t) {
if (suit(x, t) == 0.0 and elev(x, t) == 0.0) // ocean cell case
return 0.0; // the raft should move freely
else if (suit(x, 0) == 0.0 and elev(x, t) > 0.0) // hostile continental cell case
Expand Down
4 changes: 2 additions & 2 deletions example/geography_graph_4.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ namespace geo = quetzal::geography;
struct MySpatialGrid
{
// it is just required to define these two functions
constexpr int width() const { return 30; }
constexpr int height() const { return 10; }
constexpr int width() const { return 300; }
constexpr int height() const { return 100; }
};

int main()
Expand Down
File renamed without changes.
17 changes: 3 additions & 14 deletions src/include/quetzal/geography/graph/from_grid.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ namespace quetzal::geography
/// @param v An example of information to be stored on vertices
/// @param e An example of information to be stored on edges
/// @param vicinity A policy class giving the connectivity method to be applied
/// @param directionality A policy class giving the directionality (isotropy or anisotropy)
/// @param directionality A policy class giving the directionality (isotropy or anistropy)
/// @param bound A BoundPolicy
/// @return A graph with the desired level of connectivity
template <two_dimensional SpatialGrid, class VertexProperty, class EdgeProperty, class Vicinity,
Expand All @@ -31,21 +31,10 @@ auto from_grid(SpatialGrid const &grid, VertexProperty const &v, EdgeProperty co
Directionality dir, Policy const &bounding_policy)
{
using graph_type = quetzal::geography::graph<VertexProperty, EdgeProperty, typename Vicinity::connectedness, Directionality>;
// using graph_type = typename Vicinity::graph_type<Directionality, VertexProperty, EdgeProperty>;
// Graph size has to be static in dense graphs :/
graph_type graph( grid.width() * grid.height() + bounding_policy.num_extra_vertices() ) ;
vicinity.connect(graph, grid, bounding_policy);

if constexpr ( ! std::is_same_v<VertexProperty, no_property>) {
for( auto vertex : graph.vertices() ){
graph[vertex] = v;
}
}

if constexpr ( ! std::is_same_v<EdgeProperty, no_property>) {
for(auto edge : graph.edges()){
graph[edge] = e;
}
}

return graph;
}

Expand Down

0 comments on commit 1f67e4b

Please sign in to comment.