Package com.anylogic.engine
- java.lang.Object
- com.anylogic.engine.CustomDistributionAbstract<E>
- 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.
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 | Description |
---|---|
CustomDistributionAbstract() |
Modifier and Type | Method | Description |
---|---|---|
E | get() |
Returns a random value according to distribution parameters.
|
double | get |
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. |
double | get |
Generates a sample of truncated custom distribution.
This method requires a random number generator. |
abstract E | get |
Returns a random value according to distribution parameters and given random
number generator.
|
int | getInt() |
Returns a random integer according to distribution parameters, if possible.
|
abstract int | getInt |
Returns a random integer according to distribution parameters, if possible.
|
CustomDistributionAbstract<E> | setRandom |
Sets random number generator for distribution.
|
String | toString() |
Returns the textual representation of the custom distribution.
|
public CustomDistributionAbstract()
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
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
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
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
public CustomDistributionAbstract<E> setRandom(Random newRandom)
Sets random number generator for distribution.
- Parameters:
newRandom
- random number generator- Returns:
- updated class with set RNG
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
This distribution is stretched by
For more details see
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 rightstretch
- the stretch parameter that indicates how much the distribution will be stretchedrng
- the random number generator.- Returns:
- the generated sample
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
For more details see
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 rightstretch
- the stretch parameter that indicates how much the distribution will be stretched- Returns:
- the generated sample
public String toString()
Returns the textual representation of the custom distribution.