% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/add_effects.R
\name{add_losses}
\alias{add_losses}
\title{Add losses}
\usage{
add_losses(
  x,
  losses = NULL,
  effect_type = c("delta", "after"),
  effect_aggregation = c("sum", "mean")
)
}
\arguments{
\item{x}{A \code{Problem} object created with \code{\link{create_problem}}. It
must already contain feasible actions; run \code{\link{add_actions}} first.}

\item{losses}{Alias of \code{effects}, used for symmetry with
\code{add_benefits()}.}

\item{effect_type}{Character string indicating how supplied effect values are
interpreted. Must be one of:
\itemize{
\item \code{"delta"}: values represent signed net changes,
\item \code{"after"}: values represent after-action amounts and are
converted to net changes relative to baseline feature amounts.
}}

\item{effect_aggregation}{Character string giving the aggregation used when
converting raster values to planning-unit level. Must be one of
\code{"sum"} or \code{"mean"}.}
}
\value{
An updated \code{Problem} object containing:
\describe{
\item{\code{dist_effects}}{The canonical filtered effects table,
containing only rows with \code{loss > 0}.}
\item{\code{dist_loss}}{A convenience table containing only the loss
component.}
\item{\code{losses_meta}}{Metadata for the stored loss table.}
}
}
\description{
Convenience wrapper around \code{\link{add_effects}} that keeps only negative
effects, represented by rows with \code{loss > 0}.

This function is useful when the workflow is focused only on damaging
consequences of actions and a loss-only wrapper is more convenient than
calling \code{add_effects(..., component = "loss")} directly. Internally,
it calls \code{add_effects()} with \code{component = "loss"}.
The canonical stored result therefore contains only rows whose effect
satisfies \eqn{\mathrm{loss}_{iaf} > 0}.

In addition, a mirror table containing only the loss component is stored in
\code{x$data$dist_loss}.
}
\examples{
pu <- data.frame(id = 1:2, cost = c(1, 2))
features <- data.frame(id = 1, name = "sp1")
dist_features <- data.frame(pu = 1:2, feature = 1, amount = c(5, 10))

p <- create_problem(
  pu = pu,
  features = features,
  dist_features = dist_features
)

p <- add_actions(
  p,
  data.frame(id = "harvest")
)

eff <- data.frame(
  pu = c(1, 2),
  action = c("harvest", "harvest"),
  feature = c(1, 1),
  delta = c(2, -4)
)

p <- add_losses(p, losses = eff)
p$data$dist_loss

}
\seealso{
\code{\link{add_effects}},
\code{\link{add_benefits}},
\code{\link{add_objective_min_loss}}
}
