Counter
A Counter tracks cumulative non-negative values over the course of a simulation.
Unlike a standard Variable, a Counter is specifically designed for tally-based metrics (e.g., number of parts produced, number of customers served). It provides built-in support for threshold-based actions, such as stopping the simulation when a target production count is met.
Key Behaviors:
Monotonicity: Increments must be non-negative to ensure the counter represents a cumulative total.
Lifecycle Management: Automatically resets to initialValue at the start of each replication to ensure experimental repeatability.
Threshold Signaling: When the counter reaches replicationCountLimit, it triggers all registered CountActionIfc callbacks.
Across-Replication Statistics: Automatically captures the final value of each replication for higher-level statistical analysis.
Usage Example:
val partsProduced = Counter(this, "PartsProduced", countLimit = 100.0, stopOnLimit = true)
// The simulation will now automatically call executive.stop() when value hits 100.0
partsProduced.increment()Parameters
The ModelElement that owns this counter, typically a Model.
An optional descriptive name for the counter, used in logs and reports.
The value the counter starts with at the beginning of every replication. Defaults to 0.0.
The threshold at which CountActionIfc actions are triggered. Defaults to Double.POSITIVE_INFINITY.
If true, a StoppingAction is automatically attached to this counter, which will terminate the simulation replication once the countLimit is reached. Note: This only applies if countLimit is finite.
Inheritors
Constructors
Properties
Returns a StatisticAccessorIfc for the across replication statistics that have been collected on this Counter
Returns the default reporting option. True means that the response should appear on the default reports
If true, the response will emit a pair Pair(time, value) every time a new value is assigned
Sets the initial value of the count limit. Only relevant prior to each replication. Changing during a replication has no effect until the next replication.
Sets the initial value of the variable. Only relevant prior to each replication. Changing during a replication has no effect until the next replication.
The previous value, before the current value changed
Changes the count action limit during the replication. WARNING: This value will automatically be reset to the initialCountLimit at the beginning of each replication so that each replication starts in the same state. If you want to control the count limit for each replication, you should use the initialCountLimit.
Functions
Assigns the value of the counter 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
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.
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.
Increments the value of the variable by the amount supplied. Throws an IllegalArgumentException if the value is negative.
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
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.
Resets the counter to the supplied value.