Julia syntax for calculating a scenario
To calculate a scenario with NEMO, use the calculatescenario
function. The only required argument is dbpath
; NEMO provides a default value for all other arguments.
NemoMod.calculatescenario
— Functioncalculatescenario(
dbpath::String;
jumpmodel::JuMP.Model = Model(Cbc.Optimizer),
calcyears::Array{Int, 1} = Array{Int, 1}(),
varstosave::String = "vdemandnn, vnewcapacity, vtotalcapacityannual,
vproductionbytechnologyannual, vproductionnn, vusebytechnologyannual,
vusenn, vtotaldiscountedcost",
restrictvars::Bool = true,
reportzeros::Bool = false,
continuoustransmission::Bool = false,
forcemip::Bool = false,
startvalsdbpath::String = "",
startvalsvars::String = "",
precalcresultspath::String = "",
writefilename::String = "",
writefileformat::MathOptInterface.FileFormats.FileFormat = MathOptInterface.FileFormats.FORMAT_MPS,
traperrors::Bool = true,
quiet::Bool = false)
Calculates a scenario specified in a scenario database. Returns a MathOptInterface.TerminationStatusCode
indicating the termination status of the JuMP
model used for the calculation (e.g., OPTIMAL::TerminationStatusCode = 1
).
Arguments
dbpath::String
: Path to the scenario database, which must be a SQLite version 3 database that implements NEMO's scenario database structure. See NEMO's documentation on scenario databases for details. Empty scenario databases can be generated with NEMO'screatenemodb
function.jumpmodel::JuMP.Model
: JuMP model object specifying the solver to be used for the calculation. Examples:Model(optimizer_with_attributes(GLPK.Optimizer, "presolve" => true))
,Model(CPLEX.Optimizer)
,Model(optimizer_with_attributes(Gurobi.Optimizer, "NumericFocus" => 1))
,direct_model(Gurobi.Optimizer())
. Note that the solver's Julia package (Julia wrapper) must be installed. See the documentation for JuMP for information on how to specify a solver and set solver options.calcyears::Union{Vector{Int}, Vector{Vector{Int}}}
: Years to include in the calculation (should be a subset of the years defined in the scenario database). If a single vector of years is provided, NEMO calculates the scenario for those years with perfect foresight. If multiple vectors of years are provided, NEMO performs a limited foresight calculation for the scenario: it calculates the first group of years with perfect foresight, takes the results as the starting point for the second group of years, calculates the second group with perfect foresight, and so on through the last group. In this case, the vectors of years should not overlap and should be in chronological order. If this argument is omitted (or an empty vector is provided), all years in the scenario database are calculated with perfect foresight. If a vector of years is provided that does not intersect with the years in the scenario database, it is ignored.varstosave::String
: Comma-delimited list of output variables whose results should be saved in the scenario database when the scenario is calculated. See NEMO's documentation on outputs for information on the variables that are available.restrictvars::Bool
: Indicates whether NEMO should conduct additional data analysis to limit the set of variables created in the optimization problem for the scenario. By default, to improve performance, NEMO selectively creates certain variables to avoid combinations of subscripts that do not exist in the scenario's data. This option increases the stringency of this filtering. It requires more processing time as the problem is built, but it can substantially reduce the solve time for large models.reportzeros::Bool
: Indicates whether results saved in the scenario database should include values equal to zero. Specifyingfalse
can substantially improve the performance of large models.continuoustransmission::Bool
: Indicates whether continuous (true
) or binary (false
) variables are used to represent investment decisions for candidate transmission lines. Not relevant in scenarios that do not model transmission.forcemip::Bool
: Forces NEMO to formulate the optimization problem for the scenario as a mixed-integer problem. This can improve performance with some solvers (e.g., CPLEX, Mosek). If this option is set tofalse
, the input parameters for the scenario (i.e., in the scenario database) determine whether the optimization problem is mixed-integer.startvalsdbpath::String
: Path to a previously calculated scenario database from which NEMO should take starting values for variables in the optimization problem formulated in this function. This argument is used in conjunction withstartvalsvars
.startvalsvars::String
: Comma-delimited list of variables for which starting values should be set. See NEMO's documentation on outputs for information on the variables that are available. NEMO takes starting values from output variable results saved in the database identified bystartvalsdbpath
. Saved results are matched to variables in the optimization problem using the variables' subscripts, and starting values are set with JuMP'sset_start_value
function. Ifstartvalsvars
is an empty string, NEMO sets starting values for all variables present in both the optimization problem and thestartvalsdbpath
database.precalcresultspath::String
: Path to a previously calculated scenario database that NEMO should copy over the database specified bydbpath
. This argument can also be a directory containing previously calculated scenario databases, in which case NEMO copies any file in the directory with the same name as thedbpath
database. The intent of the argument is to short-circuit calculations in situations where valid results already exist.writefilename::String
: Instructs NEMO to write the optimization problem for the scenario to the specified file (without solving the problem). In limited foresight calculations, one file is written for each group of years being optimized (an integer suffix is added to each file's name to ensure uniqueness). If a path is not included inwritefilename
, the file(s) is/are written to the Julia working directory. Ifwritefilename
ends in.gz
or.bz2
, the file(s) is/are compressed with Gzip or BZip2, respectively. If bothprecalcresultspath
andwritefilename
are specified,writefilename
is ignored.writefileformat::MathOptInterface.FileFormats.FileFormat
: Data format used for the file named inwritefilename
. Common formats includeMathOptInterface.FileFormats.FORMAT_MPS
(MPS format) andMathOptInterface.FileFormats.FORMAT_LP
(LP format). See the documentation forMathOptInterface
for additional options.traperrors::Bool
: Indicates whether errors should be trapped and communicated with a standard message that directs users to report the problem to the NEMO team.quiet::Bool
: Suppresses low-priority status messages (which are otherwise printed toSTDOUT
).
To access calculatescenario
within Julia, you must first tell Julia you want to use NEMO. This is done with the using
command.
julia> using NemoMod
julia> NemoMod.calculatescenario("c:/temp/scenario_db.sqlite")
If you want to provide a value for the jumpmodel
argument, make sure to include JuMP
and your solver's Julia package in the using
command. For example:
julia> using NemoMod, JuMP, CPLEX
julia> NemoMod.calculatescenario("c:/temp/scenario_db.sqlite"; jumpmodel = Model(CPLEX.Optimizer), forcemip = true)