Skip to content

Commit

Permalink
feat: add write_decomposition
Browse files Browse the repository at this point in the history
  • Loading branch information
CharlyAL15 committed Sep 30, 2024
1 parent 09dc084 commit 30611d5
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/OPFSDP.jl
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ include("core.jl")
include("io/read_matpower.jl")
include("io/read_rawgo.jl")
include("io/read_network.jl")
include("io/write_decomposition.jl")
include("utils/graphs.jl")
include("decompose/cliques.jl")
include("decompose/cliquetree.jl")
Expand All @@ -36,6 +37,7 @@ include("solve/solve.jl")


export read_matpower, read_rawgo, read_network
export write_decomposition
export display_opf
export chordal_extension
export merge_cliques!, merge_molzahn!
Expand Down
3 changes: 3 additions & 0 deletions src/decompose/merge/merge.jl
Original file line number Diff line number Diff line change
Expand Up @@ -72,18 +72,21 @@ Apply the Molzahn et al. merging alogrithm to the chordal graph represented by `
`L` is a percentage of the number of cliques in `maximal_cliques`. It is used to stop the merging.
"""
function merge_molzahn!(cadj, maximal_cliques, clique_tree, L::Float64=0.1)
total_cost = 0
treshold = L * length(maximal_cliques)
if treshold < 2
treshold = 2
end
while length(maximal_cliques) > treshold
costs = compute_merge_cost_all(maximal_cliques, clique_tree)
i, k, cost = argmin(x -> x[3], costs)
total_cost += -cost
clique = union(maximal_cliques[i], maximal_cliques[k])
clique_tree = merge_clique!(i, k, clique, maximal_cliques, clique_tree)
end
for c in maximal_cliques
make_subgraph_complete!(cadj, c)
end
println("TOTAL REWARD: $(total_cost)")
end
merge_cliques!(cadj, maximal_cliques, clique_tree, merge_alg::MolzahnMerge) = merge_molzahn!(cadj, maximal_cliques, clique_tree, merge_alg.L)
3 changes: 3 additions & 0 deletions src/decompose/merge/sliwak.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
function compute_merge_coefficient(network::PowerFlowNetwork)

end
17 changes: 17 additions & 0 deletions src/io/write_decomposition.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
function get_object_str(object)
name = string(typeof(object))
object_fieldnames = sort(collect(map(string, fieldnames(typeof(object)))))
key_val_str = join(["$f:$(getfield(object, Symbol(f)))" for f in object_fieldnames], ";")
return "($(name)|$(key_val_str))"
end

function write_decomposition(path::AbstractString, extension::AbstractChordalExtension)
network = OPFSDP.read_matpower(path)
name = splitext(splitdir(path)[end])[1]
cadj = OPFSDP.cholesky_extension(network)
cliques = OPFSDP.maximal_cliques(cadj)
cliquetree = OPFSDP.maximal_cliquetree(cliques)
open("$(name)_$(get_object_str(extension)).txt", "w") do io
writedlm(io, cadj, ',')
end
end

0 comments on commit 30611d5

Please sign in to comment.