-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbc-algorithm.java
More file actions
173 lines (162 loc) · 5.46 KB
/
bc-algorithm.java
File metadata and controls
173 lines (162 loc) · 5.46 KB
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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
static Limits create_limits(QX npQX, BinMG binMG){
/* """
npQX[kx][kx]
binMG[](bitY,kx)
-
listLimits[(xbit, ybit)]
xPrevConnections[(xbit, ybit)]
connection (xbit, ybit)
xPrevLimitList[(xbit, ybit)]
""" */
VertexSetPair connection;
Limits xPrevConnections;
Limits xPrevLimitList;
Limits listLimits = new Limits();
for(int indx=0; indx<npQX.len(); indx++){
if (indx == 0) {
connection = binMG.get_x_connection(indx);
listLimits.append(connection);
continue;
}
else{
xPrevConnections = binMG.get_sorted_prev_connections(indx,npQX);
if (xPrevConnections.len() > 0)
xPrevLimitList = listLimits.get_prev_connected_limits(xPrevConnections);
else //# First vertex in connected component
xPrevLimitList = new Limits();
connection = binMG.get_x_connection(indx);
listLimits.append(connection);
if (xPrevLimitList.len() > 0) {
xPrevLimitList.add_xy_bits_to_prev(indx,binMG);
xPrevLimitList.check_dupl_y_in_prev();
listLimits.check_prev_y_in_limits(xPrevLimitList);
listLimits.extend(xPrevLimitList);
}
}
}
return listLimits;
}
//#----------
//# BinMG
Limits get_sorted_prev_connections(int indx, QX npQX) {
/* """
It gets previous connected vertexes for current vertex
indx: int
npQX[kx][kx]
binMG[(binY,kx)]
-
prev_connections[](xbit, ybit)
""" */
Limits prev_connections = new Limits();
for(int i=0; i<indx; i++){
if (npQX.get_el(indx,i) == 1)
prev_connections.append(this.get_x_connection(i));
}
return prev_connections;
}
//#----------
//# Limits
Limits get_prev_connected_limits(Limits xPrevConnections){
/* """
for each prev connected vertex we get limits with it
listLimits[](xbit, ybit)
xPrevConnections[](xbit, ybit)
-
prev_limits[](xbit, ybit)
""" */
int thisLen = this.len();
Limits prev_limits = new Limits();
HashSet<Integer> hs = new HashSet<Integer>(Math.ceil(thisLen*4/3.0));
for(int i=0; i<xPrevConnections.len(); i++){
VertexSet xPrev = xPrevConnections.get_x(i);
for(int k=0; k<thisLen; k++) {
if (!hs.contains(k) && (this.get_x(k).vand(xPrev).to_long() != 0) ) {
prev_limits.append(this.get_row(k));
hs.add(k);
}
}
}
return prev_limits;
}
//#----------
//# BinMG
VertexSetPair get_x_connection(int indx) {
/* """
binMG[(bitY,kx)]
return (xbit, ybit)
""" */
VertexSet x = new VertexSet(indx);
VertexSet y = this.get_y(indx);
return new VertexSetPair(x, y);
}
//#----------
//# Limits
void add_xy_bits_to_prev(int indx,BinMG binMG){
/* """
adding current x & y to each previous limit
binMG[(bitY,kx)]
xPrevLimitList[(xbit, ybit)]
""" */
VertexSetPair xy = binMG.get_x_connection(indx);
VertexSet x = xy.get_x();
VertexSet y = xy.get_y();
for(int i=0; i<this.len(); i++) {
VertexSetPair pair = new VertexSetPair(this.get_x(i).vor(x), this.get_y(i).vor(y));
this.set_row(i, pair);
}
}
//#----------
//# Limits
void check_dupl_y_in_prev(){
/* """
check and clear previous limits for duplicated y
xPrevLimitList[(xbit, ybit)]
""" */
int lenP = this.len();
for(int kp=(lenP-1); kp>-1; kp--) {
VertexSet yp = this.get_y(kp);
if (yp.eq(VertexSet.EMPTY_SET())) continue;
for(int kl=(kp-1); kl>-1; kl--){
if (this.get_y(kl).eq(yp)) {
this.set_row(kp, new VertexSetPair(this.get_x(kp).vor(this.get_x(kl)), yp) ) ;
this.set_row(kl, VertexSetPair.EMPTY_TURTLE()) ;
}
}
}
//# clear previous limits
//# clear list
this.clear_limits();
}
//#----------
//# Limits
void check_prev_y_in_limits(Limits xPrevLimitList) {
/* """
check and clear common limits for duplicated y by previous limits
listLimits[(xbit, ybit)]
xPrevLimitList[(xbit, ybit)]
""" */
int lenP = xPrevLimitList.len();
int lenL = this.len();
for(int kp=0; kp<lenP; kp++){
VertexSet yp = xPrevLimitList.get_y(kp);
for(int kl=0; kl<lenL; kl++)
if (this.get_y(kl).eq(yp)) {
xPrevLimitList.set_row(kp, new VertexSetPair(xPrevLimitList.get_x(kp).vor(this.get_x(kl)), yp) );
this.set_row(kl, VertexSetPair.EMPTY_TURTLE());
}
}
//# clear limits
//# clear list
this.clear_limits();
}
//#----------
//# Limits
void clear_limits(){
int lenLimits = this.len();
for(int k=(lenLimits-1); k>-1; k--) {
// VertexSetPair row = this.get_row(k);
VertexSet x = this.get_x(k);
VertexSet y = this.get_x(k);
if( x.eq(VertexSet.EMPTY_SET()) && y.eq(VertexSet.EMPTY_SET())) this.delete(k);
}
}