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)
work unchanged. The transitional names solve_mod() / solve_scen() are
deprecated aliases.
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,
...,
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,echo,run,run.conflict,n.threads, ...). Forsolve_scenario(), arguments are passed to.executeScenario(). Setecho = 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>").- 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())
ek <- topia$modules$electricity$R3
mod <- newModel("TOPIA", data = ek$repo,
calendar = topia$modules$calendars$s4_h24,
region = ek$regions,
horizon = topia$modules$horizons$base,
discount = 0.05)
mod <- setGeoscale(mod, ek$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)
} # }
