Skip to content

Commit

Permalink
Add run_scenario(connection) (#699)
Browse files Browse the repository at this point in the history
  • Loading branch information
clizbe authored Jul 29, 2024
1 parent 7f05483 commit 62746b4
Showing 1 changed file with 48 additions and 15 deletions.
63 changes: 48 additions & 15 deletions src/run-scenario.jl
Original file line number Diff line number Diff line change
@@ -1,35 +1,31 @@
export run_scenario

"""
energy_problem = run_scenario(input_folder[, output_folder; optimizer, parameters])
energy_problem = run_scenario(connection; optimizer, parameters, write_lp_file, log_file, show_log)
Run the scenario in the given `input_folder` and return the energy problem.
The `output_folder` is optional. If it is specified, save the sets, parameters, and solution to the `output_folder`.
Run the scenario in the given `connection` and return the energy problem.
The `optimizer` and `parameters` keyword arguments can be used to change the optimizer
(the default is HiGHS) and its parameters. The variables are passed to the [`solve_model`](@ref) function.
Set `write_lp_file = true` to export the problem that is sent to the solver to a file for viewing.
Set `show_log = false` to silence printing the log while running.
Specify a `log_file` name to export the log to a file.
"""
function run_scenario(
input_folder::AbstractString,
output_folder::String = "";
connection;
output_folder = "",
optimizer = HiGHS.Optimizer,
parameters = default_parameters(optimizer),
write_lp_file = false,
log_file = "",
show_log = true,
)
energy_problem =
@timeit to "create_energy_problem_from_csv_folder" create_energy_problem_from_csv_folder(
input_folder,
)
energy_problem = @timeit to "create EnergyProblem from connection" EnergyProblem(connection)

@timeit to "create_model!" create_model!(energy_problem; write_lp_file = write_lp_file)
@timeit to "create_model!" create_model!(energy_problem; write_lp_file)

@timeit to "solve and store solution" solve_model!(
energy_problem,
optimizer;
parameters = parameters,
)
@timeit to "solve and store solution" solve_model!(energy_problem, optimizer; parameters)

if output_folder != ""
@timeit to "save_solution_to_file" save_solution_to_file(output_folder, energy_problem)
Expand All @@ -46,3 +42,40 @@ function run_scenario(

return energy_problem
end

"""
energy_problem = run_scenario(input_folder[, output_folder; optimizer, parameters, write_lp_file, log_file, show_log])
Run the scenario in the given `input_folder` and return the energy problem.
The `output_folder` is optional. If it is specified, save the sets, parameters, and solution to the `output_folder`.
The `optimizer` and `parameters` keyword arguments can be used to change the optimizer
(the default is HiGHS) and its parameters. The variables are passed to the [`solve_model`](@ref) function.
Set `write_lp_file = true` to export the problem that is sent to the solver to a file for viewing.
Set `show_log = false` to silence printing the log while running.
Specify a `log_file` name to export the log to a file.
"""

function run_scenario(
input_folder::AbstractString,
output_folder::String = "";
optimizer = HiGHS.Optimizer,
parameters = default_parameters(optimizer),
write_lp_file = false,
log_file = "",
show_log = true,
)
connection = create_connection_and_import_from_csv_folder(input_folder)

return run_scenario(
connection;
output_folder,
optimizer,
parameters,
write_lp_file,
log_file,
show_log,
)
end

0 comments on commit 62746b4

Please sign in to comment.