/** Function calculating the profit value* */ public double Calculate_profit( List<h.entities.Pschedule> schedule, BigDecimal currentPowerUsedForCooling, BigDecimal unitCpuReplacement, BigDecimal unitPowerCost) { double profit; double powerCost = currentPowerUsedForCooling.doubleValue() * unitPowerCost.doubleValue(); int nbDeadCpus = 0; double revenue = 0; for (Pschedule s : schedule) { revenue = s.getTotalRevenue().doubleValue(); if (s.getCpu().getHealth().getStatus() == 1) { nbDeadCpus++; } } double maintenanceCost = nbDeadCpus * unitCpuReplacement.doubleValue(); System.out.println("Revenu :" + revenue); System.out.println("maintenanceCost :" + maintenanceCost); System.out.println("powerCost :" + powerCost); profit = (revenue - maintenanceCost - powerCost); return profit; }
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(); }