Package org.cloudsimplus.testbeds
Class Experiment
java.lang.Object
org.cloudsimplus.testbeds.AbstractRunnable
org.cloudsimplus.testbeds.Experiment
- All Implemented Interfaces:
Runnable
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 Summary
Fields inherited from class org.cloudsimplus.testbeds.AbstractRunnable
verbose
-
Constructor Summary
ModifierConstructorDescriptionExperiment
(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 TypeMethodDescriptionprotected final void
build()
Creates the simulation scenario to run the experiment.protected void
Creates all the Cloudlets required by the experiment and submits them to a Broker.protected abstract DatacenterBroker
Creates a DatacenterBroker.protected void
Creates a list of brokers.protected abstract Cloudlet
createCloudlet
(DatacenterBroker broker) 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 abstract Vm
createVm
(DatacenterBroker broker, int id) createVms
(DatacenterBroker broker) Creates the Vms to be used by the experiment.Gets the list of created DatacenterBrokers.int
Gets the number of brokers to create.int
int
getIndex()
The index that identifies the current experiment run.Gets the object that is in charge to run the experiment.long
getSeed()
final CloudSim
protected Function<DatacenterBroker,
Integer> Gets aFunction
that receives aDatacenterBroker
and returns the number of Vms to create for that broker.boolean
protected final VmAllocationPolicy
protected final int
protected final int
nextVmId()
abstract void
Prints the results for the experiment.final 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.<T extends Experiment>
TsetBeforeExperimentBuild
(Consumer<T> beforeExperimentBuild) Sets aConsumer
that will be called before the simulation scenario is built.<T extends Experiment>
TsetBeforeExperimentRun
(Consumer<T> beforeExperimentRun) Sets aConsumer
that will be called before starting the simulation.setBrokersNumber
(int brokersNumber) Sets the number of brokers to create.void
setDatacentersNumber
(int datacentersNumber) protected final void
setHostsNumber
(int hostsNumber) void
setVmAllocationPolicySupplier
(Supplier<VmAllocationPolicy> vmAllocationPolicySupplier) final void
setVmsByBrokerFunction
(Function<DatacenterBroker, Integer> vmsByBrokerFunction) Sets aFunction
that receives aDatacenterBroker
and returns the number of Vms to create for that broker.toString()
Methods inherited from class org.cloudsimplus.testbeds.AbstractRunnable
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:
-
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:
-
-
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()
-
getRunner
Gets the object that is in charge to run the experiment.- Returns:
-
getBrokerList
Gets the list of created DatacenterBrokers.- Returns:
-
setBeforeExperimentBuild
Sets aConsumer
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
Creates a DatacenterBroker.- Returns:
- the created DatacenterBroker
-
createDatacenter
Creates a datacenter using aVmAllocationPolicy
supplied by thevmAllocationPolicySupplier
.- Parameters:
index
- index of the datacenter being created, from thedatacentersNumber
.- Returns:
- See Also:
-
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
-
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 Consumer to set- Returns:
-
setBeforeExperimentRun
Sets aConsumer
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 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
-