Commit c1b660b9 authored by Anton Beloglazov's avatar Anton Beloglazov

- Fixed energy calculation: if fromUtilization == 0 and toUtilization == 0, it's…

- Fixed energy calculation: if fromUtilization == 0 and toUtilization == 0, it's assumed that the host is switched off and therefore energy is 0.
parent f7f3f15a
...@@ -24,7 +24,7 @@ import org.cloudbus.cloudsim.provisioners.RamProvisioner; ...@@ -24,7 +24,7 @@ import org.cloudbus.cloudsim.provisioners.RamProvisioner;
* @since CloudSim Toolkit 2.0 * @since CloudSim Toolkit 2.0
*/ */
public class PowerHost extends HostDynamicWorkload { public class PowerHost extends HostDynamicWorkload {
/** The power model. */ /** The power model. */
private PowerModel powerModel; private PowerModel powerModel;
...@@ -58,7 +58,7 @@ public class PowerHost extends HostDynamicWorkload { ...@@ -58,7 +58,7 @@ public class PowerHost extends HostDynamicWorkload {
public double getPower() { public double getPower() {
return getPower(getUtilizationOfCpu()); return getPower(getUtilizationOfCpu());
} }
/** /**
* Gets the power. For this moment only consumed by all PEs. * Gets the power. For this moment only consumed by all PEs.
* *
...@@ -75,7 +75,7 @@ public class PowerHost extends HostDynamicWorkload { ...@@ -75,7 +75,7 @@ public class PowerHost extends HostDynamicWorkload {
} }
return power; return power;
} }
/** /**
* Gets the max power that can be consumed by the host. * Gets the max power that can be consumed by the host.
* *
...@@ -91,7 +91,7 @@ public class PowerHost extends HostDynamicWorkload { ...@@ -91,7 +91,7 @@ public class PowerHost extends HostDynamicWorkload {
} }
return power; return power;
} }
/** /**
* Gets the energy consumption using linear interpolation of the utilization change. * Gets the energy consumption using linear interpolation of the utilization change.
* *
...@@ -101,11 +101,14 @@ public class PowerHost extends HostDynamicWorkload { ...@@ -101,11 +101,14 @@ public class PowerHost extends HostDynamicWorkload {
* @return the energy * @return the energy
*/ */
public double getEnergyLinearInterpolation(double fromUtilization, double toUtilization, double time) { public double getEnergyLinearInterpolation(double fromUtilization, double toUtilization, double time) {
if (fromUtilization == 0 && toUtilization == 0) {
return 0;
}
double fromPower = getPower(fromUtilization); double fromPower = getPower(fromUtilization);
double toPower = getPower(toUtilization); double toPower = getPower(toUtilization);
return (fromPower + (toPower - fromPower) / 2) * time; return (fromPower + (toPower - fromPower) / 2) * time;
} }
/** /**
* Sets the power model. * Sets the power model.
* *
...@@ -123,5 +126,5 @@ public class PowerHost extends HostDynamicWorkload { ...@@ -123,5 +126,5 @@ public class PowerHost extends HostDynamicWorkload {
public PowerModel getPowerModel() { public PowerModel getPowerModel() {
return powerModel; return powerModel;
} }
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment