Skip to content

Commit

Permalink
Print lower and upper bounds
Browse files Browse the repository at this point in the history
  • Loading branch information
dhadka committed Dec 20, 2024
1 parent 7893557 commit 5e47a86
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 2 deletions.
3 changes: 1 addition & 2 deletions .classpath
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
<classpath>
<classpathentry kind="src" output="target/classes" path="src/main/java">
<attributes>
<attribute name="optional" value="true"/>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
Expand All @@ -13,7 +12,6 @@
</classpathentry>
<classpathentry kind="src" output="target/test-classes" path="src/test/java">
<attributes>
<attribute name="optional" value="true"/>
<attribute name="maven.pomderived" value="true"/>
<attribute name="test" value="true"/>
</attributes>
Expand All @@ -22,6 +20,7 @@
<attributes>
<attribute name="maven.pomderived" value="true"/>
<attribute name="test" value="true"/>
<attribute name="optional" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-14">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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));
}
Expand Down

0 comments on commit 5e47a86

Please sign in to comment.