diff --git a/docs/make.jl b/docs/make.jl index a715080a5e..48042b517c 100644 --- a/docs/make.jl +++ b/docs/make.jl @@ -83,17 +83,16 @@ makedocs(; canonical="https://genxproject.github.io/GenX/stable", assets=String[], ), - pages=[p for p in pages], - warnonly=true + pages=[p for p in pages] ) -# deploydocs(; -# repo="github.com/GenXProject/GenX.git", -# target = "build", -# branch = "gh-pages", -# devbranch = "main", -# devurl = "dev", -# push_preview=true, -# versions = ["stable" => "v^", "v#.#"], -# forcepush = false, -# ) +deploydocs(; + repo="github.com/GenXProject/GenX.git", + target = "build", + branch = "gh-pages", + devbranch = "main", + devurl = "dev", + push_preview=true, + versions = ["stable" => "v^", "v#.#"], + forcepush = false, +) diff --git a/docs/src/developer_guide.md b/docs/src/developer_guide.md index fe0e05adb4..4472f9d0cf 100644 --- a/docs/src/developer_guide.md +++ b/docs/src/developer_guide.md @@ -140,13 +140,13 @@ julia> get(thermal_gen[1], :new_build, 0) 0 ``` -- [`GenX.has(r::AbstractResource, sym::Symbol)`](@ref): Returns `true` if the resource `r` has the attribute `sym`, and `false` otherwise. +- [`GenX.haskey(r::AbstractResource, sym::Symbol)`](@ref): Returns `true` if the resource `r` has the attribute `sym`, and `false` otherwise. Example: ```jldoctest example_thermal -julia> has(thermal_gen[1], :existing_cap_mw) +julia> haskey(thermal_gen[1], :existing_cap_mw) true -julia> has(thermal_gen[1], :new_build) +julia> haskey(thermal_gen[1], :new_build) false ``` diff --git a/src/GenX.jl b/src/GenX.jl index b661090238..508fccceb6 100644 --- a/src/GenX.jl +++ b/src/GenX.jl @@ -23,9 +23,6 @@ export write_multi_stage_outputs export run_genx_case! export run_timedomainreduction! -# GenX types -export AbstractResource - using JuMP # used for mathematical programming using DataFrames #This package allows put together data into a matrix using CSV diff --git a/src/additional_tools/modeling_to_generate_alternatives.jl b/src/additional_tools/modeling_to_generate_alternatives.jl index d7361675ae..97400b54b1 100644 --- a/src/additional_tools/modeling_to_generate_alternatives.jl +++ b/src/additional_tools/modeling_to_generate_alternatives.jl @@ -20,93 +20,94 @@ where, $\beta_{zr}$ is a random objective fucntion coefficient betwen $[0,100]$ """ function mga(EP::Model, path::AbstractString, setup::Dict, inputs::Dict) - if setup["ModelingToGenerateAlternatives"]==1 + if setup["ModelingToGenerateAlternatives"]==1 # Start MGA Algorithm println("MGA Module") - # Objective function value of the least cost problem - Least_System_Cost = objective_value(EP) + # Objective function value of the least cost problem + Least_System_Cost = objective_value(EP) - # Read sets - gen = inputs["RESOURCES"] - T = inputs["T"] # Number of time steps (hours) - Z = inputs["Z"] # Number of zonests - zones = unique(inputs["R_ZONES"]) + # Read sets + gen = inputs["RESOURCES"] + T = inputs["T"] # Number of time steps (hours) + Z = inputs["Z"] # Number of zonests + zones = unique(inputs["R_ZONES"]) - # Create a set of unique technology types - resources_with_mga = gen[ids_with_mga(gen)] - TechTypes = unique(resource_type_mga.(resources_with_mga)) + # Create a set of unique technology types + resources_with_mga = gen[ids_with_mga(gen)] + TechTypes = unique(resource_type_mga.(resources_with_mga)) - # Read slack parameter representing desired increase in budget from the least cost solution - slack = setup["ModelingtoGenerateAlternativeSlack"] + # Read slack parameter representing desired increase in budget from the least cost solution + slack = setup["ModelingtoGenerateAlternativeSlack"] - ### Variables ### + ### Variables ### - @variable(EP, vSumvP[TechTypes = 1:length(TechTypes), z = 1:Z] >= 0) # Variable denoting total generation from eligible technology of a given type + @variable(EP, vSumvP[TechTypes = 1:length(TechTypes), z = 1:Z] >= 0) # Variable denoting total generation from eligible technology of a given type - ### End Variables ### + ### End Variables ### - ### Constraints ### + ### Constraints ### - # Constraint to set budget for MGA iterations - @constraint(EP, budget, EP[:eObj] <= Least_System_Cost * (1 + slack) ) + # Constraint to set budget for MGA iterations + @constraint(EP, budget, EP[:eObj] <= Least_System_Cost * (1 + slack) ) - # Constraint to compute total generation in each zone from a given Technology Type + # Constraint to compute total generation in each zone from a given Technology Type function resource_in_zone_with_TechType(tt::Int64, z::Int64) condition::BitVector = (resource_type_mga.(gen) .== TechTypes[tt]) .& (zone_id.(gen) .== z) return resource_id.(gen[condition]) end - @constraint(EP,cGeneration[tt = 1:length(TechTypes), z = 1:Z], vSumvP[tt,z] == sum(EP[:vP][y,t] * inputs["omega"][t] for y in resource_in_zone_with_TechType(tt,z), t in 1:T)) + @constraint(EP,cGeneration[tt = 1:length(TechTypes), z = 1:Z], vSumvP[tt,z] == sum(EP[:vP][y,t] * inputs["omega"][t] for y in resource_in_zone_with_TechType(tt,z), t in 1:T)) - ### End Constraints ### + ### End Constraints ### - ### Create Results Directory for MGA iterations - outpath_max = joinpath(path, "MGAResults_max") - if !(isdir(outpath_max)) - mkdir(outpath_max) - end - outpath_min = joinpath(path, "MGAResults_min") - if !(isdir(outpath_min)) - mkdir(outpath_min) - end + ### Create Results Directory for MGA iterations + outpath_max = joinpath(path, "MGAResults_max") + if !(isdir(outpath_max)) + mkdir(outpath_max) + end + outpath_min = joinpath(path, "MGAResults_min") + if !(isdir(outpath_min)) + mkdir(outpath_min) + end - ### Begin MGA iterations for maximization and minimization objective ### - mga_start_time = time() + ### Begin MGA iterations for maximization and minimization objective ### + mga_start_time = time() - print("Starting the first MGA iteration") + print("Starting the first MGA iteration") - for i in 1:setup["ModelingToGenerateAlternativeIterations"] + for i in 1:setup["ModelingToGenerateAlternativeIterations"] - # Create random coefficients for the generators that we want to include in the MGA run for the given budget - pRand = rand(length(TechTypes),length(zones)) + # Create random coefficients for the generators that we want to include in the MGA run for the given budget + pRand = rand(length(TechTypes),length(zones)) - ### Maximization objective - @objective(EP, Max, sum(pRand[tt,z] * vSumvP[tt,z] for tt in 1:length(TechTypes), z in 1:Z )) + ### Maximization objective + @objective(EP, Max, sum(pRand[tt,z] * vSumvP[tt,z] for tt in 1:length(TechTypes), z in 1:Z )) - # Solve Model Iteration - status = optimize!(EP) + # Solve Model Iteration + status = optimize!(EP) - # Create path for saving MGA iterations - mgaoutpath_max = joinpath(outpath_max, string("MGA", "_", slack,"_", i)) + # Create path for saving MGA iterations + mgaoutpath_max = joinpath(outpath_max, string("MGA", "_", slack,"_", i)) - # Write results - write_outputs(EP, mgaoutpath_max, setup, inputs) + # Write results + write_outputs(EP, mgaoutpath_max, setup, inputs) - ### Minimization objective - @objective(EP, Min, sum(pRand[tt,z] * vSumvP[tt,z] for tt in 1:length(TechTypes), z in 1:Z )) + ### Minimization objective + @objective(EP, Min, sum(pRand[tt,z] * vSumvP[tt,z] for tt in 1:length(TechTypes), z in 1:Z )) - # Solve Model Iteration - status = optimize!(EP) + # Solve Model Iteration + status = optimize!(EP) - # Create path for saving MGA iterations - mgaoutpath_min = joinpath(outpath_min, string("MGA", "_", slack,"_", i)) + # Create path for saving MGA iterations + mgaoutpath_min = joinpath(outpath_min, string("MGA", "_", slack,"_", i)) - # Write results - write_outputs(EP, mgaoutpath_min, setup, inputs) + # Write results + write_outputs(EP, mgaoutpath_min, setup, inputs) - end + end - total_time = time() - mga_start_time - ### End MGA Iterations ### + total_time = time() - mga_start_time + ### End MGA Iterations ### end + end diff --git a/src/model/resources/resources.jl b/src/model/resources/resources.jl index a71e99b3c7..7b67d7fee4 100644 --- a/src/model/resources/resources.jl +++ b/src/model/resources/resources.jl @@ -101,21 +101,6 @@ function Base.get(r::AbstractResource, sym::Symbol, default) return haskey(r, sym) ? getproperty(r,sym) : default end -""" - has(r::AbstractResource, sym::Symbol) - -Check if an `AbstractResource` object has a specific attribute. - -# Arguments: -- `r::AbstractResource`: The resource object. -- `sym::Symbol`: The symbol representing the attribute name. - -# Returns: -- `true` if the attribute exists in the object, `false` otherwise. - -""" -has(r::AbstractResource, sym::Symbol) = haskey(r, sym) - """ Base.getproperty(rs::Vector{<:AbstractResource}, sym::Symbol) diff --git a/test/test_resource_split.jl b/test/test_resource_split.jl deleted file mode 100644 index ad1e10144a..0000000000 --- a/test/test_resource_split.jl +++ /dev/null @@ -1,68 +0,0 @@ -using GenX -# using Gurobi -using HiGHS -using Logging, LoggingExtras - -optimizer = HiGHS.Optimizer -# optimizer = Gurobi.Optimizer - -# case = "Example_Systems/Electrolyzer_Example" -case = "test/LoadResourceData/test_gen_non_colocated" -# case = "test/LoadResourceData/test_gen_vre_stor" -# case = "test/VREStor" - -genx_settings = GenX.get_settings_path(case, "genx_settings.yml") -setup = configure_settings(genx_settings) - -settings_path = GenX.get_settings_path(case) - -println("Configuring Solver") -OPTIMIZER = configure_solver(settings_path, optimizer) - -# const ModelScalingFactor = 1e+3 -# scale_factor = setup["ParameterScale"] == 1 ? ModelScalingFactor : 1 - -# # get path to resources data -# resources_folder = setup["ResourcePath"] -# resources_folder = joinpath(case,resources_folder) - -# # load resources data and scale it if necessary -# resources = GenX.load_scaled_resources_data(resources_folder, scale_factor) - -# # add policies-related attributes to resource dataframe -# policy_folder = setup["PolicyPath"] -# policy_folder = joinpath(case, policy_folder) -# GenX._add_policies_to_resources!(policy_folder, resources) - -inputs = load_inputs(setup, case); - -gen = inputs["RESOURCES"]; - -time_elapsed = @elapsed EP = generate_model(setup, inputs, OPTIMIZER) -println("Time to generate model: $time_elapsed") - -@profview generate_model(setup, inputs, OPTIMIZER) - -println("Solving Model") -EP, solve_time = solve_model(EP, setup) - -println("Loading Inputs") -function test_1(setup, case) - warnerror_logger = ConsoleLogger(stderr, Logging.Error) - - with_logger(warnerror_logger) do - redirect_stdout(devnull) do - input_data = load_inputs(setup, case) - end - end -end - -function test_2(setup, input_data, OPTIMIZER) - redirect_stdout(devnull) do - EP = generate_model(setup, input_data, OPTIMIZER) - end -end - -using BenchmarkTools -@benchmark test_1($setup, $case) -@benchmark test_2($setup, $input_data, $OPTIMIZER) \ No newline at end of file