Exemple #1
0
  public void start(ArrayList aC_fct, ParameterHolder aC_params, JavaPlot aC_plot) {

    gC_params = aC_params;
    gC_plot = aC_plot;

    java.text.NumberFormat fn =
        (java.text.NumberFormat) java.text.NumberFormat.getInstance(java.util.Locale.GERMANY);
    fn.setMinimumFractionDigits(2);
    fn.setMaximumFractionDigits(2);

    /* run each experiment */
    int counter = 0;

    /* loop through all functions. */
    do {

      TestFunction cur_fct = (TestFunction) aC_fct.get(counter);
      System.out.println();

      String lC_meanlast;
      /* -- ABC 1 -- */
      /*

      System.out.println("sABC1");
      gC_params.put(GlobalParameters.Name, "standardABC1");
      standardABC1 lC_abc1 = new standardABC1(cur_fct, gC_params);
      lC_meanlast = runABC(lC_abc1);
      System.out.println(lC_meanlast);
      */
      /* -- ABC 2 -- */
      // System.out.println("sABC2");
      // gC_params.put(GlobalParameters.Name, "standardABC2");
      // standardABC2 lC_abc2 = new standardABC2(cur_fct, gC_params);
      // lC_meanlast = runABC(lC_abc2);
      // System.out.println(lC_meanlast);

      /* -- standard ABC -- */
      gC_params.put(GlobalParameters.Name, "sabc");
      runABC(cur_fct);

      /* m1_abc */
      // gC_params.put(GlobalParameters.Name, "m1_abc");
      // runABC(cur_fct);

      /* m2_abc */
      // gC_params.put(GlobalParameters.Name, "m2_abc");
      // runABC(cur_fct);

      /* m3_abc */
      // gC_params.put(GlobalParameters.Name, "m3_abc");
      // runABC(cur_fct);

      // gC_params.put(GlobalParameters.Name, "m4_abc");
      // runABC(cur_fct);

      /*gC_params.put(GlobalParameters.Name, "m5_abc");
      runABC(cur_fct);
      */
      gC_params.put(GlobalParameters.Name, "m6_abc");
      runABC(cur_fct);

    } while (++counter != aC_fct.size());
  }
Exemple #2
0
  private static void runABC(TestFunction cur_fct) {

    /* get nr of runs */
    Integer nr_runs = (Integer) gC_params.get(GlobalParameters.nr_runs);

    /* array holding best values for each run */
    double[] values = new double[nr_runs];

    /* array holding the iteration number when goal was reached */
    int[] lia_iterations = new int[nr_runs];

    int li_popSize = (Integer) gC_params.get(GlobalParameters.popSize);

    int li_iterations;

    /* decide how many evaluations, depends on function */
    double li_fctid = cur_fct.getID();
    if (li_fctid == 1 || li_fctid == 2) {
      li_iterations = (Integer) gC_params.get(GlobalParameters.numEval1) / li_popSize;
    } else {
      li_iterations = (Integer) gC_params.get(GlobalParameters.numEval2) / li_popSize;
    }

    /* for plotting, mean value of each cycle and cycle number */
    double[][] lda_bestvalue = new double[nr_runs][li_iterations];

    System.out.println(gC_params.get(GlobalParameters.Name));

    for (int i = 0; i < nr_runs; i++) {

      ModelInterface lC_model = null;

      if (gC_params.get(GlobalParameters.Name) == "sabc") {
        lC_model = new s_abc(cur_fct, gC_params);
      } else if (gC_params.get(GlobalParameters.Name) == "m1_abc") {
        lC_model = new m1_abc(cur_fct, gC_params);
      } else if (gC_params.get(GlobalParameters.Name) == "m2_abc") {
        lC_model = new m2_abc(cur_fct, gC_params);
      } else if (gC_params.get(GlobalParameters.Name) == "m3_abc") {
        lC_model = new m3_abc(cur_fct, gC_params);
      } else if (gC_params.get(GlobalParameters.Name) == "m4_abc") {
        lC_model = new m4_abc(cur_fct, gC_params);
      } else if (gC_params.get(GlobalParameters.Name) == "m5_abc") {
        lC_model = new m5_abc(cur_fct, gC_params);
      } else if (gC_params.get(GlobalParameters.Name) == "m6_abc") {
        lC_model = new m6_abc(cur_fct, gC_params);
      }

      if (lC_model != null) {

        double[] ld_best_it = run(lC_model, li_iterations, lda_bestvalue[i]);
        values[i] = ld_best_it[0];
        lia_iterations[i] = (int) ld_best_it[1];

        System.out.print(".");

      } else {
        break;
      }
    }

    /* calculate and print the mean, median, best, worsed, expected number of iterations
     * for reaching the goal/optima from all the experiments
     */
    System.out.print("\n[" + cur_fct.getName() + "]");
    // printIterationStatistics(lia_iterations);

    /* calculate mean for each cycle */
    double[][] lda_offperformance = new double[li_iterations][2];
    double[][] lda_globalbest = new double[li_iterations][2];

    double ld_bestvaluesum = 0;

    for (int i = 0; i < li_iterations; i++) {

      /* calculate mean of best value in each iteration */
      ld_bestvaluesum += lda_bestvalue[0][i];
      System.out.println(lda_bestvalue[0][i]);

      lda_offperformance[i][1] = (ld_bestvaluesum / (i + 1));
      lda_offperformance[i][0] = i;

      lda_globalbest[i][1] = lda_bestvalue[0][i];
      lda_globalbest[i][0] = i;
    }

    double ld_mean = mean(values);

    DataSetPlot lC_ptmp = new DataSetPlot(lda_offperformance);
    PlotStyle lC_style = new PlotStyle(Style.LINES);
    lC_ptmp.setPlotStyle(lC_style);
    lC_ptmp.setTitle((String) gC_params.get(GlobalParameters.Name) + ":op");
    gC_plot.addPlot(lC_ptmp);

    DataSetPlot lC_btmp = new DataSetPlot(lda_globalbest);
    // PlotStyle lC_bstyle = new PlotStyle(Style.LINES);
    lC_btmp.setPlotStyle(lC_style);
    lC_btmp.setTitle((String) gC_params.get(GlobalParameters.Name) + ":gbest");
    gC_plot.addPlot(lC_btmp);

    System.out.println(sc_fn.format(ld_mean) + " +/- " + sc_fn.format(sd(values, ld_mean)) + "\t");
  }