TWResponse

open class TWResponse @JvmOverloads constructor(parent: ModelElement, name: String? = null, initialValue: Double = 0.0, allowedDomain: Interval = Interval(0.0, Double.POSITIVE_INFINITY), countLimit: Double = Double.POSITIVE_INFINITY) : Response, TimeWeightedIfc, TWResponseCIfc(source)

A time-weighted response represents a time-persistent type variable for which time-based statistics are automatically collected when the value of the response variable is assigned.

How it Works:

Unlike a Counter, which just sums values, a TWResponse calculates the area under the curve of the variable's value over time divided by the total time. This is done by tracking the previous value and the time of the last change. Whenever the value is updated, it calculates the weight (time since last change) and collects the previous value with that weight into the within-replication statistic.

Statistical Persistence:

  • Warm-up: When warmUp is called, the accumulated area is cleared, but the current value is retained to start the fresh statistics.

  • Replication End: The replicationEnded method automatically performs a final "update" to ensure the area from the last change until the end of the simulation is captured.

Parameters

parent

the parent model element containing this response

name

the unique name of the response. If a name is not assigned (null), a name will be assigned. A common naming convention would be to name the response based on the parent's name to ensure uniqueness within the context of the parent. For example, "${this.name}:SomeResponseName", where "this" refers to the parent.

initialValue

this is the initial value of the response variable. It is only used internally.

allowedDomain

This is an interval that defines the set of legal values for the response. By default, this is [0, POSITIVE_INFINITY). If supplied, this provides a method to check if invalid values are assigned to the response. For example, if the response represents time, you might want to change the allowed domain to not include negative values.

countLimit

specifies a limit that when reached will cause counter-actions to be invoked. By default, this is POSITIVE_INFINITY. A common count action would be to stop the simulation when a particular number of observations have been reached. By default, there are no count actions. Thus, if a count limit is specified, the user is responsible for providing what to do via the functions that add count actions. Otherwise, no actions occur when the limit is reached.

Inheritors

Constructors

Link copied to clipboard
constructor(parent: ModelElement, name: String? = null, initialValue: Double = 0.0, allowedDomain: Interval = Interval(0.0, Double.POSITIVE_INFINITY), countLimit: Double = Double.POSITIVE_INFINITY)

Properties

Link copied to clipboard
@set:KSLControl(controlType = ControlType.DOUBLE, name = "initialValue", lowerBound = 0.0)
open override var initialValue: Double

Sets the initial value of the variable. Only relevant prior to each replication. Changing during a replication has no effect until the next replication.

Link copied to clipboard
open override var previousTimeOfChange: Double
Link copied to clipboard
open override var previousValue: Double

The previous value, before the current value changed

Link copied to clipboard
open override var timeOfChange: Double
Link copied to clipboard
open override val weight: Double

Functions

Link copied to clipboard
protected open override fun assignInitialValue(value: Double)

Assigns the value of the variable to the supplied value. Ensures that time of change is 0.0 and previous value and previous time of change are the same as the current value and current time without notifying any update observers

Link copied to clipboard
protected open override fun assignValue(newValue: Double)
Link copied to clipboard
protected open override fun beforeExperiment()

This method should be overridden by subclasses that need logic to be performed prior to an experiment. The beforeExperiment method allows model elements to be set up prior to the first replication within an experiment. It is called once before any replications occur.

Link copied to clipboard
protected open override fun beforeReplication()

This method should be overridden by subclasses that need actions performed prior to each replication. It is called prior to each replication and can be used to initialize the model element. It is called before initialize() is called.

Link copied to clipboard
fun decrement(decrease: Double = 1.0)

Decrements the value of the variable by the amount supplied. Throws an IllegalArgumentException if the value is negative.

Link copied to clipboard
fun increment(increase: Double = 1.0)

Increments the value of the variable by the amount supplied. Throws an IllegalArgumentException if the value is negative.

Link copied to clipboard
protected open override fun initialize()

This method should be overridden by subclasses that need actions performed to initialize prior to a replication. It is called once before each replication occurs if the model element wants initialization. It is called after beforeReplication() is called

Link copied to clipboard
protected open override fun replicationEnded()

This method should be overridden by subclasses that need actions performed when the replication ends and prior to the calling of afterReplication(). It is called when each replication ends and can be used to collect data from the model element, etc.

Link copied to clipboard
protected open override fun timedUpdate()

This method should be overridden by subclasses that need actions performed at each timed update event during each replication. It is called for each timed update during each replication if the model element reacts to timed update actions.

Link copied to clipboard
protected open override fun warmUp()

This method should be overridden by subclasses that need actions performed at the warm-up event during each replication. It is called once during each replication if the model element reacts to warm-up actions.