RandomVariable

open class RandomVariable(parent: ModelElement, rSource: RandomIfc, name: String? = null) : RandomElement, RandomIfc, PreviousValueIfc

A random variable (RandomVariable) is a function that maps a probability space to a real number. A random variable uses a RandomIfc to provide the underlying mapping to a real number via the value() method.

To construct a RandomVariable the user must provide an instance of a class that implements the RandomIfc interface as the initial random source. This source is used to initialize the source of randomness for each replication.

WARNING: For efficiency, this class uses a direct reference to the supplied initial random source. It simply wraps the supplied object reference to a random source so that it can be utilized within the KSL model. Because of the direct reference to the random source, a change to the state of the random source will be reflected in the use of that instance within this class. Thus, mutating the state of the random source will also see those mutations reflected in the usage of this class. This may or not be what is expected by the client. For example, mutating the state of the initial random source during a replication may cause each replication to start with different initial conditions.

Using the randomSource property allows the user to change the source of randomness during a replication. The source of randomness during a replication is set to the reference of the initial random source prior to running any replications. This ensures that each replication uses the same random source during the replication, unless the random source is changed during a replication. However, the user may use the randomSource property to immediately change the source of randomness during the replication. This change is in effect only during the current replication. After each replication, the source of randomness is set back to the reference to the initial random source. This ensures that each replication starts off using the same random source. For this reason, the use of initialRandomSource property should be limited to before or after running a simulation experiment.

The initial source is used to set up the source used during the replication. If the client changes the reference to the initial source, this change does not become effective until the beginning of the next replication. In other words, the random source used during the replication is unaffected. However, the client might change the initial random source during a replication. If this occurs, the change happens but the replication will continue to use its current random source as defined by the randomSource property. The change in the initial random source does not really take effect until the beginning of the NEXT replication. Again, mutating the initial random source during a replication is generally a bad idea unless you really know what you are doing.

Changing the initial random source between experiments (simulation runs) is very common. For example, to set up an experiment that has different random characteristics the client can and should change the initial source of randomness (either by mutating the initial random source or by supplying a reference to a different initial random source).

To facilitate the synchronization of random number streams, the underlying random number stream will automatically be advanced to its next sub-stream after each replication. This occurs by default unless the resetNextSubStreamOption is set to false.

Inheritors

Constructors

Link copied to clipboard
constructor(parent: ModelElement, rSource: RandomIfc, name: String? = null)

Properties

Link copied to clipboard

If true, the stream will automatically participate in having its stream advanced to the next sub-stream via stream managers

Link copied to clipboard

A flag to control whether the model element reacts to after experiment actions.

Link copied to clipboard

A flag to control whether the model element reacts to after replication actions.

Link copied to clipboard
override var antithetic: Boolean

Tells the stream to start producing antithetic variates

Link copied to clipboard

A flag to control whether the model element reacts to before experiment actions.

Link copied to clipboard

A flag to control whether the model element reacts to before replication actions.

Link copied to clipboard

Indicates the current status of the model element for observers of ModelElement.Status

Link copied to clipboard
open override val id: Int
Link copied to clipboard

A flag to control whether the model element reacts to initialization actions

Link copied to clipboard
open override var initialRandomSource: RandomIfc

Provides a reference to the underlying source of randomness to initialize each replication. Controls the underlying RandomIfc source for the element. This is the source to which each replication will be initialized. This is only used when the replication is initialized. Changing the reference has no effect during a replication.

Link copied to clipboard

Controls whether warning of changing the initial random source during a replication is logged, default is true.

Link copied to clipboard
open override var label: String?
Link copied to clipboard

the left traversal count for pre-order traversal of the model element tree

Link copied to clipboard

the model that contains this element

Link copied to clipboard

Returns a string representation of the model element and its child model elements. Useful for realizing the model element hierarchy.

Link copied to clipboard

A flag to control whether the model element participates in monte carlo actions.

Link copied to clipboard
override val name: String
Link copied to clipboard

Gets the number of model elements contained by this model elements.

Link copied to clipboard

Indicates the previous status of the model element for observers of ModelElement.Status This allows the transition to be noted by observers

Link copied to clipboard
open override var previousValue: Double

The previous value from the sequence of values a double representing the last value in the sequence

Link copied to clipboard

Provides a reference to the underlying source of randomness during the replication. Controls the underlying RandomIfc source. This changes the source for the current replication only. The random variable will start to use this source immediately; however if a replication is started after this method is called, the random source will be reassigned to the initial random source before the next replication is executed. To change the random source for the entire experiment (all replications) use the initialRandomSource property

Link copied to clipboard

A flag to control whether the model element reacts to end replication actions.

Link copied to clipboard

If true, the stream will automatically participate in having its stream reset to its start stream via stream managers

Link copied to clipboard

the right traversal count for pre-order traversal of the model element tree

Link copied to clipboard
override var rnStream: RNStreamIfc

The random number stream for the current replication based on the current setting of property randomSource. If the underlying stream is changed, the change will only be in effect for the current replication and no stream control will take place based on the model's control of streams.

Link copied to clipboard

The spatial model associated with this model element. By default, each model element uses its parent model element's spatial model unless changed via this property. This changes the spatial model for this model element and no others.

Link copied to clipboard
open val streamNumber: Int
Link copied to clipboard

The current simulation time

Link copied to clipboard

