-
Notifications
You must be signed in to change notification settings - Fork 3
/
Permutation.m
executable file
·71 lines (55 loc) · 1.77 KB
/
Permutation.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
% "Permutation.m" finds an elimination ordering of the network graph.
% SDP Solver of Optimal Power Flow: beta version
% Ramtin Madani([email protected])
% Morteza Ashraphijuo([email protected])
% Javad Lavaei([email protected])
% Columbia University
% Last Modified: October 07, 2014
function [tw, perm, bags] = Permutation(busL,fbusL,tbusL,statusL,alpha)
nb = length(busL);
nl = length(fbusL);
busN = sparse(busL, ones(nb,1), (1:nb) );
fbusN = busN(fbusL);
tbusN = busN(tbusL);
perm = zeros(nb,1);
neighbour = cell(nb,1);
bags = cell(nb,1);
for ii = 1 : nl
if statusL(ii)
neighbour{fbusN(ii)} = union( neighbour{fbusN(ii)}, tbusL(ii) );
neighbour{tbusN(ii)} = union( neighbour{tbusN(ii)}, fbusL(ii) );
end
end
fil = Fill_In(busN,neighbour,busL);
deg = Deg(busN,neighbour,busL);
tw = 1;
for ii = 1 : nb
[a,m] = min(fil);
if a ~= 0
[a,m] = min( alpha*deg + fil);
end
perm(ii) = busL(m);
bb = union(perm(ii),neighbour{m});
bags{ii} = bb;
if length(bb) > tw + 1
tw = length(bb) - 1;
end
nn = busN(neighbour{m});
nn2 = neighbour{m};
for jj = 1 : length(nn)
kk = nn(jj);
nn2 = union(nn2,neighbour{kk});
neighbour{kk} = setdiff(neighbour{kk},busL(m));
neighbour{kk} = union(neighbour{kk},setdiff(neighbour{m},busL(kk)));
end
ff = Fill_In(busN,neighbour,nn2);
fil(busN(nn2)) = ff;
dd = Deg(busN,neighbour,neighbour{m});
deg(nn) = dd;
fil(m) = Inf;
deg(m) = Inf;
neighbour{m} = 0;
end
disp('Upper bound on treewidth:');
disp(tw);
end