diff --git a/src/create-model.jl b/src/create-model.jl index 5e2295a4..62c899b5 100644 --- a/src/create-model.jl +++ b/src/create-model.jl @@ -3,8 +3,8 @@ export create_model!, create_model """ create_model!(energy_problem; kwargs...) -Create the internal model of an [`TulipaEnergyModel.EnergyProblem`](@ref). -Any keyword argument will be passed to the underlyting [`create_model`](@ref). +Create the internal model of a [`TulipaEnergyModel.EnergyProblem`](@ref). +Any keyword argument will be passed to the underlying [`create_model`](@ref). """ function create_model!(energy_problem; kwargs...) energy_problem.model = @timeit to "create_model" create_model( @@ -32,10 +32,18 @@ end profiles, model_parameters; write_lp_file = false, - enable_names = true + enable_names = true, + direct_model = false, + optimizer_with_attributes = optimizer_with_attributes(HiGHS.Optimizer), ) Create the energy model manually. We recommend using [`create_model!`](@ref) instead. + +If `enable_names = false` then variables and constraints in the model will not be assigned names, which improves speed but reduces the readability of log messages. +For more information, see [`JuMP.set_string_names_on_creation`](https://jump.dev/JuMP.jl/stable/api/JuMP/#set_string_names_on_creation). + +If `direct_model = true` then a JuMP `direct_model` will be created using `optimizer_with_attributes`, which has memory improvements. +For more information, see [`JuMP.direct_model`](https://jump.dev/JuMP.jl/stable/api/JuMP/#direct_model). """ function create_model( connection, @@ -46,9 +54,15 @@ function create_model( model_parameters; write_lp_file = false, enable_names = true, + direct_model = false, + #optimizer_with_attributes = optimizer_with_attributes(HiGHS.Optimizer), ) ## Model - model = JuMP.Model() + if direct_model + model = JuMP.direct_model(optimizer_with_attributes) + else + model = JuMP.Model() + end JuMP.set_string_names_on_creation(model, enable_names) diff --git a/src/solve-model.jl b/src/solve-model.jl index 60d48028..c0c004ba 100644 --- a/src/solve-model.jl +++ b/src/solve-model.jl @@ -34,6 +34,8 @@ end Solve the JuMP model. The `optimizer` argument should be an MILP solver from the JuMP list of [supported solvers](https://jump.dev/JuMP.jl/stable/installation/#Supported-solvers). By default we use HiGHS. +Note: If `create_model(; direct_model = true)` the `optimizer` cannot be changed in `solve_model`, but can be changed in the `optimizer_with_attributes` argument of [`create_model`](@ref). +For more information, see the [JuMP documentation](https://jump.dev/JuMP.jl/stable/api/JuMP/#direct_model). The keyword argument `parameters` should be passed as a list of `key => value` pairs. These can be created manually, obtained using [`default_parameters`](@ref), or read from a file