Class Experiment

java.lang.Object
org.cloudsimplus.testbeds.AbstractRunnable
org.cloudsimplus.testbeds.Experiment
All Implemented Interfaces:
Runnable

public abstract class Experiment extends AbstractRunnable
An abstract class to implement simulation experiments that can be executed in a repeatable way by a ExperimentRunner.
Since:
CloudSim Plus 1.0
Author:
Manoel Campos da Silva Filho
  • Field Details

    • runner

      protected final ExperimentRunner runner
    • hostsNumber

      protected int hostsNumber
  • Constructor Details

    • Experiment

      public Experiment(long seed)
      Creates a simulation experiment that is not linked to a runner, to enable it to execute just one run.
    • Experiment

      public Experiment(int index, ExperimentRunner runner)
      Instantiates a simulation experiment with 1 Datacenter by default.
      Parameters:
      index - the index that identifies the current experiment run.
      runner - The ExperimentRunner that is in charge of executing this experiment a defined number of times and to collect data for statistical analysis.
      See Also:
    • Experiment

      protected Experiment(int index, ExperimentRunner runner, long seed)
      Instantiates a simulation experiment that will create 1 broker and 1 Datacenter by default.
      Parameters:
      index - the index that identifies the current experiment run.
      runner - The ExperimentRunner to execute the experiment. If omitted, it means the experiment is independent and may be run just once. If you don't provide a runner, you must provide a seed
      seed - the seed to be set. If a runner is given, this value is ignored and the seed is generated from the runner base seed. If you don't provide a seed, you must provide a runner.
      See Also:
  • Method Details

    • getCloudletList

      public final List<Cloudlet> getCloudletList()
    • getVmList

      public List<Vm> getVmList()
    • getIndex

      public int getIndex()
      The index that identifies the current experiment run.
      Returns:
    • run

      public final void run()
      Builds the simulation scenario and starts execution.
      Throws:
      RuntimeException
    • isFirstExperimentCreated

      public boolean isFirstExperimentCreated()
    • printResults

      public abstract void printResults()
      Prints the results for the experiment. The method has to be implemented by subclasses in order to output the experiment results.
      See Also:
      • printResultsInternal()
    • getRunner

      public ExperimentRunner getRunner()
      Gets the object that is in charge to run the experiment.
      Returns:
    • getBrokerList

      public List<DatacenterBroker> getBrokerList()
      Gets the list of created DatacenterBrokers.
      Returns:
    • setBeforeExperimentBuild

      public <T extends Experiment> T setBeforeExperimentBuild(Consumer<T> beforeExperimentBuild)
      Sets a Consumer that will be called before the simulation scenario is built.

      Setting a Consumer object is optional.

      Type Parameters:
      T - the class of the experiment
      Parameters:
      beforeExperimentBuild - the beforeExperimentBuild Consumer to set
      Returns:
    • build

      protected final void build()
      Creates the simulation scenario to run the experiment.
    • createBrokers

      protected void createBrokers()
      Creates a list of brokers. This is the entry-point for broker creation.
    • createBroker

      protected abstract DatacenterBroker createBroker()
      Creates a DatacenterBroker.
      Returns:
      the created DatacenterBroker
    • createDatacenter

      protected Datacenter createDatacenter(int index)
      Creates a datacenter using a VmAllocationPolicy supplied by the vmAllocationPolicySupplier.
      Parameters:
      index - index of the datacenter being created, from the datacentersNumber.
      Returns:
      See Also:
    • createCloudlets

      protected abstract List<Cloudlet> createCloudlets(DatacenterBroker broker)
      Creates a list of Cloudlets to be used by the experiment.
      Parameters:
      broker - the broker to create the Cloudlets to
      Returns:
      the list of created cloudlets
    • createCloudlet

      protected abstract Cloudlet createCloudlet(DatacenterBroker broker)
    • createVms

      protected List<Vm> createVms(DatacenterBroker broker)
      Creates the Vms to be used by the experiment.
      Parameters:
      broker -
      Returns:
      the List of created VMs
    • createVm

      protected abstract Vm createVm(DatacenterBroker broker, int id)
    • nextVmId

      protected final int nextVmId()
    • nextCloudletId

      protected final int nextCloudletId()
    • createAndSubmitCloudletsInternal

      protected void createAndSubmitCloudletsInternal(DatacenterBroker broker)
      Creates all the Cloudlets required by the experiment and submits them to a Broker. This the entry-point for Cloudlets creation.
      Parameters:
      broker - broker to submit Cloudlets to
    • createHosts

      protected final List<Host> createHosts()
    • createHost

      protected abstract Host createHost(int id)
    • setAfterExperimentBuild

      public <T extends Experiment> Experiment setAfterExperimentBuild(Consumer<T> afterExperimentBuild)
      Sets a Consumer that will be called after the simulation scenario is built, which is before starting the simulation.

      Setting a Consumer object is optional.

      Type Parameters:
      T - the class of the experiment
      Parameters:
      afterExperimentBuild - the afterExperimentBuild Consumer to set
      Returns:
    • setBeforeExperimentRun

      public <T extends Experiment> T setBeforeExperimentRun(Consumer<T> beforeExperimentRun)
      Sets a Consumer that will be called before starting the simulation.

      Setting a Consumer object is optional.

      Type Parameters:
      T - the class of the experiment
      Parameters:
      beforeExperimentRun - the beforeExperimentRun Consumer to set
      Returns:
    • setAfterExperimentFinish

      public <T extends Experiment> Experiment setAfterExperimentFinish(Consumer<T> afterExperimentFinishConsumer)
      Sets a Consumer object that will receive the experiment instance after the experiment finishes, then it performs some post-processing tasks. These tasks are defined by the developer using the current class and can include collecting data for statistical analysis.

      Inside this Consumer, you must call ExperimentRunner.addMetricValue(String, Double) to collect values for each desired metric.

      Setting a Consumer object is optional.

      Type Parameters:
      T - the class of the experiment
      Parameters:
      afterExperimentFinishConsumer - a Consumer instance to set
      Returns:
    • getSimulation

      public final CloudSim getSimulation()
    • getBrokersNumber

      public int getBrokersNumber()
      Gets the number of brokers to create.
      Returns:
    • setBrokersNumber

      public Experiment setBrokersNumber(int brokersNumber)
      Sets the number of brokers to create.
      Parameters:
      brokersNumber - the value to set
    • getDatacenterList

      public List<Datacenter> getDatacenterList()
    • getSeed

      public long getSeed()
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • setVmsByBrokerFunction

      public final void setVmsByBrokerFunction(Function<DatacenterBroker,Integer> vmsByBrokerFunction)
      Sets a Function that receives a DatacenterBroker and returns the number of Vms to create for that broker. If you want all brokers to have the same amount of VMs, you can give a lambda expression such as broker -> NUMBER_OF_VMS_TO_CREATE.
      Parameters:
      vmsByBrokerFunction - the Function to set
    • getVmsByBrokerFunction

      protected Function<DatacenterBroker,Integer> getVmsByBrokerFunction()
      Gets a Function that receives a DatacenterBroker and returns the number of Vms to create for that broker.
    • setHostsNumber

      protected final void setHostsNumber(int hostsNumber)
    • getDatacentersNumber

      public int getDatacentersNumber()
    • setDatacentersNumber

      public void setDatacentersNumber(int datacentersNumber)
    • setVmAllocationPolicySupplier

      public void setVmAllocationPolicySupplier(Supplier<VmAllocationPolicy> vmAllocationPolicySupplier)
    • newVmAllocationPolicy

      protected final VmAllocationPolicy newVmAllocationPolicy()