View source: R/add_constraint_budget.R
| add_constraint_budget | R Documentation |
Add a budget constraint to a planning problem.
This function stores one budget-constraint specification in the
Problem object so that it can later be incorporated when the
optimization model is assembled. Multiple budget constraints can be added by
calling this function repeatedly, provided that no duplicated combination of
action subset and constraint sense is introduced.
add_constraint_budget(
x,
budget,
sense,
tolerance = 0,
actions = NULL,
include_pu_cost = TRUE,
include_action_cost = TRUE,
name = NULL
)
x |
A |
budget |
Numeric scalar greater than or equal to zero. Target value for the constrained budget. |
sense |
Character string indicating the type of budget constraint. Must
be one of |
tolerance |
Numeric scalar greater than or equal to zero. Only used when
|
actions |
Optional subset of actions to which the constraint applies.
If |
include_pu_cost |
Logical scalar indicating whether planning-unit costs
should be included in the constrained budget. This is only supported when
|
include_action_cost |
Logical scalar indicating whether action costs should be included in the constrained budget. |
name |
Optional character string used as the label of the stored linear
constraint when it is later added to the optimization model. If
|
Calls accumulate constraints for distinct action scopes, cost components, or senses. Repeating the same combination raises an error, even with a different threshold or name. To change it, rebuild from the problem before the constraint was added. Explicit names must be unique within the budget-constraint family; omitted names are generated automatically.
Use this function when spending limits or minimum spending requirements must be imposed either on the full problem or on the subset of selected decisions associated with specific actions.
Let \mathcal{I} denote the set of planning units and let
\mathcal{A} denote the set of actions. Let
w_i \in \{0,1\} denote the binary variable indicating whether planning
unit i \in \mathcal{I} is selected by at least one decision in the
model, and let x_{ia} \in \{0,1\} denote the binary variable
indicating whether action a \in \mathcal{A} is selected in planning
unit i \in \mathcal{I}.
The total constrained budget can include two cost components:
planning-unit costs, associated with w_i;
action costs, associated with x_{ia}.
The arguments include_pu_cost and include_action_cost
determine which of these components are included in the stored budget
constraint.
When actions = NULL, the constraint refers to the total budget across
the whole problem. In that case, depending on the values of
include_pu_cost and include_action_cost, the constrained
quantity is one of the following:
If only planning-unit costs are included:
\sum_{i \in \mathcal{I}} c_i^{pu} w_i
If only action costs are included:
\sum_{i \in \mathcal{I}} \sum_{a \in \mathcal{A}} c_{ia}^{act} x_{ia}
If both components are included:
\sum_{i \in \mathcal{I}} c_i^{pu} w_i +
\sum_{i \in \mathcal{I}} \sum_{a \in \mathcal{A}} c_{ia}^{act} x_{ia}
Depending on sense, this function stores one of the following
constraints:
If sense = "min":
C \ge B
If sense = "max":
C \le B
If sense = "equal" and tolerance = 0:
C = B
If sense = "equal" and tolerance > 0, the equality is stored as
a two-sided band:
B - \tau \le C \le B + \tau
where C denotes the selected cost expression and \tau is the
value supplied through tolerance.
When actions is not NULL, only action costs can be included.
In that case, let \mathcal{A}^\star \subseteq \mathcal{A} denote the
selected subset of actions, and the constrained quantity is
\sum_{i \in \mathcal{I}} \sum_{a \in \mathcal{A}^\star} c_{ia}^{act} x_{ia}.
Action-specific budget constraints only support action costs. Therefore,
include_pu_cost = TRUE is only allowed when actions = NULL,
because planning-unit costs are not action-specific.
This function only stores the constraint specification; it does not validate the feasibility of the threshold against the available cost data at this stage.
Multiple budget constraints can be stored in a Problem object.
However, at most one can be stored for the same combination of action subset
and constraint sense. Attempting to add a duplicated
actions–sense combination results in an error.
An updated Problem object with the new budget-constraint
specification appended to the stored budget-constraint table.
create_problem
# Load a complete simulated planning problem.
example_data <- load_sim_multiaction()
p <- 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
)
p <- add_constraint_budget(
x = p,
budget = 10,
sense = "max",
include_pu_cost = TRUE,
include_action_cost = TRUE
)
p <- add_constraint_budget(
x = p,
budget = 4,
sense = "max",
actions = "restore",
include_pu_cost = FALSE,
include_action_cost = TRUE
)
p <- add_constraint_budget(
x = p,
budget = 1,
sense = "min",
actions = "restore",
include_pu_cost = FALSE,
include_action_cost = TRUE
)
p$data$constraints$budget
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.