From 5e47a86b4363566d41cadafad469fab4c6137aaa Mon Sep 17 00:00:00 2001 From: David Hadka Date: Fri, 20 Dec 2024 05:43:59 -0700 Subject: [PATCH] Print lower and upper bounds --- .classpath | 3 +- .../benchmarks/BenchmarkProviderTest.java | 37 +++++++++++++++++++ 2 files changed, 38 insertions(+), 2 deletions(-) diff --git a/.classpath b/.classpath index 5b70b35..84e4094 100644 --- a/.classpath +++ b/.classpath @@ -2,7 +2,6 @@ - @@ -13,7 +12,6 @@ - @@ -22,6 +20,7 @@ + diff --git a/src/test/java/org/moeaframework/benchmarks/BenchmarkProviderTest.java b/src/test/java/org/moeaframework/benchmarks/BenchmarkProviderTest.java index 8209974..fd122bd 100644 --- a/src/test/java/org/moeaframework/benchmarks/BenchmarkProviderTest.java +++ b/src/test/java/org/moeaframework/benchmarks/BenchmarkProviderTest.java @@ -17,13 +17,18 @@ */ package org.moeaframework.benchmarks; +import java.util.Arrays; import java.util.concurrent.TimeUnit; import org.junit.Assert; import org.junit.Assume; import org.junit.Test; import org.moeaframework.Executor; +import org.moeaframework.core.Problem; +import org.moeaframework.core.Solution; import org.moeaframework.core.spi.ProblemFactory; +import org.moeaframework.core.variable.EncodingUtils; +import org.moeaframework.core.variable.RealVariable; /** * Tests to ensure each benchmark problem can be instantiated with the MOEA Framework and reference sets exist. @@ -37,6 +42,38 @@ protected void test(String problemName, boolean hasReferenceSet) { .withMaxEvaluations(1000) .run(); + System.out.println(problemName); + + try (Problem problem = ProblemFactory.getInstance().getProblem(problemName)) { + Solution solution = problem.newSolution(); + + for (int i = 0; i < solution.getNumberOfVariables(); i++) { + RealVariable rv = (RealVariable)solution.getVariable(i); + rv.setValue(rv.getLowerBound()); + } + + problem.evaluate(solution); + System.out.println(" Lower Bound:"); + System.out.println(" Vars: " + Arrays.toString(EncodingUtils.getReal(solution))); + System.out.println(" Objs: " + Arrays.toString(solution.getObjectives())); + System.out.println(" Constrs: " + Arrays.toString(solution.getConstraints())); + + solution = problem.newSolution(); + + for (int i = 0; i < solution.getNumberOfVariables(); i++) { + RealVariable rv = (RealVariable)solution.getVariable(i); + rv.setValue(rv.getUpperBound()); + } + + problem.evaluate(solution); + System.out.println(" Upper Bound:"); + System.out.println(" Vars: " + Arrays.toString(EncodingUtils.getReal(solution))); + System.out.println(" Objs: " + Arrays.toString(solution.getObjectives())); + System.out.println(" Constrs: " + Arrays.toString(solution.getConstraints())); + + System.out.println(); + } + if (hasReferenceSet) { Assert.assertNotNull("Missing reference set", ProblemFactory.getInstance().getReferenceSet(problemName)); }