Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bus merging logic to ensure correct bus type updates #937

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 11 additions & 3 deletions src/core/data.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2687,12 +2687,12 @@ end
given a network data dict merges buses that are connected by closed switches
converting the dataset into a pure bus-branch model.
"""
function resolve_swithces!(data::Dict{String,<:Any})
apply_pm!(_resolve_swithces!, data)
function resolve_switches!(data::Dict{String,<:Any})
apply_pm!(_resolve_switches!, data)
end

""
function _resolve_swithces!(data::Dict{String,<:Any})
function _resolve_switches!(data::Dict{String,<:Any})
if length(data["switch"]) <= 0
return
end
Expand Down Expand Up @@ -2721,7 +2721,15 @@ function _resolve_swithces!(data::Dict{String,<:Any})
for bus_set in Set(values(bus_sets))
bus_min = minimum(bus_set)
Memento.info(_LOGGER, "merged buses $(join(bus_set, ",")) in to bus $(bus_min) based on switch status")

# Merging a PV bus into a PQ bus results in a PV bus.
# Therefore, the resulting bus should always have the highest bus_type,
# but it should never be of type 4 (disconnected).
bus_type = maximum(data["bus"]["$i"]["bus_type"] for i in bus_set)
bus_type = min(bus_type, 3)

for i in bus_set
data["bus"]["$i"]["bus_type"] = bus_type
if i != bus_min
bus_id_map[i] = bus_min
end
Expand Down
2 changes: 1 addition & 1 deletion src/core/data_basic.jl
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ function make_basic_network!(data::Dict{String,<:Any})
end

# remove switches by merging buses
resolve_swithces!(data)
resolve_switches!(data)

# switch resolution can result in new parallel branches
correct_branch_directions!(data)
Expand Down
3 changes: 2 additions & 1 deletion test/data.jl
Original file line number Diff line number Diff line change
Expand Up @@ -879,10 +879,11 @@ end
@testset "test resolve switches" begin
@testset "5-bus with switches" begin
data = PowerModels.parse_file("../test/data/matpower/case5_sw.m")
resolve_swithces!(data)
resolve_switches!(data)

@test length(data["switch"]) == 0
@test length(data["bus"]) == 4
@test data["bus"]["1"]["bus_type"] == 2

result = solve_opf(data, ACPPowerModel, nlp_solver)

Expand Down
Loading