package org.uma.jmetal.runner.multiobjective;

import org.uma.jmetal.algorithm.Algorithm;
import org.uma.jmetal.algorithm.multiobjective.smpso.SMPSOBuilder;
import org.uma.jmetal.operator.MutationOperator;
import org.uma.jmetal.operator.impl.mutation.PolynomialMutation;
import org.uma.jmetal.problem.DoubleProblem;
import org.uma.jmetal.runner.AbstractAlgorithmRunner;
import org.uma.jmetal.solution.DoubleSolution;
import org.uma.jmetal.util.AlgorithmRunner;
import org.uma.jmetal.util.JMetalLogger;
import org.uma.jmetal.util.ProblemUtils;
import org.uma.jmetal.util.archive.BoundedArchive;
import org.uma.jmetal.util.archive.impl.CrowdingDistanceArchive;
import org.uma.jmetal.util.evaluator.impl.SequentialSolutionListEvaluator;
import org.uma.jmetal.util.pseudorandom.impl.MersenneTwisterGenerator;

import java.util.List;

/**
 * Class for configuring and running the SMPSO algorithm
 *
 * @author Antonio J. Nebro <antonio@lcc.uma.es>
 */
public class SMPSORunner extends AbstractAlgorithmRunner {
  /**
   * @param args Command line arguments. The first (optional) argument specifies
   *             the problem to solve.
   * @throws org.uma.jmetal.util.JMetalException
   * @throws java.io.IOException
   * @throws SecurityException
   * Invoking command:
  java org.uma.jmetal.runner.multiobjective.SMPSORunner problemName [referenceFront]
   */
  public static void main(String[] args) throws Exception {
    DoubleProblem problem;
    Algorithm<List<DoubleSolution>> algorithm;
    MutationOperator<DoubleSolution> mutation;

    String referenceParetoFront = "" ;

    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.ZDT4";
      referenceParetoFront = "jmetal-problem/src/test/resources/pareto_fronts/ZDT4.pf" ;
    }

    problem = (DoubleProblem) ProblemUtils.<DoubleSolution> loadProblem(problemName);

    BoundedArchive<DoubleSolution> archive = new CrowdingDistanceArchive<DoubleSolution>(100) ;

    double mutationProbability = 1.0 / problem.getNumberOfVariables() ;
    double mutationDistributionIndex = 20.0 ;
    mutation = new PolynomialMutation(mutationProbability, mutationDistributionIndex) ;

    algorithm = new SMPSOBuilder(problem, archive)
        .setMutation(mutation)
        .setMaxIterations(250)
        .setSwarmSize(100)
        .setRandomGenerator(new MersenneTwisterGenerator())
        .setSolutionListEvaluator(new SequentialSolutionListEvaluator<DoubleSolution>())
        .build();

    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) ;
    }
  }
}

@@ -15,37 +15,38 @@
 a.jmetal.runner.
-multi
+single
 objective;%0A%0Aimpo
@@ -310,16 +310,128 @@
 roblem;%0A
+import org.uma.jmetal.problem.singleobjective.Rosenbrock;%0Aimport org.uma.jmetal.problem.singleobjective.Sphere;%0A
 import o
@@ -836,24 +836,151 @@
 tEvaluator;%0A
+import org.uma.jmetal.util.fileoutput.SolutionListOutput;%0Aimport org.uma.jmetal.util.fileoutput.impl.DefaultFileOutputContext;%0A
 import org.u
@@ -1039,16 +1039,44 @@
 rator;%0A%0A
+import java.util.ArrayList;%0A
 import j
@@ -1810,493 +1810,37 @@
     
-String referenceParetoFront = %22%22 ;%0A%0A    String problemName ;%0A    if (args.length == 1) %7B%0A      problemName = args%5B0%5D;%0A    %7D else if (args.length == 2) %7B%0A      problemName = args%5B0%5D ;%0A      referenceParetoFront = args%5B1%5D ;%0A    %7D else %7B%0A      problemName = %22org.uma.jmetal.problem.multiobjective.zdt.ZDT4%22;%0A      referenceParetoFront = %22jmetal-problem/src/test/resources/pareto_fronts/ZDT4.pf%22 ;%0A    %7D%0A%0A    problem = (DoubleProblem) ProblemUtils.%3CDoubleSolution%3E loadProblem(problemName)
+problem = new Rosenbrock(10) 
 ;%0A%0A 
@@ -2668,24 +2668,274 @@
 ingTime();%0A%0A
+    new SolutionListOutput(population)%0A            .setSeparator(%22%5Ct%22)%0A            .setVarFileOutputContext(new DefaultFileOutputContext(%22VAR.tsv%22))%0A            .setFunFileOutputContext(new DefaultFileOutputContext(%22FUN.tsv%22))%0A            .print();%0A%0A
     JMetalLo
@@ -3005,162 +3005,177 @@
 %22);%0A
-%0A
     
-printFinalSolutionSet(population);%0A    if (!referenceParetoFront.equals(%22%22)) %7B%0A      printQualityIndicators(population, referenceParetoFront) ;%0A    %7D
+JMetalLogger.logger.info(%22Objectives values have been written to file FUN.tsv%22);%0A    JMetalLogger.logger.info(%22Variables values have been written to file VAR.tsv%22);%0A
 %0A  %7D

Add new runner class