Skip to content

Commit

Permalink
Update tests
Browse files Browse the repository at this point in the history
  • Loading branch information
dhadka committed Dec 20, 2024
1 parent c5a1c8a commit 4d5f73e
Show file tree
Hide file tree
Showing 7 changed files with 59 additions and 25 deletions.
24 changes: 12 additions & 12 deletions native/WDS/src/models.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand All @@ -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);
}

Expand Down
4 changes: 2 additions & 2 deletions src/test/java/org/moeaframework/benchmarks/HBVTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand All @@ -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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public void testLowerBound() {
testSolution("LakeProblem",
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, 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, 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, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 },
new double[] { 0.05773962737399343, 0.0, 1.0, 1.0 },
new double[] { 0.0 },
new double[] { 1.0 },
true);
}

Expand All @@ -45,7 +45,7 @@ public void testUpperBound() {
testSolution("LakeProblem",
new double[] { 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1 },
new double[] { 2.2865409710232774, 1.7347608882104941, 1.0, 0.06 },
new double[] { 0.79 },
new double[] { 0.06 },
false);
}

Expand Down
6 changes: 6 additions & 0 deletions src/test/java/org/moeaframework/benchmarks/RadarTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
8 changes: 4 additions & 4 deletions src/test/java/org/moeaframework/benchmarks/WDSTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,17 +34,17 @@ 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 double[] { 0.17467288672924042, -6.119567394256592 },
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);
}

@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 double[] { 0.3297256529331207, 0.7125067114830017 },
new int[] { 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7 },
new double[] { 0.3297256529331207, -0.7125067114830017 },
new double[] { 0.0 },
true);
}
Expand Down

0 comments on commit 4d5f73e

Please sign in to comment.