Power Model:
public class ModelPower extends PowerModelCubic{
double max=1; //Maximum amount of power a host can utilize
double k=0.5; // 50% of the power is utilized when a host is in idle state.
……;
……..;
public double getPower(double utilization) throws IllegalArgumentException {
if (utilization < 0 || utilization > 1) {
throw new IllegalArgumentException("Utilization value must be between 0 and 1");
}
if (utilization == 0) {
return 0;
}
double s=k*max+(1-k)*max*utilization; // Example Power Model.
return s;
}
}
int size = getHostList().size();
double[] power = new double[size];
for( int i=0; i<size; i++ ) {
host = getHostList().get(j); // get each Host from the list
int hid = host.getId();
double availmip=host.getAvailableMips(); //retrieves the available Cpu capacity
avgCPU[i]=((mips-availmip)/mips)*100 power[i]=host.getPower(Math.abs(avgCPU[i])); // Energy consumped the host
System.out.println("Average power consumption: "+power);
}