-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAlgorithm.pde
More file actions
85 lines (65 loc) · 2.56 KB
/
Algorithm.pde
File metadata and controls
85 lines (65 loc) · 2.56 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
class Algorithm{
Algorithm(Edges ABC){
//int count = ABC.edges.length;
while(uniSet()){
int e = (int)random(ABC.edges.size());
println("1: ", e, ABC.edges.size());
print("2: ");
ABC.edges.get(e).getValue();
if(ABC.edges.get(e).points[0]+ABC.edges.get(e).points[2]==0||
ABC.edges.get(e).points[1]+ABC.edges.get(e).points[3]==0||
ABC.edges.get(e).points[0]+ABC.edges.get(e).points[2]==2*height||
ABC.edges.get(e).points[1]+ABC.edges.get(e).points[3]==2*height){
println("3: Skipped");//NO need to get rid of edge
}
else{
ABC.divide();
//Horizontal----------------------
if(ABC.edges.get(e).points[1]==ABC.edges.get(e).points[3]){
println("Horizontal");
if(Sets[ABC.edges.get(e).points[0]][ABC.edges.get(e).points[3]-1]!=Sets[ABC.edges.get(e).points[0]][ABC.edges.get(e).points[3]]){
int z = Sets[ABC.edges.get(e).points[0]][ABC.edges.get(e).points[3]];
//Union----------------------------------
for(int i=0;i<h;i++){
for(int j=0;j<h;j++){
if(Sets[i][j]==z){
Sets[i][j] = Sets[ABC.edges.get(e).points[0]][ABC.edges.get(e).points[3]-1];
}
}
}
//===================================
ABC.deleteElem(e);
}
}
//==================================================================
//vertical------------------------------------
else if(Sets[ABC.edges.get(e).points[2]-1][ABC.edges.get(e).points[1]]!=Sets[ABC.edges.get(e).points[2]][ABC.edges.get(e).points[1]]){
println("Vertical");
int z = Sets[ABC.edges.get(e).points[2]][ABC.edges.get(e).points[1]];
//Union----------------------------------
for(int i=0;i<h;i++){
for(int j=0;j<h;j++){
if(Sets[i][j]==z){
Sets[i][j] = Sets[ABC.edges.get(e).points[2]-1][ABC.edges.get(e).points[1]];
}
}
}
//===================================
ABC.deleteElem(e);
}
//=================================================================================
ABC.multiply();
}
}
}
boolean uniSet(){
for(int i=0;i<h;i++){
for(int j=0;j<h;j++){
if(Sets[0][0]!=Sets[i][j]){
return true;
}
}
}
return false;
}
}