solve_model() interpolates a model with interpolate_model() and solves
it (an already-interpolated scenario passed to it is solved as-is; an
un-interpolated one is interpolated first). solve_scenario() solves a
scenario that was already interpolated with interpolate_model() and
errors otherwise. Both reuse the write / run / read framework
(.executeScenario()); all solver backends (GLPK/GMPL, GAMS, Pyomo, JuMP,
and the mm matrix route) work unchanged.
Usage
solve_model(
object,
name = NULL,
solver = NULL,
ondisk = FALSE,
fold = FALSE,
...
)
solve_scenario(
object,
name = object@name,
solver = NULL,
solver.dir = NULL,
transient = FALSE,
force = FALSE,
kvl = NULL,
variant = NULL,
wait = TRUE,
...,
tmp.dir = NULL,
tmp.del = NULL
)
# S4 method for class 'model,character'
solve(a, b, ...)Arguments
- object
a model object (
solve_model()) or an interpolated scenario object (solve_scenario()).- name
character name of the scenario to create / return.
- solver
a character or list with solver settings. When
NULL, the scenario's own solver settings orget_default_solver()are used.- ondisk, fold
passed to
interpolate_model(). Defaults (FALSE/FALSE) keep parameters in memory and unfolded, matching the shape the writers expect.- ...
for
solve_model(), arguments are routed tointerpolate_model()(settings / calendar / horizon / model data) or to the solver run (solver.dir,transient,force,read.solution,wait,verbose,run,run.conflict,n.threads, ...). Forsolve_scenario(), arguments are passed to.executeScenario(). Setverbose = FALSEfor a quiet run: it silences both the progress messages and the solver's own console output.rundoubles as the run label:TRUE/FALSEkeeps its historical meaning (run the solver or only write the script), while a character value names the run — the solve lands in<scenario>/runs/<run>/(orruns/<variant>/<run>/for an own-problem variant) with arun.ymlprovenance record (default label: the solver directory name, e.g."glpk").run.conflictcontrols an existing recorded run under the same label:"overwrite"(default),"suffix"(append-2,-3, ...),"error". Seescenario_runs()to list runs andread_solution()to switch between them.- solver.dir
character, an EXTERNAL solver working directory. When set, the solve runs there verbatim and records no run; the default (
NULL) solves into the scenario's own run directoryruns/[<variant>/]<label>/.- transient
logical, use a throwaway timestamp directory deleted after the run (no run record).
- force
logical, re-solve a scenario already solved to optimal.
- kvl
logical or
NULL; what the caller expects of Kirchhoff's voltage law. It GUARDS rather than builds – the cycle constraints are baked in at interpolation time, so this is the last chance to notice that a solve is about to differ from what was asked for.NULLreports what the scenario actually carries.- variant
character (
solve_scenario()only): declare the scenario's interpolated problem an OWN-PROBLEM VARIANT of this name. Its solves land inruns/<variant>/<solve>/, andsave_scenario()stores the variant's problem (modInp, settings snapshot,variant.yml) underruns/<variant>/— once, shared by all its solves — leaving the scenario-level (base) problem untouched. Switch between problems withread_solution()(run = "<variant>/<solve>"vsrun = "<solve>").- wait
logical.
TRUE(default) blocks until the solver exits.FALSElaunches it detached and returns at once, leaving the run record atstatus: "running"for the solver's process to close; collect the result later withread_solution()(save = TRUEto keep it). Detached solving works for the backends that launch a solver process – GLPK, GAMS, Pyomo and JuMP – and is refused together withread.solution = TRUE,transient = TRUEor an externalsolver.dir, none of which can be honoured once the call returns before the solve does.- tmp.dir, tmp.del
deprecated aliases of
solver.dir/transient.- a, b
the
solve()S4 signature:athe model,bthe scenario name.
Examples
if (FALSE) { # \dontrun{
open_project(tempdir())
topia_elc <- topia$modules$electricity
mod <- newModel("TOPIA", data = topia_elc$repo,
calendar = topia$modules$calendars$d365_h24_1dps,
region = topia_elc$regions,
horizon = topia$modules$horizons$BY2025_50_by10,
discount = 0.05)
mod <- setGeoscale(mod, topia_elc$geoscale)
scen <- solve_model(mod, name = "BASE", solver = solver_options$glpk)
sum(getData(scen, "vObjective", merge = TRUE)$value)
# or in two steps, which is what you want when the inputs need inspecting
# before the solver sees them
scen <- interpolate_model(mod, name = "BASE2")
scen <- solve_scenario(scen, solver = solver_options$glpk)
} # }
