Class PoissonDistr
java.lang.Object
org.cloudbus.cloudsim.distributions.PoissonDistr
- All Implemented Interfaces:
DiscreteDistribution
,StatisticalDistribution
public class PoissonDistr extends Object implements DiscreteDistribution
A Pseudo-Random Number Generator which returns numbers
following a Poisson Distribution, modeling the probability of an event
to happen a number of times in a given time interval.
- Since:
- CloudSim Plus 1.2.0
- Author:
- Manoel Campos da Silva Filho
- See Also:
- Poisson Distribution
-
Constructor Summary
Constructors Constructor Description PoissonDistr(double lambda)
Creates a Poisson Pseudo-Random Number Generator to check the probability of 1 event (k = 1
) to happen at each time interval.PoissonDistr(double lambda, long seed)
Creates a Poisson Pseudo-Random Number Generator to check the probability of 1 event (k = 1
) to happen at each time interval. -
Method Summary
Modifier and Type Method Description double
eventsArrivalProbability()
Gets the probability to arrivek
events in the current time, considering the mean arrival timelambda (λ)
, which is represented asPr(k events in time period)
.boolean
eventsHappened()
Checks if at the current time,k
events have happened, considering theprobability of these k events
to happen in a time interval.double
getInterArrivalMeanTime()
Gets the mean time between arrival of two events, which is the inverse oflambda (λ)
.int
getK()
Gets the number of events to check the probability for them to happen in a time interval (default 1).double
getLambda()
Gets the average number of events (λ) that are expected to happen at each 1 time unit.long
getSeed()
Gets the seed used to initialize the generatorboolean
isApplyAntitheticVariates()
Indicates if the Pseudo-Random Number Generator (RNG) applies the Antithetic Variates Technique in order to reduce variance of experiments using the generated numbers.static void
main(String[] args)
Tests the simulations of customers arrivals in a Poisson process.double
originalSample()
Generate a new pseudo random number directly from theRealDistribution.sample()
method.double
sample()
Gets a random number that represents the next time (from current time or last generated event) that an event will happen, considering the events arrival rate defined bylambda (λ)
.PoissonDistr
setApplyAntitheticVariates(boolean applyAntitheticVariates)
Indicates if the Pseudo-Random Number Generator (RNG) applies the Antithetic Variates Technique in order to reduce variance of experiments using the generated numbers.void
setK(int k)
Sets the number of events to check the probability to happen in a time interval.
-
Constructor Details
-
PoissonDistr
public PoissonDistr(double lambda, long seed)Creates a Poisson Pseudo-Random Number Generator to check the probability of 1 event (k = 1
) to happen at each time interval.- Parameters:
lambda
- the average number of events that happen at each 1 time unit. If one considers the unit as minute, this value means the average number of arrivals at each minute.seed
- the seed to initialize the internal uniform Pseudo-Random Number Generator- See Also:
setK(int)
,setLambda(double)
-
PoissonDistr
public PoissonDistr(double lambda)Creates a Poisson Pseudo-Random Number Generator to check the probability of 1 event (k = 1
) to happen at each time interval.- Parameters:
lambda
- average number of events by interval. For instance, if it was defined 1 event to be expected at each 2.5 minutes, it means that 0.4 event is expected at each minute (1/2.5).- See Also:
setK(int)
-
-
Method Details
-
getLambda
public double getLambda()Gets the average number of events (λ) that are expected to happen at each 1 time unit. It is the expected number of events to happen each time, also called the event rate or rate parameter.If one considers the unit as minute, this value means the average number of arrivals at each minute. It's the inverse of the
getInterArrivalMeanTime()
.- Returns:
-
eventsArrivalProbability
public double eventsArrivalProbability()Gets the probability to arrivek
events in the current time, considering the mean arrival timelambda (λ)
, which is represented asPr(k events in time period)
. It computes the Probability Mass Function (PMF) of the Poisson distribution.- Returns:
- the probability of a
random variable
to be equal to k - See Also:
- Poisson Probability Mass Function
-
eventsHappened
public boolean eventsHappened()Checks if at the current time,k
events have happened, considering theprobability of these k events
to happen in a time interval.- Returns:
- true if k events have happened at the current time, false otherwise
-
sample
public double sample()Gets a random number that represents the next time (from current time or last generated event) that an event will happen, considering the events arrival rate defined bylambda (λ)
. The time unit (if seconds, minutes, hours, etc) is the same considered when setting a value to thelambda
attribute.Calling this method for the first time returns the next event arrival time. The retuning values for consecutive calls can be dealt in one of the following ways:
- If you are generating all random event arrivals at the beginning of the simulation, you need to add the previous time to the next event arrival time. This way, the arrival time of the previous event is added to the next one. For instance, if consecutive calls to this method return the values 60 and 25, from the current time, that means: (i) the first event will arrive in 60 seconds; (ii) the next event will arrive in 85 seconds, that is 25 seconds after the first one.
- If you are generating event arrivals during simulation runtime, you must NOT add the previous time to the generated event time, just use the returned value as the event arrival time.
Poisson inter-arrival times are independent and identically distributed exponential random variables with mean 1/λ.
-
getSeed
public long getSeed()Description copied from interface:StatisticalDistribution
Gets the seed used to initialize the generator- Specified by:
getSeed
in interfaceStatisticalDistribution
- Returns:
-
isApplyAntitheticVariates
public boolean isApplyAntitheticVariates()Description copied from interface:StatisticalDistribution
Indicates if the Pseudo-Random Number Generator (RNG) applies the Antithetic Variates Technique in order to reduce variance of experiments using the generated numbers. This technique doesn't work for all the cases. However, in the cases it can be applied, in order to it work, one have to perform some actions. Consider an experiment that has to run "n" times. The first half of these experiments has to use the seeds the developer want. However, the second half of the experiments have to set the applyAntitheticVariates attribute to true and use the seeds of the first half of experiments. Thus, the first half of experiments are run using PRNGs that return random numbers as U(0, 1)[seed_1], ..., U(0, 1)[seed_n]. The second half of experiments then uses the seeds of the first half of experiments, returning random numbers as 1 - U(0, 1)[seed_1], ..., 1 - U(0, 1)[seed_n].- Specified by:
isApplyAntitheticVariates
in interfaceStatisticalDistribution
- Returns:
- true if the technique is applied, false otherwise
- See Also:
StatisticalDistribution.setApplyAntitheticVariates(boolean)
-
setApplyAntitheticVariates
Description copied from interface:StatisticalDistribution
Indicates if the Pseudo-Random Number Generator (RNG) applies the Antithetic Variates Technique in order to reduce variance of experiments using the generated numbers.- Specified by:
setApplyAntitheticVariates
in interfaceStatisticalDistribution
- Parameters:
applyAntitheticVariates
- true if the technique is to be applied, false otherwise- See Also:
StatisticalDistribution.isApplyAntitheticVariates()
-
originalSample
public double originalSample()Description copied from interface:StatisticalDistribution
Generate a new pseudo random number directly from theRealDistribution.sample()
method. This way, theAntithetic Variates Technique
is ignored if enabled.Usually you shouldn't call this method but
StatisticalDistribution.sample()
instead.- Specified by:
originalSample
in interfaceStatisticalDistribution
- Returns:
- the next pseudo random number in the sequence, following the
implemented distribution, ignoring the
Antithetic Variates Technique
if enabled
-
getK
public int getK()Gets the number of events to check the probability for them to happen in a time interval (default 1).- Returns:
-
setK
public void setK(int k)Sets the number of events to check the probability to happen in a time interval.- Parameters:
k
- the value to set
-
getInterArrivalMeanTime
public double getInterArrivalMeanTime()Gets the mean time between arrival of two events, which is the inverse oflambda (λ)
. The time unit (if seconds, minutes, hours, etc) is the same considered when setting a value to thelambda
attribute.- Returns:
-
main
Tests the simulations of customers arrivals in a Poisson process. All the code inside this method is just to try the class. That is way it declares internal methods as Functional objects, instead of declaring such methods at the class level and just calling them.- Parameters:
args
-
-