AnyLogic
Expand
Font size
Type Parameters:
E - type of stored variables
All Implemented Interfaces:
Serializable
Direct Known Subclasses:
CustomDistributionContinuous, CustomDistributionDiscrete, CustomDistributionOptions

public abstract class CustomDistributionAbstract<E>
extends Object
implements Serializable
This abstract class is used to generate random numbers from a probability density function (PDF) that is defined by the user. Each draw requires a random number generator, so there are two different modes the CustomDistributionAbstract can work:
1. You do not provide the RNG in the constructor, but supply it each time you call get( Random ). In this case the CustomDistribution can safely be made static and shared across multiple models and objects.
2. You provide the RNG with calling method setRandom(...) after the constructor, the RNG is then remembered in the CustomDistributionAbstract and you can use get() method without any parameters. This is simpler syntax, but such CustomDistribution cannot be shared between models with different RNGs used. The get( Random ) method can still be used in that case.
Author:
AnyLogic North America, LLC https://anylogic.com
See Also:
Serialized Form

Constructor Summary

ConstructorDescription
CustomDistributionAbstract() 

Method Summary

Modifier and TypeMethodDescription
Eget()
Returns a random value according to distribution parameters.
doubleget(double min, double max, double shift, double stretch)
Generates a sample of truncated custom distribution.
This method uses the random number generator set during construction and throws exception if no RNG was set.
This distribution is stretched by stretch coefficient, then shifted to the right by shift, after that it is truncated to fit in [min, max] interval.
doubleget(double min, double max, double shift, double stretch, Random rng)
Generates a sample of truncated custom distribution.
This method requires a random number generator.
abstract Eget(Random r)
Returns a random value according to distribution parameters and given random number generator.
intgetInt()
Returns a random integer according to distribution parameters, if possible.
abstract intgetInt(Random r)
Returns a random integer according to distribution parameters, if possible.
CustomDistributionAbstract<E>setRandom(Random newRandom)
Sets random number generator for distribution.
StringtoString()
Returns the textual representation of the custom distribution.

Methods inherited from class java.lang.Object

equals, getClass, hashCode, notify, notifyAll, wait, wait, wait

Constructor Details

CustomDistributionAbstract

public CustomDistributionAbstract()

Method Details

get

public E get()
      throws RuntimeException
Returns a random value according to distribution parameters. Random number generator should be set before calling this function.
Returns:
random value from distribution
Throws:
RuntimeException

get

public abstract E get(Random r)
Returns a random value according to distribution parameters and given random number generator.
Parameters:
r - random number generator
Returns:
random value from distribution

getInt

public int getInt()
           throws RuntimeException
Returns a random integer according to distribution parameters, if possible. Random number generator should be set before calling this function.
Returns:
random integer from distribution
Throws:
RuntimeException

getInt

public abstract int getInt(Random r)
Returns a random integer according to distribution parameters, if possible.
Parameters:
r - random number generator
Returns:
random integer from distribution

setRandom

public CustomDistributionAbstract<E> setRandom(Random newRandom)
Sets random number generator for distribution.
Parameters:
newRandom - random number generator
Returns:
updated class with set RNG

get

public double get(double min,
 double max,
 double shift,
 double stretch,
 Random rng)
Generates a sample of truncated custom distribution.
This method requires a random number generator. If you are calling it from an Agent or an Experiment and wish to use the default RNG of the simulation engine you may write get( getDefaultRandomGenerator() ).
This distribution is stretched by stretch coefficient, then shifted to the right by shift, after that it is truncated to fit in [min, max] interval. Truncation is performed by discarding every sample outside this interval and taking subsequent try.
For more details see get(Random)
Parameters:
min - the minimum value that this function will return. The distribution is truncated to return values above this. If the sample (stretched and shifted) is below this value it will be discarded and another sample will be drawn. Use -infinity for "No limit".
max - the maximum value that this function will return. The distribution is truncated to return values below this. If the sample (stretched and shifted) is bigger than this value it will be discarded and another sample will be drawn. Use +infinity for "No limit".
shift - the shift parameter that indicates how much the (stretched) distribution will shifted to the right
stretch - the stretch parameter that indicates how much the distribution will be stretched
rng - the random number generator.
Returns:
the generated sample

get

public double get(double min,
 double max,
 double shift,
 double stretch)
Generates a sample of truncated custom distribution.
This method uses the random number generator set during construction and throws exception if no RNG was set.
This distribution is stretched by stretch coefficient, then shifted to the right by shift, after that it is truncated to fit in [min, max] interval. Truncation is performed by discarding every sample outside this interval and taking subsequent try.
For more details see get()
Parameters:
min - the minimum value that this function will return. The distribution is truncated to return values above this. If the sample (stretched and shifted) is below this value it will be discarded and another sample will be drawn. Use -infinity for "No limit".
max - the maximum value that this function will return. The distribution is truncated to return values below this. If the sample (stretched and shifted) is bigger than this value it will be discarded and another sample will be drawn. Use +infinity for "No limit".
shift - the shift parameter that indicates how much the (stretched) distribution will shifted to the right
stretch - the stretch parameter that indicates how much the distribution will be stretched
Returns:
the generated sample

toString

public String toString()
Returns the textual representation of the custom distribution.
Overrides:
toString in class Object
Returns:
the textual representation of the custom distribution