Exemplo 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;
    }
  }
Exemplo n.º 2
0
  private void generateReport(String reportName, long time) {
    FileWriter outFile = null;
    try {
      outFile = new FileWriter(reportName);
    } catch (Exception e) {
      e.printStackTrace();
    }
    PrintWriter out = new PrintWriter(outFile);
    String bigline =
        "*************************************************************************************************\n";
    String shortLine = "*******************************************\n";
    out.write(bigline);
    out.write(" GLOBAL REPORT OF THE SCHEDULE OPTIMIZATION\n");
    out.write(bigline);
    out.write("\n");
    out.write("\n");

    out.write(shortLine);
    out.write("Time of the optimization:\n");
    out.write(Float.valueOf(time / 1000) + " sec\n");
    out.write(shortLine);
    out.write("\n");
    out.write("\n");

    out.write(shortLine);
    out.write("Number of generated and analysed schedules:\n");
    out.write(String.valueOf(this.nbSchedulesAnalysed) + "\n");
    out.write(shortLine);
    out.write("\n");
    out.write("\n");

    out.write(shortLine);
    out.write("Description of the schedules:\n");
    for (List<Pschedule> s : this.schedules_analysed) {
      out.write("**\n");
      out.write("Schedule number: " + String.valueOf(this.schedules_analysed.indexOf(s)) + "\n");
      out.write("TimeStamp: " + String.valueOf(s.get(0).getTime()) + "\n");
      out.write("Revenue: " + String.valueOf(s.get(0).getTotalRevenue()) + "\n");

      out.write("CPUs: \n");
      for (Pschedule row : s) {
        Cpu cpu = row.getCpu();
        List<Job> jobs = Integration.getJobRows(cpu.getCpuid());
        if (jobs.size() > 0) {
          out.write("     id: " + String.valueOf(cpu.getCpuid()) + "\n");
          out.write("     Jobs: \n");

          for (Job job : jobs) {
            out.write("        **\n");
            out.write("		id: " + String.valueOf(job.getJid()) + "\n");
            out.write("		duration: " + String.valueOf(job.getDuration()) + "\n");
            out.write("		priority: " + String.valueOf(job.getPriority()) + "\n");
            out.write("		revenue: " + String.valueOf(job.getRevenue()) + "\n");
            out.write("        **\n");
          }
        }
      }
      out.write("**\n");
    }
    out.write(shortLine);
    out.write("\n");
    out.write("\n");

    out.write(shortLine);
    out.write("Result of the optimization:\n");
    out.write("Optimized schedule found ? (YES/NO): ");
    if (this.profit_optimized) {
      out.write("YES\n");
    } else {
      out.write("NO\n");
      out.write("\n");
      out.write("Schedule with profit found ? (YES/NO): ");
      if (this.profit_found) {
        out.write("YES\n");
      } else {
        out.write("NO\n");
      }
    }
    out.write(shortLine);
    out.write("\n");
    out.write("\n");

    if ((this.opti_schedule != null)) {
      out.write(shortLine);
      if (this.profit_optimized) {
        out.write("Optimized schedule:\n");
      } else {
        out.write("Best schedule:\n");
      }
      List<Schedule> schedule = Integration.getScheduleRows();
      out.write(
          "Schedule number: "
              + String.valueOf(this.schedules_analysed.indexOf(this.opti_schedule))
              + "\n");
      out.write("TimeStamp: " + String.valueOf(schedule.get(0).getTime()) + "\n");
      out.write("Revenue: " + String.valueOf(schedule.get(0).getTotalRevenue()) + "\n");
      out.write("CPUs: \n");
      for (Schedule row : schedule) {
        Cpu cpu = row.getCpu();
        List<Job> jobs = Integration.getJobRows(cpu.getCpuid());
        if (jobs.size() > 0) {
          out.write("     id: " + String.valueOf(cpu.getCpuid()) + "\n");
          out.write("     Jobs: \n");

          for (Job job : jobs) {
            out.write("        **\n");
            out.write("		id: " + String.valueOf(job.getJid()) + "\n");
            out.write("		duration: " + String.valueOf(job.getDuration()) + "\n");
            out.write("		priority: " + String.valueOf(job.getPriority()) + "\n");
            out.write("		revenue: " + String.valueOf(job.getRevenue()) + "\n");
            out.write("        **\n");
          }
        }
      }
      out.write("**\n");
      out.write("Profit: " + String.valueOf(this.opti_profit) + "\n");
      out.write(shortLine);
      out.write("\n");
      out.write("\n");

      out.write(shortLine);
      out.write("Cpu Health Model:\n");
      out.write("\n");
      boolean noDead = true;
      for (Schedule row : schedule) {
        Cpu cpu = row.getCpu();
        if (cpu.getHealth().getStatus() == 1) {
          if (noDead) {
            out.write("CPUs that will need to be replaced: \n");
          }
          noDead = false;
          out.write("id: " + String.valueOf(cpu.getCpuid()) + "\n");
          out.write("Pmap1s: " + String.valueOf(cpu.getPmap1s()) + "\n");
          out.write("Pmap2s: " + String.valueOf(cpu.getPmap2s()) + "\n");
        }
      }
      if (noDead) {
        out.write("No CPUs will need to be replaced: \n");
      }
      out.write("\n");
      out.write("\n");
    }
    out.close();
  }
