Skip to content

Commit

Permalink
Apply JuliaFormatter
Browse files Browse the repository at this point in the history
  • Loading branch information
cfe316 committed Oct 3, 2023
1 parent cc62c2e commit cd8741c
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 28 deletions.
65 changes: 40 additions & 25 deletions src/model/resources/maintenance.jl
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,12 @@ end
maintenance_duration: length of a maintenance period
maintenance_begin_hours: collection of hours in which maintenance is allowed to start
"""
function controlling_maintenance_start_hours(p::Int, t::Int, maintenance_duration::Int, maintenance_begin_hours)
function controlling_maintenance_start_hours(
p::Int,
t::Int,
maintenance_duration::Int,
maintenance_begin_hours,
)
controlled_hours = hoursbefore(p, t, 0:(maintenance_duration-1))
return intersect(controlled_hours, maintenance_begin_hours)
end
Expand Down Expand Up @@ -77,18 +82,20 @@ end
integer_operational_unit_committment: whether this plant has integer unit
committment for operational variables.
"""
function maintenance_constraints!(EP::Model,
inputs::Dict,
resource_name::AbstractString,
suffix::AbstractString,
r_id::Int,
maint_begin_cadence::Int,
maint_dur::Int,
maint_freq_years::Int,
cap::Float64,
vcommit::Symbol,
ecap::Symbol,
integer_operational_unit_committment::Bool)
function maintenance_constraints!(
EP::Model,
inputs::Dict,
resource_name::AbstractString,
suffix::AbstractString,
r_id::Int,
maint_begin_cadence::Int,
maint_dur::Int,
maint_freq_years::Int,
cap::Float64,
vcommit::Symbol,
ecap::Symbol,
integer_operational_unit_committment::Bool,
)

T = 1:inputs["T"] # Number of time steps (hours)
hours_per_subperiod = inputs["hours_per_subperiod"]
Expand All @@ -105,10 +112,14 @@ function maintenance_constraints!(EP::Model,
maintenance_begin_hours = 1:maint_begin_cadence:T[end]

# create variables
vMDOWN = EP[down] = @variable(EP, [t in T], base_name=down_name, lower_bound=0)
vMSHUT = EP[shut] = @variable(EP, [t in maintenance_begin_hours],
base_name=shut_name,
lower_bound=0)
vMDOWN = EP[down] = @variable(EP, [t in T], base_name = down_name, lower_bound = 0)
vMSHUT =
EP[shut] = @variable(
EP,
[t in maintenance_begin_hours],
base_name = shut_name,
lower_bound = 0
)

if integer_operational_unit_committment
set_integer.(vMDOWN)
Expand All @@ -125,18 +136,22 @@ function maintenance_constraints!(EP::Model,
end)

# Plant is non-committed during maintenance
@constraint(EP, [t in T], ecap[y] / cap - vcommit[y,t] >= vMDOWN[t])

controlling_hours(t) = controlling_maintenance_start_hours(hours_per_subperiod,
t,
maint_dur,
maintenance_begin_hours)
@constraint(EP, [t in T], ecap[y] / cap - vcommit[y, t] >= vMDOWN[t])

controlling_hours(t) = controlling_maintenance_start_hours(
hours_per_subperiod,
t,
maint_dur,
maintenance_begin_hours,
)
# Plant is down for the required number of hours
@constraint(EP, [t in T], vMDOWN[t] == sum(vMSHUT[controlling_hours(t)]))

# Plant require maintenance every (certain number of) year(s)
@constraint(EP, sum(vMSHUT[t] for t in maintenance_begin_hours) >=
ecap[y] / cap / maint_freq_years)
@constraint(
EP,
sum(vMSHUT[t] for t in maintenance_begin_hours) >= ecap[y] / cap / maint_freq_years
)

return down, shut
end
Expand Down
4 changes: 1 addition & 3 deletions src/write_outputs/write_maintenance.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@ function write_simple_csv(filename::AbstractString, df::DataFrame)
CSV.write(filename, df)
end

function write_simple_csv(filename::AbstractString,
header::Vector,
matrix)
function write_simple_csv(filename::AbstractString, header::Vector, matrix)
df = DataFrame(matrix, header)
write_simple_csv(filename, df)
end
Expand Down

0 comments on commit cd8741c

Please sign in to comment.