public static void main(String[] args) throws JMException, ClassNotFoundException {
    int numberOfVariables = 20;
    int populationSize = 10;
    int maxEvaluations = 1000000;

    Problem problem; // The problem to solve
    Algorithm algorithm; // The algorithm to use

    // problem = new Sphere("Real", numberOfVariables) ;
    // problem = new Easom("Real") ;
    // problem = new Griewank("Real", populationSize) ;
    // problem = new Schwefel("Real", numberOfVariables) ;
    problem = new Rosenbrock("Real", numberOfVariables);
    // problem = new Rastrigin("Real", numberOfVariables) ;

    algorithm = new CMAES(problem);

    /* Algorithm parameters*/
    algorithm.setInputParameter("populationSize", populationSize);
    algorithm.setInputParameter("maxEvaluations", maxEvaluations);

    /* 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 written to file FUN");
    population.printObjectivesToFile("FUN");
    System.out.println("Variables values have been written to file VAR");
    population.printVariablesToFile("VAR");
  } // main
Ejemplo n.º 2
0
  /**
   * 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
Ejemplo n.º 3
0
  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 the MOCell algorithm with default parameter settings
   *
   * @return an algorithm object
   * @throws jmetal.util.JMException
   */
  public Algorithm configure() throws JMException {
    Algorithm algorithm;
    Operator crossover;
    Operator mutation;
    Operator improvement; // Operator for improvement

    HashMap parameters; // Operator parameters

    QualityIndicator indicators;

    // Creating the problem
    algorithm = new AbYSS(problem_);

    // Algorithm parameters
    algorithm.setInputParameter("populationSize", populationSize_);
    algorithm.setInputParameter("refSet1Size", refSet1Size_);
    algorithm.setInputParameter("refSet2Size", refSet2Size_);
    algorithm.setInputParameter("archiveSize", archiveSize_);
    algorithm.setInputParameter("maxEvaluations", maxEvaluations_);

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

    parameters = new HashMap();
    parameters.put("improvementRounds", 1);
    parameters.put("problem", problem_);
    parameters.put("mutation", mutation);
    improvement = new MutationLocalSearch(parameters);

    // Adding the operators to the algorithm
    algorithm.addOperator("crossover", crossover);
    algorithm.addOperator("improvement", improvement);

    /* 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;
  } // Constructor
  /**
   * 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
Ejemplo n.º 6
0
  /**
   * 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
Ejemplo n.º 7
0
  /**
   * @param args Command line arguments.
   * @throws JMException
   * @throws IOException
   * @throws SecurityException Usage: three options - jmetal.metaheuristics.nsgaII.NSGAII_main -
   *     jmetal.metaheuristics.nsgaII.NSGAII_main problemName -
   *     jmetal.metaheuristics.nsgaII.NSGAII_main problemName paretoFrontFile
   */
  public static void main(String[] args)
      throws JMException, SecurityException, IOException, 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

    HashMap parameters; // Operator parameters

    // Logger object and file to store log messages
    // logger_      = Configuration.logger_ ;
    fileHandler_ = new FileHandler("NSGAII_main.log");
    // logger_.addHandler(fileHandler_) ;

    problem = new QOP();
    int corridas;
    String caso;
    nrocaso = 0;
    Poblacion population = new Poblacion(50);
    while (nrocaso < casosDePrueba.length) {
      corridas = 1;
      long initTime2 = System.currentTimeMillis();
      while (corridas < 11) {
        algorithm = new NSGAII_G10(problem, nrocaso);
        caso = casosDePrueba[nrocaso];

        // algorithm = new ssNSGAII(problem);

        // Algorithm parameters
        algorithm.setInputParameter("populationSize", 5);
        algorithm.setInputParameter("maxEvaluations", 2500);
        algorithm.setInputParameter("probMutacion", 1); // 10%
        algorithm.setInputParameter("nrocaso", nrocaso);
        algorithm.setInputParameter("corridas", corridas);

        // 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("BinaryTournament2", parameters) ;
        */

        // Add the operators to the algorithm
        /*algorithm.addOperator("crossover",crossover);
        algorithm.addOperator("mutation",mutation);
        algorithm.addOperator("selection",selection);*/
        // algorithm.addOperator("torneobinario", torneobinario);

        // Add the indicator object to the algorithm

        // System.out.println(" "+corridas);
        // Execute the Algorithm
        long initTime = System.currentTimeMillis();
        // System.out.println(caso + "-" + corridas + " Test Genetico.");

        population = algorithm.execute();
        long estimatedTime = System.currentTimeMillis() - initTime;

        // Result messages
        if (population != null) {
          // logger_.info("Total execution time: "+estimatedTime + "ms");
          // logger_.info("Variables values have been writen to file VAR");
          population.printVariablesToFile("VAR_p3" + caso);
          // logger_.info("Objectives values have been writen to file FUN");
          population.printObjectivesToFile("FUN_p3" + caso);
        } else {
          System.out.println("No arrojo resultados");
        }

        /*if (indicators != null) {
          logger_.info("Quality indicators") ;
          logger_.info("Hypervolume: " + indicators.getHypervolume(population)) ;
          logger_.info("GD         : " + indicators.getGD(population)) ;
          logger_.info("IGD        : " + indicators.getIGD(population)) ;
          logger_.info("Spread     : " + indicators.getSpread(population)) ;
          logger_.info("Epsilon    : " + indicators.getEpsilon(population)) ;

          int evaluations = ((Integer)algorithm.getOutputParameter("evaluations")).intValue();
          logger_.info("Speed      : " + evaluations + " evaluations") ;
        } // if*/
        corridas++;
      }
      long estimatedTime2 = System.currentTimeMillis() - initTime2;
      long tiempo = estimatedTime2;
      long hora = tiempo / 3600000;
      long restohora = tiempo % 3600000;
      long minuto = restohora / 60000;
      long restominuto = restohora % 60000;
      long segundo = restominuto / 1000;
      long restosegundo = restominuto % 1000;
      String time = hora + ":" + minuto + ":" + segundo + "." + restosegundo;
      time = " Tiempo: " + time;
      String fin = casosDePrueba[nrocaso] + " FIN - Test Genetico. Tiempo:" + time;
      // fin += " - Nº Generaciones: " + evaluations;
      System.out.println(fin);
      if (population != null) population.printFinalResults();

      nrocaso++;
    }

    System.out.println("FIN Prueba Algoritmo Genetico. (Segment-Oriented).");
  } // main
Ejemplo n.º 8
0
Archivo: Main.java Proyecto: ai-se/SPL
  /** @param args the command line arguments -- modelname, alg_name, evaluation_times, [runid] */
  public static void main(String[] args) throws Exception {

    try {
      String name = args[0];
      URL location = Main.class.getProtectionDomain().getCodeSource().getLocation();
      String loc = location.toString();
      String project_path =
          loc.substring(5, loc.lastIndexOf("SPL/")) + "SPL/"; // with '/' at the end
      String fm = project_path + "dimacs_data/" + name + ".dimacs";
      String augment = fm + ".augment";
      String dead = fm + ".dead";
      String mandatory = fm + ".mandatory";
      String seed = fm + ".richseed";
      String opfile = fm + ".sipop";

      Problem p = new ProductLineProblem(fm, augment, mandatory, dead, seed);
      //            Problem p = new ProductLineProblemNovelPrep(fm, augment, mandatory, dead, seed,
      // opfile);
      //            GroupedProblem.grouping((ProductLineProblem) p, 100); System.exit(0);
      Algorithm a;
      int evaluation_times = Integer.parseInt(args[2]);
      String alg_name = args[1];
      String runid = "";
      if (args.length >= 4) {
        runid = args[3];
      }

      switch (alg_name) {
        case "IBEA":
          a = new SPL_SettingsIBEA(p).configureICSE2013(evaluation_times);
          break;
        case "SIPIBEA":
          a = new SPL_SettingsIBEA(p).configureSIPIBEA(evaluation_times);
          break;
        case "SPEA2":
          a = new SPL_SettingsEMOs(p).configureSPEA2(evaluation_times);
          break;
        case "NSGA2":
          a = new SPL_SettingsEMOs(p).configureNSGA2(evaluation_times);
          break;
        case "IBEASEED":
          a = new SPL_SettingsIBEA(p).configureIBEASEED(evaluation_times);
          break;
        case "SATIBEA":
          // a = new SPL_SettingsIBEA(p).configureICSE15(1000, fm, ((ProductLineProblem)
          // p).getNumFeatures(),
          // ((ProductLineProblem) p).getConstraints());
          a =
              new SPL_SettingsIBEA(p)
                  .configureSATIBEA(
                      evaluation_times,
                      fm,
                      ((ProductLineProblem) p).getNumFeatures(),
                      ((ProductLineProblem) p).getConstraints());
          break;
        default:
          a = new SPL_SettingsIBEA(p).configureICSE2013(evaluation_times);
      }

      long start = System.currentTimeMillis();
      SolutionSet pop = a.execute();
      float total_time = (System.currentTimeMillis() - start) / 1000.0f;

      String file_tag =
          name + "_" + alg_name + '_' + evaluation_times / 1000 + "k_" + runid + ".txt";
      String file_path = project_path + "j_res/" + file_tag;
      File file = new File(file_path);

      if (!file.exists()) {
        file.createNewFile();
      }

      FileWriter fw = new FileWriter(file.getAbsoluteFile());
      BufferedWriter bw = new BufferedWriter(fw);

      for (int i = 0; i < pop.size(); i++) {
        Variable v = pop.get(i).getDecisionVariables()[0];
        bw.write((Binary) v + "\n");
        System.out.println("Conf" + (i + 1) + ": " + (Binary) v + " ");
      }

      bw.write("~~~\n");

      for (int i = 0; i < pop.size(); i++) {
        Variable v = pop.get(i).getDecisionVariables()[0];
        for (int j = 0; j < pop.get(i).getNumberOfObjectives(); j++) {
          bw.write(pop.get(i).getObjective(j) + " ");
          System.out.print(pop.get(i).getObjective(j) + " ");
        }
        bw.write("\n");
        System.out.println("");
      }

      System.out.println(total_time);
      bw.write("~~~\n" + total_time + "\n");

      bw.close();
      fw.close();

    } catch (Exception e) {
      e.printStackTrace();
    }
  }
Ejemplo n.º 9
0
  /**
   * @param args Command line arguments. The first (optional) argument specifies the problem to
   *     solve.
   * @throws JMException
   */
  public static void main(String[] args) throws JMException, IOException, 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

    QualityIndicator indicators; // Object to get quality indicators

    HashMap parameters; // Operator parameters

    // Logger object and file to store log messages
    logger_ = Configuration.logger_;
    fileHandler_ = new FileHandler("FastPGA_main.log");
    logger_.addHandler(fileHandler_);

    indicators = null;
    if (args.length == 1) {
      Object[] params = {"Real"};
      problem = (new ProblemFactory()).getProblem(args[0], params);
    } // if
    else if (args.length == 2) {
      Object[] params = {"Real"};
      problem = (new ProblemFactory()).getProblem(args[0], params);
      indicators = new QualityIndicator(problem, args[1]);
    } // if
    else { // Default problem
      problem = new Kursawe("Real", 3);
      // problem = new Kursawe("BinaryReal", 3);
      // problem = new Water("Real");
      // problem = new ZDT1("ArrayReal", 100);
      // problem = new ConstrEx("Real");
      // problem = new DTLZ1("Real");
      // problem = new OKA2("Real") ;
    } // else

    algorithm = new FastPGA(problem);

    algorithm.setInputParameter("maxPopSize", 100);
    algorithm.setInputParameter("initialPopulationSize", 100);
    algorithm.setInputParameter("maxEvaluations", 25000);
    algorithm.setInputParameter("a", 20.0);
    algorithm.setInputParameter("b", 1.0);
    algorithm.setInputParameter("c", 20.0);
    algorithm.setInputParameter("d", 0.0);

    // Parameter "termination"
    // If the preferred stopping criterium is PPR based, termination must
    // be set to 0; otherwise, if the algorithm is intended to iterate until
    // a give number of evaluations is carried out, termination must be set to
    // that number
    algorithm.setInputParameter("termination", 1);

    // Mutation and Crossover for Real codification
    parameters = new HashMap();
    parameters.put("probability", 0.9);
    parameters.put("distributionIndex", 20.0);
    crossover = CrossoverFactory.getCrossoverOperator("SBXCrossover", parameters);
    // crossover.setParameter("probability",0.9);
    // crossover.setParameter("distributionIndex",20.0);

    parameters = new HashMap();
    parameters.put("probability", 1.0 / problem.getNumberOfVariables());
    parameters.put("distributionIndex", 20.0);
    mutation = MutationFactory.getMutationOperator("PolynomialMutation", parameters);
    // Mutation and Crossover for Binary codification

    parameters = new HashMap();
    parameters.put("comparator", new FPGAFitnessComparator());
    selection = new BinaryTournament(parameters);

    algorithm.addOperator("crossover", crossover);
    algorithm.addOperator("mutation", mutation);
    algorithm.addOperator("selection", selection);

    long initTime = System.currentTimeMillis();
    SolutionSet population = algorithm.execute();
    long estimatedTime = System.currentTimeMillis() - initTime;

    // Result messages
    logger_.info("Total execution time: " + estimatedTime + "ms");
    logger_.info("Variables values have been writen to file VAR");
    population.printVariablesToFile("VAR");
    logger_.info("Objectives values have been writen to file FUN");
    population.printObjectivesToFile("FUN");

    if (indicators != null) {
      logger_.info("Quality indicators");
      logger_.info("Hypervolume: " + indicators.getHypervolume(population));
      logger_.info("GD         : " + indicators.getGD(population));
      logger_.info("IGD        : " + indicators.getIGD(population));
      logger_.info("Spread     : " + indicators.getSpread(population));
      logger_.info("Epsilon    : " + indicators.getEpsilon(population));

      int evaluations = ((Integer) algorithm.getOutputParameter("evaluations")).intValue();
      logger_.info("Speed      : " + evaluations + " evaluations");
    } // if
  } // main