-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrhombusCheck.m
74 lines (43 loc) · 1.71 KB
/
rhombusCheck.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
function [hiveFail,failedRhombuses,totalDefect] = rhombusCheck(Hijk,n)
%% Function for checking rhombus inequalities for AWHives
%outputs number of failed rhombuses and the failed rhombus indices as an f x 8 matrix.
%n is the vector space dimension, and Hijk is a sparse hive matrix.
totalDefect = 0;
%% Setup storage
hiveFail = 0;
failedRhombuses = zeros(n*(n-1)*3/2,8);
%% Loop over all possible indices and check the 3 rhombuses at each point
for k = 1:(n+1)
for i = 1:(n+2-k)
%% Right Inequality
if i <= (n-k)
temp = Hijk(k,i) + Hijk(k+1,i+1) - Hijk(k,i+1) - Hijk(k+1,i);
if temp > 0
hiveFail = hiveFail + 1;
failedRhombuses(hiveFail,:) = [k i k+1 i+1 k i+1 k+1 i];
totalDefect = totalDefect + temp;
end
end
%% Top Inequality
if i > 2
temp = Hijk(k,i) + Hijk(k+1,i-2) - Hijk(k,i-1) - Hijk(k+1,i-1);
if temp > 0
hiveFail = hiveFail + 1;
failedRhombuses(hiveFail,:) = [k i k+1 i-2 k i-1 k+1 i-1];
totalDefect = totalDefect + temp;
end
end
%% Left Inequality
if k > 2
temp = Hijk(k,i) + Hijk(k-2,i+1) - Hijk(k-1,i) - Hijk(k-1,i+1);
if temp > 0
hiveFail = hiveFail + 1;
failedRhombuses(hiveFail,:) = [k i k-2 i+1 k-1 i k-1 i+1];
totalDefect = totalDefect + temp;
end
end
end
end
%% Remove any unused rows in the failedRhombuses matrix
failedRhombuses(~any(failedRhombuses,2),:) = [];
end