Example #1
0
  private static double[] run(ModelInterface aC_model, int ai_mcn, double[] ada_bestvalues) {

    int li_breakcond = 0;

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

    double best = 10E10;

    TestFunction fct = aC_model.getFct();
    fct.resetSeverity();

    while (li_breakcond != ai_mcn) {

      /* Iterate one step, method returns true if a perfect solution was found inside,
       * when having fit(i) = 0, prevents devision by Zero (calc Select Probs) and
       * breaks further calculations (onlookers).
       */

      aC_model.Iterate();
      fct.addToSeverity(0.1);

      // save the last best
      Solution lC_globalbest = aC_model.getBestSolution();

      /* on every step the best, later be used to make a mean with more experiments */
      ada_bestvalues[li_breakcond] = lC_globalbest.value;

      li_breakcond++;
    }

    double[] ld_best_it = new double[2];
    ld_best_it[0] = best;
    ld_best_it[1] = li_breakcond;

    return ld_best_it;
  }
Example #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");
  }