All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.cloudbus.cloudsim.power.models.PowerModelAbstract Maven / Gradle / Ivy

Go to download

CloudSim Plus: A modern, highly extensible and easier-to-use Java 8 Framework for Modeling and Simulation of Cloud Computing Infrastructures and Services

There is a newer version: 8.0.0
Show newest version
package org.cloudbus.cloudsim.power.models;

import org.cloudbus.cloudsim.hosts.Host;

import java.util.Objects;

/**
 * An abstract implementation of a {@link PowerModel}.
 *
 * @author raysaoliveira
 * @since CloudSim Plus 1.2.0
 */
public abstract class PowerModelAbstract implements PowerModel {
    private Host host;

    @Override
    public Host getHost() {
        return host;
    }

    @Override
    public final void setHost(final Host host) {
        Objects.requireNonNull(host);
        this.host = host;
    }

    @Override
    public double getPower() {
        return getPower(host.getUtilizationOfCpu());
    }

    @Override
    public final double getPower(final double utilization) throws IllegalArgumentException {
		if (utilization < 0 || utilization > 1) {
			throw new IllegalArgumentException(
                String.format(
                    "Utilization value must be between 0 and 1. The given value was %.2f",
                    utilization));
		}

		if(!host.isActive()){
		    return 0;
        }

        return getPowerInternal(utilization);
    }

    /**
     * An internal method to be implemented by sub classes
     * to get the power consumption for the current CPU utilization.
     * 

The basic parameter validation is performed by the {@link #getPower(double)} method.

* * @param utilization the utilization percentage (between [0 and 1]) of a * resource that is critical for power consumption. * @return the power consumption * @throws IllegalArgumentException when the utilization percentage is not * between [0 and 1] */ protected abstract double getPowerInternal(final double utilization) throws IllegalArgumentException; @Override public double getEnergyLinearInterpolation( final double fromUtilization, final double toUtilization, final double time) { if(!host.isActive()) { return 0; } final double fromPower = getPower(fromUtilization); final double toPower = getPower(toUtilization); return (fromPower + (toPower - fromPower) / 2) * time; } }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy