add_action_max_per_pu: Limit the number of actions per planning unit (maximum)

View source: R/add_action_max_per_pu.R

add_action_max_per_puR Documentation

Limit the number of actions per planning unit (maximum)

Description

Store a constraint that limits the number of actions that can be selected within each planning unit (PU). The constraint has the form:

\sum_{a \in A} x_{pu,a} \le \mathrm{max}

for each PU in the selected set.

This function is data-only: it records the constraint specification in the Problem object but does not build or modify the optimization model. The constraint is later translated into linear constraints by the model builder (e.g., .pa_build_model_apply_constraints()).

Arguments

x

A Problem object created with create_problem. Must already contain actions (i.e., run add_actions first).

max

Integer scalar \ge 0. Maximum number of actions allowed per PU. Default is 1L.

pu

Optional integer vector of planning unit ids (external ids, i.e., x$data$pu$id) to which the constraint is applied. If NULL (default), the constraint applies to all PUs.

actions

Optional character vector of action ids (i.e., x$data$actions$id) to include in the sum. If NULL (default), all actions are included.

overwrite

Logical. If TRUE, replace any existing action_max_per_pu constraint stored in x$data$constraints. If FALSE (default) and a constraint already exists, an error is raised.

Details

The constraint can be applied to:

  • all planning units and all actions (default), or

  • a subset of planning units via pu, and/or

  • a subset of actions via actions.

Note that the subset is applied over the existing feasible (pu, action) pairs in x$data$dist_actions. If the requested pu/actions subset yields zero feasible pairs, the function stops with an informative error.

If x$data$model_ptr is already present (a model has been built previously), the function marks the model as dirty by setting x$data$meta$model_dirty <- TRUE, signalling that the model should be rebuilt before solving.

Value

The updated Problem object with x$data$constraints$action_max_per_pu set to a list containing the constraint specification.

See Also

add_actions


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