Skip to content

Commit 1c5d6c2

Browse files
committed
Update tests
1 parent c5a1c8a commit 1c5d6c2

File tree

7 files changed

+57
-23
lines changed

7 files changed

+57
-23
lines changed

native/WDS/src/models.c

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -298,7 +298,7 @@ void test_problem (double *xreal, double *xbin, int **gene, double *obj, double
298298

299299
// report the objectives and constraint violation
300300
obj[0]=totalCost/1000000.0; // $ => $ MM
301-
obj[1]=minResilience; // maximized
301+
obj[1]=minResilience;
302302
constr[0]=-(pressureViolation+errorSum);
303303
return;
304304
}
@@ -433,7 +433,7 @@ void test_problem (double *xreal, double *xbin, int **gene, double *obj, double
433433

434434
// report the objectives and constraint violation
435435
obj[0]=totalCost/1000000.0; // $ => $ MM
436-
obj[1]=-networkResilience; // for minimisation purpose
436+
obj[1]=networkResilience;
437437
constr[0]=-(pressureViolation+errorCode);
438438
return;
439439
}
@@ -568,7 +568,7 @@ void test_problem (double *xreal, double *xbin, int **gene, double *obj, double
568568

569569
// report the objectives and constraint violation
570570
obj[0]=totalCost/1000000.0; // $ => $ MM
571-
obj[1]=-networkResilience; // for minimisation purpose
571+
obj[1]=networkResilience;
572572
constr[0]=-(pressureViolation+errorCode);
573573
return;
574574
}
@@ -709,7 +709,7 @@ void test_problem (double *xreal, double *xbin, int **gene, double *obj, double
709709

710710
// report the objectives and constraint violation
711711
obj[0]=totalCost/1000000.0; // $ => $ MM
712-
obj[1]=-networkResilience; // for minimisation purpose
712+
obj[1]=networkResilience;
713713
constr[0]=-(violation+errorCode);
714714
return;
715715
}
@@ -868,7 +868,7 @@ void test_problem (double *xreal, double *xbin, int **gene, double *obj, double
868868

869869
// report the objectives and constraint violation
870870
obj[0]=totalCost/1000000.0; // $ => $ MM
871-
obj[1]=-networkResilience; // for minimisation purpose
871+
obj[1]=networkResilience;
872872
constr[0]=-(pressureViolation+velocityViolation+errorCode);
873873
return;
874874
}
@@ -997,7 +997,7 @@ void test_problem (double *xreal, double *xbin, int **gene, double *obj, double
997997

998998
// report the objectives and constraint violation
999999
obj[0]=totalCost/1000000.0; // $ => $ MM
1000-
obj[1]=-networkResilience; // for minimisation purpose
1000+
obj[1]=networkResilience;
10011001
constr[0]=-(headViolation+errorCode);
10021002
return;
10031003
}
@@ -1143,7 +1143,7 @@ void test_problem (double *xreal, double *xbin, int **gene, double *obj, double
11431143
// report the objectives and constraint violation
11441144
totalCost=totalCost/1000000.0;
11451145
obj[0]=totalCost; // $ => $ MM
1146-
obj[1]=-networkResilience; // for minimisation purpose
1146+
obj[1]=networkResilience;
11471147
constr[0]=-(pressureViolation+errorCode);
11481148
return;
11491149
}
@@ -1293,7 +1293,7 @@ void test_problem (double *xreal, double *xbin, int **gene, double *obj, double
12931293

12941294
// report the objectives and constraint violation
12951295
obj[0]=totalCost/1000000.0; // € => € MM
1296-
obj[1]=-networkResilience; // for minimisation purpose
1296+
obj[1]=networkResilience;
12971297
constr[0]=-(pressureViolation+velocityViolation+errorCode);
12981298
return;
12991299
}
@@ -1443,7 +1443,7 @@ void test_problem (double *xreal, double *xbin, int **gene, double *obj, double
14431443

14441444
// report the objectives and constraint violation
14451445
obj[0]=totalCost/1000000.0; // € => € MM
1446-
obj[1]=-networkResilience; // for minimisation purpose
1446+
obj[1]=networkResilience;
14471447
constr[0]=-(pressureViolation+velocityViolation+errorCode);
14481448
return;
14491449
}
@@ -1592,7 +1592,7 @@ void test_problem (double *xreal, double *xbin, int **gene, double *obj, double
15921592

15931593
// report the objectives and constraint violation
15941594
obj[0]=totalCost/1000000.0; // € => € MM
1595-
obj[1]=-networkResilience; // for minimisation purpose
1595+
obj[1]=networkResilience;
15961596
constr[0]=-(pressureViolation+velocityViolation+errorCode);
15971597
return;
15981598
}
@@ -1728,7 +1728,7 @@ void test_problem (double *xreal, double *xbin, int **gene, double *obj, double
17281728

17291729
// report the objectives and constraint violation
17301730
obj[0]=totalCost/1000000.0; // € => € MM
1731-
obj[1]=-networkResilience; // for minimisation purpose
1731+
obj[1]=networkResilience;
17321732
constr[0]=-(pressureViolation+errorCode);
17331733
return;
17341734
}
@@ -1900,7 +1900,7 @@ void test_problem (double *xreal, double *xbin, int **gene, double *obj, double
19001900

19011901
// report the objectives and constraint violation
19021902
obj[0]=totalCost/1000000.0; // £ => £ MM
1903-
obj[1]=-networkResilience; // for minimisation purpose
1903+
obj[1]=networkResilience;
19041904
constr[0]=-(pressureViolation+errorCode);
19051905
return;
19061906
}

