Newer
Older
import Enums.InitializationMethods;
import Enums.MutatorMethods;
import Enums.SelectionMethods;
import Enums.VisualizerMethods;
import java.io.BufferedInputStream;
import java.io.FileInputStream;
import java.io.IOException;
Lennart Eichhorn
committed
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Properties;
public class Config {
private String propertyPath;
private Properties properties;
private String encodingVariant;
private int seed;
private int populationSize;
private int totalGenerations;
private InitializationMethods initializationMethod;
private SelectionMethods selectionMethod;
private int k; // Number of selected Candidates to face off in a tournament selection
private MutatorMethods[] mutatorMethods;
private int pointsPerBond; // Points per hydrophobic bond, default Evaluator will work the same with any value
private int mutationAttemptsPerCandidate;
private double mutationChance;
private double mutationMultiplier;
private double mutationMinimalChance; // -> 0.01% is not worth mutating for
private int crossoverAttemptsPerCandidate;
private double crossoverChance;
private double crossoverMinimalChance; // -> 0.01% is not worth mutating for
private double crossoverMultiplier;
Lennart Eichhorn
committed
//TODO Create directories if they do not exist
private VisualizerMethods[] visualizers;
Lennart Eichhorn
committed
private String jobName;
private String imageSequenceDirectory;
private String videoDirectory;
private String logfileDirectory;
private int imageFps;
private int imagesToFpsIncrease;
private int imageFpsMax;
private boolean zoom;
private final Font font = new Font("Sans-Serif", Font.PLAIN, 15);
private final Color imageBackground = new Color(255, 255, 255);
private final Color imageConnection = new Color(0, 0, 0);
private final Color imageOutline = new Color(0, 0, 0);
private final Color imageHydrophobic = new Color(205, 0, 0);
private final Color imageHydrophilic = new Color(0, 0, 255);
private final Color imageMixed = new Color(205, 0, 205);
private final Color imageAminoText = new Color(0, 190, 190);
private final Color imageText = new Color(0,0,0);
private final String consoleEmpty = " ";
private final String consoleHydrophobic = "(o)";
private final String consoleHydrophilic = "(i)";
private final String consoleHydrophobicMulti = "{o}";
private final String consoleHydrophilicMulti = "{i}";
private final String consoleMixed = "{z}";
private final String consoleConnectionVertical = " | ";
private final String consoleConnectionHorizontal = "---";
public Config(String propertyPath) {
this.propertyPath = propertyPath;
this.properties = this.readProperties();
this.initializeProperties();
}
private Properties readProperties() {
Properties properties = new Properties();
try {
BufferedInputStream stream = new BufferedInputStream(new FileInputStream(propertyPath));
properties.load(stream);
stream.close();
} catch (IOException e) {
e.printStackTrace();
}
return properties;
}
private void initializeProperties() {
encodingVariant = this.properties.getProperty("encodingVariant");
seed = Integer.parseInt(this.properties.getProperty("seed"));
populationSize = Integer.parseInt(this.properties.getProperty("populationSize"));
totalGenerations = Integer.parseInt(this.properties.getProperty("noGenerations"));
switch (this.properties.getProperty("initializationMethod")) {
case "curl":
initializationMethod = InitializationMethods.Curl;
initializationMethod = InitializationMethods.Straight;
initializationMethod = InitializationMethods.Random;
switch (this.properties.getProperty("selectionMethod")) {
case "proportional":
selectionMethod = SelectionMethods.Proportional;
selectionMethod = SelectionMethods.Tournament;
selectionMethod = SelectionMethods.OnlyBest;
k = Integer.parseInt(this.properties.getProperty("k"));
String[] mutatorsToUse = this.properties.getProperty("mutatorMethods").split(",");
mutatorMethods = new MutatorMethods[mutatorsToUse.length];
for (int i = 0; i < mutatorsToUse.length; i++) {
if (mutatorsToUse[i].equals("singlePoint")) {
mutatorMethods[i] = MutatorMethods.SinglePoint;
} else if (mutatorsToUse[i].equals("crossover")) {
mutatorMethods[i] = MutatorMethods.Crossover;
pointsPerBond = Integer.parseInt(this.properties.getProperty("pointsPerBond"));
mutationAttemptsPerCandidate = Integer.parseInt(this.properties.getProperty("mutationAttemptsPerCandidate"));
mutationChance = Double.parseDouble(this.properties.getProperty("mutationChance"));
mutationMinimalChance = Double.parseDouble(this.properties.getProperty("mutationMinimalChance"));
mutationMultiplier = Double.parseDouble(this.properties.getProperty("mutationMultiplier"));
crossoverAttemptsPerCandidate = Integer.parseInt(this.properties.getProperty("crossoverAttemptsPerCandidate"));
crossoverChance = Double.parseDouble(this.properties.getProperty("crossoverChance"));
crossoverMinimalChance = Double.parseDouble(this.properties.getProperty("crossoverMinimalChance"));
crossoverMultiplier = Double.parseDouble(this.properties.getProperty("crossoverMultiplier"));
jobName = this.properties.getProperty("jobName");
if(jobName.equals("")) {
SimpleDateFormat formatter = new SimpleDateFormat("dd_MM_yyyy_HH-mm-ss");
Lennart Eichhorn
committed
Date date = new Date();
jobName = formatter.format(date);
}
logfileDirectory = this.properties.getProperty("logfileDirectory");
String[] visualizersToUse = this.properties.getProperty("visualizerType").split(",");
visualizers = new VisualizerMethods[visualizersToUse.length];
for (int i = 0; i < visualizersToUse.length; i++) {
switch (visualizersToUse[i]) {
case "console":
visualizers[i] = VisualizerMethods.Console;
visualizers[i] = VisualizerMethods.Image;
visualizers[i] = VisualizerMethods.Video;
case "log":
visualizers[i] = VisualizerMethods.Log;
break;
case "generation":
visualizers[i] = VisualizerMethods.Generation;
break;
Lennart Eichhorn
committed
imageSequenceDirectory = this.properties.getProperty("imageSequenceDirectory");
videoDirectory = this.properties.getProperty("videoDirectory");
imageFps = Integer.parseInt(this.properties.getProperty("imgFps"));
imagesToFpsIncrease = Integer.parseInt(this.properties.getProperty("imagesToFpsIncrease"));
imageFpsMax = Integer.parseInt(this.properties.getProperty("imgFpsMax"));
zoom = this.properties.getProperty("zoom").equals("true");
}
public Properties getProperties() {
return this.properties;
}
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
public String getEncodingVariant() {
return encodingVariant;
}
public int getSeed() {
return seed;
}
public int getPopulationSize() {
return populationSize;
}
public int getTotalGenerations() {
return totalGenerations;
}
public InitializationMethods getInitializationMethod() {
return initializationMethod;
}
public SelectionMethods getSelectionMethod() {
return selectionMethod;
}
public int getK() {
return k;
}
public MutatorMethods[] getMutatorMethods() {
return mutatorMethods;
}
public int getPointsPerBond() {
return pointsPerBond;
}
public int getMutationAttemptsPerCandidate() {
return mutationAttemptsPerCandidate;
}
public double getMutationChance() {
return mutationChance;
}
public double getMutationMultiplier() {
return mutationMultiplier;
}
public double getMutationMinimalChance() {
return mutationMinimalChance;
}
public int getCrossoverAttemptsPerCandidate() {
return crossoverAttemptsPerCandidate;
}
public double getCrossoverChance() {
return crossoverChance;
}
public double getCrossoverMinimalChance() {
return crossoverMinimalChance;
}
public double getCrossoverMultiplier() {
return crossoverMultiplier;
}
Lennart Eichhorn
committed
public String getJobName() {
return jobName;
}
public String getLogfileDirectory() {
return logfileDirectory;
}
public VisualizerMethods[] getVisualizers() {
return visualizers;
}
Lennart Eichhorn
committed
public String getImageSequenceDirectory() {
return imageSequenceDirectory + "/" + jobName;
Lennart Eichhorn
committed
public String getVideoDirectory() {
return videoDirectory;
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
}
public int getImageFps() {
return imageFps;
}
public int getImagesToFpsIncrease() {
return imagesToFpsIncrease;
}
public int getImageFpsMax() {
return imageFpsMax;
}
public boolean isZoom() {
return zoom;
}
public Font getFont() {
return font;
}
public Color getImageBackground() {
return imageBackground;
}
public Color getImageConnection() {
return imageConnection;
}
public Color getImageOutline() {
return imageOutline;
}
public Color getImageHydrophobic() {
return imageHydrophobic;
}
public Color getImageHydrophilic() {
return imageHydrophilic;
}
public Color getImageMixed() {
return imageMixed;
}
public Color getImageAminoText() {
return imageAminoText;
}
public Color getImageText() {
return imageText;
}
public String getConsoleEmpty() {
return consoleEmpty;
}
public String getConsoleHydrophobic() {
return consoleHydrophobic;
}
public String getConsoleHydrophilic() {
return consoleHydrophilic;
}
public String getConsoleHydrophobicMulti() {
return consoleHydrophobicMulti;
}
public String getConsoleHydrophilicMulti() {
return consoleHydrophilicMulti;
}
public String getConsoleMixed() {
return consoleMixed;
}
public String getConsoleConnectionVertical() {
return consoleConnectionVertical;
}
public String getConsoleConnectionHorizontal() {
return consoleConnectionHorizontal;
}