Skip to content

Commit

Permalink
refactor: clean the codebase
Browse files Browse the repository at this point in the history
  • Loading branch information
CharlyAL15 committed Jun 17, 2024
1 parent 72ad4f7 commit d53dec7
Show file tree
Hide file tree
Showing 42 changed files with 16 additions and 1,945 deletions.
Binary file removed data.zip
Binary file not shown.
14 changes: 6 additions & 8 deletions src/OPFSDP.jl
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,7 @@ include("core.jl")
include("io/read_matpower.jl")
include("io/read_rawgo.jl")
include("io/read_network.jl")
include("utils/compute_current.jl")
include("utils/compute_power.jl")
include("utils/graphs.jl")
include("display/display_opf.jl")
include("decompose/cliques.jl")
include("decompose/cliquetree.jl")
include("decompose/extension/extension.jl")
Expand All @@ -27,14 +24,15 @@ include("decompose/merge/merge.jl")
using .ReadMatpower
using .ReadRawGo

include("solve/solve_X_real/solve.jl")

include("solve/variables.jl")
include("solve/objective.jl")
include("solve/power_constraints.jl")
include("solve/voltage_constraints.jl")
include("solve/linking_constraints.jl")
include("solve/solve.jl")


export read_matpower, read_rawgo, read_network
export compute_current_origin, compute_current_destination
export compute_powers, compute_power_from, compute_power_to, str_power_from, str_power_to
export get_branches_in, get_branches_out
export display_opf
export chordal_extension
export merge_cliques!, merge_molzahn!
Expand Down
22 changes: 10 additions & 12 deletions src/core.jl
Original file line number Diff line number Diff line change
Expand Up @@ -87,28 +87,27 @@ mutable struct PowerFlowNetwork
end
end

nbus(network::PowerFlowNetwork) = length(network.buses)
ngen(network::PowerFlowNetwork) = network.ngen
nbranch(network::PowerFlowNetwork) = length(network.branches)

generators(network::PowerFlowNetwork) = vcat([gen for gen in values(network.generators)]...)
function generators(network::PowerFlowNetwork, bus_id)
if bus_id in keys(network.generators)
return network.generators[bus_id]
end
return []
end
generators(network::PowerFlowNetwork, bus_id) = bus_id in keys(network.generators) ? network.generators[bus_id] : []

buses(network::PowerFlowNetwork) = collect(values(network.buses))

branches(network::PowerFlowNetwork) = network.branches
branches(network::PowerFlowNetwork, bus_id) = [b for b in network.branches if (b.from == bus_id || b.to == bus_id)]
branches(network::PowerFlowNetwork, bus_id1, bus_id2) = [b for b in network.branches if (b.from == bus_id1 && b.to == bus_id2) || (b.from == bus_id2 && b.to == bus_id1)]
nbus(network::PowerFlowNetwork) = length(network.buses)
ngen(network::PowerFlowNetwork) = network.ngen
nbranch(network::PowerFlowNetwork) = length(network.branches)

normid(network::PowerFlowNetwork, bus_id) = findfirst(id -> id == bus_id, network.buses_order)
trueid(network::PowerFlowNetwork, norm_id) = network.buses_order[norm_id]

function refbus(network::PowerFlowNetwork)
refbuses = filter(b -> b.type == ref, collect(values(network.buses)))
return refbuses[1]
end


function hasgen(network, bus_id)
return bus_id in keys(network.generators)
end
Expand All @@ -122,6 +121,5 @@ function hasbranch_directed(network, from, to)
end

function hasbranch(network, b, a)
return !isnothing(findifrst(b -> (b.from == b && b.to == a) || (b.to == b && b.from == a),
network.branches))
return !isnothing(findifrst(b -> (b.from == b && b.to == a) || (b.to == b && b.from == a), network.branches))
end
File renamed without changes.
1 change: 0 additions & 1 deletion src/io/read_matpower.jl
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,6 @@ function check_convert_r_x(file)
return occursin("mpc.bus(:, [PD, QD]) = mpc.bus(:, [PD, QD]) / 1e3;", file)# && !occursin("%mpc.bus(:, [PD, QD]) = mpc.bus(:, [PD, QD]) / 1e3;", file))
end


function read_matpower(path::AbstractString)
file = read(open(path, "r"), String)
convert_load = check_convert_load(file)
Expand Down
5 changes: 0 additions & 5 deletions src/io/read_rawgo.jl
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ function _extract_baseMVA(lines)
return values[1]
end


function _get_line_values(line)
line_split = split(line, ',')
values = [i == 2 ? l : parse(Float64, l) for (i, l) in enumerate(line_split)]
Expand Down Expand Up @@ -60,7 +59,6 @@ function _add_bus_load!(lines, bus_dict, baseMVA)
end
end


function _add_bus_shunt!(lines, bus_dict, baseMVA)
i = _arg_to(lines, "END OF LOAD DATA BEGIN FIXED SHUNT DATA") + 1

Expand All @@ -71,7 +69,6 @@ function _add_bus_shunt!(lines, bus_dict, baseMVA)
end
end


function _extract_gen_data(lines, baseMVA)
i = _arg_to(lines, "END OF FIXED SHUNT DATA BEGIN GENERATOR DATA") + 1
gen_dict::Dict{Int,Vector{Generator}}=Dict()
Expand Down Expand Up @@ -99,11 +96,9 @@ function _extract_gen_data(lines, baseMVA)
return gen_dict, order
end


function _add_gencost_data!(network, case_dict)
end


function read_rawgo(path::AbstractString)
file = read(open(path, "r"), String)
lines = split(file, '\n')
Expand Down
9 changes: 0 additions & 9 deletions src/io/save_W_model.jl

This file was deleted.

File renamed without changes.
File renamed without changes.
File renamed without changes.
6 changes: 0 additions & 6 deletions src/solve/solve_X_real/solve.jl → src/solve/solve.jl
Original file line number Diff line number Diff line change
@@ -1,9 +1,3 @@
include("variables.jl")
include("objective.jl")
include("power_constraints.jl")
include("voltage_constraints.jl")
include("linking_constraints.jl")

function computeY(network::PowerFlowNetwork)
zero = 1e-10
_nbus = nbus(network)
Expand Down
209 changes: 0 additions & 209 deletions src/solve/solve_W/constants.jl

This file was deleted.

28 changes: 0 additions & 28 deletions src/solve/solve_W/linking_constraints.jl

This file was deleted.

16 changes: 0 additions & 16 deletions src/solve/solve_W/objective.jl

This file was deleted.

Loading

0 comments on commit d53dec7

Please sign in to comment.