View source: R/compile_model.R
| compile_model | R Documentation |
Materializes the optimization model represented by a Problem object
without solving it. This is an advanced function mainly intended for
debugging, inspection, and explicit model preparation.
In standard workflows, users normally do not need to call this function,
because solve compiles the model automatically when needed.
compile_model(x, force = FALSE, ...)
## S3 method for class 'Problem'
compile_model(x, force = FALSE, ...)
x |
A |
force |
Logical. If |
... |
Reserved for future extensions. |
Use this function when you want to prepare the optimization model explicitly before solving, inspect compiled model structures, or verify that the problem compiles successfully.
Conceptually, a Problem object stores a declarative optimization
specification: planning data, actions, effects, targets, constraints,
objectives, spatial relations, and optional method or solver settings.
compile_model() transforms that stored specification into an internal
compiled model representation that can later be reused by the solving layer.
The exact compiled representation is implementation-specific, but it may include indexed variables, prepared constraint blocks, objective structures, and internal model snapshots or pointers.
Compilation does not solve the optimization problem. Therefore, a problem may compile successfully and still later be infeasible, numerically difficult, or otherwise fail during solver execution.
A Problem object with compiled model structures stored internally.
solve
# Load a complete simulated planning problem.
example_data <- load_sim_multiaction()
x <- 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.3) |>
add_objective_min_cost(alias = "cost")
x <- compile_model(x)
# Force recompilation
x <- compile_model(x, force = TRUE)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.