Skip to content

Commit

Permalink
Merge pull request #13 from GENeSYS-MOD/feat/dispatch
Browse files Browse the repository at this point in the history
New Dispatch formulations
  • Loading branch information
stianbacke authored Nov 5, 2024
2 parents 63bd5d7 + 7501085 commit 6dd6f37
Show file tree
Hide file tree
Showing 22 changed files with 1,872 additions and 2,206 deletions.
3 changes: 1 addition & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,4 @@ docs/build/
test/script.jl
test/TestData/Results
debug_scripts
test/test.jl
test/
test/test.jl
12 changes: 8 additions & 4 deletions src/GENeSYS_MOD.jl
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ using XLSX
using CSV
using Statistics

const DenseArray = JuMP.Containers.DenseAxisArray

include("datastructures.jl")
include("utils.jl")
include("genesysmod.jl")
Expand All @@ -45,11 +47,13 @@ include("genesysmod_employment.jl")
include("genesysmod_variable_parameter.jl")
include("genesysmod_results_raw.jl")
include("genesysmod_results.jl")
include("genesysmod_results_old.jl")
include("genesysmod_levelizedcosts.jl")
include("genesysmod_emissionintensity.jl")
include("genesysmod_simple_dispatch.jl")
include("genesysmod_dispatch.jl")

export genesysmod, genesysmod_simple_dispatch
export genesysmod, genesysmod_dispatch
export NoInfeasibilityTechs, WithInfeasibilityTechs # for use with the switch infeasibility_techs
export OneNodeSimple, TwoNodes, OneNodeStorage
export NoRawResult, CSVResult, TXTResult, TXTandCSV

end
end
258 changes: 181 additions & 77 deletions src/datastructures.jl

Large diffs are not rendered by default.

