Skip to content

Commit

Permalink
feat: adding from_grid graph generation
Browse files Browse the repository at this point in the history
  • Loading branch information
Becheler committed Jan 15, 2024
1 parent 19712ab commit c4981de
Show file tree
Hide file tree
Showing 9 changed files with 568 additions and 80 deletions.
6 changes: 3 additions & 3 deletions .devcontainer/Dockerfile-ubuntu
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM ubuntu:22.04
FROM ubuntu:23.04

ARG DEBIAN_FRONTEND=noninteractive

Expand All @@ -16,6 +16,6 @@ RUN apt-get install -y --no-install-recommends\
ca-certificates \
doxygen \
graphviz \
python3-pip
pipx

RUN pip install conan==2.0.13
RUN pipx ensurepath && pipx install conan==2.0.13
9 changes: 0 additions & 9 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,4 @@
]
}
}

// Use 'forwardPorts' to make a list of ports inside the container available locally.
// "forwardPorts": [],

// Use 'postCreateCommand' to run commands after the container is created.
// "postCreateCommand": "gcc -v",

// Uncomment to connect as root instead. More info: https://aka.ms/dev-containers-non-root.
// "remoteUser": "root"
}
13 changes: 11 additions & 2 deletions .devcontainer/onCreateCommand.sh
Original file line number Diff line number Diff line change
@@ -1,2 +1,11 @@
conan install conanfile.py --profile:build=conan/profiles/linux-armv8-gcc12-release --profile:host=conan/profiles/linux-armv8-gcc12-release --build=missing --output-folder=build
conan install conanfile.py --profile:build=conan/profiles/linux-armv8-gcc12-debug --profile:host=conan/profiles/linux-armv8-gcc12-debug --build=missing --output-folder=build
conan install conanfile.py \
--profile:build=conan/profiles/linux-armv8-gcc12-release \
--profile:host=conan/profiles/linux-armv8-gcc12-release \
--build=missing \
--output-folder=build

conan install conanfile.py \
--profile:build=conan/profiles/linux-armv8-gcc12-debug \
--profile:host=conan/profiles/linux-armv8-gcc12-debug \
--build=missing \
--output-folder=build
3 changes: 2 additions & 1 deletion .vscode/extensions.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"ms-vscode.cpptools-themes",
"ms-vscode.cpptools",
"ms-vscode.cpptools-extension-pack",
"twxs.cmake"
"twxs.cmake",
"ms-azuretools.vscode-docker"
]
}
4 changes: 3 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
// Workspace settings are stored in the workspace .vscode folder and only apply when the workspace is opened.
{
"C_Cpp.default.cppStandard": "c++23",
"cmake.configureOnOpen": false,
"files.associations": {
"cwchar": "cpp",
Expand Down Expand Up @@ -77,6 +78,7 @@
"typeindex": "cpp",
"typeinfo": "cpp",
"valarray": "cpp",
"variant": "cpp"
"variant": "cpp",
"*.ipp": "cpp"
}
}
23 changes: 16 additions & 7 deletions example/geography_graph_complete.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
#include "quetzal/quetzal.hpp"
#include <filesystem>
#include <cassert>
//#include <print>
// #include <print>

namespace geo = quetzal::geography;

int main()
{
Expand All @@ -13,18 +15,25 @@ int main()
std::iota(times.begin(), times.end(), 2001);

// Initialize the landscape: for each var a key and a file, for all a time series.
using landscape_type = quetzal::geography::landscape<>;
auto env = quetzal::geography::landscape<>::from_files( { {"bio1", file1}, {"bio12", file2} }, times );
std::cout << env << std::endl;
using landscape_type = geo::landscape<>;
auto land = geo::landscape<>::from_files( { {"bio1", file1}, {"bio12", file2} }, times );
std::cout << land << std::endl;

// We convert the grid to a fully connected graph
auto graph = env.to_complete_graph<>();
auto graph1 = geo::graph_from_grid( land, geo::connect_fully(), geo::isotropy() ); // dense, isotrope migration
auto graph2 = geo::graph_from_grid( land, geo::connect_fully(), geo::anisotropy() ); // dense, anisotrope

auto graph3 = geo::graph_from_grid( land, geo::connect_4_neighbors(), geo::isotropy() ); // sparse, isotrope migration
auto graph4 = geo::graph_from_grid( land, geo::connect_4_neighbors(), geo::anisotropy() ); // sparse, anisotrope migration

auto graph5 = geo::graph_from_grid( land, geo::connect_8_neighbors(), geo::isotropy() ); // sparse, isotrope migration
auto graph6 = geo::graph_from_grid( land, geo::connect_8_neighbors(), geo::anisotropy() ); // sparse, anisotrope migration

// A little helper function
auto constexpr sphere_distance = [&]( auto const& p1, auto const& p2 ){
return env.to_latlon( p1 ).great_circle_distance( env.to_latlon( p2 ) );}
return land.to_latlon( p1 ).great_circle_distance( land.to_latlon( p2 ) );}

auto v = graph.edges()
auto v = graph1.edges()
| std::transform( [&](auto const& e){ sphere_distance( graph.source( e ), graph.target( e ) );} )
| std::transform( [&](auto const& d){ return quetzal::demography::dispersal_kernel::exponential_power( d, {.a=1., .b=5.5} ) ;} )
| std::ranges::to<std::vector>();
Expand Down
55 changes: 0 additions & 55 deletions src/include/quetzal/geography/graph/detail/graph_traits.hpp

This file was deleted.

Loading

0 comments on commit c4981de

Please sign in to comment.