This repository was archived by the owner on Dec 16, 2017. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDiGraphTester.java
More file actions
265 lines (232 loc) · 8.03 KB
/
DiGraphTester.java
File metadata and controls
265 lines (232 loc) · 8.03 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
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
import java.io.BufferedReader;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.text.SimpleDateFormat;
import java.util.Arrays;
import java.util.Calendar;
import java.util.HashMap;
import java.util.Map.Entry;
import org.junit.Test;
public class DiGraphTester {
// testfiles_dynamickeysize
// testfilesrandom
// testfiles
HashMap<String, String[]> testFiles;
//ArrayList<String> testFiles ;
String dir = System.getProperty("user.dir");
String linebreak = System.getProperty("line.separator");
String path = dir + "\\trunk\\wordladder\\ressources\\";
StringBuilder result = new StringBuilder();
int iterations = 10;
public static final String DATE_FORMAT_NOW = "yyyy_MM_dd-HH_mm_ss";
@Test
public void TestDynamicKeySize() throws IOException {
result = new StringBuilder();
Stopwatch w;
for (int i=1; i <10; i++) {
w = new Stopwatch();
DiGraph<String> dg = null;
for (int j = 0; j < iterations; j++) {
dg = new DiGraph<String>(i);
dg.buildGraph(path + "5757_alpha_10_output.txt");
}
Object[] result = {"5757_alpha_10_output.txt", "TRUE", 10, i, dg.getIterCount(), w.elapsedTime()/iterations, dg.V(), dg.E()};
writeresult(result); // Edges
}
for (int i=1; i <20; i++) {
w = new Stopwatch();
DiGraph<String> dg = null;
for (int j = 0; j < iterations; j++) {
dg = new DiGraph<String>(i);
dg.buildGraph(path + "5757_alpha_20_output.txt");
}
Object[] result = {"5757_alpha_20_output.txt", "TRUE", 20, i, dg.getIterCount(), w.elapsedTime()/iterations, dg.V(), dg.E()};
writeresult(result); // Edges
}
FileWriter fw = new FileWriter(path + "testresults_" + now() + ".txt");
fw.write(result.toString());
fw.close();
}
@Test
public void testRandomKeyAndInputSize() throws IOException {
result = new StringBuilder();
Stopwatch w;
int count = 2;
// int[] args = {10000,20000,30000,40000,50000,60000,70000,80000,90000, 100000};
// String orgfilename = "%s_random_alpha_10_output.txt";
// for (int i = 0; i< args.length; i++) {
// String filename = String.format(orgfilename, args[i]);
// w = new Stopwatch();
// DiGraph<String> dg = null;
// for (int j = 0; j<iterations; j++) {
// dg = new DiGraph<String>(5);
// dg.buildGraph(path + filename);
//
// }
// Object[] result = {count, filename, "FALSE", "2-10", "2-5", 10, dg.count, w.elapsedTime()/iterations, dg.V(), dg.E()};
// writeresult(result); // Edges
// }
//
// writeToFile(result.toString());
// result = new StringBuilder();
//
// orgfilename = "100000_random_alpha_%s_output.txt";
// count = 2;
// for (int i = 10; i<= 20; i++) {
// String filename = String.format(orgfilename, i);
// w = new Stopwatch();
// DiGraph<String> dg = null;
// for (int j = 0; j<iterations; j++) {
// dg = new DiGraph<String>(4);
// dg.buildGraph(path + filename);
//
// }
// Object[] result = {count, filename, "FALSE", "2-" + i, "2-5", 10, dg.count, w.elapsedTime()/iterations, dg.V(), dg.E()};
// writeresult(result); // Edges
// }
// writeToFile(result.toString());
iterations = 3;
//resultsb = new StringBuilder();
for (int i = 21; i > 2; i--) {
String filename = "word_list_moby_crossword.txt";
w = new Stopwatch();
int E= 0;
int V= 0;
int count2 = 0;
for (int j = 0; j<iterations; j++) {
DiGraph<String> dg = null;
dg = new DiGraph<String>(i);
dg.buildGraph(path + filename);
E = dg.E();
V= dg.V();
}
Object[] result = {count, filename, "FALSE", "2-21", "2-" + i, 10, count2, w.elapsedTime()/iterations, V,E};
System.out.println(Arrays.toString(result));
//writeresult(result); // Edges
//writeToFile(result.toString());
}
}
private void writeToFile(String s) throws IOException {
FileWriter fw = new FileWriter(path + "testresults_" + now() + ".txt");
fw.write(s);
fw.close();
}
@Test
public void TestDynamicSize() throws IOException {
//
testFiles = new HashMap<String, String[]>();
readTestFiles("testfiles.txt");
System.out.println("Testfiles:");
for (Entry<String, String[]> file : testFiles.entrySet()) {
System.out.println(file.getKey() + Arrays.toString(file.getValue()));
}
boolean constrain = true;
for (Entry<String, String[]> file : testFiles.entrySet()) {
DiGraph<String> dg = null;
String orgFilename = file.getKey();
String filename = "";
Stopwatch w = null;
if (file.getValue().length>0) {
for (String param : file.getValue()) {
//UnConstrained
filename = String.format(orgFilename, param);
System.out.println("Testing: " + String.format(filename, param));
w = new Stopwatch();
for (int i = 1; i<= iterations; i++) {
dg = new DiGraph<String>();
dg.buildGraph(path + filename);
}
writeresult(orgFilename, false); // Filnemae
writeresult("TRUE", false); // constrained
writeresult("5", false); // keylength
writeresult("4", false); // suffixlen
writeresult("10", false); // iterations
writeresult(dg.getIterCount(), false);
writeresult(w.elapsedTime()/iterations, false); // buildtime
writeresult(dg.V(), false); // Vertices
writeresult(dg.E(), true); // Edges
}
} else {
System.out.println("Testing: " +orgFilename);
w = new Stopwatch();
for (int i = 1; i<= iterations; i++) {
dg = new DiGraph<String>();
dg.buildGraph(path + orgFilename);
}
writeresult(orgFilename, false); // Filnemae
writeresult("TRUE", false); // constrained
writeresult("5", false); // keylength
writeresult("4", false); // suffixlen
writeresult("10", false); // iterations
writeresult(dg.getIterCount(), false);
writeresult(w.elapsedTime()/iterations, false); // buildtime
writeresult(dg.V(), false); // Vertices
writeresult(dg.E(), true); // Edges
}
}
FileWriter fw = new FileWriter(path + "testresults_" + now() + ".txt");
fw.write(result.toString());
fw.close();
}
private void writeresult(Object[] s) {
for (Object o:s ) result.append(String.valueOf(o) + ";");
result.append(linebreak);
}
private void writeresult(Object s, boolean isNew) {
result.append(s + ";");
if (isNew) result.append(linebreak);
}
@Test
public void getDataStats() throws IOException, FileNotFoundException {
String filename = "word_list_moby_crossword.txt";
int size = 0;
int maxlength = Integer.MIN_VALUE;
int minlength = Integer.MAX_VALUE;
String max = "";
String min = "";
BufferedReader r = new BufferedReader(new InputStreamReader(new FileInputStream(path + filename), "UTF-8"));
while(true) {
String s = r.readLine();
if (s == null) break;
size++;
if (s.length() > maxlength) {
maxlength = s.length();
max = s;
}
if (s.length() < minlength) {
minlength = s.length();
min = s;
}
}
System.out.println("File: " + filename);
System.out.println("Words: " + size);
System.out.println("Longest word: " + max + " : " + maxlength);
System.out.println("Shortest word: " + min + " : " + minlength);
}
private void readTestFiles(String filename) throws IOException {
BufferedReader r = new BufferedReader(new InputStreamReader(new FileInputStream(path + filename), "UTF-8"));
// Read all lines in the input file
while(true) {
String s = r.readLine();
if (s == null) break;
String[] args = s.split(" ");
String file = args[0];
if (args.length > 1) {
String[] params = args[1].split(",");
for (String p : params) {
testFiles.put(file, params);
}
}else {
testFiles.put(file, new String[0]);
}
}
}
public static String now() {
Calendar cal = Calendar.getInstance();
SimpleDateFormat sdf = new SimpleDateFormat(DATE_FORMAT_NOW);
return sdf.format(cal.getTime());
}
}