Skip to content

Commit

Permalink
Replace EncodingUtils
Browse files Browse the repository at this point in the history
  • Loading branch information
dhadka committed Nov 30, 2024
1 parent 6106c7a commit c22f9b4
Show file tree
Hide file tree
Showing 7 changed files with 14 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@

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;
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 @@ -21,7 +21,6 @@
import java.util.stream.IntStream;

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;
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 @@ -21,7 +21,6 @@

import org.moeaframework.core.FrameworkException;
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;
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 @@ -24,7 +24,8 @@
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 @@ -263,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 @@ -272,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 @@ -287,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 @@ -301,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 @@ -23,7 +23,7 @@
import org.junit.Test;
import org.moeaframework.algorithm.jmetal.mocks.MockBinaryProblem;
import org.moeaframework.core.Solution;
import org.moeaframework.core.variable.EncodingUtils;
import org.moeaframework.core.variable.BinaryVariable;
import org.uma.jmetal.solution.binarysolution.BinarySolution;
import org.uma.jmetal.util.binarySet.BinarySet;

Expand All @@ -50,7 +50,7 @@ public void testConvert() {

for (int i = 0; i < problem.getNumberOfVariables(); i++) {
BinarySet theirBits = theirSolution.variables().get(0);
BitSet myBits = EncodingUtils.getBitSet(mySolution.getVariable(i));
BitSet myBits = BinaryVariable.getBitSet(mySolution.getVariable(i));

Assert.assertEquals(theirBits, myBits);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
import org.moeaframework.algorithm.jmetal.mocks.MockRealProblem;
import org.moeaframework.core.Settings;
import org.moeaframework.core.Solution;
import org.moeaframework.core.variable.EncodingUtils;
import org.moeaframework.core.variable.RealVariable;
import org.uma.jmetal.solution.doublesolution.DoubleSolution;

Expand Down Expand Up @@ -51,7 +50,7 @@ public void testConvert() {
Solution mySolution = adapter.convert(theirSolution);

for (int i = 0; i < problem.getNumberOfVariables(); i++) {
Assert.assertEquals(theirSolution.variables().get(i), EncodingUtils.getReal(mySolution.getVariable(i)),
Assert.assertEquals(theirSolution.variables().get(i), RealVariable.getReal(mySolution.getVariable(i)),
Settings.EPS);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
import org.junit.Test;
import org.moeaframework.algorithm.jmetal.mocks.MockPermutationProblem;
import org.moeaframework.core.Solution;
import org.moeaframework.core.variable.EncodingUtils;
import org.moeaframework.core.variable.Permutation;
import org.uma.jmetal.solution.permutationsolution.PermutationSolution;

public class PermutationProblemAdapterTest {
Expand All @@ -47,7 +47,7 @@ public void testConvert() {
Solution mySolution = adapter.convert(theirSolution);

List<Integer> theirPermutation = theirSolution.variables();
int[] myPermutation = EncodingUtils.getPermutation(mySolution.getVariable(0));
int[] myPermutation = Permutation.getPermutation(mySolution.getVariable(0));

Assert.assertEquals(theirPermutation.size(), myPermutation.length);

Expand Down

0 comments on commit c22f9b4

Please sign in to comment.