Esempio n. 1
0
  public Date runOptimization(String reportName) {

    long start = System.currentTimeMillis();

    List<h.entities.Pschedule> currentSchedule = null;
    BigDecimal currentPowerUsedForCooling;
    int nb_iterations = 0;
    int scheduleTeamId = 2;
    int powerTeamId = 4;
    Date last_schedule = null;

    while (nb_iterations < this.nbIterationMaximum && !this.profit_optimized) {

      boolean ready = false;
      while (!ready) {
        if ((System.currentTimeMillis() - start) / 1000 >= this.timeMaximum) {
          long end = System.currentTimeMillis();
          long time = end - start;
          this.nbSchedulesAnalysed = nb_iterations;
          this.generateReport(reportName, time);
          Integration.setOptimisationActiveNumber(1);
          if (currentSchedule != null) {
            return currentSchedule.get(0).getTime();
          } else {
            return null;
          }
        }
        boolean new_schedule = false;
        if (nb_iterations == 0 && Integration.getPscheduleRows().size() > 0) {
          new_schedule = true;
        } else {
          List<Pschedule> schedule = Integration.getPscheduleRows();
          new_schedule = schedule.size() >= 0 && schedule.get(0).getTime().after(last_schedule);
        }
        ready =
            (Integration.getTeamsRow(scheduleTeamId).getActive() == 0)
                && (Integration.getTeamsRow(powerTeamId).getActive() == 0)
                && new_schedule;
      }
      Integration.setOptimisationActiveNumber(0);
      /** *** Get all the inputs************** */
      currentSchedule = Integration.getPscheduleRows();
      this.schedules_analysed.add(currentSchedule);
      last_schedule = currentSchedule.get(0).getTime();
      currentPowerUsedForCooling = Integration.getTotalPower().getPue();
      this.powers.add(currentPowerUsedForCooling);
      nb_iterations++;
      /** ************************************************** */

      /** Calculation of the profit* */
      double profit =
          Calculate_profit(
              currentSchedule,
              currentPowerUsedForCooling,
              this.unitCpuReplacement,
              this.unitPowerCost);
      this.profits.add(profit);

      /**
       * Comparison with the old value, if the value is better we set the new schedule opti_schedule
       * and the new profit opti_profit*
       */
      if (profit > opti_profit) {
        this.profit_found = true;
        this.opti_profit = profit;
        this.opti_schedule = currentSchedule;
      }

      /**
       * Comparison with the minimum value MINIMUM_PROFIT_VALUE that defines if the algorithm is
       * considered oprimized*
       */
      if (profit >= this.minimum_profit) {
        this.profit_optimized = true;
        Integration.setScheduleRows(currentSchedule);
      } else {
        Integration.setOptimisationActiveNumber(2);
      }
    }
    long end = System.currentTimeMillis();
    long time = end - start;
    this.nbSchedulesAnalysed = nb_iterations;

    this.generateReport(reportName, time);
    Integration.setOptimisationActiveNumber(1);
    if (currentSchedule != null) {
      return currentSchedule.get(0).getTime();
    } else {
      return null;
    }
  }