diff --git a/native/WDS/src/models.c b/native/WDS/src/models.c index 88579b8..b5ff885 100644 --- a/native/WDS/src/models.c +++ b/native/WDS/src/models.c @@ -298,7 +298,7 @@ void test_problem (double *xreal, double *xbin, int **gene, double *obj, double // report the objectives and constraint violation obj[0]=totalCost/1000000.0; // $ => $ MM - obj[1]=minResilience; // maximized + obj[1]=minResilience; constr[0]=-(pressureViolation+errorSum); return; } @@ -433,7 +433,7 @@ void test_problem (double *xreal, double *xbin, int **gene, double *obj, double // report the objectives and constraint violation obj[0]=totalCost/1000000.0; // $ => $ MM - obj[1]=-networkResilience; // for minimisation purpose + obj[1]=networkResilience; constr[0]=-(pressureViolation+errorCode); return; } @@ -568,7 +568,7 @@ void test_problem (double *xreal, double *xbin, int **gene, double *obj, double // report the objectives and constraint violation obj[0]=totalCost/1000000.0; // $ => $ MM - obj[1]=-networkResilience; // for minimisation purpose + obj[1]=networkResilience; constr[0]=-(pressureViolation+errorCode); return; } @@ -709,7 +709,7 @@ void test_problem (double *xreal, double *xbin, int **gene, double *obj, double // report the objectives and constraint violation obj[0]=totalCost/1000000.0; // $ => $ MM - obj[1]=-networkResilience; // for minimisation purpose + obj[1]=networkResilience; constr[0]=-(violation+errorCode); return; } @@ -868,7 +868,7 @@ void test_problem (double *xreal, double *xbin, int **gene, double *obj, double // report the objectives and constraint violation obj[0]=totalCost/1000000.0; // $ => $ MM - obj[1]=-networkResilience; // for minimisation purpose + obj[1]=networkResilience; constr[0]=-(pressureViolation+velocityViolation+errorCode); return; } @@ -997,7 +997,7 @@ void test_problem (double *xreal, double *xbin, int **gene, double *obj, double // report the objectives and constraint violation obj[0]=totalCost/1000000.0; // $ => $ MM - obj[1]=-networkResilience; // for minimisation purpose + obj[1]=networkResilience; constr[0]=-(headViolation+errorCode); return; } @@ -1143,7 +1143,7 @@ void test_problem (double *xreal, double *xbin, int **gene, double *obj, double // report the objectives and constraint violation totalCost=totalCost/1000000.0; obj[0]=totalCost; // $ => $ MM - obj[1]=-networkResilience; // for minimisation purpose + obj[1]=networkResilience; constr[0]=-(pressureViolation+errorCode); return; } @@ -1293,7 +1293,7 @@ void test_problem (double *xreal, double *xbin, int **gene, double *obj, double // report the objectives and constraint violation obj[0]=totalCost/1000000.0; // € => € MM - obj[1]=-networkResilience; // for minimisation purpose + obj[1]=networkResilience; constr[0]=-(pressureViolation+velocityViolation+errorCode); return; } @@ -1443,7 +1443,7 @@ void test_problem (double *xreal, double *xbin, int **gene, double *obj, double // report the objectives and constraint violation obj[0]=totalCost/1000000.0; // € => € MM - obj[1]=-networkResilience; // for minimisation purpose + obj[1]=networkResilience; constr[0]=-(pressureViolation+velocityViolation+errorCode); return; } @@ -1592,7 +1592,7 @@ void test_problem (double *xreal, double *xbin, int **gene, double *obj, double // report the objectives and constraint violation obj[0]=totalCost/1000000.0; // € => € MM - obj[1]=-networkResilience; // for minimisation purpose + obj[1]=networkResilience; constr[0]=-(pressureViolation+velocityViolation+errorCode); return; } @@ -1728,7 +1728,7 @@ void test_problem (double *xreal, double *xbin, int **gene, double *obj, double // report the objectives and constraint violation obj[0]=totalCost/1000000.0; // € => € MM - obj[1]=-networkResilience; // for minimisation purpose + obj[1]=networkResilience; constr[0]=-(pressureViolation+errorCode); return; } @@ -1900,7 +1900,7 @@ void test_problem (double *xreal, double *xbin, int **gene, double *obj, double // report the objectives and constraint violation obj[0]=totalCost/1000000.0; // £ => £ MM - obj[1]=-networkResilience; // for minimisation purpose + obj[1]=networkResilience; constr[0]=-(pressureViolation+errorCode); return; } diff --git a/src/test/java/org/moeaframework/benchmarks/AbstractProblemTest.java b/src/test/java/org/moeaframework/benchmarks/AbstractProblemTest.java index e971190..1465b0c 100644 --- a/src/test/java/org/moeaframework/benchmarks/AbstractProblemTest.java +++ b/src/test/java/org/moeaframework/benchmarks/AbstractProblemTest.java @@ -24,16 +24,18 @@ import org.junit.Assume; import org.junit.Ignore; import org.moeaframework.algorithm.NSGAII; -import org.moeaframework.core.Settings; import org.moeaframework.core.Solution; import org.moeaframework.core.population.NondominatedPopulation; import org.moeaframework.core.spi.ProblemFactory; +import org.moeaframework.core.variable.BinaryIntegerVariable; import org.moeaframework.core.variable.RealVariable; import org.moeaframework.problem.Problem; @Ignore("abstract test class") public class AbstractProblemTest { + private static final double EPS = 0.01; + protected void testSolve(String problemName) { try (Problem problem = ProblemFactory.getInstance().getProblem(problemName)) { Assert.assertNotNull("Problem not defined", problem); @@ -63,14 +65,40 @@ protected void testSolution(String problemName, double[] variables, double[] exp problem.evaluate(solution); try { - Assert.assertArrayEquals("Objectives do not match", expectedObjectives, solution.getObjectiveValues(), Settings.EPS); + Assert.assertArrayEquals("Objectives do not match", expectedObjectives, solution.getObjectiveValues(), EPS); + } catch (AssertionError e) { + System.out.println("Actual Objectives: " + Arrays.toString(solution.getObjectiveValues())); + throw e; + } + + try { + Assert.assertArrayEquals("Constraints do not match", expectedConstraints, solution.getConstraintValues(), EPS); + } catch (AssertionError e) { + System.out.println("Actual Constraints: " + Arrays.toString(solution.getConstraintValues())); + throw e; + } + + Assert.assertEquals("Feasibility does not match", isFeasible, solution.isFeasible()); + + } + } + + protected void testSolution(String problemName, int[] variables, double[] expectedObjectives, double[] expectedConstraints, boolean isFeasible) { + try (Problem problem = ProblemFactory.getInstance().getProblem(problemName)) { + Solution solution = problem.newSolution(); + BinaryIntegerVariable.setInt(solution, variables); + + problem.evaluate(solution); + + try { + Assert.assertArrayEquals("Objectives do not match", expectedObjectives, solution.getObjectiveValues(), EPS); } catch (AssertionError e) { System.out.println("Actual Objectives: " + Arrays.toString(solution.getObjectiveValues())); throw e; } try { - Assert.assertArrayEquals("Constraints do not match", expectedConstraints, solution.getConstraintValues(), Settings.EPS); + Assert.assertArrayEquals("Constraints do not match", expectedConstraints, solution.getConstraintValues(), EPS); } catch (AssertionError e) { System.out.println("Actual Constraints: " + Arrays.toString(solution.getConstraintValues())); throw e; diff --git a/src/test/java/org/moeaframework/benchmarks/ElectricMotorTest.java b/src/test/java/org/moeaframework/benchmarks/ElectricMotorTest.java index b795864..76fbd29 100644 --- a/src/test/java/org/moeaframework/benchmarks/ElectricMotorTest.java +++ b/src/test/java/org/moeaframework/benchmarks/ElectricMotorTest.java @@ -36,7 +36,7 @@ public void testLowerBound() { testSolution("ElectricMotor", new double[] { 100.0, 0.01, 1.0, 0.01, 0.01, 5.0E-4, 0.001, 0.1, 100.0, 0.01, 1.0, 0.01, 0.01, 5.0E-4, 0.001, 0.1, 100.0, 0.01, 1.0, 0.01, 0.01, 5.0E-4, 0.001, 0.1, 100.0, 0.01, 1.0, 0.01, 0.01, 5.0E-4, 0.001, 0.1, 100.0, 0.01, 1.0, 0.01, 0.01, 5.0E-4, 0.001, 0.1, 100.0, 0.01, 1.0, 0.01, 0.01, 5.0E-4, 0.001, 0.1, 100.0, 0.01, 1.0, 0.01, 0.01, 5.0E-4, 0.001, 0.1, 100.0, 0.01, 1.0, 0.01, 0.01, 5.0E-4, 0.001, 0.1, 100.0, 0.01, 1.0, 0.01, 0.01, 5.0E-4, 0.001, 0.1, 100.0, 0.01, 1.0, 0.01, 0.01, 5.0E-4, 0.001, 0.1 }, new double[] { -2.1178860361093237E-5, 0.9829575175304347, -2.1178860361093237E-5, 0.9829575175304347, -2.1178860361093237E-5, 0.9829575175304347, -2.1178860361093237E-5, 0.9829575175304347, -2.1178860361093237E-5, 0.9829575175304347, -2.1178860361093237E-5, 0.9829575175304347, -2.1178860361093237E-5, 0.9829575175304347, -2.1178860361093237E-5, 0.9829575175304347, -2.1178860361093237E-5, 0.9829575175304347, -2.1178860361093237E-5, 0.9829575175304347 }, - new double[] { 0.05000000000380373, 288.6959885484, 0.0, 0.0, 0.0, 0.0, 0.10000000000380374, 288.6959885484, 0.0, 0.0, 0.0, 0.0, 0.12500000000380374, 288.6959885484, 0.0, 0.0, 0.0, 0.0, 0.15000000000380373, 288.6959885484, 0.0, 0.0, 0.0, 0.0, 0.20000000000380375, 288.6959885484, 0.0, 0.0, 0.0, 0.0, 0.25000000000380374, 288.6959885484, 0.0, 0.0, 0.0, 0.0, 0.3000000000038037, 288.6959885484, 0.0, 0.0, 0.0, 0.0, 0.3500000000038037, 288.6959885484, 0.0, 0.0, 0.0, 0.0, 0.40000000000380376, 288.6959885484, 0.0, 0.0, 0.0, 0.0, 0.5000000000038037, 288.6959885484, 0.0, 0.0, 0.0, 0.0 }, + new double[] { 0.05000000000380373, 288.6959885484, 200.00000000000003, 194.5734766747823, -2.1178860361093237E-5, 0.9829575175304347, 0.10000000000380374, 288.6959885484, 200.00000000000003, 194.5734766747823, -2.1178860361093237E-5, 0.9829575175304347, 0.12500000000380374, 288.6959885484, 200.00000000000003, 194.5734766747823, -2.1178860361093237E-5, 0.9829575175304347, 0.15000000000380373, 288.6959885484, 200.00000000000003, 194.5734766747823, -2.1178860361093237E-5, 0.9829575175304347, 0.20000000000380375, 288.6959885484, 200.00000000000003, 194.5734766747823, -2.1178860361093237E-5, 0.9829575175304347, 0.25000000000380374, 288.6959885484, 200.00000000000003, 194.5734766747823, -2.1178860361093237E-5, 0.9829575175304347, 0.3000000000038037, 288.6959885484, 200.00000000000003, 194.5734766747823, -2.1178860361093237E-5, 0.9829575175304347, 0.3500000000038037, 288.6959885484, 200.00000000000003, 194.5734766747823, -2.1178860361093237E-5, 0.9829575175304347, 0.40000000000380376, 288.6959885484, 200.00000000000003, 194.5734766747823, -2.1178860361093237E-5, 0.9829575175304347, 0.5000000000038037, 288.6959885484, 200.00000000000003, 194.5734766747823, -2.1178860361093237E-5, 0.9829575175304347 }, false); } @@ -45,7 +45,7 @@ public void testUpperBound() { testSolution("ElectricMotor", new double[] { 1500.0, 1.0, 500.0, 1.0, 0.1, 0.1, 0.1, 6.0, 1500.0, 1.0, 500.0, 1.0, 0.1, 0.1, 0.1, 6.0, 1500.0, 1.0, 500.0, 1.0, 0.1, 0.1, 0.1, 6.0, 1500.0, 1.0, 500.0, 1.0, 0.1, 0.1, 0.1, 6.0, 1500.0, 1.0, 500.0, 1.0, 0.1, 0.1, 0.1, 6.0, 1500.0, 1.0, 500.0, 1.0, 0.1, 0.1, 0.1, 6.0, 1500.0, 1.0, 500.0, 1.0, 0.1, 0.1, 0.1, 6.0, 1500.0, 1.0, 500.0, 1.0, 0.1, 0.1, 0.1, 6.0, 1500.0, 1.0, 500.0, 1.0, 0.1, 0.1, 0.1, 6.0, 1500.0, 1.0, 500.0, 1.0, 0.1, 0.1, 0.1, 6.0 }, new double[] { 0.08781367214553605, 0.9739676521739131, 0.08781367214553605, 0.9739676521739131, 0.08781367214553605, 0.9739676521739131, 0.08781367214553605, 0.9739676521739131, 0.08781367214553605, 0.9739676521739131, 0.08781367214553605, 0.9739676521739131, 0.08781367214553605, 0.9739676521739131, 0.08781367214553605, 0.9739676521739131, 0.08781367214553605, 0.9739676521739131, 0.08781367214553605, 0.9739676521739131 }, - new double[] { 0.04692963432538349, 372.03768, 0.0, 583388.4728341918, 0.0, 0.0, 0.0969296343253835, 372.03768, 0.0, 583388.4728341918, 0.0, 0.0, 0.12192963432538349, 372.03768, 0.0, 583388.4728341918, 0.0, 0.0, 0.14692963432538347, 372.03768, 0.0, 583388.4728341918, 0.0, 0.0, 0.1969296343253835, 372.03768, 0.0, 583388.4728341918, 0.0, 0.0, 0.24692963432538348, 372.03768, 0.0, 583388.4728341918, 0.0, 0.0, 0.2969296343253835, 372.03768, 0.0, 583388.4728341918, 0.0, 0.0, 0.3469296343253835, 372.03768, 0.0, 583388.4728341918, 0.0, 0.0, 0.39692963432538353, 372.03768, 0.0, 583388.4728341918, 0.0, 0.0, 0.4969296343253835, 372.03768, 0.0, 583388.4728341918, 0.0, 0.0 }, + new double[] { 0.04692963432538349, 372.03768, 10.0, 588388.4728341918, 0.08781367214553605, 0.9739676521739131, 0.0969296343253835, 372.03768, 10.0, 588388.4728341918, 0.08781367214553605, 0.9739676521739131, 0.12192963432538349, 372.03768, 10.0, 588388.4728341918, 0.08781367214553605, 0.9739676521739131, 0.14692963432538347, 372.03768, 10.0, 588388.4728341918, 0.08781367214553605, 0.9739676521739131, 0.1969296343253835, 372.03768, 10.0, 588388.4728341918, 0.08781367214553605, 0.9739676521739131, 0.24692963432538348, 372.03768, 10.0, 588388.4728341918, 0.08781367214553605, 0.9739676521739131, 0.2969296343253835, 372.03768, 10.0, 588388.4728341918, 0.08781367214553605, 0.9739676521739131, 0.3469296343253835, 372.03768, 10.0, 588388.4728341918, 0.08781367214553605, 0.9739676521739131, 0.39692963432538353, 372.03768, 10.0, 588388.4728341918, 0.08781367214553605, 0.9739676521739131, 0.4969296343253835, 372.03768, 10.0, 588388.4728341918, 0.08781367214553605, 0.9739676521739131 }, false); } diff --git a/src/test/java/org/moeaframework/benchmarks/HBVTest.java b/src/test/java/org/moeaframework/benchmarks/HBVTest.java index 24160e7..2b52ed4 100644 --- a/src/test/java/org/moeaframework/benchmarks/HBVTest.java +++ b/src/test/java/org/moeaframework/benchmarks/HBVTest.java @@ -35,7 +35,7 @@ public void testReferenceSet() { public void testLowerBound() { testSolution("HBV", new double[] { 0.0, 0.5, 1.0, 10.0, 0.0, 0.3, 0.0, 0.0, 24.0, -3.0, 0.0, 0.0, 0.0, 0.0 }, - new double[] { 9.910673, 3.527903, 1.225312, 1.327312 }, + new double[] { -8.910673, 3.527903, 1.225312, 1.327312 }, new double[] { }, true); } @@ -44,7 +44,7 @@ public void testLowerBound() { public void testUpperBound() { testSolution("HBV", new double[] { 100.0, 20.0, 100.0, 20000.0, 100.0, 1.0, 2000.0, 7.0, 120.0, 3.0, 20.0, 1.0, 0.8, 7.0 }, - new double[] { 0.9951112, 3.319143, 0.6665916, 0.9936301 }, + new double[] { 0.004888769, 3.319143, 0.6665916, 0.9936301 }, new double[] { }, true); } diff --git a/src/test/java/org/moeaframework/benchmarks/RadarTest.java b/src/test/java/org/moeaframework/benchmarks/RadarTest.java index 5baf8a3..c09ed86 100644 --- a/src/test/java/org/moeaframework/benchmarks/RadarTest.java +++ b/src/test/java/org/moeaframework/benchmarks/RadarTest.java @@ -17,9 +17,15 @@ */ package org.moeaframework.benchmarks; +import org.junit.Before; import org.junit.Test; public class RadarTest extends AbstractProblemTest { + + @Before + public void setUp() { + requiresMatlab(); + } @Test public void testSolve() { diff --git a/src/test/java/org/moeaframework/benchmarks/WDSTest.java b/src/test/java/org/moeaframework/benchmarks/WDSTest.java index ce9d374..30fe993 100644 --- a/src/test/java/org/moeaframework/benchmarks/WDSTest.java +++ b/src/test/java/org/moeaframework/benchmarks/WDSTest.java @@ -34,7 +34,7 @@ public void testReferenceSet() { @Test public void testLowerBound() { testSolution("WDS(GOY)", - new double[] { 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 }, + new int[] { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, new double[] { 0.17467288672924042, -6.119567394256592 }, new double[] { -2390.6025390625 }, false); @@ -43,7 +43,7 @@ public void testLowerBound() { @Test public void testUpperBound() { testSolution("WDS(GOY)", - new double[] { 7.999999999999999, 7.999999999999999, 7.999999999999999, 7.999999999999999, 7.999999999999999, 7.999999999999999, 7.999999999999999, 7.999999999999999, 7.999999999999999, 7.999999999999999, 7.999999999999999, 7.999999999999999, 7.999999999999999, 7.999999999999999, 7.999999999999999, 7.999999999999999, 7.999999999999999, 7.999999999999999, 7.999999999999999, 7.999999999999999, 7.999999999999999, 7.999999999999999, 7.999999999999999, 7.999999999999999, 7.999999999999999, 7.999999999999999, 7.999999999999999, 7.999999999999999, 7.999999999999999, 7.999999999999999 }, + new int[] { 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8 }, new double[] { 0.3297256529331207, 0.7125067114830017 }, new double[] { 0.0 }, true);