/** * Configure the algorithm with the specified parameter experiments.settings * * @return an algorithm object * @throws jmetal.util.JMException */ public Algorithm configure() throws JMException { Algorithm algorithm; Operator selection; Operator crossover; HashMap parameters; // Operator parameters // Creating the problem Object[] problemParams = {"Real"}; problem_ = (new ProblemFactory()).getProblem(problemName_, problemParams); algorithm = new CellDE(problem_); // Algorithm parameters algorithm.setInputParameter("populationSize", populationSize_); algorithm.setInputParameter("archiveSize", archiveSize_); algorithm.setInputParameter("maxEvaluations", maxEvaluations_); algorithm.setInputParameter("feedBack", archiveFeedback_); // Crossover operator parameters = new HashMap(); parameters.put("CR", CR_); parameters.put("F", F_); crossover = CrossoverFactory.getCrossoverOperator("DifferentialEvolutionCrossover", parameters); // Add the operators to the algorithm parameters = null; selection = SelectionFactory.getSelectionOperator("BinaryTournament", parameters); algorithm.addOperator("crossover", crossover); algorithm.addOperator("selection", selection); return algorithm; } // configure
public static void main(String[] args) throws JMException, ClassNotFoundException { Problem problem; // The problem to solve Algorithm algorithm; // The algorithm to use Operator crossover; // Crossover operator Operator mutation; // Mutation operator Operator selection; // Selection operator // int bits ; // Length of bit string in the OneMax problem HashMap parameters; // Operator parameters int threads = 4; // 0 - use all the available cores IParallelEvaluator parallelEvaluator = new MultithreadedEvaluator(threads); // problem = new Sphere("Real", 10) ; problem = new Griewank("Real", 10); algorithm = new pgGA(problem, parallelEvaluator); // Generational GA /* Algorithm parameters*/ algorithm.setInputParameter("populationSize", 100); algorithm.setInputParameter("maxEvaluations", 2500000); // Mutation and Crossover for Real codification parameters = new HashMap(); parameters.put("probability", 0.9); parameters.put("distributionIndex", 20.0); crossover = CrossoverFactory.getCrossoverOperator("SBXCrossover", parameters); parameters = new HashMap(); parameters.put("probability", 1.0 / problem.getNumberOfVariables()); parameters.put("distributionIndex", 20.0); mutation = MutationFactory.getMutationOperator("PolynomialMutation", parameters); /* Selection Operator */ parameters = null; selection = SelectionFactory.getSelectionOperator("BinaryTournament", parameters); /* Add the operators to the algorithm*/ algorithm.addOperator("crossover", crossover); algorithm.addOperator("mutation", mutation); algorithm.addOperator("selection", selection); /* Execute the Algorithm */ long initTime = System.currentTimeMillis(); SolutionSet population = algorithm.execute(); long estimatedTime = System.currentTimeMillis() - initTime; System.out.println("Total execution time: " + estimatedTime); /* Log messages */ System.out.println("Objectives values have been writen to file FUN"); population.printObjectivesToFile("FUN"); System.out.println("Variables values have been writen to file VAR"); population.printVariablesToFile("VAR"); } // main
/** * Configure SPEA2 with default parameter settings * * @return an algorithm object * @throws jmetal.util.JMException */ public Algorithm configure() throws JMException { Algorithm algorithm; Operator crossover; // Crossover operator Operator mutation; // Mutation operator Operator selection; // Selection operator QualityIndicator indicators; HashMap parameters; // Operator parameters // Creating the problem algorithm = new SPEA2(problem_); // Algorithm parameters algorithm.setInputParameter("populationSize", populationSize_); algorithm.setInputParameter("archiveSize", archiveSize_); algorithm.setInputParameter("maxEvaluations", maxEvaluations_); // Mutation and Crossover for Real codification parameters = new HashMap(); parameters.put("probability", crossoverProbability_); parameters.put("distributionIndex", crossoverDistributionIndex_); crossover = CrossoverFactory.getCrossoverOperator("SBXCrossover", parameters); parameters = new HashMap(); parameters.put("probability", mutationProbability_); parameters.put("distributionIndex", mutationDistributionIndex_); mutation = MutationFactory.getMutationOperator("PolynomialMutation", parameters); // Selection operator parameters = null; selection = SelectionFactory.getSelectionOperator("BinaryTournament", parameters); // Add the operators to the algorithm algorithm.addOperator("crossover", crossover); algorithm.addOperator("mutation", mutation); algorithm.addOperator("selection", selection); /* Deleted since jMetal 4.2 // Creating the indicator object if ((paretoFrontFile_!=null) && (!paretoFrontFile_.equals(""))) { indicators = new QualityIndicator(problem_, paretoFrontFile_); algorithm.setInputParameter("indicators", indicators) ; } // if */ return algorithm; } // configure
/** * Configure the MOCell algorithm with default parameter experiments.settings * * @return an algorithm object * @throws jmetal.util.JMException */ public Algorithm configure() throws JMException { Algorithm algorithm; Crossover crossover; Mutation mutation; Operator selection; HashMap parameters; // Operator parameters // Selecting the algorithm: there are six MOCell variants Object[] problemParams = {"Real"}; problem_ = (new ProblemFactory()).getProblem(problemName_, problemParams); // algorithm = new sMOCell1(problem_) ; // algorithm = new sMOCell2(problem_) ; // algorithm = new aMOCell1(problem_) ; // algorithm = new aMOCell2(problem_) ; // algorithm = new aMOCell3(problem_) ; algorithm = new MOCell(problem_); // Algorithm parameters algorithm.setInputParameter("populationSize", populationSize_); algorithm.setInputParameter("maxEvaluations", maxEvaluations_); algorithm.setInputParameter("archiveSize", archiveSize_); algorithm.setInputParameter("feedBack", feedback_); // Mutation and Crossover for Real codification parameters = new HashMap(); parameters.put("probability", crossoverProbability_); parameters.put("distributionIndex", crossoverDistributionIndex_); crossover = CrossoverFactory.getCrossoverOperator("SBXCrossover", parameters); parameters = new HashMap(); parameters.put("probability", mutationProbability_); parameters.put("distributionIndex", mutationDistributionIndex_); mutation = MutationFactory.getMutationOperator("PolynomialMutation", parameters); // Selection Operator parameters = null; selection = SelectionFactory.getSelectionOperator("BinaryTournament", parameters); // Add the operators to the algorithm algorithm.addOperator("crossover", crossover); algorithm.addOperator("mutation", mutation); algorithm.addOperator("selection", selection); return algorithm; } // configure
public SPEA2Search(Builder builder) throws JMException { super(builder); this.populationSize = builder.populationSize; this.maxEvaluations = builder.maxEvaluations; this.archiveSize = builder.archiveSize; this.crossoverOperatorName = builder.crossoverOperatorName; this.crossoverProbability = builder.crossoverProbability; this.mutationOperatorName = builder.mutationOperatorName; if (builder.mutationProbability != 0) this.mutationProbability = builder.mutationProbability; this.selectionOperatorName = builder.selectionOperatorName; this.problem = new SeaCloudsProblem(this.appMap, this.suitableCloudOfferMap, this.topology); this.algorithm = new SPEA2(this.problem); this.metaHeuristicName = this.getAlgorithm().getClass().getSimpleName(); // Algorithm parameters this.algorithm.setInputParameter("populationSize", this.populationSize); this.algorithm.setInputParameter("maxEvaluations", this.maxEvaluations); this.algorithm.setInputParameter("archiveSize", this.archiveSize); // Crossover Operator this.parameters = new HashMap(); this.parameters.put("probability", this.crossoverProbability); // this.crossover = CrossoverFactory.getCrossoverOperator( // "MultiPointCrossover", this.parameters); this.crossover = CrossoverFactory.getCrossoverOperator( this.crossoverOperatorName.getCrossoverOperatorValue(), this.parameters); this.parameters.clear(); // Mutation Operator this.parameters.put("probability", this.mutationProbability); // this.mutation = MutationFactory.getMutationOperator( // "PACandNumOfInstancesMutation", this.parameters); this.mutation = MutationFactory.getMutationOperator( this.mutationOperatorName.getMutationOperatorValue(), this.parameters); this.parameters.clear(); // Selection Operator // this.selection = // SelectionFactory.getSelectionOperator("BinaryTournament", // this.parameters); if ((builder .selectionOperatorName .getSelectionOperatorValue() .equals(SelectionOperatorName.BEST_SOLUTION.getSelectionOperatorValue())) || (builder .selectionOperatorName .getSelectionOperatorValue() .equals(SelectionOperatorName.WORST_SOLUTION.getSelectionOperatorValue()))) { // Comparator comparator = new DominanceComparator(); Comparator comparator = new EqualSolutions(); this.parameters.put("comparator", comparator); } this.selection = SelectionFactory.getSelectionOperator( this.selectionOperatorName.getSelectionOperatorValue(), this.parameters); // Add the operators to the algorithm this.algorithm.addOperator("crossover", this.crossover); this.algorithm.addOperator("mutation", this.mutation); this.algorithm.addOperator("selection", this.selection); }