Skip to content

Commit

Permalink
v0.3.7 add reduce_tree! for Inputs{MultiPhase}
Browse files Browse the repository at this point in the history
  • Loading branch information
NLaws committed Aug 1, 2023
1 parent 7287caf commit 2a36bdb
Show file tree
Hide file tree
Showing 5 changed files with 108 additions and 2 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# CommonOPF Changelog

## v0.3.7
- add `reduce_tree!` for `Inputs{MultiPhase}` and test

## v0.3.6
- add `remove_bus!` and `reduce_tree!` from BranchFlowModel (tested there)
- add `SinglePhase` `rij` and `xij` from BFM and LDF
Expand Down
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "CommonOPF"
uuid = "dad7ea18-2b21-482e-81c1-e84414cc4b03"
authors = ["Nick Laws <[email protected]> and contributors"]
version = "0.3.6"
version = "0.3.7"

[deps]
Graphs = "86223c79-3864-5bf0-83f7-82e725a168b6"
Expand Down
1 change: 1 addition & 0 deletions docs/src/methods.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ leaf_busses
remove_bus!(j::String, p::Inputs{SinglePhase})
remove_bus!(j::String, p::Inputs{MultiPhase})
reduce_tree!(p::Inputs{SinglePhase})
reduce_tree!(p::Inputs{MultiPhase})
```

# Types
Expand Down
48 changes: 47 additions & 1 deletion src/inputs.jl
Original file line number Diff line number Diff line change
Expand Up @@ -410,6 +410,8 @@ end
combine any line sets with intermediate busses that have indegree == outdegree == 1
and is not a load bus into a single line
See `remove_bus!` for how the two lines are combined.
"""
function reduce_tree!(p::Inputs{SinglePhase}; keep_regulator_busses=true)
# TODO make graph once in Inputs ?
Expand All @@ -423,7 +425,7 @@ function reduce_tree!(p::Inputs{SinglePhase}; keep_regulator_busses=true)
end
end
for v in vertices(g)
if indegree(g, v) == outdegree(g, v) == 1 && !(int_bus_map[v] in load_buses)
if !(int_bus_map[v] in load_buses) && indegree(g, v) == outdegree(g, v) == 1
push!(reducable_buses, int_bus_map[v])
end
end
Expand All @@ -434,3 +436,47 @@ function reduce_tree!(p::Inputs{SinglePhase}; keep_regulator_busses=true)
end
@info("Removed $(length(reducable_buses)) busses.")
end


"""
reduce_tree!(p::Inputs{MultiPhase})
combine any line sets with intermediate busses that satisfy
1. indegree == outdegree == 1
2. is not a load bus and
3. has same phases in as out
into a single line.
See `remove_bus!` for how the two lines are combined.
"""
function reduce_tree!(p::Inputs{MultiPhase}; keep_regulator_busses=true)
# TODO make graph once in Inputs ?
g = make_graph(p.busses, p.edges)
int_bus_map = get_prop(g, :int_bus_map)
reducable_buses = String[]
load_buses = Set(vcat(collect(keys(p.Pload)), collect(keys(p.Qload))))
if keep_regulator_busses
for bs in keys(p.regulators) # tuple keys of bus pairs, i.e. edges
push!(load_buses, bs...)
end
end
for v in vertices(g)
if !(int_bus_map[v] in load_buses) && indegree(g, v) == outdegree(g, v) == 1
# TODO add phases to the graph instead of this mess
j = int_bus_map[v]
i, k = i_to_j(j, p)[1], j_to_k(j, p)[1]
ij_idx, jk_idx = get_ij_idx(i, j, p), get_ij_idx(j, k, p)
phases_in = Set(p.phases[ij_idx])
phases_out = Set(p.phases[jk_idx])
if phases_in == phases_out
push!(reducable_buses, int_bus_map[v])
end
end
end
@debug("Removing the following busses: \n$reducable_buses")
# replace two lines with one
for j in reducable_buses
remove_bus!(j, p)
end
@info("Removed $(length(reducable_buses)) busses.")
end
56 changes: 56 additions & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -169,4 +169,60 @@ end
# TODO put in method for use and testing
end


@testset "reduce_tree! MultiPhase" begin
#= c -- e -- e
/ [1,2] /
a -[1,2,3]- b -> a -- b
\ [2,3] \
d -- f -- f
nodes c and d should be removed b/c there is no load at them and the phases are the same
on both sides
=#
edges = [("a", "b"), ("b", "c"), ("b", "d"), ("c", "e"), ("d", "f")]
linecodes = repeat(["l1"], length(edges))
linelengths = repeat([1.0], length(edges))
phases = [[1,2,3], [1,2], [2,3], [2,1], [3,2]] # change order intentionally
substation_bus = "a"
Pload = Dict("e" => [1.0], "f" => [1.0])
Qload = Dict("e" => [0.1], "f" => [0.1])
Zdict = Dict("l1" => Dict("rmatrix"=> [1.0], "xmatrix"=> [1.0], "nphases"=> 1))
v0 = 1.0

p = Inputs(
edges,
linecodes,
linelengths,
phases,
substation_bus;
Pload=Pload,
Qload=Qload,
Sbase=1,
Vbase=1,
Zdict=Zdict,
v0=v0,
v_lolim=0.95,
v_uplim=1.05,
Ntimesteps=1,
P_up_bound=1e4,
Q_up_bound=1e4,
P_lo_bound=-1e4,
Q_lo_bound=-1e4,
Isquared_up_bounds=Dict{String, Float64}(),
relaxed=true
)

reduce_tree!(p)

@test !("c" in p.busses)
@test !("d" in p.busses)
@test !(("b", "c") in p.edges)
@test !(("b", "d") in p.edges)
@test !(("c", "e") in p.edges)
@test !(("d", "f") in p.edges)
@test ("b", "e") in p.edges
@test ("b", "f") in p.edges

end

end

2 comments on commit 2a36bdb

@NLaws
Copy link
Owner Author

@NLaws NLaws commented on 2a36bdb Aug 1, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Registration pull request created: JuliaRegistries/General/88835

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a v0.3.7 -m "<description of version>" 2a36bdbc671c2c0261027c7d35912e15397c8ec9
git push origin v0.3.7

Please sign in to comment.