Skip to content

Commit

Permalink
Remove SNAPSHOT
Browse files Browse the repository at this point in the history
  • Loading branch information
dhadka committed Jan 17, 2025
2 parents 27388ef + 1013c56 commit 188b02f
Show file tree
Hide file tree
Showing 20 changed files with 166 additions and 118 deletions.
2 changes: 1 addition & 1 deletion .classpath
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
<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-17">
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-19">
<attributes>
<attribute name="maven.pomderived" value="true"/>
</attributes>
Expand Down
7 changes: 6 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ When using Maven, add the following dependency to your `pom.xml`:
<dependency>
<groupId>org.moeaframework</groupId>
<artifactId>jmetal-plugin</artifactId>
<version>6.2.3</version>
<version>6.6.0</version>
</dependency>
```

Expand All @@ -29,7 +29,12 @@ number of this project will match the supported JMetal version. Below is a comp

JMetal Version | JMetal-Plugin Latest | Supported MOEA Framework Versions | Supported Java Versions
-------------- | -------------------- | --------------------------------- | -----------------------
<<<<<<< HEAD
**`6.2`** | **`6.2.3`** | **`>= 4.0`** | **`>= 17`**
=======
**`6.6`** | **`>= 6.6.0`** | **`>= 5.0`** | **`>= 19`**
`6.2` | `6.2.3` | `>= 4.0` | `>= 17`
>>>>>>> 1013c56e22ef1012296f6b642431a614ac8a629b
`6.2` | `6.2.0` | `3.6 - 3.11` | `>= 14`
`6.1` | `6.1.0` | `3.6 - 3.11` | `>= 14`
`6.0` | `6.0.1` | `3.5 - 3.11` | `>= 14`
Expand Down
16 changes: 15 additions & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
<dependency>
<groupId>org.moeaframework</groupId>
<artifactId>moeaframework</artifactId>
<version>4.4</version>
<version>5.0-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
<dependency>
Expand Down Expand Up @@ -223,13 +223,27 @@
</plugin>
</plugins>
</build>

<repositories>
<repository>
<id>ossrh-snapshots</id>
<url>https://oss.sonatype.org/content/repositories/snapshots/</url>
<releases><enabled>false</enabled></releases>
<snapshots><enabled>true</enabled></snapshots>
</repository>
</repositories>

<distributionManagement>
<repository>
<id>ossrh</id>
<name>Nexus Staging Repository</name>
<url>https://oss.sonatype.org/service/local/staging/deploy/maven2/</url>
</repository>
<snapshotRepository>
<id>ossrh</id>
<name>Nexus Snapshot Repository</name>
<url>https://oss.sonatype.org/content/repositories/snapshots/</url>
</snapshotRepository>
</distributionManagement>

</project>
108 changes: 58 additions & 50 deletions src/main/java/org/moeaframework/algorithm/jmetal/JMetalAlgorithms.java

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
import org.moeaframework.algorithm.jmetal.adapters.PermutationProblemAdapter;
import org.moeaframework.algorithm.jmetal.adapters.ProblemAdapter;
import org.moeaframework.core.FrameworkException;
import org.moeaframework.util.TypedProperties;
import org.moeaframework.core.TypedProperties;
import org.uma.jmetal.operator.crossover.CrossoverOperator;
import org.uma.jmetal.operator.crossover.impl.DifferentialEvolutionCrossover;
import org.uma.jmetal.operator.crossover.impl.DifferentialEvolutionCrossover.DE_VARIANT;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,9 @@
import java.util.List;
import java.util.stream.IntStream;

import org.moeaframework.core.Problem;
import org.moeaframework.core.Solution;
import org.moeaframework.core.variable.BinaryVariable;
import org.moeaframework.core.variable.EncodingUtils;
import org.moeaframework.problem.Problem;
import org.uma.jmetal.problem.binaryproblem.BinaryProblem;
import org.uma.jmetal.solution.binarysolution.BinarySolution;
import org.uma.jmetal.solution.binarysolution.impl.DefaultBinarySolution;
Expand Down Expand Up @@ -82,7 +81,7 @@ public Solution convert(BinarySolution solution) {
Solution result = problem.newSolution();

for (int i = 0; i < numberOfVariables(); i++) {
EncodingUtils.setBitSet(result.getVariable(i), solution.variables().get(i));
BinaryVariable.setBitSet(result.getVariable(i), solution.variables().get(i));
}

return result;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,9 @@
import java.util.List;
import java.util.stream.IntStream;

import org.moeaframework.core.Problem;
import org.moeaframework.core.Solution;
import org.moeaframework.core.variable.EncodingUtils;
import org.moeaframework.core.variable.RealVariable;
import org.moeaframework.problem.Problem;
import org.uma.jmetal.problem.doubleproblem.DoubleProblem;
import org.uma.jmetal.solution.doublesolution.DoubleSolution;
import org.uma.jmetal.solution.doublesolution.impl.DefaultDoubleSolution;
Expand Down Expand Up @@ -63,7 +62,7 @@ public Solution convert(DoubleSolution solution) {
Solution result = problem.newSolution();

for (int i = 0; i < numberOfVariables(); i++) {
EncodingUtils.setReal(result.getVariable(i), solution.variables().get(i));
RealVariable.setReal(result.getVariable(i), solution.variables().get(i));
}

return result;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,12 @@
import java.util.ArrayList;
import java.util.List;

import org.moeaframework.algorithm.Algorithm;
import org.moeaframework.algorithm.AlgorithmException;
import org.moeaframework.core.Algorithm;
import org.moeaframework.core.NondominatedPopulation;
import org.moeaframework.core.Problem;
import org.moeaframework.algorithm.extension.Extensions;
import org.moeaframework.core.Solution;
import org.moeaframework.util.TypedProperties;
import org.moeaframework.core.population.NondominatedPopulation;
import org.moeaframework.problem.Problem;

/**
* Adapter for JMetal algorithms. This allows JMetal algorithms to be used within the MOEA Framework as an
Expand All @@ -45,9 +45,11 @@ public class JMetalAlgorithmAdapter<T extends org.uma.jmetal.solution.Solution<?
private final ProblemAdapter<T> problem;

/**
* The max evaluations the algorithm is run.
* The maximum number of function evaluations the algorithm is run.
*/
private final int maxEvaluations;

private final Extensions extensions;

/**
* The JMetal solution set.
Expand All @@ -58,17 +60,23 @@ public class JMetalAlgorithmAdapter<T extends org.uma.jmetal.solution.Solution<?
* Constructs an adapter for the specified JMetal algorithm.
*
* @param algorithm the JMetal algorithm
* @param properties the properties used to configure this algorithm
* @param problem the problem adapter
* @param maxEvaluations the maximum number of function evaluations the algorithm is run
*/
public JMetalAlgorithmAdapter(
org.uma.jmetal.algorithm.Algorithm<List<T>> algorithm,
TypedProperties properties,
ProblemAdapter<T> problem) {
ProblemAdapter<T> problem,
int maxEvaluations) {
super();
this.algorithm = algorithm;
this.maxEvaluations = (int)properties.getDouble("maxEvaluations", 25000);
this.problem = problem;
this.maxEvaluations = maxEvaluations;
this.extensions = new Extensions(this);
}

@Override
public String getName() {
return algorithm.name();
}

@Override
Expand Down Expand Up @@ -97,14 +105,24 @@ public NondominatedPopulation getResult() {
if (solutionSet != null) {
for (int i = 0; i < solutionSet.size(); i++) {
Solution solution = problem.convert(solutionSet.get(i));
solution.setObjectives(solutionSet.get(i).objectives());
solution.setConstraints(solutionSet.get(i).constraints());
solution.setObjectiveValues(solutionSet.get(i).objectives());
solution.setConstraintValues(solutionSet.get(i).constraints());
result.add(solution);
}
}

return result;
}

@Override
public void initialize() {
extensions.onInitialize();
}

@Override
public boolean isInitialized() {
return true;
}

@Override
public void step() {
Expand All @@ -115,6 +133,8 @@ public void step() {
} catch (Exception e) {
throw new AlgorithmException(this, e);
}

extensions.onStep();
}
}

Expand All @@ -124,10 +144,17 @@ public boolean isTerminated() {
}

@Override
public void terminate() {
public void terminate() {
if (solutionSet == null) {
solutionSet = new ArrayList<T>();
}

extensions.onTerminate();
}

@Override
public Extensions getExtensions() {
return extensions;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,9 @@
import java.util.List;

import org.moeaframework.core.FrameworkException;
import org.moeaframework.core.Problem;
import org.moeaframework.core.Solution;
import org.moeaframework.core.variable.EncodingUtils;
import org.moeaframework.core.variable.Permutation;
import org.moeaframework.problem.Problem;
import org.uma.jmetal.problem.permutationproblem.PermutationProblem;
import org.uma.jmetal.solution.permutationsolution.PermutationSolution;
import org.uma.jmetal.solution.permutationsolution.impl.IntegerPermutationSolution;
Expand Down Expand Up @@ -64,7 +63,7 @@ public Solution convert(PermutationSolution<Integer> solution) {
permutation[i] = permutationList.get(i);
}

EncodingUtils.setPermutation(result.getVariable(0), permutation);
Permutation.setPermutation(result.getVariable(0), permutation);
return result;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@
*/
package org.moeaframework.algorithm.jmetal.adapters;

import org.moeaframework.core.Problem;
import org.moeaframework.core.Solution;
import org.moeaframework.problem.Problem;

/**
* Base class that facilitates passing MOEA Framework problems to JMetal.
Expand Down Expand Up @@ -103,11 +103,11 @@ public T evaluate(T solution) {
getProblem().evaluate(result);

for (int i = 0; i < result.getNumberOfObjectives(); i++) {
solution.objectives()[i] = result.getObjective(i);
solution.objectives()[i] = result.getObjectiveValue(i);
}

for (int i = 0; i < result.getNumberOfConstraints(); i++) {
solution.constraints()[i] = result.getConstraint(i);
solution.constraints()[i] = result.getConstraintValue(i);
}

return solution;
Expand Down
30 changes: 15 additions & 15 deletions src/main/java/org/moeaframework/problem/jmetal/JMetalProblems.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,10 @@
import java.util.function.Supplier;

import org.moeaframework.core.Solution;
import org.moeaframework.core.constraint.GreaterThanOrEqual;
import org.moeaframework.core.spi.RegisteredProblemProvider;
import org.moeaframework.core.variable.EncodingUtils;
import org.moeaframework.core.variable.BinaryVariable;
import org.moeaframework.core.variable.RealVariable;
import org.moeaframework.problem.AbstractProblem;
import org.uma.jmetal.problem.binaryproblem.BinaryProblem;
import org.uma.jmetal.problem.doubleproblem.DoubleProblem;
Expand Down Expand Up @@ -230,21 +232,19 @@ public void evaluate(Solution solution) {

innerProblem.evaluate(innerSolution);

solution.setObjectives(innerSolution.objectives());
solution.setConstraints(innerSolution.constraints());

// JMetal only recognizes constraints < 0 as infeasible whereas MOEA Framework treats any non-zero value
// as infeasible
for (int i = 0; i < solution.getNumberOfConstraints(); i++) {
if (solution.getConstraint(i) > 0.0) {
solution.setConstraint(i, 0.0);
}
}
solution.setObjectiveValues(innerSolution.objectives());
solution.setConstraintValues(innerSolution.constraints());
}

public Solution newSolution() {
Solution solution = new Solution(getNumberOfVariables(), getNumberOfObjectives(), getNumberOfConstraints());
initVariables(solution);

// JMetal treats any value < 0 as violating the constraint
for (int i = 0; i < getNumberOfConstraints(); i++) {
solution.setConstraint(i, GreaterThanOrEqual.to(0.0));
}

return solution;
}

Expand All @@ -264,7 +264,7 @@ public DoubleProblemWrapper(String name, DoubleProblem innerProblem) {
@Override
public void convert(Solution solution, DoubleSolution otherSolution) {
for (int i = 0; i < solution.getNumberOfVariables(); i++) {
otherSolution.variables().set(i, EncodingUtils.getReal(solution.getVariable(i)));
otherSolution.variables().set(i, RealVariable.getReal(solution.getVariable(i)));
}
}

Expand All @@ -273,7 +273,7 @@ public void initVariables(Solution solution) {
List<Bounds<Double>> bounds = innerProblem.variableBounds();

for (int i = 0; i < getNumberOfVariables(); i++) {
solution.setVariable(i, EncodingUtils.newReal(bounds.get(i).getLowerBound(), bounds.get(i).getUpperBound()));
solution.setVariable(i, new RealVariable(bounds.get(i).getLowerBound(), bounds.get(i).getUpperBound()));
}
}

Expand All @@ -288,7 +288,7 @@ public BinaryProblemWrapper(String name, BinaryProblem innerProblem) {
@Override
public void convert(Solution solution, BinarySolution otherSolution) {
for (int i = 0; i < getNumberOfVariables(); i++) {
BitSet bits = EncodingUtils.getBitSet(solution.getVariable(i));
BitSet bits = BinaryVariable.getBitSet(solution.getVariable(i));
BinarySet binarySet = new BinarySet(bits.length());

for (int j = 0; j < bits.length(); j++) {
Expand All @@ -302,7 +302,7 @@ public void convert(Solution solution, BinarySolution otherSolution) {
@Override
public void initVariables(Solution solution) {
for (int i = 0; i < getNumberOfVariables(); i++) {
solution.setVariable(i, EncodingUtils.newBinary(innerProblem.numberOfBitsPerVariable().get(i)));
solution.setVariable(i, new BinaryVariable(innerProblem.numberOfBitsPerVariable().get(i)));
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,11 @@

import org.junit.Assert;
import org.junit.Test;
import org.moeaframework.core.Algorithm;
import org.moeaframework.core.Problem;
import org.moeaframework.algorithm.Algorithm;
import org.moeaframework.core.TypedProperties;
import org.moeaframework.problem.Problem;
import org.moeaframework.problem.DTLZ.DTLZ2;
import org.moeaframework.problem.ZDT.ZDT5;
import org.moeaframework.util.TypedProperties;

/**
* Tests the {@link JMetalAlgorithms} class to ensure the JMetal algorithms can be constructed and used correctly.
Expand Down Expand Up @@ -111,15 +111,15 @@ public void testMOEAD() {

@Test
public void testMOMBI() {
TypedProperties properties = TypedProperties.withProperty("pathWeights",
TypedProperties properties = TypedProperties.of("pathWeights",
"resources/weightVectorFiles/mombi2/weight_02D_152.sld");

runTest("MOMBI-JMetal", properties, new DTLZ2(2));
}

@Test
public void testMOMBI2() {
TypedProperties properties = TypedProperties.withProperty("pathWeights",
TypedProperties properties = TypedProperties.of("pathWeights",
"resources/weightVectorFiles/mombi2/weight_02D_152.sld");

runTest("MOMBI2-JMetal", properties, new DTLZ2(2));
Expand Down
Loading

0 comments on commit 188b02f

Please sign in to comment.