Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 30 additions & 6 deletions R/data_structures.R
Original file line number Diff line number Diff line change
Expand Up @@ -242,9 +242,21 @@ extract_locked_in_constraints <- function(prioritizr_problem, verbose = TRUE) {
for (constraint in prioritizr_problem$constraints) {
# Check if this is a locked-in constraint
if (inherits(constraint, "LockedInConstraint")) {
# Extract indices using the constraint's data
if (!is.null(constraint$data) && "pu" %in% names(constraint$data)) {
locked_in <- unique(c(locked_in, constraint$data$pu))
# Extract indices from the constraint's data tibble
# The data is stored in constraint$data$data with columns: idx, zone, status
# For locked-in: status = 1 and constraint$data$lb = TRUE
if (!is.null(constraint$data) && "data" %in% names(constraint$data)) {
constraint_data <- constraint$data$data
if (!is.null(constraint_data) && "idx" %in% names(constraint_data)) {
# Extract indices where status = 1 (locked in)
if ("status" %in% names(constraint_data)) {
locked_indices <- constraint_data$idx[constraint_data$status == 1]
locked_in <- unique(c(locked_in, as.integer(locked_indices)))
} else {
# If no status column, all indices in the tibble are locked in
locked_in <- unique(c(locked_in, as.integer(constraint_data$idx)))
}
}
}
}
}
Expand All @@ -267,9 +279,21 @@ extract_locked_out_constraints <- function(prioritizr_problem, verbose = TRUE) {
for (constraint in prioritizr_problem$constraints) {
# Check if this is a locked-out constraint
if (inherits(constraint, "LockedOutConstraint")) {
# Extract indices using the constraint's data
if (!is.null(constraint$data) && "pu" %in% names(constraint$data)) {
locked_out <- unique(c(locked_out, constraint$data$pu))
# Extract indices from the constraint's data tibble
# The data is stored in constraint$data$data with columns: idx, zone, status
# For locked-out: status = 0 and constraint$data$ub = FALSE
if (!is.null(constraint$data) && "data" %in% names(constraint$data)) {
constraint_data <- constraint$data$data
if (!is.null(constraint_data) && "idx" %in% names(constraint_data)) {
# Extract indices where status = 0 (locked out)
if ("status" %in% names(constraint_data)) {
locked_indices <- constraint_data$idx[constraint_data$status == 0]
locked_out <- unique(c(locked_out, as.integer(locked_indices)))
} else {
# If no status column, all indices in the tibble are locked out
locked_out <- unique(c(locked_out, as.integer(constraint_data$idx)))
}
}
}
}
}
Expand Down
7 changes: 5 additions & 2 deletions man/calculate_whittle_scores.Rd

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

2 changes: 1 addition & 1 deletion man/can_remove_unit.Rd

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

14 changes: 11 additions & 3 deletions man/create_boundary_matrix.Rd

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

3 changes: 2 additions & 1 deletion man/create_patch_radius_dict.Rd

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

20 changes: 20 additions & 0 deletions man/extract_locked_in_constraints.Rd

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

20 changes: 20 additions & 0 deletions man/extract_locked_out_constraints.Rd

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

2 changes: 1 addition & 1 deletion man/find_edge_units.Rd

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

8 changes: 7 additions & 1 deletion man/initialize_minpatch_data.Rd

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

4 changes: 3 additions & 1 deletion man/make_patch_dict.Rd

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

6 changes: 4 additions & 2 deletions man/removal_violates_targets.Rd

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

12 changes: 12 additions & 0 deletions man/run_minpatch.Rd

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

17 changes: 15 additions & 2 deletions man/validate_inputs.Rd

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

Loading