src/test/java/org/moeaframework/benchmarks/AbstractProblemTest.java

Lines changed: 31 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,16 +24,18 @@
2424
import org.junit.Assume;
2525
import org.junit.Ignore;
2626
import org.moeaframework.algorithm.NSGAII;
27-
import org.moeaframework.core.Settings;
2827
import org.moeaframework.core.Solution;
2928
import org.moeaframework.core.population.NondominatedPopulation;
3029
import org.moeaframework.core.spi.ProblemFactory;
30+
import org.moeaframework.core.variable.BinaryIntegerVariable;
3131
import org.moeaframework.core.variable.RealVariable;
3232
import org.moeaframework.problem.Problem;
3333

3434
@Ignore("abstract test class")
3535
public class AbstractProblemTest {
3636

37+
private static final double EPS = 0.01;
38+
3739
protected void testSolve(String problemName) {
3840
try (Problem problem = ProblemFactory.getInstance().getProblem(problemName)) {
3941
Assert.assertNotNull("Problem not defined", problem);
@@ -63,14 +65,40 @@ protected void testSolution(String problemName, double[] variables, double[] exp
6365
problem.evaluate(solution);
6466

6567
try {
66-
Assert.assertArrayEquals("Objectives do not match", expectedObjectives, solution.getObjectiveValues(), Settings.EPS);
68+
Assert.assertArrayEquals("Objectives do not match", expectedObjectives, solution.getObjectiveValues(), EPS);
69+
} catch (AssertionError e) {
70+
System.out.println("Actual Objectives: " + Arrays.toString(solution.getObjectiveValues()));
71+
throw e;
72+
}
73+
74+
try {
75+
Assert.assertArrayEquals("Constraints do not match", expectedConstraints, solution.getConstraintValues(), EPS);
76+
} catch (AssertionError e) {
77+
System.out.println("Actual Constraints: " + Arrays.toString(solution.getConstraintValues()));
78+
throw e;
79+
}
80+
81+
Assert.assertEquals("Feasibility does not match", isFeasible, solution.isFeasible());
82+
83+
}
84+
}
85+
86+
protected void testSolution(String problemName, int[] variables, double[] expectedObjectives, double[] expectedConstraints, boolean isFeasible) {
87+
try (Problem problem = ProblemFactory.getInstance().getProblem(problemName)) {
88+
Solution solution = problem.newSolution();
89+
BinaryIntegerVariable.setInt(solution, variables);
90+
91+
problem.evaluate(solution);
92+
93+
try {
94+
Assert.assertArrayEquals("Objectives do not match", expectedObjectives, solution.getObjectiveValues(), EPS);
6795
} catch (AssertionError e) {
6896
System.out.println("Actual Objectives: " + Arrays.toString(solution.getObjectiveValues()));
6997
throw e;
7098
}
7199

72100
try {
73-
Assert.assertArrayEquals("Constraints do not match", expectedConstraints, solution.getConstraintValues(), Settings.EPS);
101+
Assert.assertArrayEquals("Constraints do not match", expectedConstraints, solution.getConstraintValues(), EPS);
74102
} catch (AssertionError e) {
75103
System.out.println("Actual Constraints: " + Arrays.toString(solution.getConstraintValues()));
76104
throw e;

src/test/java/org/moeaframework/benchmarks/ElectricMotorTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ public void testLowerBound() {
3636
testSolution("ElectricMotor",
3737
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 },
3838
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 },
39-
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 },
39+
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 },
4040
false);
4141
}
4242

@@ -45,7 +45,7 @@ public void testUpperBound() {
4545
testSolution("ElectricMotor",
4646
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 },
4747
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 },
48-
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 },
48+
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 },
4949
false);
5050
}
5151

