forked from alexshtf/trem_opf_solver
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnode_data.m
93 lines (78 loc) · 2.87 KB
/
node_data.m
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
classdef node_data < handle
properties
sonIndices
curves
end
methods(Static)
function arr = make_array(sz)
arr(sz) = node_data();
end
function curves = decompose_phi_curves(volts, ps, qs)
breaks = monotonic_seq(volts);
curves = cell(1, numel(breaks));
from = 1;
for i = 1:numel(breaks)
range = from:breaks(i);
curves{i} = phi_curve(volts(range), ps(range), qs(range));
from = breaks(i);
end
end
function lb = min_volt(curve)
lb = curve.vmin;
end
function ub = max_volt(curve)
ub = curve.vmax;
end
end
methods
function pass_impedance(obj, Z)
phi_curves = cell(1, obj.num_curves());
phi_indices = cell(1, obj.num_curves());
for i = 1:numel(phi_curves)
curve = obj.curves{i};
indices = obj.sonIndices(:, i);
[v_tilde, s_tilde] = pass_impedance(curve.vs, curve.ss, Z);
phi_curves{i} = node_data.decompose_phi_curves(...
v_tilde, real(s_tilde), imag(s_tilde));
phi_indices{i} = repmat(indices, [1, numel(phi_curves{i})]);
end
obj.sonIndices = horzcat(phi_indices{:});
obj.curves = horzcat(phi_curves{:});
end
function merge_curves(obj, children, d, constraint)
son_indices = cell(1, numel(children));
for i = 1:numel(children)
son_indices{i} = 1:(children(i).num_curves());
end
son_indices = combvec(son_indices{:});
for i = 1:size(son_indices, 2)
idx = son_indices(:, i);
curves_to_merge = cell(1, numel(children));
for j = 1:numel(children)
curves_to_merge{j} = children(j).curves{idx(j)};
end
merged = merge_curves(d, curves_to_merge, constraint);
if isa(merged, 'struct')
obj.add_curve(idx, merged);
end
end
if obj.num_curves() == 0
error('Problem is infeasible');
end
end
function s = sample_phi(obj, idx, v)
s = obj.curves{idx}.sample_phi(v);
end
function n = num_curves(obj)
n = numel(obj.curves);
end
function obj = node_data()
obj.sonIndices = [];
obj.curves = cell(0,0);
end
function add_curve(obj, indices, curve)
obj.sonIndices(:, end+1) = indices(:);
obj.curves{end+1} = curve;
end
end
end