diff --git a/pom.xml b/pom.xml
index 7c4237a..7d8943b 100644
--- a/pom.xml
+++ b/pom.xml
@@ -14,7 +14,7 @@
com.debacharya
nsgaii
- 3.0.4
+ 3.0.10
jar
2019
diff --git a/src/main/java/com/debacharya/nsgaii/NSGA2.java b/src/main/java/com/debacharya/nsgaii/NSGA2.java
index d77ddce..d9f2af8 100644
--- a/src/main/java/com/debacharya/nsgaii/NSGA2.java
+++ b/src/main/java/com/debacharya/nsgaii/NSGA2.java
@@ -123,6 +123,9 @@ public Population run() {
Reporter.terminate(child, this.configuration.objectives);
+ if(Reporter.autoTerminate)
+ Reporter.commitToDisk();
+
return child;
}
diff --git a/src/main/java/com/debacharya/nsgaii/Reporter.java b/src/main/java/com/debacharya/nsgaii/Reporter.java
index a7c1285..e5af5ff 100644
--- a/src/main/java/com/debacharya/nsgaii/Reporter.java
+++ b/src/main/java/com/debacharya/nsgaii/Reporter.java
@@ -30,28 +30,37 @@
import com.debacharya.nsgaii.objectivefunction.AbstractObjectiveFunction;
import com.debacharya.nsgaii.plugin.GraphPlot;
+import java.io.File;
import java.io.FileWriter;
+import java.nio.file.Files;
+import java.nio.file.Paths;
import java.util.List;
import java.util.concurrent.ThreadLocalRandom;
public class Reporter {
- private static final int fileHash = ThreadLocalRandom.current().nextInt(10000, 100000);
- private static final StringBuilder writeContent = new StringBuilder();
-
+ private static int fileHash = ThreadLocalRandom.current().nextInt(10000, 100000);
+ private static StringBuilder writeContent = new StringBuilder();
private static GraphPlot allGenerationGraph;
public static boolean silent = false;
+ public static boolean autoTerminate = true;
public static boolean plotGraph = true;
public static boolean plotCompiledGraphForEveryGeneration = true;
public static boolean plotGraphForEveryGeneration = false;
public static boolean writeToDisk = true;
public static boolean diskWriteSuccessful = true;
+ public static String outputDirectory = "";
public static String filename = "NSGA-II-report-" + Reporter.fileHash + ".txt";
public static void init(Configuration configuration) {
if(silent && !writeToDisk) return;
+ if(!Reporter.outputDirectory.isEmpty() && !Reporter
+ .outputDirectory
+ .substring(Reporter.outputDirectory.length() - 1)
+ .equals(File.separator))
+ Reporter.outputDirectory += File.separator;
p("\n[ " + java.time.LocalDateTime.now() + " ]");
p("\n** To stop reporter from printing to console, change Reporter.silent to true or call Configuration.beSilent()");
@@ -59,7 +68,7 @@ public static void init(Configuration configuration) {
"** Reporter is" +
(Reporter.writeToDisk ? "" : " not") +
" writing to disk" +
- (Reporter.writeToDisk ? (" at " + Reporter.filename) : "") +
+ (Reporter.writeToDisk ? (" at " + Reporter.outputDirectory + Reporter.filename) : "") +
"."
);
@@ -168,17 +177,33 @@ public static void terminate(Population finalChild, List geneticCode = DefaultPluginProvider.defaultGeneticCodeProducer().produce(7000);
+
+ Reporter.reportGeneticCode(geneticCode.stream().map(e -> (AbstractAllele) e).collect(Collectors.toList()));
+ }
+}
diff --git a/src/test/java/NSGA2Test.java b/src/test/java/NSGA2Test.java
index 4a2a052..3f9ce54 100644
--- a/src/test/java/NSGA2Test.java
+++ b/src/test/java/NSGA2Test.java
@@ -1,11 +1,14 @@
+import com.debacharya.nsgaii.Configuration;
import com.debacharya.nsgaii.NSGA2;
+import com.debacharya.nsgaii.Reporter;
import com.debacharya.nsgaii.datastructure.Population;
public class NSGA2Test {
public static void main(String[] args) {
- NSGA2 nsga2 = new NSGA2();
+ Configuration configuration = new Configuration();
+ NSGA2 nsga2 = new NSGA2(configuration);
Population paretoFront = nsga2.run();
}
}
diff --git a/src/test/java/ZDT1Test.java b/src/test/java/ZDT1Test.java
index 75a5206..2dd8aaa 100644
--- a/src/test/java/ZDT1Test.java
+++ b/src/test/java/ZDT1Test.java
@@ -24,8 +24,8 @@ public static void main(String[] args) {
configuration.objectives = objectives;
- configuration.setPopulationSize(100);
- configuration.setGenerations(500);
+ configuration.setPopulationSize(200);
+ configuration.setGenerations(100);
configuration.setChromosomeLength(30);
configuration.setGeneticCodeProducer(DefaultPluginProvider.valueEncodedGeneticCodeProducer(0, 1));
configuration.setMutation(new PolynomialMutation(0, 1));
diff --git a/v1/src/main/java/io/onclave/nsga/ii/api/GraphPlot.java b/v1/src/main/java/io/onclave/nsga/ii/api/GraphPlot.java
index ef0bc57..7edbb44 100644
--- a/v1/src/main/java/io/onclave/nsga/ii/api/GraphPlot.java
+++ b/v1/src/main/java/io/onclave/nsga/ii/api/GraphPlot.java
@@ -15,7 +15,6 @@
import org.jfree.data.xy.XYSeriesCollection;
import org.jfree.ui.ApplicationFrame;
-import java.awt.*;
import java.util.Random;
/**
diff --git a/v2/src/main/java/io/onclave/nsga/ii/api/GraphPlot.java b/v2/src/main/java/io/onclave/nsga/ii/api/GraphPlot.java
index 462da96..9e572da 100644
--- a/v2/src/main/java/io/onclave/nsga/ii/api/GraphPlot.java
+++ b/v2/src/main/java/io/onclave/nsga/ii/api/GraphPlot.java
@@ -15,7 +15,6 @@
import org.jfree.data.xy.XYSeriesCollection;
import org.jfree.ui.ApplicationFrame;
-import java.awt.*;
import java.util.Random;
/**