Skip to content

Commit

Permalink
Version 0.1.4. Add locked_in and locked_out arguments.
Browse files Browse the repository at this point in the history
  • Loading branch information
cadam00 committed Jan 19, 2025
1 parent 74fbbe7 commit bfe0ac5
Show file tree
Hide file tree
Showing 43 changed files with 10,464 additions and 109 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Package: priorCON
Type: Package
Title: Graph Community Detection Methods into Systematic Conservation Planning
Version: 0.1.3
Version: 0.1.4
Authors@R: c(person("Christos", "Adam", role = c("aut", "cre"),
email = "[email protected]",
comment = c(ORCID = "0009-0003-3244-7034")),
Expand Down
7 changes: 4 additions & 3 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,17 @@ importFrom("brainGraph", "s_core")
importFrom("grDevices", "terrain.colors")
importFrom("stats", "complete.cases")
importFrom("utils", "read.csv")
importFrom("igraph", "graph_from_data_frame", "as.undirected", "simplify",
importFrom("igraph", "graph_from_data_frame", "as_undirected", "simplify",
"igraph_opt", "cluster_louvain", "sizes", "membership",
"cluster_walktrap", "eigen_centrality", "betweenness", "strength",
"as_data_frame", "E", "V", "delete_vertices", "page_rank")
importFrom("sf", "st_sfc", "st_crs", "st_as_sf", "st_cast", "st_combine",
"st_crs<-")
importFrom("tmap", "tm_shape", "tm_raster", "tm_lines")
importFrom("prioritizr", "problem", "add_max_utility_objective",
"add_binary_decisions", "add_relative_targets", "add_default_solver",
"eval_target_coverage_summary")
"add_binary_decisions", "add_relative_targets", "add_default_solver",
"eval_target_coverage_summary", "add_locked_in_constraints",
"add_locked_out_constraints")


export("basic_scenario")
Expand Down
7 changes: 7 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
# priorCON 0.1.4

## Major changes

- Add `locked_in` and `locked_out` arguments in `priorCON::basic_scenario` and
`priorCON::connectivity_scenario`.

# priorCON 0.1.3

## Minor changes
Expand Down
26 changes: 22 additions & 4 deletions R/functions_connect.R
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ get_metrics <- function(connect_mat, which_community="s_core"){
colnames(edge_list_i) <- c("from","to","weight")

directed_graph_wgt <- graph_from_data_frame(edge_list_i, directed = TRUE)
net_result <- as.undirected(directed_graph_wgt, mode = "collapse",
net_result <- as_undirected(directed_graph_wgt, mode = "collapse",
edge.attr.comb = "sum")

# Simplifying graph
Expand Down Expand Up @@ -276,7 +276,7 @@ get_metrics <- function(connect_mat, which_community="s_core"){
el <- el[stats::complete.cases(el),]

directed_graph_wgt <- graph_from_data_frame(el, directed = TRUE)
net_result <- as.undirected(directed_graph_wgt,
net_result <- as_undirected(directed_graph_wgt,
mode = "collapse",
edge.attr.comb = "sum")
net_result <- simplify(net_result, remove.multiple = TRUE,
Expand Down Expand Up @@ -310,7 +310,8 @@ get_metrics <- function(connect_mat, which_community="s_core"){

}

basic_scenario <- function(cost_raster, features_rasters, budget_perc){
basic_scenario <- function(cost_raster, features_rasters, budget_perc,
locked_in = NULL, locked_out = NULL){

if ((budget_perc < 0) || (budget_perc > 1))
stop("budget_perc must be a numeric value between 0 and 1")
Expand All @@ -331,6 +332,14 @@ basic_scenario <- function(cost_raster, features_rasters, budget_perc){
add_relative_targets(0.17) |>
add_default_solver(verbose=FALSE)

if (!is.null(locked_in)){
p0 <- p0 |> add_locked_in_constraints(locked_in)
}

if (!is.null(locked_out)){
p0 <- p0 |> add_locked_out_constraints(locked_out)
}

solution <- NULL
solution$solution <- suppressWarnings(solve(p0, force = TRUE))
names(solution$solution) <- "basic scenario"
Expand All @@ -347,7 +356,8 @@ basic_scenario <- function(cost_raster, features_rasters, budget_perc){
}

connectivity_scenario <- function(cost_raster, features_rasters=NULL,
budget_perc, pre_graphs){
budget_perc, pre_graphs,
locked_in = NULL, locked_out = NULL){

if ((budget_perc < 0) || (budget_perc > 1))
stop("budget_perc must be a numeric value between 0 and 1")
Expand Down Expand Up @@ -444,6 +454,14 @@ connectivity_scenario <- function(cost_raster, features_rasters=NULL,
add_relative_targets(0.17) |>
add_default_solver(verbose=FALSE)

if (!is.null(locked_in)){
p_cluster <- p_cluster |> add_locked_in_constraints(locked_in)
}

if (!is.null(locked_out)){
p_cluster <- p_cluster |> add_locked_out_constraints(locked_out)
}

solution <- NULL
solution$solution <- suppressWarnings(solve(p_cluster, force=TRUE))
names(solution$solution) <- "connectivity scenario"
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<!-- badges: start -->
[![CRAN status](https://www.r-pkg.org/badges/version/priorCON)](https://CRAN.R-project.org/package=priorCON)
[![Developmental version](https://img.shields.io/badge/devel%20version-0.1.3-blue.svg)](https://CRAN.R-project.org/package=priorCON)
[![Developmental version](https://img.shields.io/badge/devel%20version-0.1.4-blue.svg)](https://CRAN.R-project.org/package=priorCON)
[![R-CMD-check](https://github.com/cadam00/priorCON/actions/workflows/R-CMD-check.yaml/badge.svg)](https://github.com/cadam00/priorCON/actions/workflows/R-CMD-check.yaml)
[![Codecov test coverage](https://codecov.io/gh/cadam00/priorCON/branch/main/graph/badge.svg)](https://app.codecov.io/gh/cadam00/priorCON?branch=main)
<!-- badges: end -->
Expand Down
1 change: 0 additions & 1 deletion _pkgdown.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
url: https://cadam00.github.io/priorCON/
template:
bootstrap: 5

navbar:
left:
- icon: fa-home
Expand Down
18 changes: 4 additions & 14 deletions cran-comments.md
Original file line number Diff line number Diff line change
@@ -1,19 +1,9 @@
# priorCON 0.1.3
# priorCON 0.1.4

## Minor changes
## Major changes

- Update package authors in DESCRIPTION.

# priorCON 0.1.2

## Minor changes

- Remove redundant `r` SpatRaster object at `terra::rasterize` use (we care only
for the "geometry" of the `r`, so no need for new object).

- Update Introduction.Rmd, README and DESCRIPTION text.

- Add pkgdown website.
- Add `locked_in` and `locked_out` arguments in `priorCON::basic_scenario` and
`priorCON::connectivity_scenario`.

## R CMD check results

Expand Down
6 changes: 3 additions & 3 deletions docs/404.html

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions docs/LICENSE-text.html

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions docs/articles/Introduction.html

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions docs/articles/index.html

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit bfe0ac5

Please sign in to comment.