% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/get_solution.R
\name{get_solution_vector}
\alias{get_solution_vector}
\title{Get raw solution vector from a solution}
\usage{
get_solution_vector(x, run = 1L)
}
\arguments{
\item{x}{A \code{Solution} or \code{SolutionSet} object returned by
\code{\link{solve}}.}

\item{run}{Positive integer giving the run index to extract when \code{x} is
a \code{SolutionSet}. Default is \code{1L}.}
}
\value{
A numeric vector with one value per internal model variable.
}
\description{
Return the raw decision-variable vector produced by the solver, in the
internal model-variable order used by the optimization backend.
}
\details{
This function extracts the raw solution vector stored at
\code{x$solution$vector} for a \code{Solution} or for a selected run of a
\code{SolutionSet}.

The returned vector is in the internal variable order of the optimization
model. Depending on the problem formulation, it may include:
\itemize{
\item planning-unit selection variables,
\item action-allocation variables,
\item auxiliary variables introduced for targets, budgets, fragmentation,
or other constraints/objectives,
\item and potentially additional blocks created internally by the model
builder.
}

Therefore, this vector is primarily intended for advanced users, debugging,
diagnostics, or internal verification. It is not a user-facing allocation
table.

To inspect selected planning units or selected actions in a more interpretable
form, use \code{\link{get_pu}} or \code{\link{get_actions}} instead.

For a single solution, the returned vector corresponds to that solution.
For a \code{SolutionSet}, the \code{run} argument selects which run to
extract.
}
\examples{
\donttest{
if (requireNamespace("rcbc", quietly = TRUE)) {
  pu_tbl <- data.frame(
    id = 1:4,
    cost = c(1, 2, 3, 4)
  )

  feat_tbl <- data.frame(
    id = 1:2,
    name = c("feature_1", "feature_2")
  )

  dist_feat_tbl <- data.frame(
    pu = c(1, 1, 2, 3, 4),
    feature = c(1, 2, 2, 1, 2),
    amount = c(5, 2, 3, 4, 1)
  )

  actions_df <- data.frame(
    id = "conservation",
    name = "conservation"
  )

  effects_df <- data.frame(
    pu = c(1, 2, 3, 4),
    action = "conservation",
    feature = c(1, 1, 2, 2),
    benefit = c(2, 1, 1, 2),
    loss = c(0, 0, 0, 0)
  )

  p <- create_problem(
    pu = pu_tbl,
    features = feat_tbl,
    dist_features = dist_feat_tbl,
    cost = "cost"
  ) |>
    add_actions(actions_df, cost = 0) |>
    add_effects(effects_df) |>
    add_constraint_targets_relative(0.2) |>
    add_objective_min_cost() |>
    set_solver_cbc(time_limit = 10)

  sol <- solve(p)

  v <- get_solution_vector(sol)
  v
  length(v)
}
}

}
\seealso{
\code{\link{get_pu}},
\code{\link{get_actions}},
\code{\link{get_features}},
\code{\link{get_targets}}
}
