Skip to content

Commit

Permalink
fix bug in greedy_heuristic_prioritization() feasibility calculations
Browse files Browse the repository at this point in the history
  • Loading branch information
jeffreyhanson committed Jul 24, 2024
1 parent 6fda197 commit 2a3e7b4
Show file tree
Hide file tree
Showing 33 changed files with 76 additions and 42 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Package: surveyvoi
Type: Package
Version: 1.1.0.0
Version: 1.1.0.1
Title: Survey Value of Information
Description: Decision support tool for prioritizing sites for ecological
surveys based on their potential to improve plans for conserving
Expand Down
10 changes: 10 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,13 @@
# surveyvoi 1.1.0.1

- Update `greedy_heuristic_algorithm()` function so that it returns a solution
if it is not possible to select enough planning units to meet the target
for any species. Instead of throwing an error, it will now throw a warning
and return a solution containing the cheapest set of planning units within
the budget and locked out constraints. Note that this solution
will have an objective value of zero, because it has zero probability of
meeting any of the species' targets.

# surveyvoi 1.1.0.0

- New `greedy_heuristic_algorithm()` function that can be used to generate
Expand Down
39 changes: 30 additions & 9 deletions R/greedy_heuristic_optimization.R
Original file line number Diff line number Diff line change
Expand Up @@ -142,15 +142,36 @@ greedy_heuristic_prioritization <- function(
site_management_locked_out <- rep(FALSE, nrow(site_data))
}

## validate that targets are feasible given budget and locked out units
sorted_costs <- sort(
site_data[[site_management_cost_column]][!site_management_locked_out])
sorted_costs <- sorted_costs[
seq_len(max(feature_data[[feature_target_column]]))]
assertthat::assert_that(
sum(sorted_costs) <= total_budget,
msg = paste("targets cannot be achieved given budget and locked out",
"planning units"))
## validate it is possible to select enough planning units to meet
## the target for even a single feature,
## if not, then it's not possible to generate a single solution
## with an objective value = 0
cheapest_sol <- rep(FALSE, nrow(site_data))
cheapest_sol[site_management_locked_in] <- TRUE
if (min(feature_data[[feature_target_column]]) > sum(cheapest_sol)) {
idx <- which(!site_management_locked_out & !site_management_locked_in)
idx_costs <- site_data[[site_management_cost_column]]
idx_costs <- idx_costs[idx]
idx_order <- order(idx_costs)
idx_add <- cumsum(idx_costs[idx_order]) <= total_budget
sel_idx <- idx[idx_order[which(idx_add)]]
cheapest_sol[sel_idx] <- TRUE
}
if (
sum(cheapest_sol) < min(feature_data[[feature_target_column]])
) {
### throw warning
warning(
paste(
"it is not possible to select enough planning units to meet",
"any targets for even a single feature",
"(given the budget and locked out planning units)"
),
call. = TRUE, immediate. = FALSE
)
## return solution
return(list(x = cheapest_sol, objval = 0))
}

# create prior data
prior_data <-
Expand Down
2 changes: 1 addition & 1 deletion docs/404.html

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

2 changes: 1 addition & 1 deletion docs/articles/index.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/surveyvoi.html

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

2 changes: 1 addition & 1 deletion docs/authors.html

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

2 changes: 1 addition & 1 deletion docs/index.html

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

5 changes: 4 additions & 1 deletion docs/news/index.html

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

2 changes: 1 addition & 1 deletion docs/pkgdown.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ pkgdown: 2.0.7
pkgdown_sha: ~
articles:
surveyvoi: surveyvoi.html
last_built: 2024-07-09T23:25Z
last_built: 2024-07-24T01:46Z
urls:
reference: https://github.com/prioritizr/surveyvoi/reference
article: https://github.com/prioritizr/surveyvoi/articles
Expand Down
2 changes: 1 addition & 1 deletion docs/reference/approx_evdsi.html

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

2 changes: 1 addition & 1 deletion docs/reference/approx_near_optimal_survey_scheme.html

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

2 changes: 1 addition & 1 deletion docs/reference/approx_optimal_survey_scheme.html

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

2 changes: 1 addition & 1 deletion docs/reference/env_div_survey_scheme.html

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

2 changes: 1 addition & 1 deletion docs/reference/evdci.html

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

2 changes: 1 addition & 1 deletion docs/reference/evdsi.html

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

2 changes: 1 addition & 1 deletion docs/reference/feasible_survey_schemes.html

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

2 changes: 1 addition & 1 deletion docs/reference/fit_hglm_occupancy_models.html

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

2 changes: 1 addition & 1 deletion docs/reference/fit_xgb_occupancy_models.html

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

2 changes: 1 addition & 1 deletion docs/reference/geo_cov_survey_scheme.html

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

2 changes: 1 addition & 1 deletion docs/reference/greedy_heuristic_prioritization.html

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

2 changes: 1 addition & 1 deletion docs/reference/index.html

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

2 changes: 1 addition & 1 deletion docs/reference/n_states.html

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

2 changes: 1 addition & 1 deletion docs/reference/optimal_survey_scheme.html

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

2 changes: 1 addition & 1 deletion docs/reference/prior_probability_matrix.html

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

2 changes: 1 addition & 1 deletion docs/reference/relative_site_richness_scores.html

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

2 changes: 1 addition & 1 deletion docs/reference/relative_site_uncertainty_scores.html

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

2 changes: 1 addition & 1 deletion docs/reference/sim_data.html

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

2 changes: 1 addition & 1 deletion docs/reference/simulate_feature_data.html

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

2 changes: 1 addition & 1 deletion docs/reference/simulate_site_data.html

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

2 changes: 1 addition & 1 deletion docs/reference/surveyvoi.html

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

2 changes: 1 addition & 1 deletion docs/reference/weighted_survey_scheme.html

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

4 changes: 2 additions & 2 deletions inst/doc/surveyvoi.html
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

<meta name="author" content="Jeffrey O. Hanson" />

<meta name="date" content="2024-07-10" />
<meta name="date" content="2024-07-24" />

<title>surveyvoi: Survey Value of Information</title>

Expand Down Expand Up @@ -171,7 +171,7 @@

<h1 class="title toc-ignore">surveyvoi: Survey Value of Information</h1>
<h4 class="author">Jeffrey O. Hanson</h4>
<h4 class="date">2024-07-10</h4>
<h4 class="date">2024-07-24</h4>


<div id="TOC">
Expand Down

0 comments on commit 2a3e7b4

Please sign in to comment.