Skip to content

Commit

Permalink
Clean and address review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
lbonaldo committed Feb 12, 2024
1 parent 3c22ea6 commit 63b531e
Show file tree
Hide file tree
Showing 6 changed files with 71 additions and 157 deletions.
23 changes: 11 additions & 12 deletions docs/make.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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,
)
6 changes: 3 additions & 3 deletions docs/src/developer_guide.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
```

Expand Down
3 changes: 0 additions & 3 deletions src/GenX.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
113 changes: 57 additions & 56 deletions src/additional_tools/modeling_to_generate_alternatives.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
15 changes: 0 additions & 15 deletions src/model/resources/resources.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
68 changes: 0 additions & 68 deletions test/test_resource_split.jl

This file was deleted.

0 comments on commit 63b531e

Please sign in to comment.