Exemplo n.º 3
0
  @Init
  public void load(FMLInitializationEvent event) {
    // the meat of the mod
    // Claimed Block Ids 3000 - 3050
    ClientProxy.registerRenderInformation();

    //		stonewall = new BlockWalls(3251,
    // 1).setHardness(1.0F).setResistance(1.0F).setBlockName("ScrollShelf");
    //		stonebrickwall = new BlockWalls(3252,
    // 54).setHardness(1.0F).setResistance(1.0F).setBlockName("ScrollShelf");
    //		crackedbrickwall = new BlockWalls(3253,
    // 101).setHardness(1.0F).setResistance(1.0F).setBlockName("ScrollShelf");
    //		mossbrickwall = new BlockWalls(3254,
    // 100).setHardness(1.0F).setResistance(1.0F).setBlockName("ScrollShelf");
    //		brickwall = new BlockWalls(3255,
    // 7).setHardness(1.0F).setResistance(1.0F).setBlockName("ScrollShelf");
    //		lapiswall = new BlockWalls(3256,
    // 144).setHardness(1.0F).setResistance(1.0F).setBlockName("ScrollShelf");
    //		woodenwall = new BlockWalls(3257,
    // 4).setHardness(1.0F).setResistance(1.0F).setBlockName("ScrollShelf");
    //		sandstonewall = new BlockWalls(3258,
    // 175).setHardness(1.0F).setResistance(1.0F).setBlockName("ScrollShelf");

    Stonebrick1 =
        new BlockTerrain(Stonebrick1ID, 1)
            .setHardness(1.0F)
            .setResistance(1.0F)
            .setBlockName("Stonebrick1");
    Stonebrick2 =
        new BlockTerrain(Stonebrick2ID, 54)
            .setHardness(1.0F)
            .setResistance(1.0F)
            .setBlockName("Stonebrick1");
    Stonebrick3 =
        new BlockTerrain(Stonebrick3ID, 101)
            .setHardness(1.0F)
            .setResistance(1.0F)
            .setBlockName("Stonebrick1");
    Stonebrick4 =
        new BlockTerrain(Stonebrick4ID, 100)
            .setHardness(1.0F)
            .setResistance(1.0F)
            .setBlockName("Stonebrick1");

    stonewall =
        new BlockWalls(stonewallID, Stonebrick1)
            .setHardness(1.0F)
            .setResistance(1.0F)
            .setBlockName("stonewall");
    stonebrickwall =
        new BlockWalls(stonebrickwallID, Stonebrick2)
            .setHardness(1.0F)
            .setResistance(1.0F)
            .setBlockName("stonebrickwall");
    crackedbrickwall =
        new BlockWalls(crackedbrickwallID, Stonebrick3)
            .setHardness(1.0F)
            .setResistance(1.0F)
            .setBlockName("crackedbrickwall");
    mossbrickwall =
        new BlockWalls(mossbrickwallID, Stonebrick4)
            .setHardness(1.0F)
            .setResistance(1.0F)
            .setBlockName("mossbrickwall");
    brickwall =
        new BlockWalls(brickwallID, Block.brick)
            .setHardness(1.0F)
            .setResistance(1.0F)
            .setBlockName("brickwall");
    lapiswall =
        new BlockWalls(LapiswallID, Block.blockLapis)
            .setHardness(1.0F)
            .setResistance(1.0F)
            .setBlockName("lapiswall");
    woodenwall =
        new BlockWalls(woodenwallID, Block.planks)
            .setHardness(1.0F)
            .setResistance(1.0F)
            .setBlockName("woodenwall");
    sandstonewall =
        new BlockWalls(sandstonewallID, Block.sandStone)
            .setHardness(1.0F)
            .setResistance(1.0F)
            .setBlockName("sandstonewall");
    Netherbrickwall =
        new BlockWalls(netherbrickID, Block.netherBrick)
            .setHardness(1.0F)
            .setResistance(1.0F)
            .setBlockName("Netherbrickwall");

    addNames();
    registerBlocks();
    addRecipes();

    // Reactioncraft integration
    try {
      if (RCBDM()) {
        Integration.loadReactioncraft();
        System.out.println("Reactioncraft Chisel Mod enabled");
      }
    } catch (ClassNotFoundException e) {
      System.out.println(
          " Reactioncraft Walls'N'Fences did not find Reactioncraft Better Desert Mod, recipes disabled");
    }
  }