Skip to content

Commit

Permalink
fix genOff interface
Browse files Browse the repository at this point in the history
  • Loading branch information
Anirudh Subramanyam authored and michel2323 committed Jun 13, 2022
1 parent 68c16ae commit 3d3d439
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 45 deletions.
7 changes: 1 addition & 6 deletions examples/exatron.jl
Original file line number Diff line number Diff line change
Expand Up @@ -86,10 +86,6 @@ ranks = MPI.Comm_size(MPI.COMM_WORLD)
if MPI.Comm_rank(MPI.COMM_WORLD) == 0
println("ProxAL/ExaTron $ranks ranks, $T periods, $K contingencies")
end
# Tuple(genid, Pmin, Pmax)
genOff = Dict{Int,Vector{Tuple{Int,Float64,Float64}}}()
# At time period 2 switch generator 3 off by setting Pmin = Pmax = 0.0
genOff[2] = [(3, 0.0, 0.0)]
cur_logger = global_logger(NullLogger())
elapsed_t = @elapsed begin
# redirect_stdout(devnull) do
Expand All @@ -98,8 +94,7 @@ elapsed_t = @elapsed begin
load_file,
modelinfo,
algparams,
backend;
genOff=genOff
backend
)
# end
end
Expand Down
5 changes: 2 additions & 3 deletions src/Evaluators/ProxALEvalutor.jl
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,7 @@ function ProxALEvaluator(
modelinfo::ModelInfo,
algparams::AlgParams,
space::AbstractBackend=JuMPBackend(),
comm::Union{MPI.Comm,Nothing} = MPI.COMM_WORLD;
genOff::Union{Dict{Int,Vector{Tuple{Int,Float64,Float64}}},Nothing} = nothing,
comm::Union{MPI.Comm,Nothing} = MPI.COMM_WORLD
)
rawdata = RawData(case_file, load_file)
opfdata = opf_loaddata(
Expand Down Expand Up @@ -65,7 +64,7 @@ function ProxALEvaluator(
end

# ctgs_arr = deepcopy(rawdata.ctgs_arr)
problem = ProxALProblem(opfdata, rawdata, modelinfo, algparams, space, comm; genOff=genOff)
problem = ProxALProblem(opfdata, rawdata, modelinfo, algparams, space, comm)
return ProxALEvaluator(problem, modelinfo, algparams, opfdata, rawdata, space, comm)
end

Expand Down
33 changes: 10 additions & 23 deletions src/OPF/opfdata.jl
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,8 @@ end
load_scale::Float64=1.0,
ramp_scale::Float64=0.0,
corr_scale::Float64=0.1,
lineOff=Line()
lineOff=Line(),
genOff::Vector{Int}=Int[],
)
Loads the multi-period ACOPF instance data from `raw`
Expand All @@ -216,6 +217,9 @@ These are set in `ModelInfo`. See [Model parameters](@ref).
`lineOff` is a transmission line that can be deleted to
represent a contingency.
`genOff` is a vector of generator indices that can be turned off
to represent a contingency.
NOTE: If `raw.genfuel_arr` is undefined for generator ``g``,
then the ramp rate is set equal to ``p_{g}^{max}``.
Otherwise, the ramp rate is set based on the genfuel type as follows.
Expand All @@ -237,7 +241,7 @@ function opf_loaddata(raw::RawData;
ramp_scale::Float64=0.0,
corr_scale::Float64=0.1,
lineOff=Line(),
genOff::Union{Vector{Tuple{Int,Float64,Float64}},Nothing} = nothing)
genOff::Vector{Int}=Int[])
#
# load buses
#
Expand Down Expand Up @@ -311,7 +315,8 @@ function opf_loaddata(raw::RawData;
ncols_gens = size(gen_arr, 2)


gens_on = findall(gen_arr[:, 8].!=0); num_on = length(gens_on)
gens_on = findall(gen_arr[:, 8].!=0); setdiff!(gens_on, genOff)
num_on = length(gens_on)
num_off = num_gens-num_on
if num_off > 0
@warn("loaddata: $(num_off) generators are off and will be discarded (out of $(num_gens))", maxlog=1)
Expand Down Expand Up @@ -341,26 +346,8 @@ function opf_loaddata(raw::RawData;
generators[i].mBase = gen_arr[git,7]
generators[i].status = gen_arr[git,8]
@assert generators[i].status==1
if !isa(genOff, Nothing) && i getindex.(genOff,1)
# Pmax is stored at 3rd entry of Tuple
Pmax = genOff[findfirst(x -> x[1] == i, genOff)][3]
# Pmin is stored at 2nd entry of Tuple
Pmin = genOff[findfirst(x -> x[1] == i, genOff)][2]
if Pmax == 0.0 && Pmin == 0.0
generators[i].Pmax = 0.0
generators[i].Pmin = 0.0
generators[i].Qmax = 0.0
generators[i].Qmin = 0.0
println("Switched generator $i off Pmax = Pmin = Qmax = Qmin = 0.0")
else
generators[i].Pmax = Pmax
generators[i].Pmin = Pmin
println("Changed generator $i to Pmin = $Pmin and Pmax = $Pmax")
end
else
generators[i].Pmax = gen_arr[git,9] / baseMVA
generators[i].Pmin = gen_arr[git,10] / baseMVA
end
generators[i].Pmax = gen_arr[git,9] / baseMVA
generators[i].Pmin = gen_arr[git,10] / baseMVA
generators[i].Pc1 = gen_arr[git,11]
generators[i].Pc2 = gen_arr[git,12]
generators[i].Qc1min = gen_arr[git,13]
Expand Down
5 changes: 2 additions & 3 deletions src/ProxAL.jl
Original file line number Diff line number Diff line change
Expand Up @@ -202,8 +202,7 @@ function ProxALProblem(
modelinfo::ModelInfo,
algparams::AlgParams,
backend::AbstractBackend,
comm::Union{MPI.Comm,Nothing};
genOff::Union{Dict{Int,Vector{Tuple{Int,Float64,Float64}}},Nothing} = nothing,
comm::Union{MPI.Comm,Nothing}
)
# initial values
x = OPFPrimalSolution(opfdata, modelinfo)
Expand All @@ -219,7 +218,7 @@ function ProxALProblem(
blocks = OPFBlocks(
opfdata, rawdata;
modelinfo=modelinfo, algparams=algparams,
backend=backend, comm, genOff=genOff,
backend=backend, comm=comm
)
blkLinIndex = LinearIndices(blocks.blkIndex)
for blk in blkLinIndex
Expand Down
11 changes: 1 addition & 10 deletions src/blocks.jl
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@ function OPFBlocks(
backend=JuMPBlockBackend,
algparams::AlgParams = AlgParams(),
comm::Union{MPI.Comm,Nothing},
genOff::Union{Dict{Int,Vector{Tuple{Int,Float64,Float64}}},Nothing} = nothing,
)
ngen = length(opfdata.generators)
nbus = length(opfdata.buses)
Expand All @@ -80,7 +79,6 @@ function OPFBlocks(
modelinfo,
t, k;
decompCtgs=false,
genOff::Union{Nothing,Vector{Tuple{Int,Float64,Float64}}}=nothing,
)
lineOff = Line()
if length(rawdata.ctgs_arr) < k - 1
Expand All @@ -99,7 +97,6 @@ function OPFBlocks(
ramp_scale=modelinfo.ramp_scale,
corr_scale=modelinfo.corr_scale,
lineOff=lineOff,
genOff=genOff,
)
return data
end
Expand All @@ -115,14 +112,8 @@ function OPFBlocks(
@assert k > 0
localinfo.num_ctgs = 0
end
_genOff = nothing
if genOff != nothing
_genOff = haskey(genOff,t) ? genOff[t] : nothing
end
localdata = load_local_data(rawdata, opfdata, localinfo, t, k;
decompCtgs=algparams.decompCtgs,
genOff=_genOff,
)
decompCtgs=algparams.decompCtgs)
# Create block model
localmodel = backend(blk, localdata, rawdata, algparams, localinfo, t, k, T)
else
Expand Down

0 comments on commit 3d3d439

Please sign in to comment.