The energy consumption of fog device is calculated by the power of all hosts in a certain time frame of execution. The “UpdateEnergyConsumption” method in FogDevice class is used to calculate the energy consumption, it is the extension of PowerDatacenter class.
private void updateEnergyConsumption() {
double totalMipsAllocated = 0;
double timeNow = CloudSim.clock();
double currentEnergyConsumption = getEnergyConsumption();
double newEnergyConsumption = currentEnergyConsumption + (timeNow-lastUtilizationUpdateTime)*getHost().getPowerModel().getPower(lastUtilization);
setEnergyConsumption(newEnergyConsumption);
lastUtilization = Math.min(1, totalMipsAllocated/getHost().getTotalMips());
lastUtilizationUpdateTime = timeNow;
}
private FogDevice getCloud(){
for(FogDevice dev : getFogDevices())
if(dev.getName().equals("cloud"))
return dev;
return null;
}
private void printCostDetails(){
System.out.println("Cost of execution in cloud = "+getCloud().getTotalCost());
}