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

Commit

Permalink
Update to MOEAFramework 4.0
Browse files Browse the repository at this point in the history
  • Loading branch information
dhadka committed Apr 6, 2024
1 parent 24465e2 commit 10e63d4
Show file tree
Hide file tree
Showing 11 changed files with 110 additions and 62 deletions.
4 changes: 3 additions & 1 deletion .classpath
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
<classpathentry excluding="**" kind="src" output="target/classes" path="src/main/resources">
<attributes>
<attribute name="maven.pomderived" value="true"/>
<attribute name="optional" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="src" output="target/test-classes" path="src/test/java">
Expand All @@ -22,9 +23,10 @@
<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-1.8">
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-17">
<attributes>
<attribute name="maven.pomderived" value="true"/>
</attributes>
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ jobs:
strategy:
fail-fast: false
matrix:
java: [ '8', '11', '16', '17', '18', '19', '20' ]
java: [ '17', '18', '19', '20', '21' ]
steps:
- uses: actions/checkout@v3
- name: Set up JDK ${{ matrix.java }}
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/stage.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,10 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Set up JDK 16
- name: Set up JDK 17
uses: actions/setup-java@v3
with:
java-version: 16
java-version: 17
distribution: temurin
- name: Install required software
run: |
Expand Down
2 changes: 1 addition & 1 deletion COPYING
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Copyright 2009-2022 David Hadka and other contributors. All rights reserved.
Copyright 2009-2024 David Hadka and other contributors. All rights reserved.

