Skip to content

Commit 4b996ca

Browse files
authored
Merge pull request #6 from SpatialPlanning/devel
Fix constraint errors
2 parents f1cb03e + daf14bc commit 4b996ca

14 files changed

Lines changed: 613 additions & 20 deletions

R/data_structures.R

Lines changed: 30 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -242,9 +242,21 @@ extract_locked_in_constraints <- function(prioritizr_problem, verbose = TRUE) {
242242
for (constraint in prioritizr_problem$constraints) {
243243
# Check if this is a locked-in constraint
244244
if (inherits(constraint, "LockedInConstraint")) {
245-
# Extract indices using the constraint's data
246-
if (!is.null(constraint$data) && "pu" %in% names(constraint$data)) {
247-
locked_in <- unique(c(locked_in, constraint$data$pu))
245+
# Extract indices from the constraint's data tibble
246+
# The data is stored in constraint$data$data with columns: idx, zone, status
247+
# For locked-in: status = 1 and constraint$data$lb = TRUE
248+
if (!is.null(constraint$data) && "data" %in% names(constraint$data)) {
249+
constraint_data <- constraint$data$data
250+
if (!is.null(constraint_data) && "idx" %in% names(constraint_data)) {
251+
# Extract indices where status = 1 (locked in)
252+
if ("status" %in% names(constraint_data)) {
253+
locked_indices <- constraint_data$idx[constraint_data$status == 1]
254+
locked_in <- unique(c(locked_in, as.integer(locked_indices)))
255+
} else {
256+
# If no status column, all indices in the tibble are locked in
257+
locked_in <- unique(c(locked_in, as.integer(constraint_data$idx)))
258+
}
259+
}
248260
}
249261
}
250262
}
@@ -267,9 +279,21 @@ extract_locked_out_constraints <- function(prioritizr_problem, verbose = TRUE) {
267279
for (constraint in prioritizr_problem$constraints) {
268280
# Check if this is a locked-out constraint
269281
if (inherits(constraint, "LockedOutConstraint")) {
270-
# Extract indices using the constraint's data
271-
if (!is.null(constraint$data) && "pu" %in% names(constraint$data)) {
272-
locked_out <- unique(c(locked_out, constraint$data$pu))
282+
# Extract indices from the constraint's data tibble
283+
# The data is stored in constraint$data$data with columns: idx, zone, status
284+
# For locked-out: status = 0 and constraint$data$ub = FALSE
285+
if (!is.null(constraint$data) && "data" %in% names(constraint$data)) {
286+
constraint_data <- constraint$data$data
287+
if (!is.null(constraint_data) && "idx" %in% names(constraint_data)) {
288+
# Extract indices where status = 0 (locked out)
289+
if ("status" %in% names(constraint_data)) {
290+
locked_indices <- constraint_data$idx[constraint_data$status == 0]
291+
locked_out <- unique(c(locked_out, as.integer(locked_indices)))
292+
} else {
293+
# If no status column, all indices in the tibble are locked out
294+
locked_out <- unique(c(locked_out, as.integer(constraint_data$idx)))
295+
}
296+
}
273297
}
274298
}
275299
}

man/calculate_whittle_scores.Rd

Lines changed: 5 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/can_remove_unit.Rd

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/create_boundary_matrix.Rd

Lines changed: 11 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/create_patch_radius_dict.Rd

Lines changed: 2 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/extract_locked_in_constraints.Rd

Lines changed: 20 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/extract_locked_out_constraints.Rd

Lines changed: 20 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/find_edge_units.Rd

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/initialize_minpatch_data.Rd

Lines changed: 7 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/make_patch_dict.Rd

Lines changed: 3 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)