Skip to content
This repository was archived by the owner on Jan 17, 2025. It is now read-only.

Commit 10e63d4

Browse files
committed
Update to MOEAFramework 4.0
1 parent 24465e2 commit 10e63d4

File tree

11 files changed

+110
-62
lines changed

11 files changed

+110
-62
lines changed

.classpath

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
<classpathentry excluding="**" kind="src" output="target/classes" path="src/main/resources">
1010
<attributes>
1111
<attribute name="maven.pomderived" value="true"/>
12+
<attribute name="optional" value="true"/>
1213
</attributes>
1314
</classpathentry>
1415
<classpathentry kind="src" output="target/test-classes" path="src/test/java">
@@ -22,9 +23,10 @@
2223
<attributes>
2324
<attribute name="maven.pomderived" value="true"/>
2425
<attribute name="test" value="true"/>
26+
<attribute name="optional" value="true"/>
2527
</attributes>
2628
</classpathentry>
27-
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8">
29+
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-17">
2830
<attributes>
2931
<attribute name="maven.pomderived" value="true"/>
3032
</attributes>

.github/workflows/ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ jobs:
1010
strategy:
1111
fail-fast: false
1212
matrix:
13-
java: [ '8', '11', '16', '17', '18', '19', '20' ]
13+
java: [ '17', '18', '19', '20', '21' ]
1414
steps:
1515
- uses: actions/checkout@v3
1616
- name: Set up JDK ${{ matrix.java }}

.github/workflows/stage.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,10 @@ jobs:
2525
runs-on: ubuntu-latest
2626
steps:
2727
- uses: actions/checkout@v3
28-
- name: Set up JDK 16
28+
- name: Set up JDK 17
2929
uses: actions/setup-java@v3
3030
with:
31-
java-version: 16
31+
java-version: 17
3232
distribution: temurin
3333
- name: Install required software
3434
run: |

COPYING

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
Copyright 2009-2022 David Hadka and other contributors. All rights reserved.
1+
Copyright 2009-2024 David Hadka and other contributors. All rights reserved.
22

