get_solution_states: Get planning-unit states from stored solutions

View source: R/analysis_get.R

get_solution_statesR Documentation

Get planning-unit states from stored solutions

Description

Convert stored planning-unit/action decisions into one canonical action state per planning unit and solution.

Usage

get_solution_states(x)

Arguments

x

A solutionset-class object returned by solve.

Details

Selected action names are sorted and joined with "+". Planning units without a selected action receive the state "unmanaged". The selected column retains the planning-unit selection indicator when it is available in the stored planning-unit summary.

Value

A data.frame with columns solution_id, pu, selected, state, managed, and n_actions. solution_id is returned as an integer.

See Also

get_actions, get_planning_units, selection_consistency, linkage_transition

Examples

# Load a complete simulated multi-action problem.
example_data <- load_sim_multiaction()

problem <- create_problem(
  pu = example_data$planning_units,
  features = example_data$features,
  dist_features = example_data$dist_features,
  cost = "cost"
) |>
  add_actions(
    example_data$actions,
    cost = example_data$action_costs
  ) |>
  add_effects(
    example_data$effect_assumptions
  ) |>
  add_constraint_targets_relative(0.05) |>
  add_objective_min_cost(
    alias = "cost",
    include_pu_cost = FALSE
  ) |>
  add_objective_max_effect(
    alias = "benefit"
  ) |>
  set_method_weighted_sum(
    aliases = c("cost", "benefit"),
    runs = set_runs_grid(n = 5),
    normalize_weights = TRUE
  )

if (requireNamespace("rcbc", quietly = TRUE)) {
  problem <- set_solver_cbc(problem, verbose = FALSE)
  solutions <- solve(problem)

  states <- get_solution_states(solutions)
  head(states)

  # Inspect one solution from the returned table.
  solution_ids <- unique(states$solution_id)
  states[states$solution_id == solution_ids[1L], ]

  # Or filter the complete SolutionSet first.
  one_solution <- solution_filter(
    solutions,
    solution_id = solution_ids[1L]
  )
  get_solution_states(one_solution)
}


multiscape documentation built on Oct. 12, 2026, 5:08 p.m.