org.uma.jmetal.experiment.BinaryProblemsStudy Maven / Gradle / Ivy
// This program 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.
//
// This program 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 this program. If not, see .
package org.uma.jmetal.experiment;
import org.uma.jmetal.algorithm.Algorithm;
import org.uma.jmetal.algorithm.multiobjective.mocell.MOCellBuilder;
import org.uma.jmetal.algorithm.multiobjective.mochc.MOCHCBuilder;
import org.uma.jmetal.algorithm.multiobjective.nsgaii.NSGAIIBuilder;
import org.uma.jmetal.algorithm.multiobjective.spea2.SPEA2Builder;
import org.uma.jmetal.operator.CrossoverOperator;
import org.uma.jmetal.operator.MutationOperator;
import org.uma.jmetal.operator.SelectionOperator;
import org.uma.jmetal.operator.impl.crossover.HUXCrossover;
import org.uma.jmetal.operator.impl.crossover.SBXCrossover;
import org.uma.jmetal.operator.impl.crossover.SinglePointCrossover;
import org.uma.jmetal.operator.impl.mutation.BitFlipMutation;
import org.uma.jmetal.operator.impl.mutation.PolynomialMutation;
import org.uma.jmetal.operator.impl.selection.RandomSelection;
import org.uma.jmetal.operator.impl.selection.RankingAndCrowdingSelection;
import org.uma.jmetal.problem.BinaryProblem;
import org.uma.jmetal.problem.Problem;
import org.uma.jmetal.problem.multiobjective.OneZeroMax;
import org.uma.jmetal.problem.multiobjective.zdt.ZDT1;
import org.uma.jmetal.problem.multiobjective.zdt.ZDT5;
import org.uma.jmetal.qualityindicator.impl.Epsilon;
import org.uma.jmetal.qualityindicator.impl.GenerationalDistance;
import org.uma.jmetal.qualityindicator.impl.InvertedGenerationalDistance;
import org.uma.jmetal.qualityindicator.impl.InvertedGenerationalDistancePlus;
import org.uma.jmetal.qualityindicator.impl.Spread;
import org.uma.jmetal.qualityindicator.impl.hypervolume.PISAHypervolume;
import org.uma.jmetal.solution.BinarySolution;
import org.uma.jmetal.solution.DoubleSolution;
import org.uma.jmetal.util.JMetalException;
import org.uma.jmetal.util.evaluator.impl.SequentialSolutionListEvaluator;
import org.uma.jmetal.util.experiment.Experiment;
import org.uma.jmetal.util.experiment.ExperimentBuilder;
import org.uma.jmetal.util.experiment.component.ComputeQualityIndicators;
import org.uma.jmetal.util.experiment.component.ExecuteAlgorithms;
import org.uma.jmetal.util.experiment.component.GenerateBoxplotsWithR;
import org.uma.jmetal.util.experiment.component.GenerateFriedmanTestTables;
import org.uma.jmetal.util.experiment.component.GenerateLatexTablesWithStatistics;
import org.uma.jmetal.util.experiment.component.GenerateReferenceParetoFront;
import org.uma.jmetal.util.experiment.component.GenerateWilcoxonTestTablesWithR;
import org.uma.jmetal.util.experiment.util.ExperimentAlgorithm;
import org.uma.jmetal.util.experiment.util.ExperimentProblem;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
/**
* Example of experimental study based on solving two binary problems with four algorithms: NSGAII,
* SPEA2, MOCell, and MOCHC
*
* This experiment assumes that the reference Pareto front are not known, so the names of files
* containing them and the directory where they are located must be specified.
*
* Six quality indicators are used for performance assessment.
*
* The steps to carry out the experiment are: 1. Configure the experiment 2. Execute the algorithms
* 3. Generate the reference Pareto fronts 4. Compute que quality indicators 5. Generate Latex
* tables reporting means and medians 6. Generate Latex tables with the result of applying the
* Wilcoxon Rank Sum Test 7. Generate Latex tables with the ranking obtained by applying the
* Friedman test 8. Generate R scripts to obtain boxplots
*
* @author Antonio J. Nebro
*/
public class BinaryProblemsStudy {
private static final int INDEPENDENT_RUNS = 25;
public static void main(String[] args) throws IOException {
if (args.length != 1) {
throw new JMetalException("Needed arguments: experimentBaseDirectory");
}
String experimentBaseDirectory = args[0];
List> problemList = new ArrayList<>();
problemList.add(new ExperimentProblem<>(new ZDT5()));
problemList.add(new ExperimentProblem<>(new OneZeroMax(512)));
List>> algorithmList =
configureAlgorithmList(problemList);
Experiment> experiment;
experiment = new ExperimentBuilder>("BinaryProblemsStudy")
.setAlgorithmList(algorithmList)
.setProblemList(problemList)
.setExperimentBaseDirectory(experimentBaseDirectory)
.setOutputParetoFrontFileName("FUN")
.setOutputParetoSetFileName("VAR")
.setReferenceFrontDirectory(experimentBaseDirectory+"/referenceFronts")
.setIndicatorList(Arrays.asList(
new Epsilon(), new Spread(), new GenerationalDistance(),
new PISAHypervolume(),
new InvertedGenerationalDistance(),
new InvertedGenerationalDistancePlus())
)
.setIndependentRuns(INDEPENDENT_RUNS)
.setNumberOfCores(8)
.build();
new ExecuteAlgorithms<>(experiment).run();
new GenerateReferenceParetoFront(experiment).run();
new ComputeQualityIndicators<>(experiment).run();
new GenerateLatexTablesWithStatistics(experiment).run();
new GenerateWilcoxonTestTablesWithR<>(experiment).run();
new GenerateFriedmanTestTables<>(experiment).run();
new GenerateBoxplotsWithR<>(experiment).setRows(1).setColumns(2).setDisplayNotch().run();
}
/**
* The algorithm list is composed of pairs {@link Algorithm} + {@link Problem} which form part of
* a {@link ExperimentAlgorithm}, which is a decorator for class {@link Algorithm}.
*/
static List>> configureAlgorithmList(
List> problemList) {
List>> algorithms = new ArrayList<>();
for (int i = 0; i < problemList.size(); i++) {
Algorithm> algorithm = new NSGAIIBuilder(
problemList.get(i).getProblem(),
new SinglePointCrossover(1.0),
new BitFlipMutation(1.0 / ((BinaryProblem) problemList.get(i).getProblem()).getNumberOfBits(0)))
.setMaxEvaluations(25000)
.setPopulationSize(100)
.build();
algorithms.add(new ExperimentAlgorithm<>(algorithm, problemList.get(i).getTag()));
}
for (int i = 0; i < problemList.size(); i++) {
Algorithm> algorithm = new SPEA2Builder(
problemList.get(i).getProblem(),
new SinglePointCrossover(1.0),
new BitFlipMutation(1.0 / ((BinaryProblem) problemList.get(i).getProblem()).getNumberOfBits(0)))
.setMaxIterations(250)
.setPopulationSize(100)
.build();
algorithms.add(new ExperimentAlgorithm<>(algorithm, problemList.get(i).getTag()));
}
for (int i = 0; i < problemList.size(); i++) {
Algorithm> algorithm = new MOCellBuilder(
problemList.get(i).getProblem(),
new SinglePointCrossover(1.0),
new BitFlipMutation(1.0 / ((BinaryProblem) problemList.get(i).getProblem()).getNumberOfBits(0)))
.setMaxEvaluations(25000)
.setPopulationSize(100)
.build();
algorithms.add(new ExperimentAlgorithm<>(algorithm, problemList.get(i).getTag()));
}
for (int i = 0; i < problemList.size(); i++) {
CrossoverOperator crossoverOperator;
MutationOperator mutationOperator;
SelectionOperator, BinarySolution> parentsSelection;
SelectionOperator, List> newGenerationSelection;
crossoverOperator = new HUXCrossover(1.0);
parentsSelection = new RandomSelection();
newGenerationSelection = new RankingAndCrowdingSelection(100);
mutationOperator = new BitFlipMutation(0.35);
Algorithm> algorithm = new MOCHCBuilder(
(BinaryProblem) problemList.get(i).getProblem())
.setInitialConvergenceCount(0.25)
.setConvergenceValue(3)
.setPreservedPopulation(0.05)
.setPopulationSize(100)
.setMaxEvaluations(25000)
.setCrossover(crossoverOperator)
.setNewGenerationSelection(newGenerationSelection)
.setCataclysmicMutation(mutationOperator)
.setParentSelection(parentsSelection)
.setEvaluator(new SequentialSolutionListEvaluator())
.build();
algorithms.add(new ExperimentAlgorithm<>(algorithm, problemList.get(i).getTag()));
}
return algorithms;
}
}