-
Notifications
You must be signed in to change notification settings - Fork 7
/
powerCaseGraph.m
35 lines (30 loc) · 1.27 KB
/
powerCaseGraph.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
function G = powerCaseGraph(caseObject)
nnodes = size(caseObject.bus,1);
nline = size(caseObject.lineBranch,1);
ntrafo = size(caseObject.trafoBranch,1);
busID = caseObject.bus(:,1);
%% Indexing
ext2intID = zeros(max(busID),1);
ext2intID(caseObject.bus(:,1))=(1:nnodes)';
caseObject.bus(:,1) = (1:nnodes)';
caseObject.gen(:,1) = ext2intID(caseObject.gen(:,1));
if (nline~=0)
caseObject.lineBranch(:,1) = ext2intID(caseObject.lineBranch(:,1));
caseObject.lineBranch(:,2) = ext2intID(caseObject.lineBranch(:,2));
end
if (ntrafo~=0)
caseObject.trafoBranch(:,1) = ext2intID(caseObject.trafoBranch(:,1));
caseObject.trafoBranch(:,2) = ext2intID(caseObject.trafoBranch(:,2));
end
%% Initialization
linkList = [[caseObject.lineBranch(:,1);caseObject.trafoBranch(:,1)],...
[caseObject.lineBranch(:,2);caseObject.trafoBranch(:,2)]];
for n=1:(nline+ntrafo)
link = linkList(n,:);
A_rows(2*n-1:2*n) = [link(1);link(2)];
A_cols(2*n-1:2*n) = [link(2);link(1)];
A_vals(2*n-1:2*n) = 1;
end
A = sparse(A_rows,A_cols,A_vals,nnodes,nnodes); %A-matrix allocation
G = graph(A,cellstr(num2str(busID)));
end