87 changes: 34 additions & 53 deletions src/genesysmod.jl
Original file line number Diff line number Diff line change
Expand Up @@ -23,20 +23,21 @@ Run the whole model. It runs the whole process from input data reading to
result processing. For information about the switches, refer to the datastructure documentation.
"""
function genesysmod(;elmod_daystep, elmod_hourstep, solver, DNLPsolver, year=2018,
model_region="minimal", data_base_region="DE",
model_region="minimal", data_base_region="DE",
data_file="Data_Europe_openENTRANCE_technoFriendly_combined_v00_kl_21_03_2022_new",
hourly_data_file = "Hourly_Data_Europe_v09_kl_23_02_2022",
threads=4, emissionPathway="MinimalExample", emissionScenario="globalLimit",
socialdiscountrate=0.05, inputdir="Inputdata\\", resultdir="Results\\",
switch_infeasibility_tech = 0, switch_investLimit=1, switch_ccs=0,
threads=4, emissionPathway="MinimalExample", emissionScenario="globalLimit",
socialdiscountrate=0.05, inputdir="Inputdata\\", resultdir="Results\\",
switch_infeasibility_tech = NoInfeasibilityTechs(), switch_investLimit=1, switch_ccs=0,
switch_ramping=0,switch_weighted_emissions=1,set_symmetric_transmission=0,switch_intertemporal=0,
switch_base_year_bounds = 0,switch_peaking_capacity = 1, set_peaking_slack =1.0,
set_peaking_minrun_share =0.15, set_peaking_res_cf=0.5, set_peaking_min_thermal=0.5, set_peaking_startyear = 2025,
set_peaking_minrun_share =0.15, set_peaking_res_cf=0.5, set_peaking_min_thermal=0.5, set_peaking_startyear = 2025,
switch_peaking_with_storages = 0, switch_peaking_with_trade = 0,switch_peaking_minrun = 0,
switch_employment_calculation = 0, switch_endogenous_employment = 0,
employment_data_file = "", elmod_nthhour = 0, elmod_starthour = 8,
elmod_dunkelflaute = 0, switch_raw_results = 0, switch_processed_results = 0, write_reduced_timeserie = 1, switch_LCOE_calc=0,
switch_reserve=0,switch_base_year_bounds_debugging=0)
employment_data_file = "", elmod_nthhour = 0, elmod_starthour = 8,
elmod_dunkelflaute = 0, switch_raw_results = NoRawResult(), switch_processed_results = 0, write_reduced_timeserie = 1, switch_LCOE_calc=0,
switch_reserve=0,switch_base_year_bounds_debugging=0,
extr_str_results = "inv_run", extr_str_dispatch="dispatch_run")

if elmod_nthhour != 0 && (elmod_daystep !=0 || elmod_hourstep !=0)
@warn "Both elmod_nthhour and elmod_daystep/elmod_hourstep are defined.
Expand All @@ -56,9 +57,9 @@ function genesysmod(;elmod_daystep, elmod_hourstep, solver, DNLPsolver, year=201
end

elmod_nthhour = Int64(elmod_daystep * 24 + elmod_hourstep)
switch_dispatch = 0
switch_dispatch = NoDispatch()

Switch = GENeSYS_MOD.Switch(year,
switch = Switch(year,
solver,
DNLPsolver,
model_region,
Expand Down Expand Up @@ -102,6 +103,8 @@ function genesysmod(;elmod_daystep, elmod_hourstep, solver, DNLPsolver, year=201
switch_processed_results,
write_reduced_timeserie,
switch_LCOE_calc,
extr_str_results,
extr_str_dispatch,
switch_reserve)

starttime= Dates.now()
Expand All @@ -111,29 +114,29 @@ function genesysmod(;elmod_daystep, elmod_hourstep, solver, DNLPsolver, year=201
# ####### Load data from provided excel files and declarations #############
#

Sets, Params, Emp_Sets = genesysmod_dataload(Switch);
Sets, Params, Emp_Sets = genesysmod_dataload(switch);
Maps = make_mapping(Sets,Params)
Vars=genesysmod_dec(model,Sets,Params,Switch,Maps)
Vars=genesysmod_dec(model,Sets,Params,switch,Maps)
#
# ####### Settings for model run (Years, Regions, etc) #############
#

Settings=genesysmod_settings(Sets, Params, Switch.socialdiscountrate)
Settings=genesysmod_settings(Sets, Params, switch.socialdiscountrate)

#end
#
# ####### apply general model bounds #############
#

genesysmod_bounds(model,Sets,Params,Vars,Settings,Switch,Maps)
genesysmod_bounds(model,Sets,Params,Vars,Settings,switch,Maps)

# create tech, fuel and mode of operation mapping

#
# ####### Including Equations #############
#

genesysmod_equ(model,Sets,Params,Vars,Emp_Sets,Settings,Switch,Maps)
considered_duals = genesysmod_equ(model,Sets,Params,Vars,Emp_Sets,Settings,switch,Maps)
#
# ####### CPLEX Options #############
#
Expand All @@ -145,28 +148,20 @@ function genesysmod(;elmod_daystep, elmod_hourstep, solver, DNLPsolver, year=201
#set_optimizer_attribute(model, "Names", "no")
set_optimizer_attribute(model, "Method", 2)
set_optimizer_attribute(model, "BarHomogeneous", 1)
set_optimizer_attribute(model, "ResultFile", "Solution_julia.sol")
file = open("gurobi.opt","w")
write(file,"threads $threads ")
write(file,"method 2 ")
#write(file,"names no ")
write(file,"barhomogeneous 1 ")
#write(file,"timelimit 1000000 ")
close(file)
set_optimizer_attribute(model, "LogFile", joinpath(resultdir,"Run_$(elmod_nthhour)_$(today()).log"))
elseif string(solver) == "CPLEX.Optimizer"
set_optimizer_attribute(model, "CPX_PARAM_THREADS", threads)
set_optimizer_attribute(model, "CPX_PARAM_PARALLELMODE", -1)
set_optimizer_attribute(model, "CPX_PARAM_LPMETHOD", 4)
set_optimizer_attribute(model, "CPX_PARAM_SOLUTIONTYPE", 2)
env = model.moi_backend.optimizer.model.env
CPXsetlogfilename(env, joinpath(resultdir,"Run_$(elmod_nthhour)_$(today()).log"), "w+")
#set_optimizer_attribute(model, "CPX_PARAM_BAROBJRNG", 1e+075)

file = open("cplex.opt","w")
write(file,"threads $threads ")
write(file,"parallelmode -1 ")
write(file,"lpmethod 4 ")
#write(file,"quality yes ")
#write(file,"barobjrng 1e+075 ")
#write(file,"tilim 1000000 ")
close(file)
elseif string(solver) == "HiGHS.Optimizer"
set_optimizer_attribute(model, "solver", "ipm")
#set_optimizer_attribute(model, "solver", "pdlp")
set_optimizer_attribute(model, "run_crossover", "off")
set_optimizer_attribute(model, "log_file", joinpath(resultdir,"Run_$(elmod_nthhour)_$(today()).log"))
end

println("model_region = $model_region")
Expand Down Expand Up @@ -194,29 +189,15 @@ function genesysmod(;elmod_daystep, elmod_hourstep, solver, DNLPsolver, year=201
elseif termination_status(model) == MOI.OPTIMAL
VarPar = genesysmod_variable_parameter(model, Sets, Params, Vars)
if switch_processed_results == 1
GENeSYS_MOD.genesysmod_results(model, Sets, Params, VarPar, Vars, Switch,
Settings, Maps, elapsed,(switch_dispatch == 1 ? "dispatch" : ""))
# GENeSYS_MOD.genesysmod_results_old(model, Sets, Params, VarPar, Vars, Switch,
# Settings, elapsed,"dispatch")
end
if switch_raw_results == 1
GENeSYS_MOD.genesysmod_results_raw(model, Switch,(switch_dispatch == 1 ? "dispatch" : ""))
end
if string(solver) == "CPLEX.Optimizer"
file = open(joinpath(resultdir, "cplex.sol"), "w")
# Write variable names and values to the file
for v in all_variables(model)
if value.(v) > 0
val = value.(v)
str = string(v)
println(file, "$str = $val")
end
end
genesysmod_results(model, Sets, Params, VarPar, Vars, switch,
Settings, Maps, elapsed, switch.extr_str_results)
end
genesysmod_results_raw(model, VarPar, Params, switch,switch.extr_str_results, switch.switch_raw_results)
genesysmod_getspecifiedduals(model,switch,switch.extr_str_results, considered_duals)
else
println("Termination status:", termination_status(model), ".")
end

return model, Dict("Sets" => Sets, "Params" => Params,
"Switch" => Switch)
end
"Switch" => switch)
end
Loading

0 comments on commit 6dd6f37

Please sign in to comment.