You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by er...@apache.org on 2022/02/06 23:39:57 UTC
[commons-math] 07/07: Replaced convoluted way to print to "System.out" (examples).
This is an automated email from the ASF dual-hosted git repository.
erans pushed a commit to branch feature__MATH-1563__genetic_algorithm
in repository https://gitbox.apache.org/repos/asf/commons-math.git
commit e9a895f5faee7e416d5aba8bb28b96180f0fdc4f
Author: Gilles Sadowski <gi...@gmail.com>
AuthorDate: Mon Feb 7 00:29:00 2022 +0100
Replaced convoluted way to print to "System.out" (examples).
---
.../adaptive/AdaptiveMathFunctionOptimizer.java | 4 ----
.../mathfunctions/legacy/LegacyMathFunctionOptimizer.java | 13 +------------
.../examples/ga/mathfunctions/MathFunctionOptimizer.java | 4 ----
.../math4/examples/ga/tsp/legacy/LegacyTSPOptimizer.java | 13 +------------
.../apache/commons/math4/examples/ga/tsp/TSPOptimizer.java | 4 ----
5 files changed, 2 insertions(+), 36 deletions(-)
diff --git a/commons-math-examples/examples-ga/examples-ga-math-functions-adaptive/src/main/java/org/apache/commons/math4/examples/ga/mathfunctions/adaptive/AdaptiveMathFunctionOptimizer.java b/commons-math-examples/examples-ga/examples-ga-math-functions-adaptive/src/main/java/org/apache/commons/math4/examples/ga/mathfunctions/adaptive/AdaptiveMathFunctionOptimizer.java
index 8a1c303..54352eb 100644
--- a/commons-math-examples/examples-ga/examples-ga-math-functions-adaptive/src/main/java/org/apache/commons/math4/examples/ga/mathfunctions/adaptive/AdaptiveMathFunctionOptimizer.java
+++ b/commons-math-examples/examples-ga/examples-ga-math-functions-adaptive/src/main/java/org/apache/commons/math4/examples/ga/mathfunctions/adaptive/AdaptiveMathFunctionOptimizer.java
@@ -76,10 +76,7 @@ public final class AdaptiveMathFunctionOptimizer {
// best chromosome from the final population
final Chromosome<Coordinate> bestFinal = finalPopulation.getFittestChromosome();
- logger.info("*********************************************");
- logger.info("***********Optimization Result***************");
logger.info(bestFinal.toString());
-
}
private static Population<Coordinate> getInitialPopulation(int dimension, int populationSize) {
@@ -92,5 +89,4 @@ public final class AdaptiveMathFunctionOptimizer {
}
return population;
}
-
}
diff --git a/commons-math-examples/examples-ga/examples-ga-math-functions-legacy/src/main/java/org/apache/commons/math4/examples/ga/mathfunctions/legacy/LegacyMathFunctionOptimizer.java b/commons-math-examples/examples-ga/examples-ga-math-functions-legacy/src/main/java/org/apache/commons/math4/examples/ga/mathfunctions/legacy/LegacyMathFunctionOptimizer.java
index ff59919..a58e575 100644
--- a/commons-math-examples/examples-ga/examples-ga-math-functions-legacy/src/main/java/org/apache/commons/math4/examples/ga/mathfunctions/legacy/LegacyMathFunctionOptimizer.java
+++ b/commons-math-examples/examples-ga/examples-ga-math-functions-legacy/src/main/java/org/apache/commons/math4/examples/ga/mathfunctions/legacy/LegacyMathFunctionOptimizer.java
@@ -16,10 +16,6 @@
*/
package org.apache.commons.math4.examples.ga.mathfunctions.legacy;
-import java.io.BufferedWriter;
-import java.io.IOException;
-import java.io.OutputStreamWriter;
-
import org.apache.commons.math3.genetics.BinaryChromosome;
import org.apache.commons.math3.genetics.BinaryMutation;
import org.apache.commons.math3.genetics.Chromosome;
@@ -75,14 +71,7 @@ public final class LegacyMathFunctionOptimizer {
// best chromosome from the final population
final Chromosome bestFinal = finalPopulation.getFittestChromosome();
- try (BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(System.out, ENCODING))) {
- writer.write("*********************************************");
- writer.newLine();
- writer.write("***********Optimization Result***************");
- writer.write(bestFinal.toString());
- } catch (IOException e) {
- throw new RuntimeException(e);
- }
+ System.out.println("best=" + bestFinal.toString());
}
private static Population getInitialPopulation(int dimension, int populationSize, double elitismRate) {
diff --git a/commons-math-examples/examples-ga/examples-ga-math-functions/src/main/java/org/apache/commons/math4/examples/ga/mathfunctions/MathFunctionOptimizer.java b/commons-math-examples/examples-ga/examples-ga-math-functions/src/main/java/org/apache/commons/math4/examples/ga/mathfunctions/MathFunctionOptimizer.java
index 035267a..1efa728 100644
--- a/commons-math-examples/examples-ga/examples-ga-math-functions/src/main/java/org/apache/commons/math4/examples/ga/mathfunctions/MathFunctionOptimizer.java
+++ b/commons-math-examples/examples-ga/examples-ga-math-functions/src/main/java/org/apache/commons/math4/examples/ga/mathfunctions/MathFunctionOptimizer.java
@@ -81,10 +81,7 @@ public final class MathFunctionOptimizer {
// best chromosome from the final population
final Chromosome<Coordinate> bestFinal = finalPopulation.getFittestChromosome();
- logger.info("*********************************************");
- logger.info("***********Optimization Result***************");
logger.info(bestFinal.toString());
-
}
private static Population<Coordinate> getInitialPopulation(int dimension, int populationSize) {
@@ -97,5 +94,4 @@ public final class MathFunctionOptimizer {
}
return population;
}
-
}
diff --git a/commons-math-examples/examples-ga/examples-ga-tsp-legacy/src/main/java/org/apache/commons/math4/examples/ga/tsp/legacy/LegacyTSPOptimizer.java b/commons-math-examples/examples-ga/examples-ga-tsp-legacy/src/main/java/org/apache/commons/math4/examples/ga/tsp/legacy/LegacyTSPOptimizer.java
index c6059b3..9afe928 100644
--- a/commons-math-examples/examples-ga/examples-ga-tsp-legacy/src/main/java/org/apache/commons/math4/examples/ga/tsp/legacy/LegacyTSPOptimizer.java
+++ b/commons-math-examples/examples-ga/examples-ga-tsp-legacy/src/main/java/org/apache/commons/math4/examples/ga/tsp/legacy/LegacyTSPOptimizer.java
@@ -16,9 +16,6 @@
*/
package org.apache.commons.math4.examples.ga.tsp.legacy;
-import java.io.BufferedWriter;
-import java.io.IOException;
-import java.io.OutputStreamWriter;
import java.util.List;
import org.apache.commons.math3.genetics.ElitisticListPopulation;
@@ -73,14 +70,7 @@ public class LegacyTSPOptimizer {
@SuppressWarnings("unchecked")
final RandomKey<City> bestFinal = (RandomKey<City>) finalPopulation.getFittestChromosome();
- try (BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(System.out, ENCODING))) {
- writer.write("*********************************************");
- writer.newLine();
- writer.write("***********Optimization Result***************");
- writer.write(bestFinal.toString());
- } catch (IOException e) {
- throw new RuntimeException(e);
- }
+ System.out.println("best=" + bestFinal.toString());
}
private static Population getInitialPopulation(List<City> cities, int populationSize, double elitismRate) {
@@ -92,5 +82,4 @@ public class LegacyTSPOptimizer {
return simulationPopulation;
}
-
}
diff --git a/commons-math-examples/examples-ga/examples-ga-tsp/src/main/java/org/apache/commons/math4/examples/ga/tsp/TSPOptimizer.java b/commons-math-examples/examples-ga/examples-ga-tsp/src/main/java/org/apache/commons/math4/examples/ga/tsp/TSPOptimizer.java
index 3b209c3..59024d4 100644
--- a/commons-math-examples/examples-ga/examples-ga-tsp/src/main/java/org/apache/commons/math4/examples/ga/tsp/TSPOptimizer.java
+++ b/commons-math-examples/examples-ga/examples-ga-tsp/src/main/java/org/apache/commons/math4/examples/ga/tsp/TSPOptimizer.java
@@ -79,11 +79,7 @@ public final class TSPOptimizer {
final RealValuedChromosome<List<City>> bestFinal = (RealValuedChromosome<List<City>>) finalPopulation
.getFittestChromosome();
- logger.info("*********************************************");
- logger.info("***********Optimization Result***************");
-
logger.info(bestFinal.decode().toString());
-
}
private static Population<List<City>> getInitialPopulation(List<City> cities, int populationSize) {