src/test/java/org/moeaframework/benchmarks/HBVTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ public void testReferenceSet() {
3535
public void testLowerBound() {
3636
testSolution("HBV",
3737
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 },
38-
new double[] { 9.910673, 3.527903, 1.225312, 1.327312 },
38+
new double[] { -8.910673, 3.527903, 1.225312, 1.327312 },
3939
new double[] { },
4040
true);
4141
}
@@ -44,7 +44,7 @@ public void testLowerBound() {
4444
public void testUpperBound() {
4545
testSolution("HBV",
4646
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 },
47-
new double[] { 0.9951112, 3.319143, 0.6665916, 0.9936301 },
47+
new double[] { 0.004888769, 3.319143, 0.6665916, 0.9936301 },
4848
new double[] { },
4949
true);
5050
}

src/test/java/org/moeaframework/benchmarks/LakeProblemTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ public void testLowerBound() {
3636
testSolution("LakeProblem",
3737
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 },
3838
new double[] { 0.05773962737399343, 0.0, 1.0, 1.0 },
39-
new double[] { 0.0 },
39+
new double[] { 1.0 },
4040
true);
4141
}
4242

@@ -45,7 +45,7 @@ public void testUpperBound() {
4545
testSolution("LakeProblem",
4646
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 },
4747
new double[] { 2.2865409710232774, 1.7347608882104941, 1.0, 0.06 },
48-
new double[] { 0.79 },
48+
new double[] { 0.06 },
4949
false);
5050
}
5151

src/test/java/org/moeaframework/benchmarks/RadarTest.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,15 @@
1717
*/
1818
package org.moeaframework.benchmarks;
1919

20+
import org.junit.Before;
2021
import org.junit.Test;
2122

2223
public class RadarTest extends AbstractProblemTest {
24+
25+
@Before
26+
public void setUp() {
27+
requiresMatlab();
28+
}
2329

2430
@Test
2531
public void testSolve() {

src/test/java/org/moeaframework/benchmarks/WDSTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ public void testReferenceSet() {
3434
@Test
3535
public void testLowerBound() {
3636
testSolution("WDS(GOY)",
37-
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 },
37+
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 },
3838
new double[] { 0.17467288672924042, -6.119567394256592 },
3939
new double[] { -2390.6025390625 },
4040
false);
@@ -43,7 +43,7 @@ public void testLowerBound() {
4343
@Test
4444
public void testUpperBound() {
4545
testSolution("WDS(GOY)",
46-
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 },
46+
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 },
4747
new double[] { 0.3297256529331207, 0.7125067114830017 },
4848
new double[] { 0.0 },
4949
true);

0 commit comments

Comments
 (0)