Skip to content

Commit

Permalink
v0.3.3 mv trim_tree! and leaf_busses to CommonOPF
Browse files Browse the repository at this point in the history
  • Loading branch information
NLaws committed Jul 26, 2023
1 parent 46dee4e commit fc04f51
Show file tree
Hide file tree
Showing 5 changed files with 7 additions and 55 deletions.
4 changes: 2 additions & 2 deletions Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "BranchFlowModel"
uuid = "73c867df-75f8-459f-abd8-059b58de1e18"
authors = ["Nick Laws"]
version = "0.3.2"
version = "0.3.3"

[deps]
CommonOPF = "dad7ea18-2b21-482e-81c1-e84414cc4b03"
Expand All @@ -13,7 +13,7 @@ MetaGraphs = "626554b9-1ddb-594c-aa3c-2596fe9399a5"
SparseArrays = "2f01184e-e22b-5df5-ae63-d93ebab69eaf"

[compat]
CommonOPF = "0.3.2"
CommonOPF = "0.3.3"
Graphs = "1.8"
JSON = "0.21"
JuMP = "1"
Expand Down
2 changes: 0 additions & 2 deletions src/BranchFlowModel.jl
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,7 @@ export
current_values_by_time_edge,
line_flow_values_by_time_edge,
reduce_tree!,
trim_tree!,
make_graph,
leaf_busses,
init_inputs!,
set_inputs!,
split_at_busses,
Expand Down
21 changes: 3 additions & 18 deletions src/decomposition.jl
Original file line number Diff line number Diff line change
@@ -1,18 +1,3 @@
"""
leaf_busses(p::Inputs)
returns `Vector{String}` containing all of the leaf busses in `p.busses`
"""
function leaf_busses(p::Inputs)
leafs = String[]
for j in p.busses
if !isempty(i_to_j(j, p)) && isempty(j_to_k(j, p))
push!(leafs, j)
end
end
return leafs
end


"""
connecting_busses(mg::MetaDiGraph, v)
Expand Down Expand Up @@ -71,20 +56,20 @@ function init_inputs!(ps::Vector{Inputs{SinglePhase}}; init_vs::Dict = Dict())
if p.substation_bus in keys(init_vs)
p.v0 = init_vs[p.substation_bus]
end
leafs = leaf_busses(p)
leafs = CommonOPF.leaf_busses(p)
for pp in ps
if pp.substation_bus in leafs
if isempty(pp.Pload)
@warn "The Pload dictionary is empty for the sub network with head bus $(pp.substation_bus).\
\nThis indicates that there are probably lines with no loads on the ends in the larger network.\
\nTry using trim_tree! to eliminate the deadend branches."
\nTry using CommonOPF.trim_tree! to eliminate the deadend branches."
else
p.Pload[pp.substation_bus] = sum( values(pp.Pload) )
end
if isempty(pp.Qload)
@warn "The Qload dictionary is empty for the sub network with head bus $(pp.substation_bus).\
\nThis indicates that there are probably lines with no loads on the ends in the larger network.\
\nTry using trim_tree! to eliminate the deadend branches."
\nTry using CommonOPF.trim_tree! to eliminate the deadend branches."
else
p.Qload[pp.substation_bus] = sum( values(pp.Qload) )
end
Expand Down
31 changes: 0 additions & 31 deletions src/inputs.jl
Original file line number Diff line number Diff line change
Expand Up @@ -29,37 +29,6 @@ function reduce_tree!(p::Inputs{SinglePhase}; keep_regulator_busses=true)
end


function trim_tree_once!(p::Inputs{SinglePhase})
trimmable_busses = setdiff(leaf_busses(p), union(keys(p.Pload), keys(p.Qload)))
if isempty(trimmable_busses) return false end
trimmable_edges = Tuple[]
for j in trimmable_busses
for i in i_to_j(j, p)
push!(trimmable_edges, (i,j))
end
end
@debug("Deleting the following edges from the Inputs:")
for edge in trimmable_edges @debug(edge) end
for (i,j) in trimmable_edges
delete_edge_ij!(i, j, p)
delete_bus_j!(j, p)
end
true
end


function trim_tree!(p::Inputs{SinglePhase})
n_edges_before = length(p.edges)
trimming = trim_tree_once!(p)
while trimming
trimming = trim_tree_once!(p)
end
n_edges_after = length(p.edges)
@info("Removed $(n_edges_before - n_edges_after) edges.")
true
end


function make_sub_inputs(
p::Inputs{SinglePhase},
edges_to_delete::Vector,
Expand Down
4 changes: 2 additions & 2 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -900,10 +900,10 @@ end



# TODO test trim_tree!
# TODO test CommonOPF.trim_tree!
delete!(p.Pload, "e")
delete!(p.Qload, "e")
trim_tree!(p)
BranchFlowModel.CommonOPF.trim_tree!(p)
end

end # all tests

2 comments on commit fc04f51

@NLaws
Copy link
Owner Author

@NLaws NLaws commented on fc04f51 Jul 26, 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/88348

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.3 -m "<description of version>" fc04f516ed87fd24282483c330828b1a1e73a7d8
git push origin v0.3.3

Please sign in to comment.