-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathpowergrid.jl
36 lines (33 loc) · 1.16 KB
/
powergrid.jl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
using Random;
using LinearAlgebra;
using SparseArrays;
using DataFrames;
using CSV;
using NetworkOP;
using Plots;
include("utils.jl");
function read_Powergrid()
df_topology = CSV.read("data/opsahl-powergrid/out.opsahl-powergrid", delim=' ', header=["src","dst"])
id2num_topology = Dict{Int64,Int64}(id=>i for (i,id) in enumerate(unique(vcat(df_topology[:src],df_topology[:dst]))));
n = length(id2num_topology);
#---------------------------------------------------------------------------------------
I = Vector{Int64}();
J = Vector{Int64}();
V = Vector{Float64}();
for i in 1:size(df_topology,1)
if (df_topology[i,1] != df_topology[i,2])
#------------------------
push!(I,id2num_topology[df_topology[i,1]]);
push!(J,id2num_topology[df_topology[i,2]]);
push!(V,1.0);
#------------------------
push!(I,id2num_topology[df_topology[i,2]]);
push!(J,id2num_topology[df_topology[i,1]]);
push!(V,1.0);
#------------------------
end
end
A = sparse(I,J,V,n,n);
FN = NetworkOP.FlowNetwork(A);
return FN, nothing, nothing
end