The MOEA Framework is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ Add the following dependency to your `pom.xml`:
<dependency>
<groupId>org.moeaframework</groupId>
<artifactId>gd</artifactId>
<version>1.2</version>
<version>2.0</version>
</dependency>
```

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

## License

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

The MOEA Framework is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by
Expand Down
10 changes: 5 additions & 5 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,15 @@

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>8</maven.compiler.source>
<maven.compiler.target>8</maven.compiler.target>
<maven.compiler.source>17</maven.compiler.source>
<maven.compiler.target>17</maven.compiler.target>
</properties>

<dependencies>
<dependency>
<groupId>org.moeaframework</groupId>
<artifactId>moeaframework</artifactId>
<version>3.2</version>
<version>4.0</version>
<scope>provided</scope>
</dependency>
<dependency>
Expand All @@ -58,13 +58,13 @@
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<version>2.11.0</version>
<version>2.15.1</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
<version>3.12.0</version>
<version>3.14.0</version>
<scope>provided</scope>
</dependency>
<dependency>
Expand Down
21 changes: 19 additions & 2 deletions src/main/java/org/moeaframework/gd/Example.java
Original file line number Diff line number Diff line change
@@ -1,3 +1,20 @@
/* Copyright 2009-2024 David Hadka
*
* This file is part of the MOEA Framework.
*
* The MOEA Framework is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or (at your
* option) any later version.
*
* The MOEA Framework is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
* License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with the MOEA Framework. If not, see <http://www.gnu.org/licenses/>.
*/
package org.moeaframework.gd;

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

// collect data for MOEA/D with Generalized Decomposition - by targeting the Pareto front
// points, we should get extremely close to the optimum
// collect data for MOEA/D with Generalized Decomposition - by targeting the Pareto front points, we should
// get extremely close to the optimum
analyzer.addAll("GD-MOEA/D", executor
.withAlgorithm("GD-MOEA/D")
.withProperty("targets", "pf/DTLZ2.3D.pf")
Expand Down
63 changes: 32 additions & 31 deletions src/main/java/org/moeaframework/gd/GDMOEAD.java
Original file line number Diff line number Diff line change
@@ -1,22 +1,37 @@
/* Copyright 2009-2024 David Hadka
*
* This file is part of the MOEA Framework.
*
* The MOEA Framework is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or (at your
* option) any later version.
*
* The MOEA Framework is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
* License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with the MOEA Framework. If not, see <http://www.gnu.org/licenses/>.
*/
package org.moeaframework.gd;

import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.List;

import org.moeaframework.algorithm.MOEAD;
import org.moeaframework.core.FrameworkException;
import org.moeaframework.core.Population;
import org.moeaframework.core.PopulationIO;
import org.moeaframework.core.Problem;
import org.moeaframework.core.Solution;
import org.moeaframework.core.operator.RandomInitialization;
import org.moeaframework.core.initialization.RandomInitialization;
import org.moeaframework.core.spi.OperatorFactory;
import org.moeaframework.core.variable.RealVariable;
import org.moeaframework.util.io.CommentedLineReader;
import org.moeaframework.util.io.Resources;
import org.moeaframework.util.io.Resources.ResourceOption;
import org.moeaframework.util.weights.NormalBoundaryDivisions;
import org.moeaframework.util.weights.NormalBoundaryIntersectionGenerator;
import org.moeaframework.util.weights.WeightGenerator;
Expand All @@ -32,9 +47,8 @@ public GDMOEAD(Problem problem, String targets) {
}

public GDMOEAD(Problem problem, NormalBoundaryDivisions divisions) {
this(problem,
new GeneralizedDecomposition(new NormalBoundaryIntersectionGenerator(
problem.getNumberOfObjectives(), divisions)));
this(problem, new GeneralizedDecomposition(new NormalBoundaryIntersectionGenerator(
problem.getNumberOfObjectives(), divisions)));
}

public GDMOEAD(Problem problem, WeightGenerator weightGenerator) {
Expand All @@ -50,35 +64,22 @@ public GDMOEAD(Problem problem, WeightGenerator weightGenerator) {
}

private static List<double[]> loadTargets(String resource) {
Population population = null;

try {
File file = new File(resource);
File file = Resources.asFile(GDMOEAD.class, "/" + resource, ResourceOption.REQUIRED,
ResourceOption.TEMPORARY, ResourceOption.FILE);

if (file.exists()) {
population = PopulationIO.readObjectives(file);
} else {
try (InputStream input = GDMOEAD.class.getResourceAsStream("/" + resource)) {
if (input != null) {
population = PopulationIO.readObjectives(new CommentedLineReader(new InputStreamReader(input)));
}
}
Population population = Population.loadObjectives(file);

List<double[]> targets = new ArrayList<double[]>();

for (Solution solution : population) {
targets.add(solution.getObjectives());
}

return targets;
} catch (IOException e) {
throw new FrameworkException("failed to load " + resource, e);
}

if (population == null) {
throw new FrameworkException("could not find " + resource);
}

List<double[]> targets = new ArrayList<double[]>();

for (Solution solution : population) {
targets.add(solution.getObjectives());
}

return targets;
}

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

import org.moeaframework.core.Algorithm;
Expand Down
28 changes: 11 additions & 17 deletions src/main/java/org/moeaframework/gd/GeneralizedDecomposition.java
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* Copyright 2009-2022 David Hadka
/* Copyright 2009-2024 David Hadka
*
* This file is part of the MOEA Framework.
*
Expand Down Expand Up @@ -30,15 +30,13 @@
import com.joptimizer.optimizers.LPPrimalDualMethod;

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

/**
* Constructs a weight generator transforming the given weights into those
* defined by generalized decomposition.
* Constructs a weight generator transforming the given weights into those defined by generalized decomposition.
*
* @param generator the weight generator
*/
Expand All @@ -59,8 +56,8 @@ public GeneralizedDecomposition(WeightGenerator generator) {
}

/**
* Constructs a weight generator transforming the given target points into
* the required Chebychef scalaring function weights.
* Constructs a weight generator transforming the given target points into the required Chebychef scalarizing
* function weights.
*
* @param targets the target points normalized on the unit hypervolume
*/
Expand All @@ -86,8 +83,7 @@ public List<double[]> generate() {
}

private static double[] solve_chebychev(double[] x) {
// This function uses JOptimizer to solve the following convex
// optimization problem:
// This function uses JOptimizer to solve the following convex optimization problem:
//
// minimize norm_inf(X*w)
// subject to
Expand All @@ -97,8 +93,7 @@ private static double[] solve_chebychev(double[] x) {
// X is an n x n diagonal matrix
// w is a n x 1 vector
//
// norm_inf(X*w) is solved by introducing a slack variable, t, and
// adding constraints X*w <= t and X*w >= -t.
// norm_inf(X*w) is solved by introducing a slack variable, t, and adding constraints X*w <= t and X*w >= -t.

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

// use JOptimizer to solve the LP
ConvexMultivariateRealFunction[] inequalities =
new ConvexMultivariateRealFunction[4 * x.length];
ConvexMultivariateRealFunction[] inequalities = new ConvexMultivariateRealFunction[4 * x.length];

for (int i = 0; i < 4 * x.length; i++) {
inequalities[i] = new LinearMultivariateRealFunction(G[i], -h[i]);
Expand Down
17 changes: 17 additions & 0 deletions src/test/java/org/moeaframework/gd/GDMOEADProviderTest.java
Original file line number Diff line number Diff line change
@@ -1,3 +1,20 @@
/* Copyright 2009-2024 David Hadka
*
* This file is part of the MOEA Framework.
*
* The MOEA Framework is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or (at your
* option) any later version.
*
* The MOEA Framework is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
* License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with the MOEA Framework. If not, see <http://www.gnu.org/licenses/>.
*/
package org.moeaframework.gd;

import org.junit.Assert;
Expand Down

0 comments on commit 10e63d4

Please sign in to comment.