Package org.cloudsimplus.testbeds
Class Experiment
java.lang.Object
org.cloudsimplus.testbeds.AbstractExperiment
org.cloudsimplus.testbeds.Experiment
- All Implemented Interfaces:
Runnable
public abstract class Experiment extends AbstractExperiment
A base 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 Summary
Fields Modifier and Type Field Description protected int
hostsNumber
protected ExperimentRunner
runner
Fields inherited from class org.cloudsimplus.testbeds.AbstractExperiment
verbose
-
Constructor Summary
Constructors Modifier Constructor Description Experiment(int index, ExperimentRunner runner)
Instantiates a simulation experiment with 1 Datacenter by default.protected
Experiment(int index, ExperimentRunner runner, long seed)
Instantiates a simulation experiment that will create 1 broker and 1 Datacenter by default.Experiment(long seed)
Creates a simulation experiment that is not linked to a runner, to enable it to execute just one run. -
Method Summary
Modifier and Type Method Description protected void
build()
Creates the simulation scenario to run the experiment.protected void
createAndSubmitCloudletsInternal(DatacenterBroker broker)
Creates all the Cloudlets required by the experiment and submits them to a Broker.protected abstract DatacenterBroker
createBroker()
Creates a DatacenterBroker.protected void
createBrokers()
Creates a list of brokers.protected abstract Cloudlet
createCloudlet(DatacenterBroker broker)
protected abstract List<Cloudlet>
createCloudlets(DatacenterBroker broker)
Creates a list of Cloudlets to be used by the experiment.protected Datacenter
createDatacenter(int index)
Creates a datacenter using aVmAllocationPolicy
supplied by thevmAllocationPolicySupplier
.protected abstract Host
createHost(int id)
protected List<Host>
createHosts()
protected abstract Vm
createVm(DatacenterBroker broker, int id)
protected List<Vm>
createVms(DatacenterBroker broker)
Creates the Vms to be used by the experiment.List<DatacenterBroker>
getBrokerList()
Gets the list of created DatacenterBrokers.int
getBrokersNumber()
Gets the number of brokers to create.List<Cloudlet>
getCloudletList()
List<Datacenter>
getDatacenterList()
int
getDatacentersNumber()
int
getIndex()
The index that identifies the current experiment run.ExperimentRunner
getRunner()
Gets the object that is in charge to run the experiment.long
getSeed()
CloudSim
getSimulation()
List<Vm>
getVmList()
protected Function<DatacenterBroker,Integer>
getVmsByBrokerFunction()
Gets aFunction
that receives aDatacenterBroker
and returns the number of Vms to create for that broker.boolean
isFirstExperimentCreated()
protected VmAllocationPolicy
newVmAllocationPolicy()
protected int
nextCloudletId()
protected int
nextVmId()
abstract void
printResults()
Prints the results for the experiment.void
run()
Builds the simulation scenario and starts execution.<T extends Experiment>
ExperimentsetAfterExperimentBuild(Consumer<T> afterExperimentBuild)
Sets aConsumer
that will be called after the simulation scenario is built, which is before starting the simulation.<T extends Experiment>
ExperimentsetAfterExperimentFinish(Consumer<T> afterExperimentFinishConsumer)
Sets aConsumer
object that will receive the experiment instance after the experiment finishes, then it performs some post-processing tasks.Experiment
setBrokersNumber(int brokersNumber)
Sets the number of brokers to create.void
setDatacentersNumber(int datacentersNumber)
protected void
setHostsNumber(int hostsNumber)
void
setVmAllocationPolicySupplier(Supplier<VmAllocationPolicy> vmAllocationPolicySupplier)
void
setVmsByBrokerFunction(Function<DatacenterBroker,Integer> vmsByBrokerFunction)
Sets aFunction
that receives aDatacenterBroker
and returns the number of Vms to create for that broker.String
toString()
Methods inherited from class org.cloudsimplus.testbeds.AbstractExperiment
isNotVerbose, isVerbose, print, print, println, println, println, setVerbose
-
Field Details
-
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
Instantiates a simulation experiment with 1 Datacenter by default.- Parameters:
index
- the index that identifies the current experiment run.runner
- TheExperimentRunner
that is in charge of executing this experiment a defined number of times and to collect data for statistical analysis.- See Also:
setDatacentersNumber(int)
-
Experiment
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
- TheExperimentRunner
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 seedseed
- 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:
setBrokersNumber(int)
,setDatacentersNumber(int)
-
-
Method Details
-
getCloudletList
-
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()
-
build
protected final void build()Creates the simulation scenario to run the experiment. -
createDatacenter
Creates a datacenter using aVmAllocationPolicy
supplied by thevmAllocationPolicySupplier
.- Parameters:
index
- index of the datatacenter being created, from thedatacentersNumber
.- Returns:
- See Also:
setVmAllocationPolicySupplier(Supplier)
-
createBrokers
protected void createBrokers()Creates a list of brokers. This is the entry-point for broker creation. -
createBroker
Creates a DatacenterBroker.- Returns:
- the created DatacenterBroker
-
createCloudlets
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
-
createVms
Creates the Vms to be used by the experiment.- Parameters:
broker
-- Returns:
- the List of created VMs
-
createVm
-
nextVmId
protected final int nextVmId() -
nextCloudletId
protected final int nextCloudletId() -
createAndSubmitCloudletsInternal
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
-
createHost
-
getRunner
Gets the object that is in charge to run the experiment.- Returns:
-
getBrokerList
Gets the list of created DatacenterBrokers.- Returns:
-
setAfterExperimentBuild
Sets aConsumer
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 to set- Returns:
-
setAfterExperimentFinish
public <T extends Experiment> Experiment setAfterExperimentFinish(Consumer<T> afterExperimentFinishConsumer)Sets aConsumer
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
- aConsumer
instance to set- Returns:
-
getSimulation
-
getBrokersNumber
public int getBrokersNumber()Gets the number of brokers to create.- Returns:
-
setBrokersNumber
Sets the number of brokers to create.- Parameters:
brokersNumber
- the value to set
-
getDatacenterList
-
getSeed
public long getSeed() -
toString
-
setVmsByBrokerFunction
Sets aFunction
that receives aDatacenterBroker
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 asbroker -> NUMBER_OF_VMS_TO_CREATE
.- Parameters:
vmsByBrokerFunction
- theFunction
to set
-
getVmsByBrokerFunction
Gets aFunction
that receives aDatacenterBroker
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
-
newVmAllocationPolicy
-