[go: nahoru, domu]

Skip to content

Commit

Permalink
MOEAD added to Main experimentation
Browse files Browse the repository at this point in the history
  • Loading branch information
castellanos94 committed Jul 4, 2021
1 parent a0848f2 commit 96993eb
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 1 deletion.
38 changes: 38 additions & 0 deletions src/main/java/com/castellanos94/experimentation/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import com.castellanos94.algorithms.AbstractAlgorithm;
import com.castellanos94.algorithms.multi.IMOACO_R;
import com.castellanos94.algorithms.multi.IMOACO_R_P;
import com.castellanos94.algorithms.multi.MOEAD;
import com.castellanos94.algorithms.multi.MOGWO;
import com.castellanos94.algorithms.multi.MOGWO_P;
import com.castellanos94.algorithms.multi.MOGWO_O;
Expand All @@ -22,6 +23,7 @@
import com.castellanos94.algorithms.multi.PI_MOGWO;
import com.castellanos94.components.Ranking;
import com.castellanos94.components.impl.DominanceComparator;
import com.castellanos94.datatype.Data;
import com.castellanos94.instances.DTLZ_Instance;
import com.castellanos94.mcda.SatClassifier;
import com.castellanos94.operators.CrossoverOperator;
Expand All @@ -34,6 +36,7 @@
import com.castellanos94.problems.DTLZP;
import com.castellanos94.solutions.DoubleSolution;
import com.castellanos94.solutions.Solution;
import com.castellanos94.utils.ReferenceHyperplane;
import com.castellanos94.utils.Tools;
import picocli.CommandLine;
import picocli.CommandLine.Command;
Expand Down Expand Up @@ -91,6 +94,13 @@ private enum AlgorithmNames {
@Option(names = {
"-xi" }, description = " convergence rate control parameter for IMOACOR", showDefaultValue = Visibility.ALWAYS)
private double xi = 0.5;
@Option(names = {
"-approach-moead" }, description = "Approach used for scalarization function", showDefaultValue = Visibility.ALWAYS)
private MOEAD.APPROACH apporachUsed = MOEAD.APPROACH.TCHEBYCHEFF;

@Option(names = {
"-neighborhood-size-moead" }, description = "Neighborhood size for moead", showDefaultValue = Visibility.ALWAYS)
private int neighborhoodSize = 20;

public static void main(String[] args) {
System.exit(new CommandLine(new Main()).setCaseInsensitiveEnumValuesAllowed(true).execute(args));
Expand Down Expand Up @@ -370,11 +380,38 @@ else if (numberOfObjectives == 8)
if (_algorithmName == AlgorithmNames.PIMOGWO) {
return new PI_MOGWO<>(problem, (int) options.get("pop_size"), maxIterations, new RepairBoundary());
}
if (_algorithmName == AlgorithmNames.MOEAD) {
ArrayList<ArrayList<Data>> weights = generateWeight(problem, (int) options.get("partitions"));

return new MOEAD<>(problem, maxIterations, weights.size(), weights, neighborhoodSize,
(CrossoverOperator<DoubleSolution>) options.get("crossover"),
(MutationOperator<DoubleSolution>) options.get("mutation"), new RepairBoundary(),
new DominanceComparator<>(), apporachUsed);
}
return null;

}

private static ArrayList<ArrayList<Data>> generateWeight(DTLZP problem, int h) {
if (problem.getNumberOfObjectives() <= 5) {
ReferenceHyperplane<DoubleSolution> referenceHyperplane = new ReferenceHyperplane<>(
problem.getNumberOfObjectives(), h);
referenceHyperplane.execute();
ArrayList<ArrayList<Data>> data = referenceHyperplane.transformToData();
return data;
}

ReferenceHyperplane<DoubleSolution> referenceHyperplane = new ReferenceHyperplane<>(
problem.getNumberOfObjectives(), 3);
referenceHyperplane.execute();
ArrayList<ArrayList<Data>> data = referenceHyperplane.transformToData();
ReferenceHyperplane<DoubleSolution> referenceHyperplane2 = new ReferenceHyperplane<>(
problem.getNumberOfObjectives(), 2);
referenceHyperplane2.execute();
data.addAll(referenceHyperplane2.transformToData());
return data;
}

public static HashMap<String, Object> setup(int numberOfObjectives) {
HashMap<String, Object> map = new HashMap<>();
switch (numberOfObjectives) {
Expand Down Expand Up @@ -405,6 +442,7 @@ public static HashMap<String, Object> setup(int numberOfObjectives) {
map.put("mutation", new PolynomialMutation());
return map;
}

public int getNumberOfObjectives() {
return numberOfObjectives;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,24 @@

import com.castellanos94.operators.RepairOperator;
import com.castellanos94.solutions.DoubleSolution;
import org.apache.commons.math3.util.Precision;

import com.castellanos94.utils.Tools;

/**
* This class is only for repair [0,1] with tolerance treshold
*/
public class RepairBoundary implements RepairOperator<DoubleSolution> {
private double epsilon;

public RepairBoundary(double epsilon) {
this.epsilon = epsilon;
}

public RepairBoundary() {
this(6 * Math.pow(10, -16));
}

@Override
public Void execute(DoubleSolution solution) {
for (int i = 0; i < solution.getVariables().size(); i++) {
Expand All @@ -14,7 +29,8 @@ public Void execute(DoubleSolution solution) {
if (Double.isNaN(var)) {
solution.setVariable(i, Tools.getRandomNumberInRange(l, u).doubleValue());
} else {
if (l == 0 && var < 6 * Math.pow(10, -16)) {
if (l == 0 || Precision.compareTo(l, var, epsilon) <= 0) {
// if (l == 0 && var < 6 * Math.pow(10, -16)) {
solution.setVariable(i, l);
} else if (var < l) {
solution.setVariable(i, l);
Expand Down

0 comments on commit 96993eb

Please sign in to comment.