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 intCOUNTER_LIMIT_REACHEDAn "enum" for the counter state.protected ResponseVariablemyAcrossIntervalResponseA 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 StatisticmyAcrossRepStatStatistic used to collect the across replication statistics on the final value of the counter for each replicationprotected doublemyCountAtPreviousTimedUpdateRemembers the count at the previous timed updateprotected java.util.Collection<CounterActionListenerIfc>myCounterActionsA collection containing the counter actions for the counterprotected booleanmyCountLimitFlagIndicates that the limit has not yet been reachedprotected doublemyInitialValueThe initial value of the counterprotected doublemyLastUpdateTimeTime of last update intervalprotected doublemyLimitSets a limit for the counter to fire an actionprotected doublemyPrevTimeOfChangeThe previous time that the counter changedprotected doublemyPrevValueThe previous value of the counterprotected doublemyTimeOfChangeThe time that the counter changedprotected doublemyTimeOfWarmUpThe time of the warm up if it occurs, 0.0 otherwiseprotected doublemyTotalDuringTimedUpdateRemembers the total during a timed updateprotected doublemyValueThe 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 booleanaddCounterActionListener(CounterActionListenerIfc action)Adds a counter action listener.voidaddStoppingAction()Tells the Counter to add an CounterActionIfc that will automatically stop the replication when the counter limit is reached.protected voidafterReplication()This method should be overridden by subclasses that need actions performed after each replication.protected voidbeforeExperiment()This method should be overridden by subclasses that need logic to be performed prior to an experiment.booleancheckForCounterLimitReachedState()Returns true if the counter's last observer state is equal to COUNTER_LIMIT_REACHEDResponseVariablegetAcrossIntervalResponse()If the time interval collection is turned on a ResponseVariable is created for capturing statistics across the intervals.StatisticAccessorIfcgetAcrossReplicationStatistic()Gets a copy of the statistics that have been accumulated across all replications for this variable.doublegetCounterActionLimit()doublegetCounterLimit()The limit used to trigger counter actionsbooleangetDefaultReportingOption()Returns the default reporting option.doublegetInitialValue()Returns the value used to initialize the counter prior to each replicationdoublegetPreviousTimeOfChange()The time that it changed before the getValue() was setdoublegetPreviousValue()Gets the previous number from the sequence of valuesdoublegetTimeOfChange()The time that the counter was set to getValue()doublegetTotalDuringTimedUpdate()The amount the counter changed during the timed updatedoublegetValue()This method simply returns the value.voidincrement()Increments the value of the variable by 1 at the current time.voidincrement(double value)Increments the value of the variable by the amount supplied.protected voidinitialize()Resets the counter and notifies any initialization observersprotected voidnotifyCounterActions()protected voidnotifyCounterLimitReachedObservers()The method is used to notify observers that this model element has triggered its counter limitprotected voidnotifyUpdateObservers()The method is used to notify observers that this model element has been updated.booleanremoveCounterActionListener(CounterActionListenerIfc action)Removes the counter action listenerprotected voidremovedFromModel()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.voidresetCounter(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.voidresetCounter(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.voidsetCountBasedStopLimit(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.voidsetCounterActionLimit(long limit)Use to set the counter limitvoidsetDefaultReportingOption(boolean flag)Sets the default reporting option.protected voidsetInitialValue(long initialValue)Sets the initial value of the counter.protected voidsetValue(double value)Sets the value of the counter, ensures a check against the limit Does not notify any update observersprotected voidtimedUpdate()This method should be overridden by subclasses that need actions performed at each timed update event during each replication.voidturnOnTimeIntervalCollection(double interval)Turns on the collection of statistics across intervals of time, defined by the interval lengthvoidturnOnTimeIntervalTrace()Turns on tracing to a file of the time interval response if and only if time interval collection has been turned onvoidturnOnTimeIntervalTrace(boolean header)Turns on tracing to a file of the time interval response if and only if time interval collection has been turned onvoidturnOnTimeIntervalTrace(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 onvoidturnOnTimeIntervalTrace(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 voidwarmUp()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:GetValueIfcThis method simply returns the value.- Specified by:
getValuein interfaceGetValueIfc- Returns:
- The value.
-
getPreviousValue
public final double getPreviousValue()
Description copied from interface:PreviousValueIfcGets the previous number from the sequence of values- Specified by:
getPreviousValuein 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:
getCounterActionLimitin 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:CounterActionIfcReturns true if the counter's last observer state is equal to COUNTER_LIMIT_REACHED- Specified by:
checkForCounterLimitReachedStatein interfaceCounterActionIfc- Returns:
-
addStoppingAction
public final void addStoppingAction()
Description copied from interface:CounterActionIfcTells the Counter to add an CounterActionIfc that will automatically stop the replication when the counter limit is reached.- Specified by:
addStoppingActionin interfaceCounterActionIfc
-
addCounterActionListener
public final boolean addCounterActionListener(CounterActionListenerIfc action)
Description copied from interface:CounterActionIfcAdds a counter action listener. It will be called if the counter's limit is set and it is reached.- Specified by:
addCounterActionListenerin interfaceCounterActionIfc- Returns:
-
removeCounterActionListener
public final boolean removeCounterActionListener(CounterActionListenerIfc action)
Description copied from interface:CounterActionIfcRemoves the counter action listener- Specified by:
removeCounterActionListenerin 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:
setDefaultReportingOptionin 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:
getDefaultReportingOptionin 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:ModelElementThis 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:
beforeExperimentin classModelElement
-
initialize
protected void initialize()
Resets the counter and notifies any initialization observers- Overrides:
initializein classModelElement
-
afterReplication
protected void afterReplication()
Description copied from class:ModelElementThis method should be overridden by subclasses that need actions performed after each replication. It is called after replicationEnded() has been called.- Overrides:
afterReplicationin classModelElement
-
warmUp
protected void warmUp()
Initialize the value to zero at the warm up time and notify warm up observers- Overrides:
warmUpin classModelElement
-
timedUpdate
protected void timedUpdate()
Description copied from class:ModelElementThis 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:
timedUpdatein 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:
notifyUpdateObserversin classModelElement
-
removedFromModel
protected void removedFromModel()
Description copied from class:AggregatableThis 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:
removedFromModelin classAggregatable
-
-