frontier_neighbors: Identify neighboring solutions in objective space

View source: R/analysis_frontier.R

frontier_neighborsR Documentation

Identify neighboring solutions in objective space

Description

Connect nearby stored solutions in normalized objective space. The resulting pairs can be supplied directly to objective–decision linkage functions.

Usage

frontier_neighbors(
  x,
  objectives = NULL,
  method = c("auto", "sequence", "mst", "knn"),
  metric = c("euclidean", "manhattan", "chebyshev"),
  k = 1L
)

Arguments

x

A solutionset-class object returned by solve.

objectives

Optional character vector of objective aliases. If NULL, all registered objectives are used.

method

Neighborhood method: "auto", "sequence", "mst", or "knn".

metric

Objective-space distance metric: "euclidean", "manhattan", or "chebyshev".

k

Number of nearest neighbors used only by method = "knn".

The first selected objective orients all pairs and, for method = "sequence", also orders the solutions. Supply the desired ordering objective first in objectives.

Details

Objective values are oriented to minimization and normalized using the solutions retained in the supplied SolutionSet. The function does not remove dominated or repeated solutions; use solution_filter or solution_unique beforehand when required.

method = "auto" uses a sequence for one or two objectives and a minimum spanning tree for higher-dimensional objective spaces.

Value

A data.frame with from_solution, to_solution, objective_distance, and objective-specific values and changes. Analysis settings are retained as attributes.

See Also

frontier_distances, linkage_distances, linkage_turnover

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)

  neighbors <- frontier_neighbors(
    solutions,
    objectives = c("benefit", "cost")
  )

  neighbors

  frontier_neighbors(
    solutions,
    objectives = c("cost", "benefit"),
    method = "knn",
    k = 2
  )
}


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