Skip to content

Commit

Permalink
support reuse of Gurobi environment for multistage models
Browse files Browse the repository at this point in the history
  • Loading branch information
NLaws committed Nov 2, 2024
1 parent 73ab92d commit 1620708
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 4 deletions.
1 change: 1 addition & 0 deletions docs/src/User_Guide/model_configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ The following tables summarize the model settings parameters and their default/p

|**Parameter** | **Description**|
| :------------ | :-----------|
|Solver | OPTIONAL name of solver. Default is "HiGHS" effectively. It is necessary to set `Solver: "Gurobi"` when [reusing the same gurobi environment for multiple solves](https://github.com/jump-dev/Gurobi.jl?tab=readme-ov-file#reusing-the-same-gurobi-environment-for-multiple-solves).
|EnableJuMPStringNames | Flag to enable/disable JuMP string names to improve the performance.|
||1 = enable JuMP string names.|
||0 = disable JuMP string names.|
Expand Down
6 changes: 4 additions & 2 deletions src/case_runners/case_runner.jl
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,8 @@ function run_genx_case_simple!(case::AbstractString, mysetup::Dict, optimizer::A

### Configure solver
println("Configuring Solver")
OPTIMIZER = configure_solver(settings_path, optimizer)
solver_name = lowercase(get(mysetup, "Solver", ""))
OPTIMIZER = configure_solver(settings_path, optimizer; solver_name=solver_name)

#### Running a case

Expand Down Expand Up @@ -137,7 +138,8 @@ function run_genx_case_multistage!(case::AbstractString, mysetup::Dict, optimize

### Configure solver
println("Configuring Solver")
OPTIMIZER = configure_solver(settings_path, optimizer)
solver_name = lowercase(get(mysetup, "Solver", ""))
OPTIMIZER = configure_solver(settings_path, optimizer; solver_name=solver_name)

model_dict = Dict()
inputs_dict = Dict()
Expand Down
6 changes: 4 additions & 2 deletions src/configure_solver/configure_solver.jl
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,10 @@ Currently supported solvers include: "Gurobi", "CPLEX", "Clp", "Cbc", or "SCIP"
# Returns
- `optimizer::MathOptInterface.OptimizerWithAttributes`: the configured optimizer instance.
"""
function configure_solver(solver_settings_path::String, optimizer::Any)
solver_name = infer_solver(optimizer)
function configure_solver(solver_settings_path::String, optimizer::Any; solver_name::String="")
if isempty(solver_name)
solver_name = infer_solver(optimizer)
end
path = joinpath(solver_settings_path, solver_name * "_settings.yml")

configure_functions = Dict("highs" => configure_highs,
Expand Down

0 comments on commit 1620708

Please sign in to comment.