| get_objectives | R Documentation |
Extract objective values from the runs stored in a
solutionset-class object.
get_objectives(x, format = c("wide", "long"))
x |
A |
format |
Character. Output representation, either |
Objective values are read from run-table columns named
value_<objective>, where <objective> is the registered
objective alias.
Runs without a stored solution may contain missing objective values. Filter
the SolutionSet beforehand with solution_filter when
only solved runs should be included.
Public objective tables are keyed by integer solution_id. Use
get_runs when the relationship between attempted
run_ids and stored solutions is required. In long format, every
solution-objective combination occupies one row. In wide format, every
stored solution occupies one row and every objective occupies one column.
If format = "long", a data.frame with columns
solution_id, objective, and value.
If format = "wide", a data.frame with integer
solution_id and one column per objective.
get_runs,
frontier_extremes,
frontier_distances
# Load a complete simulated planning 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 = 3),
normalize_weights = TRUE
)
if (requireNamespace("rcbc", quietly = TRUE)) {
problem <- set_solver_cbc(
problem,
verbose = FALSE
)
solutions <- solve(problem)
# Long format
get_objectives(
solutions,
format = "long"
)
# Wide format
get_objectives(
solutions,
format = "wide"
)
# Objective values from usable runs only
usable_solutions <- solution_filter(
solutions,
feasible_only = TRUE
)
get_objectives(usable_solutions)
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.