Skip to content

Commit

Permalink
Added function to run Tulipa in one line (#216)
Browse files Browse the repository at this point in the history
  • Loading branch information
clizbe authored Nov 8, 2023
1 parent aa104f4 commit d61a6d8
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 21 deletions.
1 change: 1 addition & 0 deletions src/TulipaEnergyModel.jl
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ using JuMP
include("input-tables.jl")
include("io.jl")
include("model.jl")
include("run-scenario.jl")
include("time-resolution.jl")

end
35 changes: 35 additions & 0 deletions src/run-scenario.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
export run_scenario

"""
run_scenario(input_folder)
run_scenario(input_folder, output_folder)
Run the scenario in the given input_folder and return the sets, parameters, and solution.
If the output_folder is specified, save the sets, parameters, and solution to the output_folder.
"""

function run_scenario(input_folder::AbstractString; write_lp_file = false)
parameters, sets = create_parameters_and_sets_from_file(input_folder)
graph = create_graph(
joinpath(input_folder, "assets-data.csv"),
joinpath(input_folder, "flows-data.csv"),
)
model = create_model(graph, parameters, sets; write_lp_file = write_lp_file)
solution = solve_model(model)
return sets, graph, parameters, solution
end

function run_scenario(
input_folder::AbstractString,
output_folder::AbstractString;
write_lp_file = false,
)
sets, graph, parameters, solution = run_scenario(input_folder; write_lp_file)
save_solution_to_file(
output_folder,
sets.assets_investment,
solution.assets_investment,
parameters.assets_unit_capacity,
)
return sets, graph, parameters, solution
end
24 changes: 3 additions & 21 deletions test/test-case-studies.jl
Original file line number Diff line number Diff line change
@@ -1,31 +1,13 @@
@testset "Norse Case Study" begin
dir = joinpath(INPUT_FOLDER, "Norse")
parameters, sets = create_parameters_and_sets_from_file(dir)
graph = create_graph(joinpath(dir, "assets-data.csv"), joinpath(dir, "flows-data.csv"))
model = create_model(graph, parameters, sets)
solution = solve_model(model)
@test solution.objective_value 164432875.02939 atol = 1e-5
save_solution_to_file(
OUTPUT_FOLDER,
sets.assets_investment,
solution.assets_investment,
parameters.assets_unit_capacity,
)
_, _, _, solution = run_scenario(dir)
@test solution.objective_value 1.6443286362357396e8 atol = 1e-5
end

@testset "Tiny Case Study" begin
dir = joinpath(INPUT_FOLDER, "Tiny")
parameters, sets = create_parameters_and_sets_from_file(dir)
graph = create_graph(joinpath(dir, "assets-data.csv"), joinpath(dir, "flows-data.csv"))
model = create_model(graph, parameters, sets; write_lp_file = true)
solution = solve_model(model)
_, _, _, solution = run_scenario(dir, OUTPUT_FOLDER; write_lp_file = true)
@test solution.objective_value 269238.43825 atol = 1e-5
save_solution_to_file(
OUTPUT_FOLDER,
sets.assets_investment,
solution.assets_investment,
parameters.assets_unit_capacity,
)
end

@testset "Infeasible Case Study" begin
Expand Down

0 comments on commit d61a6d8

Please sign in to comment.