Package jsl.modeling.elements.variable
Class Counter
- java.lang.Object
-
- jsl.simulation.ModelElement
-
- jsl.modeling.elements.variable.Aggregatable
-
- jsl.modeling.elements.variable.Counter
-
- All Implemented Interfaces:
CounterActionIfc
,DefaultReportingOptionIfc
,ObservableIfc
,GetNameIfc
,GetValueIfc
,IdentityIfc
,PreviousValueIfc
public class Counter extends Aggregatable implements CounterActionIfc, DefaultReportingOptionIfc
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class jsl.simulation.ModelElement
ModelElement.EventBuilderIfc<T>, ModelElement.EventScheduler<T>, ModelElement.ModelElementComparator, ModelElement.RequestBuilder, ModelElement.RequestDurationIfc, ModelElement.RequestTimeIfc, ModelElement.RequestUsingIfc, ModelElement.TimedUpdateEventAction, ModelElement.TimeUnitIfc<T>, ModelElement.WarmUpEventAction
-
-
Field Summary
Fields Modifier and Type Field Description static int
COUNTER_LIMIT_REACHED
An "enum" for the counter state.protected ResponseVariable
myAcrossIntervalResponse
A Counter can have a timed update action during a replication This response collects the average of the total count during each timed update interval.protected Statistic
myAcrossRepStat
Statistic used to collect the across replication statistics on the final value of the counter for each replicationprotected double
myCountAtPreviousTimedUpdate
Remembers the count at the previous timed updateprotected java.util.Collection<CounterActionListenerIfc>
myCounterActions
A collection containing the counter actions for the counterprotected boolean
myCountLimitFlag
Indicates that the limit has not yet been reachedprotected double
myInitialValue
The initial value of the counterprotected double
myLastUpdateTime
Time of last update intervalprotected double
myLimit
Sets a limit for the counter to fire an actionprotected double
myPrevTimeOfChange
The previous time that the counter changedprotected double
myPrevValue
The previous value of the counterprotected double
myTimeOfChange
The time that the counter changedprotected double
myTimeOfWarmUp
The time of the warm up if it occurs, 0.0 otherwiseprotected double
myTotalDuringTimedUpdate
Remembers the total during a timed updateprotected double
myValue
The current value of the counter-
Fields inherited from class jsl.modeling.elements.variable.Aggregatable
myAggregates
-
Fields inherited from class jsl.simulation.ModelElement
AFTER_EXPERIMENT, AFTER_REPLICATION, BEFORE_EXPERIMENT, BEFORE_REPLICATION, CONDITIONAL_ACTION_REGISTRATION, DEFAULT_TIMED_EVENT_PRIORITY, INITIALIZED, MONTE_CARLO, myAfterExperimentOption, myAfterReplicationOption, myBeforeExperimentOption, myBeforeReplicationOption, myInitializationOption, myLengthOfWarmUp, myModelElements, myMonteCarloOption, myObservableComponent, myReplicationEndedOption, myTimedUpdateActionListener, myTimedUpdateEvent, myTimedUpdateInterval, myTimedUpdateOption, myTimedUpdatePriority, myWarmUpActionListener, myWarmUpEvent, myWarmUpIndicator, myWarmUpOption, myWarmUpPriority, NONE, REMOVED_FROM_MODEL, REPLICATION_ENDED, TIME_UNIT_DAY, TIME_UNIT_HOUR, TIME_UNIT_MILLISECOND, TIME_UNIT_MINUTE, TIME_UNIT_SECOND, TIME_UNIT_WEEK, TIMED_UPDATE, UPDATE, WARMUP
-
-
Constructor Summary
Constructors Constructor Description Counter(ModelElement parent)
Counter(ModelElement parent, long limit)
Counter(ModelElement parent, long initialValue, long limit)
Counter(ModelElement parent, long initialValue, long limit, java.lang.String name)
Counter(ModelElement parent, long limit, java.lang.String name)
Counter(ModelElement parent, java.lang.String name)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description boolean
addCounterActionListener(CounterActionListenerIfc action)
Adds a counter action listener.void
addStoppingAction()
Tells the Counter to add an CounterActionIfc that will automatically stop the replication when the counter limit is reached.protected void
afterReplication()
This method should be overridden by subclasses that need actions performed after each replication.protected void
beforeExperiment()
This method should be overridden by subclasses that need logic to be performed prior to an experiment.boolean
checkForCounterLimitReachedState()
Returns true if the counter's last observer state is equal to COUNTER_LIMIT_REACHEDResponseVariable
getAcrossIntervalResponse()
If the time interval collection is turned on a ResponseVariable is created for capturing statistics across the intervals.StatisticAccessorIfc
getAcrossReplicationStatistic()
Gets a copy of the statistics that have been accumulated across all replications for this variable.double
getCounterActionLimit()
double
getCounterLimit()
The limit used to trigger counter actionsboolean
getDefaultReportingOption()
Returns the default reporting option.double
getInitialValue()
Returns the value used to initialize the counter prior to each replicationdouble
getPreviousTimeOfChange()
The time that it changed before the getValue() was setdouble
getPreviousValue()
Gets the previous number from the sequence of valuesdouble
getTimeOfChange()
The time that the counter was set to getValue()double
getTotalDuringTimedUpdate()
The amount the counter changed during the timed updatedouble
getValue()
This method simply returns the value.void
increment()
Increments the value of the variable by 1 at the current time.void
increment(double value)
Increments the value of the variable by the amount supplied.protected void
initialize()
Resets the counter and notifies any initialization observersprotected void
notifyCounterActions()
protected void
notifyCounterLimitReachedObservers()
The method is used to notify observers that this model element has triggered its counter limitprotected void
notifyUpdateObservers()
The method is used to notify observers that this model element has been updated.boolean
removeCounterActionListener(CounterActionListenerIfc action)
Removes the counter action listenerprotected void
removedFromModel()
This method should be overridden by subclasses that need actions performed when a model element is removed from a model after the replication has started.void
resetCounter(double value, boolean notifyUpdateObservers)
Resets the counter to the supplied value and clears the counter limit flag If timed updates are on, then count since the last timed update will be set to the supplied value.void
resetCounter(long value)
Resets the counter to the supplied value and clears the counter limit flag If timed updates are on, then count since the last timed update will be set to the supplied value.void
setCountBasedStopLimit(double countLimit)
Sets the count limit for determining when the count based stopping should occur If countLimit is less than or equal to current count when set then the action will occur the next time that the variable changes Sets a limit and adds a stopping action.void
setCounterActionLimit(long limit)
Use to set the counter limitvoid
setDefaultReportingOption(boolean flag)
Sets the default reporting option.protected void
setInitialValue(long initialValue)
Sets the initial value of the counter.protected void
setValue(double value)
Sets the value of the counter, ensures a check against the limit Does not notify any update observersprotected void
timedUpdate()
This method should be overridden by subclasses that need actions performed at each timed update event during each replication.void
turnOnTimeIntervalCollection(double interval)
Turns on the collection of statistics across intervals of time, defined by the interval lengthvoid
turnOnTimeIntervalTrace()
Turns on tracing to a file of the time interval response if and only if time interval collection has been turned onvoid
turnOnTimeIntervalTrace(boolean header)
Turns on tracing to a file of the time interval response if and only if time interval collection has been turned onvoid
turnOnTimeIntervalTrace(java.lang.String fileName)
Turns on tracing to a file of the time interval response if and only if time interval collection has been turned onvoid
turnOnTimeIntervalTrace(java.lang.String fileName, boolean header)
Turns on tracing to a file of the time interval response if and only if time interval collection has been turned onprotected void
warmUp()
Initialize the value to zero at the warm up time and notify warm up observers-
Methods inherited from class jsl.modeling.elements.variable.Aggregatable
attachAggregate, detachAggregate, initialize_, notifyAggregatesOfInitialization, notifyAggregatesOfModelRemoval, notifyAggregatesOfValueChange, notifyAggregatesOfWarmUp, warmUp_
-
Methods inherited from class jsl.simulation.ModelElement
addObserver, addObserverToModelElements, afterExperiment, afterExperiment_, afterReplication_, asString, beforeExperiment_, beforeReplication, beforeReplication_, buildEventGenerator, cancelTimedUpdateEvent, cancelWarmUpEvent, changeParentModelElement, checkForAfterExperiment, checkForAfterReplication, checkForBeforeExperiment, checkForBeforeReplication, checkForConditionalActionRegistration, checkForInitialize, checkForMonteCarlo, checkForRemoveFromModel, checkForReplicationEnded, checkForTimedUpdate, checkForUpdate, checkForWarmUp, checkObserverState, checkWarmUpOption, clearModelElementObservers, contains, countObservers, createEntity, createEntity, createQObject, day, deleteObserver, deleteObserverFromModelElements, deleteObservers, findModelElementWithWarmUpEvent, getAfterExperimentOption, getAfterReplicationOption, getAllCounters, getAllModelElements, getAllRandomElements, getAllResponseVariables, getAllVariables, getBeforeExperimentOption, getBeforeReplicationOption, getChildModelElementIterator, getCurrentReplicationNumber, getDefaultEntityType, getExecutive, getExperiment, getId, getInitializationOption, getInitializationOrderAsString, getLeftPreOrderTraversalCount, getLengthOfWarmUp, getModel, getModelElementCompartor, getModelElementsAsString, getModelElementsAsString, getModelElementsAsString, getMonteCarloOption, getName, getNumberOfModelElements, getObserverState, getParentModelElement, getPreviousObserverState, getReplicationEndedOption, getRightPreOrderTraversalCount, getSimulation, getSpatialModel, getStringLabel, getThisElementsCounters, getThisElementsModelElements, getThisElementsRandomVariables, getThisElementsResponseVariables, getThisElementsVariables, getTime, getTimedUpdateInterval, getTimedUpdateOption, getUpdateNotificationFlag, getVariable, getWarmUpEventTime, getWarmUpOption, hour, indent, isTimedUpdateEventScheduled, isWarmedUp, isWarmUpEventScheduled, isWarmUpScheduled, millisecond, minute, montecarlo, montecarlo_, notifyAfterExperimentObservers, notifyAfterReplicationObservers, notifyBeforeExperimentObservers, notifyBeforeReplicationObservers, notifyConditionalActionRegistrationObservers, notifyInitializationObservers, notifyMonteCarloObservers, notifyObservers, notifyObservers, notifyRemovingFromModelObservers, notifyReplicationEndedObservers, notifyTimedUpdateObservers, notifyWarmUpObservers, registerConditionalActions, registerConditionalActions_, removeFromModel, replicationEnded, replicationEnded_, schedule, second, seize, setAfterExperimentOption, setAfterExperimentOptionForModelElements, setAfterReplicationOption, setAfterReplicationOptionForModelElements, setBeforeExperimentOption, setBeforeExperimentOptionForModelElements, setBeforeReplicationOption, setBeforeReplicationOptionForModelElements, setInitializationOption, setInitializationOptionForModelElements, setLengthOfWarmUp, setModel, setMonteCarloOption, setMonteCarloOptionForModelElements, setName, setObserverState, setParentModelElement, setReplicationEndedOption, setReplicationEndedOptionForModelElements, setSpatialModel, setStringLabel, setTimedUpdateInterval, setTimedUpdateOption, setTimedUpdateOptionForModelElements, setUpdateNotificationFlag, setWarmUpOption, setWarmUpOptionForModelElements, stopExecutive, stopExecutive, timedUpdate_, toString, update, useControls, week
-
-
-
-
Field Detail
-
COUNTER_LIMIT_REACHED
public static final int COUNTER_LIMIT_REACHED
An "enum" for the counter state.
-
myInitialValue
protected double myInitialValue
The initial value of the counter
-
myValue
protected double myValue
The current value of the counter
-
myPrevValue
protected double myPrevValue
The previous value of the counter
-
myTimeOfChange
protected double myTimeOfChange
The time that the counter changed
-
myPrevTimeOfChange
protected double myPrevTimeOfChange
The previous time that the counter changed
-
myLimit
protected double myLimit
Sets a limit for the counter to fire an action
-
myCountLimitFlag
protected boolean myCountLimitFlag
Indicates that the limit has not yet been reached
-
myCounterActions
protected java.util.Collection<CounterActionListenerIfc> myCounterActions
A collection containing the counter actions for the counter
-
myCountAtPreviousTimedUpdate
protected double myCountAtPreviousTimedUpdate
Remembers the count at the previous timed update
-
myTotalDuringTimedUpdate
protected double myTotalDuringTimedUpdate
Remembers the total during a timed update
-
myAcrossRepStat
protected Statistic myAcrossRepStat
Statistic used to collect the across replication statistics on the final value of the counter for each replication
-
myAcrossIntervalResponse
protected ResponseVariable myAcrossIntervalResponse
A Counter can have a timed update action during a replication This response collects the average of the total count during each timed update interval. For example, a timed update interval of 1 hour can be set. Each hour this response will observe the count for that hour and collect averages across the timed update intervals
-
myLastUpdateTime
protected double myLastUpdateTime
Time of last update interval
-
myTimeOfWarmUp
protected double myTimeOfWarmUp
The time of the warm up if it occurs, 0.0 otherwise
-
-
Constructor Detail
-
Counter
public Counter(ModelElement parent)
- Parameters:
parent
-
-
Counter
public Counter(ModelElement parent, long limit)
- Parameters:
parent
-limit
-
-
Counter
public Counter(ModelElement parent, long initialValue, long limit)
- Parameters:
parent
-initialValue
-limit
-
-
Counter
public Counter(ModelElement parent, java.lang.String name)
- Parameters:
parent
-name
-
-
Counter
public Counter(ModelElement parent, long limit, java.lang.String name)
- Parameters:
parent
-limit
-name
-
-
Counter
public Counter(ModelElement parent, long initialValue, long limit, java.lang.String name)
- Parameters:
parent
-initialValue
-limit
-name
-
-
-
Method Detail
-
getCounterLimit
public final double getCounterLimit()
The limit used to trigger counter actions- Returns:
-
setCountBasedStopLimit
public final void setCountBasedStopLimit(double countLimit)
Sets the count limit for determining when the count based stopping should occur If countLimit is less than or equal to current count when set then the action will occur the next time that the variable changes Sets a limit and adds a stopping action. The executive will be stopped when the limit is reached.- Parameters:
countLimit
- must be >=0, zero implies no count limit
-
setInitialValue
protected final void setInitialValue(long initialValue)
Sets the initial value of the counter. It might start at a value greater than 1 prior to the simulation. This value will be used to initialize the counter prior to each replication- Parameters:
initialValue
-
-
getInitialValue
public final double getInitialValue()
Returns the value used to initialize the counter prior to each replication- Returns:
-
increment
public final void increment()
Increments the value of the variable by 1 at the current time.
-
increment
public final void increment(double value)
Increments the value of the variable by the amount supplied. Throws an IllegalArgumentException if the value is negative.- Parameters:
value
- The amount to increment by. Must be non-negative.
-
getValue
public final double getValue()
Description copied from interface:GetValueIfc
This method simply returns the value.- Specified by:
getValue
in interfaceGetValueIfc
- Returns:
- The value.
-
getPreviousValue
public final double getPreviousValue()
Description copied from interface:PreviousValueIfc
Gets the previous number from the sequence of values- Specified by:
getPreviousValue
in interfacePreviousValueIfc
- Returns:
- a double representing the last value in the sequence
-
getPreviousTimeOfChange
public double getPreviousTimeOfChange()
The time that it changed before the getValue() was set- Returns:
- the PrevTimeOfChange
-
getTimeOfChange
public double getTimeOfChange()
The time that the counter was set to getValue()- Returns:
- the TimeOfChange
-
getCounterActionLimit
public final double getCounterActionLimit()
- Specified by:
getCounterActionLimit
in interfaceCounterActionIfc
- Returns:
- Returns the counter's limit.
-
setCounterActionLimit
public final void setCounterActionLimit(long limit)
Use to set the counter limit- Parameters:
limit
- , must be > 0
-
getTotalDuringTimedUpdate
public final double getTotalDuringTimedUpdate()
The amount the counter changed during the timed update- Returns:
- Returns the totalDuringTimedUpdate.
-
checkForCounterLimitReachedState
public final boolean checkForCounterLimitReachedState()
Description copied from interface:CounterActionIfc
Returns true if the counter's last observer state is equal to COUNTER_LIMIT_REACHED- Specified by:
checkForCounterLimitReachedState
in interfaceCounterActionIfc
- Returns:
-
addStoppingAction
public final void addStoppingAction()
Description copied from interface:CounterActionIfc
Tells the Counter to add an CounterActionIfc that will automatically stop the replication when the counter limit is reached.- Specified by:
addStoppingAction
in interfaceCounterActionIfc
-
addCounterActionListener
public final boolean addCounterActionListener(CounterActionListenerIfc action)
Description copied from interface:CounterActionIfc
Adds a counter action listener. It will be called if the counter's limit is set and it is reached.- Specified by:
addCounterActionListener
in interfaceCounterActionIfc
- Returns:
-
removeCounterActionListener
public final boolean removeCounterActionListener(CounterActionListenerIfc action)
Description copied from interface:CounterActionIfc
Removes the counter action listener- Specified by:
removeCounterActionListener
in interfaceCounterActionIfc
- Returns:
-
resetCounter
public final void resetCounter(long value)
Resets the counter to the supplied value and clears the counter limit flag If timed updates are on, then count since the last timed update will be set to the supplied value. Notifies update observers of the state change- Parameters:
value
- , must be < getCounterLimit() and >=0
-
resetCounter
public final void resetCounter(double value, boolean notifyUpdateObservers)
Resets the counter to the supplied value and clears the counter limit flag If timed updates are on, then count since the last timed update will be set to the supplied value.- Parameters:
value
- , must be < getCounterLimit() and >=0notifyUpdateObservers
- If true, any update observers will be notified otherwise they will not be notified
-
setDefaultReportingOption
public void setDefaultReportingOption(boolean flag)
Sets the default reporting option. True means the response will appear on default reports- Specified by:
setDefaultReportingOption
in interfaceDefaultReportingOptionIfc
- Parameters:
flag
-
-
getDefaultReportingOption
public boolean getDefaultReportingOption()
Returns the default reporting option. True means that the response should appear on the default reports- Specified by:
getDefaultReportingOption
in interfaceDefaultReportingOptionIfc
- Returns:
-
getAcrossReplicationStatistic
public final StatisticAccessorIfc getAcrossReplicationStatistic()
Gets a copy of the statistics that have been accumulated across all replications for this variable.- Returns:
- A Statistic representing the across replication statistics.
-
getAcrossIntervalResponse
public final ResponseVariable getAcrossIntervalResponse()
If the time interval collection is turned on a ResponseVariable is created for capturing statistics across the intervals. This returns this value or null if time interval collection has not been turned on- Returns:
- the response or null
-
turnOnTimeIntervalCollection
public final void turnOnTimeIntervalCollection(double interval)
Turns on the collection of statistics across intervals of time, defined by the interval length- Parameters:
interval
-
-
turnOnTimeIntervalTrace
public final void turnOnTimeIntervalTrace()
Turns on tracing to a file of the time interval response if and only if time interval collection has been turned on
-
turnOnTimeIntervalTrace
public final void turnOnTimeIntervalTrace(boolean header)
Turns on tracing to a file of the time interval response if and only if time interval collection has been turned on- Parameters:
header
- true means include the header
-
turnOnTimeIntervalTrace
public final void turnOnTimeIntervalTrace(java.lang.String fileName)
Turns on tracing to a file of the time interval response if and only if time interval collection has been turned on- Parameters:
fileName
- the name of the file to write the trace
-
turnOnTimeIntervalTrace
public final void turnOnTimeIntervalTrace(java.lang.String fileName, boolean header)
Turns on tracing to a file of the time interval response if and only if time interval collection has been turned on- Parameters:
fileName
- the name of the file to write the traceheader
- true means include the header
-
setValue
protected void setValue(double value)
Sets the value of the counter, ensures a check against the limit Does not notify any update observers- Parameters:
value
- The value to assign to the counter
-
beforeExperiment
protected void beforeExperiment()
Description copied from class:ModelElement
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 setup prior to the first replication within an experiment. It is called once before any replications occur.- Overrides:
beforeExperiment
in classModelElement
-
initialize
protected void initialize()
Resets the counter and notifies any initialization observers- Overrides:
initialize
in classModelElement
-
afterReplication
protected void afterReplication()
Description copied from class:ModelElement
This method should be overridden by subclasses that need actions performed after each replication. It is called after replicationEnded() has been called.- Overrides:
afterReplication
in classModelElement
-
warmUp
protected void warmUp()
Initialize the value to zero at the warm up time and notify warm up observers- Overrides:
warmUp
in classModelElement
-
timedUpdate
protected void timedUpdate()
Description copied from class:ModelElement
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.- Overrides:
timedUpdate
in classModelElement
-
notifyCounterLimitReachedObservers
protected final void notifyCounterLimitReachedObservers()
The method is used to notify observers that this model element has triggered its counter limit
-
notifyCounterActions
protected final void notifyCounterActions()
-
notifyUpdateObservers
protected void notifyUpdateObservers()
The method is used to notify observers that this model element has been updated.- Overrides:
notifyUpdateObservers
in classModelElement
-
removedFromModel
protected void removedFromModel()
Description copied from class:Aggregatable
This method should be overridden by subclasses that need actions performed when a model element is removed from a model after the replication has started.- Overrides:
removedFromModel
in classAggregatable
-
-