forked from robince/partial-info-decomp
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlattice2d.m
46 lines (39 loc) · 1.08 KB
/
lattice2d.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
function lat = lattice2d()
% build 2d redundancy lattice
lat.Nx = 2;
lat.Nnodes = 4;
lat.Nelements = 3;
lat.elements = {1, 2, [1 2]};
lat.A = { {1 2}, {1}, {2}, {[1 2]} };
% lat.labels = { '{1}{2}', '{1}', '{2}', '{12}' }
lat.level = [1 2 2 3];
lat.Nlevels = max(lat.level);
labels = cell(size(lat.A));
for ni=1:lat.Nnodes
thsA = lat.A{ni};
st = cell(size(thsA));
for ai=1:length(st)
st{ai} = sprintf('{%s}',sprintf('%d',thsA{ai}));
end
labels{ni} = sprintf('%s',st{:});
end
lat.labels = labels;
nodes = containers.Map(lat.labels, 1:lat.Nnodes);
parents = cell(1,lat.Nnodes);
parents{nodes('{1}{2}')} = [nodes('{1}') nodes('{2}')];
parents{nodes('{1}')} = nodes('{12}');
parents{nodes('{2}')} = nodes('{12}');
% build children for birectional link
children = cell(1,lat.Nnodes);
for ni=1:lat.Nnodes
for parent=parents{ni}
children{parent} = [children{parent} ni];
end
end
lat.nodes = nodes;
lat.parents = parents;
lat.children = children;
lat.top = nodes('{12}');
lat.bottom = nodes('{1}{2}');
lat.Icap = NaN(1,lat.Nnodes);
lat.PI = NaN(1,lat.Nnodes);