16f90fbc
Eduardo Eloy
database and impl...
|
1
2
|
import java.io.File;
import java.io.FileNotFoundException;
|
29a181fe
Eduardo Eloy
paretoworking and...
|
3
|
import java.util.Scanner;
|
16f90fbc
Eduardo Eloy
database and impl...
|
4
5
6
|
public class UG {
String external;
|
2cd288b3
Eduardo Eloy
project can now i...
|
7
8
9
|
String internal;
int[] adj;
float area;
|
16f90fbc
Eduardo Eloy
database and impl...
|
10
|
int[] presc;
|
2cd288b3
Eduardo Eloy
project can now i...
|
11
|
int[][] periods;
|
df0e5c82
Eduardo Eloy
added region para...
|
12
|
int[] wood;
|
16f90fbc
Eduardo Eloy
database and impl...
|
13
|
int[] cork;
|
16f90fbc
Eduardo Eloy
database and impl...
|
14
|
float mediumX;
|
2cd288b3
Eduardo Eloy
project can now i...
|
15
16
17
18
|
float mediumY;
int time;
boolean valid;
|
16f90fbc
Eduardo Eloy
database and impl...
|
19
|
String region;
|
44aa78ff
Eduardo Eloy
implementation at...
|
20
|
String[] externalPresc;
|
2cd288b3
Eduardo Eloy
project can now i...
|
21
|
|
5276b92b
Eduardo Eloy
added multi-crite...
|
22
23
24
|
static public int[] returnInsertable(Scanner myReader){
String data = myReader.nextLine();
|
2cd288b3
Eduardo Eloy
project can now i...
|
25
|
String[] str_split = data.split(",", 0);
|
5276b92b
Eduardo Eloy
added multi-crite...
|
26
|
int size = str_split.length;
|
2cd288b3
Eduardo Eloy
project can now i...
|
27
|
int[] toInsert = new int [size];
|
a9dbe944
Eduardo Eloy
added new ways of...
|
28
29
30
|
for(int i=0; i<size; i++) {
toInsert[i] = Integer.parseInt(str_split[i]);
}
|
2cd288b3
Eduardo Eloy
project can now i...
|
31
32
33
|
return toInsert;
}
|
0142c195
Eduardo Eloy
more solution res...
|
34
|
static public int[] returnInsertable2(Scanner myReader){
|
16f90fbc
Eduardo Eloy
database and impl...
|
35
36
37
38
39
40
41
42
43
44
45
46
|
String data = myReader.nextLine();
String[] str_split = data.split(",", 0);
int size = str_split.length;
int[] toInsert = new int[size];
for(int i=0; i<size; i++) {
toInsert[i] = (int)Float.parseFloat(str_split[i]);
}
return toInsert;
}
static public int[] returnPeriods(String data){
String[] str_split = data.split(",", 0);
|
44aa78ff
Eduardo Eloy
implementation at...
|
47
48
49
50
51
52
53
54
55
56
57
|
int size = str_split.length;
int[] toInsert = new int [size];
for(int i=0; i<size; i++) {
toInsert[i] = Integer.parseInt(str_split[i]);
}
return toInsert;
}
|
2cd288b3
Eduardo Eloy
project can now i...
|
58
|
static public void fillArray(UG[] array, String dir, float X, float Y, int maxDistance) {
|
16f90fbc
Eduardo Eloy
database and impl...
|
59
60
61
|
int index = 0;
try { // idea: pass a directory, which should contain files called
|
2cd288b3
Eduardo Eloy
project can now i...
|
62
|
// graph_init, ugs_init, ...
|
16f90fbc
Eduardo Eloy
database and impl...
|
63
|
File myObj = new File(dir + "/graph_init");
|
2cd288b3
Eduardo Eloy
project can now i...
|
64
|
Scanner myReaderAdj = new Scanner(myObj);
|
16f90fbc
Eduardo Eloy
database and impl...
|
65
66
67
68
|
File myObj2 = new File(dir + "/ugs_init");
Scanner myReaderPresc = new Scanner(myObj2);
|
2cd288b3
Eduardo Eloy
project can now i...
|
69
70
71
|
File myObj3 = new File(dir + "/area_init");
Scanner myReaderArea = new Scanner(myObj3);
|
16f90fbc
Eduardo Eloy
database and impl...
|
72
|
File myObj4 = new File(dir + "/period_init");
|
2cd288b3
Eduardo Eloy
project can now i...
|
73
74
|
Scanner myReaderPeriod = new Scanner(myObj4);
|
16f90fbc
Eduardo Eloy
database and impl...
|
75
|
File myObj5 = new File(dir + "/external_init");
|
2cd288b3
Eduardo Eloy
project can now i...
|
76
|
Scanner myReaderExternal = new Scanner(myObj5);
|
16f90fbc
Eduardo Eloy
database and impl...
|
77
78
|
File myObj6 = new File(dir + "/xvertex_init");
|
2cd288b3
Eduardo Eloy
project can now i...
|
79
80
81
|
Scanner myReaderXVertex = new Scanner(myObj6);
File myObj7 = new File(dir + "/yvertex_init");
|
16f90fbc
Eduardo Eloy
database and impl...
|
82
|
Scanner myReaderYVertex = new Scanner(myObj7);
|
2cd288b3
Eduardo Eloy
project can now i...
|
83
84
85
86
87
88
89
90
|
File myObj8 = new File(dir + "/wood_init");
Scanner myReaderWood = new Scanner(myObj8);
File myObj9 = new File(dir + "/cork_init");
Scanner myReaderCork = new Scanner(myObj9);
File myObj10 = new File(dir + "/internal_init");
|
16f90fbc
Eduardo Eloy
database and impl...
|
91
|
Scanner myReaderInternal = new Scanner(myObj10);
|
2cd288b3
Eduardo Eloy
project can now i...
|
92
93
94
|
File myObj11 = new File(dir + "/region_init");
Scanner myReaderRegion = new Scanner(myObj11);
|
16f90fbc
Eduardo Eloy
database and impl...
|
95
|
|
2cd288b3
Eduardo Eloy
project can now i...
|
96
97
|
while (myReaderAdj.hasNextLine()) {
|
16f90fbc
Eduardo Eloy
database and impl...
|
98
|
UG toInsert = new UG();
|
2cd288b3
Eduardo Eloy
project can now i...
|
99
|
|
16f90fbc
Eduardo Eloy
database and impl...
|
100
|
|
16f90fbc
Eduardo Eloy
database and impl...
|
101
|
toInsert.mediumX = Float.parseFloat(myReaderXVertex.nextLine());
|
2cd288b3
Eduardo Eloy
project can now i...
|
102
103
104
|
toInsert.mediumY = Float.parseFloat(myReaderYVertex.nextLine());
double d = Math.sqrt(Math.pow (toInsert.mediumX - X, 2) + Math.pow (toInsert.mediumY - Y, 2));
toInsert.region = myReaderRegion.nextLine();
|
16f90fbc
Eduardo Eloy
database and impl...
|
105
|
if(d <= maxDistance){
|
2cd288b3
Eduardo Eloy
project can now i...
|
106
107
108
109
|
toInsert.valid = true;
}
else{
toInsert.valid = false;
|
16f90fbc
Eduardo Eloy
database and impl...
|
110
|
}
|
2cd288b3
Eduardo Eloy
project can now i...
|
111
112
113
|
toInsert.adj = returnInsertable(myReaderAdj);
|
16f90fbc
Eduardo Eloy
database and impl...
|
114
|
toInsert.presc = returnInsertable(myReaderPresc);
|
16f90fbc
Eduardo Eloy
database and impl...
|
115
|
toInsert.external = myReaderExternal.nextLine();
|
2cd288b3
Eduardo Eloy
project can now i...
|
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
|
toInsert.internal = myReaderInternal.nextLine();
toInsert.area = Float.parseFloat(myReaderArea.nextLine());
String data = myReaderPeriod.nextLine();
String[] str_split = data.split("/", 0);
int size = str_split.length;
toInsert.periods = new int[size][];
for(int i = 0; i < size; i++) {
toInsert.periods[i] = returnPeriods(str_split[i]);
}
toInsert.wood = returnInsertable2(myReaderWood);
toInsert.cork = returnInsertable2(myReaderCork);
|
16f90fbc
Eduardo Eloy
database and impl...
|
132
|
array[index] = toInsert;
|
2cd288b3
Eduardo Eloy
project can now i...
|
133
|
index++;
|
16f90fbc
Eduardo Eloy
database and impl...
|
134
135
|
}
|
2cd288b3
Eduardo Eloy
project can now i...
|
136
137
138
139
140
141
142
143
144
|
myReaderAdj.close();
myReaderPresc.close();
myReaderArea.close();
myReaderExternal.close();
myReaderXVertex.close();
myReaderYVertex.close();
myReaderWood.close();
myReaderCork.close();
myReaderRegion.close();
|
16f90fbc
Eduardo Eloy
database and impl...
|
145
146
|
} catch (FileNotFoundException e) {
|
44aa78ff
Eduardo Eloy
implementation at...
|
147
|
System.out.println("An error occurred.");
|
16f90fbc
Eduardo Eloy
database and impl...
|
148
149
150
151
|
e.printStackTrace();
}
}
|
2cd288b3
Eduardo Eloy
project can now i...
|
152
153
154
155
156
|
static public void fillArray(UG[] array, String dir, String region) {
int index = 0;
|
16f90fbc
Eduardo Eloy
database and impl...
|
157
|
try { // idea: pass a directory, which should contain files called
|
2cd288b3
Eduardo Eloy
project can now i...
|
158
159
|
// graph_init, ugs_init, ...
File myObj = new File(dir + "/graph_init");
|
16f90fbc
Eduardo Eloy
database and impl...
|
160
|
Scanner myReaderAdj = new Scanner(myObj);
|
df0e5c82
Eduardo Eloy
added region para...
|
161
162
163
|
File myObj2 = new File(dir + "/ugs_init");
Scanner myReaderPresc = new Scanner(myObj2);
|
2cd288b3
Eduardo Eloy
project can now i...
|
164
165
|
File myObj3 = new File(dir + "/area_init");
|
16f90fbc
Eduardo Eloy
database and impl...
|
166
|
Scanner myReaderArea = new Scanner(myObj3);
|
2cd288b3
Eduardo Eloy
project can now i...
|
167
168
|
File myObj4 = new File(dir + "/period_init");
|
16f90fbc
Eduardo Eloy
database and impl...
|
169
|
Scanner myReaderPeriod = new Scanner(myObj4);
|
2cd288b3
Eduardo Eloy
project can now i...
|
170
171
|
File myObj5 = new File(dir + "/external_init");
|
16f90fbc
Eduardo Eloy
database and impl...
|
172
|
Scanner myReaderExternal = new Scanner(myObj5);
|
2cd288b3
Eduardo Eloy
project can now i...
|
173
174
|
File myObj6 = new File(dir + "/xvertex_init");
|
16f90fbc
Eduardo Eloy
database and impl...
|
175
|
Scanner myReaderXVertex = new Scanner(myObj6);
|
2cd288b3
Eduardo Eloy
project can now i...
|
176
177
|
File myObj7 = new File(dir + "/yvertex_init");
|
16f90fbc
Eduardo Eloy
database and impl...
|
178
|
Scanner myReaderYVertex = new Scanner(myObj7);
|
2cd288b3
Eduardo Eloy
project can now i...
|
179
180
|
File myObj8 = new File(dir + "/wood_init");
|
16f90fbc
Eduardo Eloy
database and impl...
|
181
|
Scanner myReaderWood = new Scanner(myObj8);
|
2cd288b3
Eduardo Eloy
project can now i...
|
182
183
|
File myObj9 = new File(dir + "/cork_init");
|
16f90fbc
Eduardo Eloy
database and impl...
|
184
|
Scanner myReaderCork = new Scanner(myObj9);
|
2cd288b3
Eduardo Eloy
project can now i...
|
185
186
|
File myObj10 = new File(dir + "/internal_init");
|
16f90fbc
Eduardo Eloy
database and impl...
|
187
|
Scanner myReaderInternal = new Scanner(myObj10);
|
2cd288b3
Eduardo Eloy
project can now i...
|
188
189
|
File myObj11 = new File(dir + "/region_init");
|
16f90fbc
Eduardo Eloy
database and impl...
|
190
|
Scanner myReaderRegion = new Scanner(myObj11);
|
2cd288b3
Eduardo Eloy
project can now i...
|
191
192
|
|
16f90fbc
Eduardo Eloy
database and impl...
|
193
|
while (myReaderAdj.hasNextLine()) {
|
2cd288b3
Eduardo Eloy
project can now i...
|
194
|
UG toInsert = new UG();
|
a9dbe944
Eduardo Eloy
added new ways of...
|
195
196
197
198
199
200
|
toInsert.mediumX = Float.parseFloat(myReaderXVertex.nextLine());
toInsert.mediumY = Float.parseFloat(myReaderYVertex.nextLine());
toInsert.region = myReaderRegion.nextLine();
|
2cd288b3
Eduardo Eloy
project can now i...
|
201
|
if(!region.equalsIgnoreCase(toInsert.region)){
|
16f90fbc
Eduardo Eloy
database and impl...
|
202
|
toInsert.valid = true;
|
44aa78ff
Eduardo Eloy
implementation at...
|
203
|
}
|
0142c195
Eduardo Eloy
more solution res...
|
204
|
else{
|
2cd288b3
Eduardo Eloy
project can now i...
|
205
206
|
toInsert.valid = false;
}
|
16f90fbc
Eduardo Eloy
database and impl...
|
207
|
|
2cd288b3
Eduardo Eloy
project can now i...
|
208
209
|
toInsert.adj = returnInsertable(myReaderAdj);
|
a9dbe944
Eduardo Eloy
added new ways of...
|
210
211
|
toInsert.presc = returnInsertable(myReaderPresc);
toInsert.external = myReaderExternal.nextLine();
|
df0e5c82
Eduardo Eloy
added region para...
|
212
213
|
toInsert.internal = myReaderInternal.nextLine();
toInsert.area = Float.parseFloat(myReaderArea.nextLine());
|
2cd288b3
Eduardo Eloy
project can now i...
|
214
|
|
16f90fbc
Eduardo Eloy
database and impl...
|
215
|
String data = myReaderPeriod.nextLine();
|
2cd288b3
Eduardo Eloy
project can now i...
|
216
217
218
219
220
221
222
223
|
String[] str_split = data.split("/", 0);
int size = str_split.length;
toInsert.periods = new int[size][];
for(int i = 0; i < size; i++) {
toInsert.periods[i] = returnPeriods(str_split[i]);
}
|
16f90fbc
Eduardo Eloy
database and impl...
|
224
225
|
toInsert.wood = returnInsertable2(myReaderWood);
|
5276b92b
Eduardo Eloy
added multi-crite...
|
226
227
228
229
|
toInsert.cork = returnInsertable2(myReaderCork);
array[index] = toInsert;
index++;
|
44aa78ff
Eduardo Eloy
implementation at...
|
230
|
}
|
16f90fbc
Eduardo Eloy
database and impl...
|
231
|
|
2cd288b3
Eduardo Eloy
project can now i...
|
232
233
234
|
myReaderAdj.close();
myReaderPresc.close();
myReaderArea.close();
|
16f90fbc
Eduardo Eloy
database and impl...
|
235
|
myReaderExternal.close();
|
2cd288b3
Eduardo Eloy
project can now i...
|
236
237
238
239
240
241
242
|
myReaderXVertex.close();
myReaderYVertex.close();
myReaderWood.close();
myReaderCork.close();
myReaderRegion.close();
} catch (FileNotFoundException e) {
|
16f90fbc
Eduardo Eloy
database and impl...
|
243
244
245
|
System.out.println("An error occurred.");
e.printStackTrace();
}
|
2cd288b3
Eduardo Eloy
project can now i...
|
246
247
|
}
|
16f90fbc
Eduardo Eloy
database and impl...
|
248
249
|
|
a9dbe944
Eduardo Eloy
added new ways of...
|
250
|
}
|
44aa78ff
Eduardo Eloy
implementation at...
|
|
|
16f90fbc
Eduardo Eloy
database and impl...
|
|
|
2cd288b3
Eduardo Eloy
project can now i...
|
|
|
df0e5c82
Eduardo Eloy
added region para...
|
|
|
2cd288b3
Eduardo Eloy
project can now i...
|
|
|
16f90fbc
Eduardo Eloy
database and impl...
|
|
|
df0e5c82
Eduardo Eloy
added region para...
|
|
|
16f90fbc
Eduardo Eloy
database and impl...
|
|
|
df0e5c82
Eduardo Eloy
added region para...
|
|
|
a9dbe944
Eduardo Eloy
added new ways of...
|
|
|
df0e5c82
Eduardo Eloy
added region para...
|
|
|
a9dbe944
Eduardo Eloy
added new ways of...
|
|
|
df0e5c82
Eduardo Eloy
added region para...
|
|
|
a9dbe944
Eduardo Eloy
added new ways of...
|
|
|
df0e5c82
Eduardo Eloy
added region para...
|
|
|
16f90fbc
Eduardo Eloy
database and impl...
|
|
|
29a181fe
Eduardo Eloy
paretoworking and...
|
|
|
a9dbe944
Eduardo Eloy
added new ways of...
|
|
|
29a181fe
Eduardo Eloy
paretoworking and...
|
|
|
a9dbe944
Eduardo Eloy
added new ways of...
|
|
|
29a181fe
Eduardo Eloy
paretoworking and...
|
|
|
a9dbe944
Eduardo Eloy
added new ways of...
|
|
|
29a181fe
Eduardo Eloy
paretoworking and...
|
|
|
16f90fbc
Eduardo Eloy
database and impl...
|
|
|