https://github.com/jMetal/jMetalDocumentation/blob/master/running.md
I just translated this page roughly.
** The only way to set the algorithm is to write a class called runner **. (It seems that we want to be able to read the settings from an external file in the next and subsequent releases)
At least one runner class is provided for the algorithms included in jMetal.
They are in the jmetal-exec
module this folder It is in.
The following five NSGA-II runner classes are given as examples. These are set to be used for different purposes.
NSGAIIRnner
: Standard NSGA-II settings for solving continuous value problems.NSGAIIInteger
: Settings for solving integer value problems.NSGAIIBinary
: Settings for solving binary problems.NSGAIIMeasures
: Similar to NSGAIIRunner
, but includes an example of how to use measures.ParallelNSGAII
: Similar to NSGAIIRunner
, but processes in parallel using threads when evaluating populations.The details of the NSGAIIRunner
class are shown below.
As shown in Javadoc, give the class name of the problem to be solved in the first argument.
The second argument is an optional parameter that gives the path of the file containing the optimal Pareto front approximation.
Given a Pareto front, it is used to calculate all available quality indicators.
public class NSGAIIRunner extends AbstractAlgorithmRunner {
/**
* @param args Command line arguments.
* @throws JMetalException
* @throws FileNotFoundException
* Invoking command: java org.uma.jmetal.runner.multiobjetive.NSGAIIRunner problemName [referenceFront]
*/
public static void main(String[] args) throws JMetalException, FileNotFoundException {
The main
method first declares the type of problem to be solved and the operator to use.
(In this example, we declare the problem of treating DoubleSolution
as an individual.)
referenceParetoFront
indicates the optimal paretofront file path given.
Problem<DoubleSolution> problem;
Algorithm<List<DoubleSolution>> algorithm;
CrossoverOperator<DoubleSolution> crossover;
MutationOperator<DoubleSolution> mutation;
SelectionOperator<List<DoubleSolution>, DoubleSolution> selection;
String referenceParetoFront = "" ;
Next, it parses the arguments given to the program. If no arguments are given, the benchmark problem is solved by default. (In this example, solve ZDT1.)
String problemName ;
if (args.length == 1) {
problemName = args[0];
} else if (args.length == 2) {
problemName = args[0] ;
referenceParetoFront = args[1] ;
} else {
problemName = "org.uma.jmetal.problem.multiobjective.zdt.ZDT1";
referenceParetoFront = "jmetal-problem/src/test/resources/pareto_fronts/ZDT1.pf" ;
}
Next, load problem
from the class name.
problem = ProblemUtils.<DoubleSolution> loadProblem(problemName);
Then, set the operator and algorithm.
double crossoverProbability = 0.9 ;
double crossoverDistributionIndex = 20.0 ;
crossover = new SBXCrossover(crossoverProbability, crossoverDistributionIndex) ;
double mutationProbability = 1.0 / problem.getNumberOfVariables() ;
double mutationDistributionIndex = 20.0 ;
mutation = new PolynomialMutation(mutationProbability, mutationDistributionIndex) ;
selection = new BinaryTournamentSelection<DoubleSolution>(new RankingAndCrowdingDistanceComparator<DoubleSolution>());
algorithm = new NSGAIIBuilder<DoubleSolution>(problem, crossover, mutation)
.setSelectionOperator(selection)
.setMaxEvaluations(25000)
.setPopulationSize(100)
.build() ;
Finally, run the algorithm and write the resulting solution to two files. Write the value of the variable in one and the value of the objective function in the other. Also, if the Pareto front is given as an argument, print the calculation results of all available quality indicators.
AlgorithmRunner algorithmRunner = new AlgorithmRunner.Executor(algorithm)
.execute() ;
List<DoubleSolution> population = algorithm.getResult() ;
long computingTime = algorithmRunner.getComputingTime() ;
JMetalLogger.logger.info("Total execution time: " + computingTime + "ms");
printFinalSolutionSet(population);
if (!referenceParetoFront.equals("")) {
printQualityIndicators(population, referenceParetoFront) ;
}
}