The time interval between TimedUpdate events. The default is zero, indicating no timed update

Link copied to clipboard

Specifies whether this model element participates in time update event specified by its parent

Link copied to clipboard

Specifies the havingPriority of this model element's timed update event.

Link copied to clipboard
open val value: Double
Link copied to clipboard

Indicates whether the warm-up action occurred sometime during the simulation for this model element. False indicates that the warm-up action has not occurred

Link copied to clipboard

Specifies if this model element will be warmed up when the warmup action occurs for its parent. The warm-up flag indicates whether this model element will be warmed up when its parent warm up event/action occurs. The default value for all model elements is true. A value of true implies that the model element allows its parent's warm up event to call the warm-up action. A value of false implies that the model element does not allow its parent's warm up event to call the warm-up action. False does not necessarily mean that the model element will not be warmed up. It may, through the use of the lengthOfWarmUp property, have its own warm up event and action.

Link copied to clipboard

Specifies the priority of this model element's warm up event.

Functions

Link copied to clipboard
override fun advanceToNextSubStream()

Positions the RNG at the beginning of its next substream

Link copied to clipboard
open override fun asString(): String
Link copied to clipboard

Cancels the timed update event for this model element.

Link copied to clipboard

Cancels the warm-up event for this model element.

Link copied to clipboard

Checks if this model element or any model element directly above this model element in the hierarchy of model elements all the way until the top Model participates in the warm-up action.

Link copied to clipboard
fun day(): Double

Returns the value of a 1-day time interval in terms of the base time unit

Link copied to clipboard

Find the first parent that has its own warm up event this guarantees that all elements below the found model element do not have their own warm-up event. A model element that has its own warm up event also opts out of the warm-up action. If the returned parent is the Model, then all are controlled by the model (unless they opt out). Elements can opt out and not have their own warm-up event. Thus, they have no warm up at all.

Link copied to clipboard

Fills up the supplied StringBuilder carrying a string representation of the model element and its child model elements Useful for realizing the model element hierarchy.

Link copied to clipboard

This method returns the planned time for the warm-up for this model element.

Link copied to clipboard
fun hour(): Double

Returns the value of a 1-hour time interval in terms of the base time unit

Link copied to clipboard

Fills a StringBuilder carrying the model element names in the order that they will be initialized

Link copied to clipboard

Checks if a warm-up event is scheduled for any model element directly above this model element in the hierarchy of model elements all the way until the top Model.

Link copied to clipboard

Checks if current status is the supplied status

Link copied to clipboard

Checks if a timed update event has been scheduled for this model element

Link copied to clipboard

Checks if a warm-up event has been scheduled for this model element

Link copied to clipboard

Returns the value of a 1 millisecond time interval in terms of the base time unit

Link copied to clipboard
fun minute(): Double

Returns the value of a 1-minute time interval in terms of the base time unit. For example, if the time unit is set to hours, then minute() should return 0.0166 (TIME_UNIT_MINUTE/TIME_UNIT_HOUR)

Link copied to clipboard
override fun resetStartStream()

The resetStartStream method will position the RNG at the beginning of its stream. This is the same location in the stream as assigned when the RNG was created and initialized.

Link copied to clipboard
override fun resetStartSubStream()

Resets the position of the RNG at the start of the current substream

Link copied to clipboard
override fun sample(): Double

open fun sample(sampleSize: Int): DoubleArray

Generates a random generated sample of the give size

Link copied to clipboard
open fun sampleAsColumns(sampleSize: Int, nCols: Int = 1): Array<DoubleArray>

Generates the number of columns nCols with each column holding a random sample of size sampleSize

Link copied to clipboard
open fun sampleAsRows(sampleSize: Int, nRows: Int = 1): Array<DoubleArray>

Generates the number of rows nRows with each row holding a random sample of size sampleSize

Link copied to clipboard
open fun sampleInto(matrix: Array<DoubleArray>)

Fills the supplied matrix with randomly generated values

open fun sampleInto(values: DoubleArray)

Fills the supplied array with randomly generated values

Link copied to clipboard
fun second(): Double

Returns the value of a 1-second time interval in terms of the base time unit

Link copied to clipboard

Sets the after experiment option of all model elements (children) contained by this model element.

Sets the after replication flag of all model elements (children) contained by this model element.

Sets the before experiment option of all model elements (children) contained by this model element.

Sets the before replication flag of all model elements (children) contained by this model element.

Link copied to clipboard

Sets the initialization option of all model elements (children) contained by this model element.

Link copied to clipboard

Sets the monte carlo option flag of all model elements (children) contained by this model element.

Sets the end replication option flag of all model elements (children) contained by this model element. Determines whether the replicationEnded() method will be called

Link copied to clipboard

Sets the timed update option flag of all model elements (children) contained by this model element.

Link copied to clipboard

Sets the warm-up option flag of all model elements (children) contained by this model element.

Link copied to clipboard
open fun sum(numInSum: Int): Double
Link copied to clipboard
open override fun toString(): String

Includes the model name, the id, the model element name, the parent name, and parent id

Link copied to clipboard
open fun useStreamNumber(streamNumber: Int)

Assigns the stream associated with the supplied number from the default RNStreamProvider

Link copied to clipboard
override fun value(): Double

This method simply returns the value.

Link copied to clipboard
fun week(): Double

Returns the value of a 1-week time interval in terms of the base time unit