33
The MOEA Framework is free software: you can redistribute it and/or modify
44
it under the terms of the GNU Lesser General Public License as published by

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ Add the following dependency to your `pom.xml`:
2424
<dependency>
2525
<groupId>org.moeaframework</groupId>
2626
<artifactId>gd</artifactId>
27-
<version>1.2</version>
27+
<version>2.0</version>
2828
</dependency>
2929
```
3030

@@ -47,7 +47,7 @@ If unset, it will default to uniformly-spaced points generated using the Normal
4747

4848
## License
4949

50-
Copyright 2009-2022 David Hadka and other contributors. All rights reserved.
50+
Copyright 2009-2024 David Hadka and other contributors. All rights reserved.
5151

5252
The MOEA Framework is free software: you can redistribute it and/or modify
5353
it under the terms of the GNU Lesser General Public License as published by

pom.xml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,15 +31,15 @@
3131

3232
<properties>
3333
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
34-
<maven.compiler.source>8</maven.compiler.source>
35-
<maven.compiler.target>8</maven.compiler.target>
34+
<maven.compiler.source>17</maven.compiler.source>
35+
<maven.compiler.target>17</maven.compiler.target>
3636
</properties>
3737

3838
<dependencies>
3939
<dependency>
4040
<groupId>org.moeaframework</groupId>
4141
<artifactId>moeaframework</artifactId>
42-
<version>3.2</version>
42+
<version>4.0</version>
4343
<scope>provided</scope>
4444
</dependency>
4545
<dependency>
@@ -58,13 +58,13 @@
5858
<dependency>
5959
<groupId>commons-io</groupId>
6060
<artifactId>commons-io</artifactId>
61-
<version>2.11.0</version>
61+
<version>2.15.1</version>
6262
<scope>provided</scope>
6363
</dependency>
6464
<dependency>
6565
<groupId>org.apache.commons</groupId>
6666
<artifactId>commons-lang3</artifactId>
67-
<version>3.12.0</version>
67+
<version>3.14.0</version>
6868
<scope>provided</scope>
6969
</dependency>
7070
<dependency>

src/main/java/org/moeaframework/gd/Example.java

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,20 @@
1+
/* Copyright 2009-2024 David Hadka
2+
*
3+
* This file is part of the MOEA Framework.
4+
*
5+
* The MOEA Framework is free software: you can redistribute it and/or modify
6+
* it under the terms of the GNU Lesser General Public License as published by
7+
* the Free Software Foundation, either version 3 of the License, or (at your
8+
* option) any later version.
9+
*
10+
* The MOEA Framework is distributed in the hope that it will be useful, but
11+
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
12+
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
13+
* License for more details.
14+
*
15+
* You should have received a copy of the GNU Lesser General Public License
16+
* along with the MOEA Framework. If not, see <http://www.gnu.org/licenses/>.
17+
*/
118
package org.moeaframework.gd;
219

320
import org.moeaframework.Analyzer;
@@ -21,8 +38,8 @@ public static void main(String[] args) {
2138
.withAlgorithm("MOEA/D")
2239
.runSeeds(50));
2340

24-
// collect data for MOEA/D with Generalized Decomposition - by targeting the Pareto front
25-
// points, we should get extremely close to the optimum
41+
// collect data for MOEA/D with Generalized Decomposition - by targeting the Pareto front points, we should
42+
// get extremely close to the optimum
2643
analyzer.addAll("GD-MOEA/D", executor
2744
.withAlgorithm("GD-MOEA/D")
2845
.withProperty("targets", "pf/DTLZ2.3D.pf")
Lines changed: 32 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,37 @@
1+
/* Copyright 2009-2024 David Hadka
2+
*
3+
* This file is part of the MOEA Framework.
4+
*
5+
* The MOEA Framework is free software: you can redistribute it and/or modify
6+
* it under the terms of the GNU Lesser General Public License as published by
7+
* the Free Software Foundation, either version 3 of the License, or (at your
8+
* option) any later version.
9+
*
10+
* The MOEA Framework is distributed in the hope that it will be useful, but
11+
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
12+
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
13+
* License for more details.
14+
*
15+
* You should have received a copy of the GNU Lesser General Public License
16+
* along with the MOEA Framework. If not, see <http://www.gnu.org/licenses/>.
17+
*/
118
package org.moeaframework.gd;
219

320
import java.io.File;
421
import java.io.IOException;
5-
import java.io.InputStream;
6-
import java.io.InputStreamReader;
722
import java.util.ArrayList;
823
import java.util.List;
924

1025
import org.moeaframework.algorithm.MOEAD;
1126
import org.moeaframework.core.FrameworkException;
1227
import org.moeaframework.core.Population;
13-
import org.moeaframework.core.PopulationIO;
1428
import org.moeaframework.core.Problem;
1529
import org.moeaframework.core.Solution;
16-
import org.moeaframework.core.operator.RandomInitialization;
30+
import org.moeaframework.core.initialization.RandomInitialization;
1731
import org.moeaframework.core.spi.OperatorFactory;
1832
import org.moeaframework.core.variable.RealVariable;
19-
import org.moeaframework.util.io.CommentedLineReader;
33+
import org.moeaframework.util.io.Resources;
34+
import org.moeaframework.util.io.Resources.ResourceOption;
2035
import org.moeaframework.util.weights.NormalBoundaryDivisions;
2136
import org.moeaframework.util.weights.NormalBoundaryIntersectionGenerator;
2237
import org.moeaframework.util.weights.WeightGenerator;
@@ -32,9 +47,8 @@ public GDMOEAD(Problem problem, String targets) {
3247
}
3348

3449
public GDMOEAD(Problem problem, NormalBoundaryDivisions divisions) {
35-
this(problem,
36-
new GeneralizedDecomposition(new NormalBoundaryIntersectionGenerator(
37-
problem.getNumberOfObjectives(), divisions)));
50+
this(problem, new GeneralizedDecomposition(new NormalBoundaryIntersectionGenerator(
51+
problem.getNumberOfObjectives(), divisions)));
3852
}
3953

4054
public GDMOEAD(Problem problem, WeightGenerator weightGenerator) {
@@ -50,35 +64,22 @@ public GDMOEAD(Problem problem, WeightGenerator weightGenerator) {
5064
}
5165

5266
private static List<double[]> loadTargets(String resource) {
53-
Population population = null;
54-
5567
try {
56-
File file = new File(resource);
68+
File file = Resources.asFile(GDMOEAD.class, "/" + resource, ResourceOption.REQUIRED,
69+
ResourceOption.TEMPORARY, ResourceOption.FILE);
5770

58-
if (file.exists()) {
59-
population = PopulationIO.readObjectives(file);
60-
} else {
61-
try (InputStream input = GDMOEAD.class.getResourceAsStream("/" + resource)) {
62-
if (input != null) {
63-
population = PopulationIO.readObjectives(new CommentedLineReader(new InputStreamReader(input)));
64-
}
65-
}
71+
Population population = Population.loadObjectives(file);
72+
73+
List<double[]> targets = new ArrayList<double[]>();
74+
75+
for (Solution solution : population) {
76+
targets.add(solution.getObjectives());
6677
}
78+
79+
return targets;
6780
} catch (IOException e) {
6881
throw new FrameworkException("failed to load " + resource, e);
6982
}
70-
71-
if (population == null) {
72-
throw new FrameworkException("could not find " + resource);
73-
}
74-
75-
List<double[]> targets = new ArrayList<double[]>();
76-
77-
for (Solution solution : population) {
78-
targets.add(solution.getObjectives());
79-
}
80-
81-
return targets;
8283
}
8384

8485
}

src/main/java/org/moeaframework/gd/GDMOEADProvider.java

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,20 @@
1+
/* Copyright 2009-2024 David Hadka
2+
*
3+
* This file is part of the MOEA Framework.
4+
*
5+
* The MOEA Framework is free software: you can redistribute it and/or modify
6+
* it under the terms of the GNU Lesser General Public License as published by
7+
* the Free Software Foundation, either version 3 of the License, or (at your
8+
* option) any later version.
9+
*
10+
* The MOEA Framework is distributed in the hope that it will be useful, but
11+
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
12+
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
13+
* License for more details.
14+
*
15+
* You should have received a copy of the GNU Lesser General Public License
16+
* along with the MOEA Framework. If not, see <http://www.gnu.org/licenses/>.
17+
*/
118
package org.moeaframework.gd;
219

320
import org.moeaframework.core.Algorithm;

src/main/java/org/moeaframework/gd/GeneralizedDecomposition.java

Lines changed: 11 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* Copyright 2009-2022 David Hadka
1+
/* Copyright 2009-2024 David Hadka
22
*
33
* This file is part of the MOEA Framework.
44
*
@@ -30,15 +30,13 @@
3030
import com.joptimizer.optimizers.LPPrimalDualMethod;
3131

3232
/**
33-
* Generates weights used to find solutions near a given set of target points.
34-
* Generalized decomposition determines the Chebychev scalarizing function
35-
* weights that are used to attain solutions near the given target points.
33+
* Generates weights used to find solutions near a given set of target points. Generalized decomposition determines
34+
* the Chebychev scalarizing function weights that are used to attain solutions near the given target points.
3635
* <p>
3736
* References:
3837
* <ol>
39-
* <li>Giagkiozis, I., R. C. Purshouse, and P. J. Fleming (2013).
40-
* "Generalized Decomposition." Evolutionary Multi-Criterion
41-
* Optimization, 7th International Conference, pp. 428-442.
38+
* <li>Giagkiozis, I., R. C. Purshouse, and P. J. Fleming (2013). "Generalized Decomposition." Evolutionary
39+
* Multi-Criterion Optimization, 7th International Conference, pp. 428-442.
4240
* </ol>
4341
*/
4442
public class GeneralizedDecomposition implements WeightGenerator {
@@ -49,8 +47,7 @@ public class GeneralizedDecomposition implements WeightGenerator {
4947
private final List<double[]> targets;
5048

5149
/**
52-
* Constructs a weight generator transforming the given weights into those
53-
* defined by generalized decomposition.
50+
* Constructs a weight generator transforming the given weights into those defined by generalized decomposition.
5451
*
5552
* @param generator the weight generator
5653
*/
@@ -59,8 +56,8 @@ public GeneralizedDecomposition(WeightGenerator generator) {
5956
}
6057

6158
/**
62-
* Constructs a weight generator transforming the given target points into
63-
* the required Chebychef scalaring function weights.
59+
* Constructs a weight generator transforming the given target points into the required Chebychef scalarizing
60+
* function weights.
6461
*
6562
* @param targets the target points normalized on the unit hypervolume
6663
*/
@@ -86,8 +83,7 @@ public List<double[]> generate() {
8683
}
8784

8885
private static double[] solve_chebychev(double[] x) {
89-
// This function uses JOptimizer to solve the following convex
90-
// optimization problem:
86+
// This function uses JOptimizer to solve the following convex optimization problem:
9187
//
9288
// minimize norm_inf(X*w)
9389
// subject to
@@ -97,8 +93,7 @@ private static double[] solve_chebychev(double[] x) {
9793
// X is an n x n diagonal matrix
9894
// w is a n x 1 vector
9995
//
100-
// norm_inf(X*w) is solved by introducing a slack variable, t, and
101-
// adding constraints X*w <= t and X*w >= -t.
96+
// norm_inf(X*w) is solved by introducing a slack variable, t, and adding constraints X*w <= t and X*w >= -t.
10297

10398
// setup the standard form matrices for LP
10499
double[] c = new double[x.length + 1];
@@ -134,8 +129,7 @@ private static double[] solve_chebychev(double[] x) {
134129
}
135130

136131
// use JOptimizer to solve the LP
137-
ConvexMultivariateRealFunction[] inequalities =
138-
new ConvexMultivariateRealFunction[4 * x.length];
132+
ConvexMultivariateRealFunction[] inequalities = new ConvexMultivariateRealFunction[4 * x.length];
139133

140134
for (int i = 0; i < 4 * x.length; i++) {
141135
inequalities[i] = new LinearMultivariateRealFunction(G[i], -h[i]);

0 commit comments

Comments
 (0)