-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathEditDistanceParallel.java
More file actions
230 lines (185 loc) · 8.11 KB
/
EditDistanceParallel.java
File metadata and controls
230 lines (185 loc) · 8.11 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
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
package editDistance;
public class EditDistanceParallel {
private String firstString;
private String secondString;
private int firstStringLength;
private int secondStringLength;
private int editMatrix[][];
private int i, j;
private int nT;
private int chunckHeight;
private int chunckWidth;
public EditDistanceParallel(String firstString, String secondString, int nT) {
super();
this.firstString = firstString;
this.secondString = secondString;
this.firstStringLength = firstString.length();
this.secondStringLength = secondString.length();
this.editMatrix = new int[firstStringLength + 1][secondStringLength + 1];
this.nT = nT;
}
private void inizialize() {
for (i = 0; i < this.firstStringLength + 1; i++)
this.editMatrix[i][0] = i;
for (j = 0; j < this.secondStringLength + 1; j++)
this.editMatrix[0][j] = j;
}
public void calculate() {
inizialize();
this.chunckHeight = this.firstStringLength / this.nT;
this.chunckWidth = this.secondStringLength / this.nT;
switch (this.nT) {
case 2:
EditThread oneTwo = new EditThread(editMatrix, 1, this.chunckHeight, 1, this.chunckWidth, firstString, secondString);
oneTwo.start();
while (oneTwo.isAlive()) {
}
EditThread twoTwo = new EditThread(editMatrix, this.chunckHeight + 1, this.firstStringLength, 1, this.chunckWidth, firstString,
secondString);
EditThread threeTwo = new EditThread(editMatrix, 1, this.chunckHeight, this.chunckWidth + 1, this.secondStringLength, firstString,
secondString);
twoTwo.start();
threeTwo.start();
while (oneTwo.isAlive() || twoTwo.isAlive()) {
}
EditThread fourTwo = new EditThread(editMatrix, this.chunckHeight + 1, this.firstStringLength, this.chunckWidth + 1,
this.secondStringLength, firstString, secondString);
fourTwo.start();
while (fourTwo.isAlive()) {
}
break;
case 3:
EditThread oneThree = new EditThread(editMatrix, 1, this.chunckHeight, 1, this.chunckWidth, firstString, secondString);
oneThree.start();
while (oneThree.isAlive()) {
}
EditThread twoThree = new EditThread(editMatrix, this.chunckHeight + 1, this.chunckHeight * 2, 1, this.chunckWidth, firstString,
secondString);
EditThread threeThree = new EditThread(editMatrix, 1, this.chunckHeight, this.chunckWidth + 1, this.chunckWidth * 2, firstString,
secondString);
twoThree.start();
threeThree.start();
while (twoThree.isAlive() || threeThree.isAlive()) {
}
EditThread fourThree = new EditThread(editMatrix, (this.chunckHeight * 2) + 1, this.firstStringLength, 1, this.chunckWidth,
firstString,
secondString);
EditThread fiveThree = new EditThread(editMatrix, this.chunckHeight + 1, this.chunckHeight * 2, this.chunckWidth + 1,
this.chunckWidth * 2, firstString,
secondString);
EditThread sixThree = new EditThread(editMatrix, 1, this.chunckHeight, (this.chunckWidth * 2) + 1, this.secondStringLength,
firstString,
secondString);
fourThree.start();
fiveThree.start();
sixThree.start();
while (fourThree.isAlive() || fiveThree.isAlive() || sixThree.isAlive()) {
}
EditThread sevenThree = new EditThread(editMatrix, (this.chunckHeight * 2) + 1, this.firstStringLength, this.chunckWidth + 1,
this.chunckWidth * 2, firstString,
secondString);
EditThread eightThree = new EditThread(editMatrix, this.chunckHeight + 1, this.chunckHeight * 2, (this.chunckWidth * 2) + 1,
this.secondStringLength, firstString,
secondString);
sevenThree.start();
eightThree.start();
while (sevenThree.isAlive() || eightThree.isAlive()) {
}
EditThread nineThree = new EditThread(editMatrix, (this.chunckHeight * 2) + 1, this.firstStringLength, (this.chunckWidth * 2) + 1,
this.secondStringLength, firstString, secondString);
nineThree.start();
while (nineThree.isAlive()) {
}
break;
case 4:
EditThread oneFour = new EditThread(editMatrix, 1, this.chunckHeight, 1, this.chunckWidth, firstString, secondString);
oneFour.start();
while (oneFour.isAlive()) {
}
EditThread twoFour = new EditThread(editMatrix, this.chunckHeight + 1, this.chunckHeight * 2, 1, this.chunckWidth, firstString,
secondString);
EditThread threeFour = new EditThread(editMatrix, 1, this.chunckHeight, this.chunckWidth + 1, this.chunckWidth * 2, firstString,
secondString);
twoFour.start();
threeFour.start();
while (twoFour.isAlive() || threeFour.isAlive()) {
}
EditThread fourFour = new EditThread(editMatrix, (this.chunckHeight * 2) + 1, this.chunckHeight * 3, 1, this.chunckWidth,
firstString,
secondString);
EditThread fiveFour = new EditThread(editMatrix, this.chunckHeight + 1, this.chunckHeight * 2, this.chunckWidth + 1,
this.chunckWidth * 2, firstString,
secondString);
EditThread sixFour = new EditThread(editMatrix, 1, this.chunckHeight, (this.chunckWidth * 2) + 1, this.chunckWidth * 3,
firstString,
secondString);
fourFour.start();
fiveFour.start();
sixFour.start();
while (fourFour.isAlive() || fiveFour.isAlive() || sixFour.isAlive()) {
}
EditThread sevenFour = new EditThread(editMatrix, (this.chunckHeight * 3) + 1, this.firstStringLength, 1, this.chunckWidth,
firstString,
secondString);
EditThread eightFour = new EditThread(editMatrix, (this.chunckHeight * 2) + 1, this.chunckHeight * 3, this.chunckWidth + 1,
this.chunckWidth * 2, firstString,
secondString);
EditThread nineFour = new EditThread(editMatrix, this.chunckHeight + 1, this.chunckHeight * 2, (this.chunckWidth * 2) + 1,
this.chunckWidth * 3,
firstString,
secondString);
EditThread tenFour = new EditThread(editMatrix, 1, this.chunckHeight, (this.chunckWidth * 3) + 1, this.secondStringLength,
firstString,
secondString);
sevenFour.start();
eightFour.start();
nineFour.start();
tenFour.start();
while (sevenFour.isAlive() || eightFour.isAlive() || nineFour.isAlive() || tenFour.isAlive()) {
}
EditThread elevenFour = new EditThread(editMatrix, (this.chunckHeight * 3) + 1, this.firstStringLength, this.chunckWidth + 1,
this.chunckWidth * 2,
firstString,
secondString);
EditThread twelveFour = new EditThread(editMatrix, (this.chunckHeight * 2) + 1, this.chunckHeight * 3, (this.chunckWidth * 2) + 1,
this.chunckWidth * 3, firstString,
secondString);
EditThread thirteenFour = new EditThread(editMatrix, this.chunckHeight + 1, this.chunckHeight * 2, (this.chunckWidth * 3) + 1,
this.secondStringLength,
firstString,
secondString);
elevenFour.start();
twelveFour.start();
thirteenFour.start();
while (elevenFour.isAlive() || twelveFour.isAlive() || thirteenFour.isAlive()) {
}
EditThread fourteenFour = new EditThread(editMatrix, (this.chunckHeight * 3) + 1, this.firstStringLength, (this.chunckWidth * 2) + 1,
this.chunckWidth * 3, firstString,
secondString);
EditThread fiveteenFour = new EditThread(editMatrix, (this.chunckHeight * 2) + 1, this.chunckHeight * 3, (this.chunckWidth * 3) + 1,
this.secondStringLength, firstString,
secondString);
fourteenFour.start();
fiveteenFour.start();
while (fourteenFour.isAlive() || fiveteenFour.isAlive()) {
}
EditThread sixteenFour = new EditThread(editMatrix, (this.chunckHeight * 3) + 1, this.firstStringLength, (this.chunckWidth * 3) + 1,
this.secondStringLength, firstString, secondString);
sixteenFour.start();
while (sixteenFour.isAlive()) {
}
break;
}
System.out.println();
System.out.println("La distanza è " + this.editMatrix[this.firstStringLength][this.secondStringLength]);
}
public void stamp() {
int i, j;
for (i = 0; i < this.firstStringLength + 1; i++) {
for (j = 0; j < this.secondStringLength + 1; j++) {
System.out.print(this.editMatrix[i][j]);
}
System.out.println();
}
}
}