@@ -9,11 +9,13 @@ cossim(x,y) = dot(x,y) / (norm(x)*norm(y))
99# #############
1010# Parameters
1111# #############
12+ network_formulation = " ACPPowerModel"
1213case_name = " pglib_opf_case300_ieee"
1314path_dataset = joinpath (dirname (@__FILE__ ), " data" )
1415case_file_path = joinpath (path_dataset, case_name)
1516case_file_path_train = joinpath (case_file_path, " input" , " train" )
1617case_file_path_test = joinpath (case_file_path, " input" , " test" )
18+ case_file_path_output = joinpath (case_file_path, " output" , string (network_formulation))
1719
1820# #############
1921# Load Data
@@ -28,14 +30,22 @@ file_train = [
2830file_test = [
2931 joinpath (case_file_path_test, file) for file in iter_files_test if occursin (" input" , file)
3032]
33+ iter_files_out = readdir (joinpath (case_file_path_output))
34+ iter_files_out = filter (x -> occursin (" arrow" , x), iter_files_out)
35+ file_outs = [
36+ joinpath (case_file_path_output, file) for file in iter_files_out if occursin (" output" , file)
37+ ]
3138
3239# Load input and output data tables
3340input_table_train = Arrow. Table (file_train)
3441input_table_test = Arrow. Table (file_test)
42+ output_table = Arrow. Table (file_outs)
3543
3644# Convert to dataframes
3745input_data_train = DataFrame (input_table_train)
3846input_data_test = DataFrame (input_table_test)
47+ output_data = DataFrame (output_table)
48+ input_data = vcat (input_data_train, input_data_test[! , Not (:in_train_convex_hull )])
3949
4050# #############
4151# Plots
@@ -58,6 +68,7 @@ function total_load_vector(input_data; is_test=false)
5868 return df
5969end
6070
71+ # ######## Plot Load Vectors #########
6172load_vector_train = total_load_vector (input_data_train)
6273load_vector_test = total_load_vector (input_data_test; is_test= true )
6374
@@ -79,4 +90,56 @@ p1 = plot(scatter(theta_train, norm_sim_train, proj = :polar, label="Train", col
7990p2 = plot (scatter (theta_test, norm_sim_test, proj = :polar , label= " Test" , color= :orange ));
8091plot (p1, p2; title= " Load Similarity" , legend= :bottomright , layout = l)
8192
93+ # ######## Plot Objective Function #########
94+ # Plot objective function for a single direction
95+
96+ # Select two points in the extremes
97+ load_vector = total_load_vector (input_data)
98+
99+ nominal_loads = Vector (load_vector[1 , Not (:id )])
100+ norm_nominal_loads = norm (nominal_loads)
101+
102+ load_vector. norm_loads = [norm (Vector (load_vector[i, Not (:id )])) for i in 1 : size (load_vector, 1 )] ./ norm_nominal_loads
103+ # join input and output data
104+ joined_data = innerjoin (load_vector, output_data[! , [:id , :operational_cost ]], on= :id )
105+
106+ # get k extreme points
107+ using L2O
108+ using Gurobi
109+ function maxk (a, k)
110+ b = partialsortperm (a, 1 : k, rev= true )
111+ return collect (zip (b, a[b]))
112+ end
113+ function mink (a, k)
114+ b = partialsortperm (a, 1 : k, rev= false )
115+ return collect (zip (b, a[b]))
116+ end
117+ k = 10
118+ idx_maxs = maxk (joined_data. norm_loads, k)
119+ idx_mins = mink (joined_data. norm_loads, k)
120+
121+ # Objective function
122+ instances_in_convex_hulls = Array {DataFrame} (undef, k)
123+ for i in 1 : k
124+ @info " Processing instance $i "
125+ instance_load_max = joined_data[idx_maxs[i][1 ]: idx_maxs[i][1 ], :]
126+ instance_load_min = joined_data[idx_mins[i][1 ]: idx_mins[i][1 ], :]
82127
128+ # find instances between the two points (i.e. in their convex hull)
129+ in_convex_hull = inconvexhull (
130+ Matrix (vcat (instance_load_max,
131+ instance_load_min)[! , Not ([:id , :norm_loads , :operational_cost ])]), Matrix (joined_data[! , Not ([:id , :norm_loads , :operational_cost ])]),
132+ Gurobi. Optimizer, silent= false , tol= 0.1 # close to convex hull
133+ )
134+
135+ instances_in_convex_hulls[i] = sort (joined_data[in_convex_hull, [:operational_cost , :norm_loads ]], :norm_loads )
136+ end
137+
138+ # Plot
139+ plotly ()
140+
141+ plt = plot (color= :blue , legend= false , xlabel= " Total Load (%)" , ylabel= " Operational Cost" , title= " AC OPF - IEEE300" );
142+ for i in 1 : k
143+ plot! (instances_in_convex_hulls[i][! , :norm_loads ] * 100 , instances_in_convex_hulls[i][! , :operational_cost ], label= " Direction $i " , color= :red , alpha= 0.4 )
144+ end
145+ plt
0 commit comments