Package jsl.modeling.elements.variable
Class Variable
- java.lang.Object
-
- jsl.simulation.ModelElement
-
- jsl.modeling.elements.variable.Aggregatable
-
- jsl.modeling.elements.variable.Variable
-
- All Implemented Interfaces:
GetInitialValueIfc
,GetPreviousTimeOfChangeIfc
,GetTimeOfChangeIfc
,GetWeightIfc
,InitialValueIfc
,SetInitialValueIfc
,SetValueIfc
,TimeWeightedIfc
,VariableIfc
,ObservableIfc
,GetNameIfc
,GetValueIfc
,IdentityIfc
,PreviousValueIfc
- Direct Known Subclasses:
ResponseVariable
public class Variable extends Aggregatable implements VariableIfc
-
-
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 protected double
myInitialValue
Holds the initial value of the variable.protected double
myLowerLimit
Represents the lowest possible value allowed for this variable Attempts to set the value of the variable to < myLowerLimit will throw an exceptionprotected double
myNextValue
The next value of the variable.protected double
myPrevTimeOfChange
The previous time that the variable changedprotected double
myPrevValue
The previous value of the variable.protected double
myTimeOfChange
The time that the variable changedprotected double
myUpperLimit
Represents the lowest possible value allowed for this variable Attempts to set the value of the variable to > myUpperLimit will throw an exceptionprotected double
myValue
The value of the variable.protected VariableTraceTextReport
myVariableTraceTextReport
Holds a reference to an observer that will trace the variable's changesprotected double
myWeight
The weight associated with the change-
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 Variable(ModelElement parent)
Creates a Variable with the given parent with initial value 0.0 over the range [Double.NEGATIVE_INFINITY, Double.POSITIVE_INFINITY]Variable(ModelElement parent, double initialValue)
Creates a Variable with the given name and initial value over the range [Double.NEGATIVE_INFINITY, Double.POSITIVE_INFINITY]Variable(ModelElement parent, double initialValue, double lowerLimit)
Creates a Variable with the initial value over the supplied range [lowerLimit, Double.POSITIVE_INFINITY]Variable(ModelElement parent, double initialValue, double lowerLimit, double upperLimit)
Creates a Variable with the initial value over the supplied range [lowerLimit, upperLimit]Variable(ModelElement parent, double initialValue, double lowerLimit, double upperLimit, java.lang.String name)
Creates a Variable with the given name and initial value over the supplied range [lowerLimit, upperLimit]Variable(ModelElement parent, double initialValue, double lowerLimit, java.lang.String name)
Creates a Variable with the given name and initial value over the supplied range [lowerLimit, Double.POSITIVE_INFINITY]Variable(ModelElement parent, double initialValue, java.lang.String name)
Creates a Variable with the given name and initial value over the supplied range The default range is [Double.NEGATIVE_INFINITY, Double.POSITIVE_INFINITY]Variable(ModelElement parent, java.lang.String name)
Creates a Variable with the given name and initial value, 0.0, over the range [Double.NEGATIVE_INFINITY, Double.POSITIVE_INFINITY]
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected void
assignInitialValue(double value)
Assigns the value of the variable to the supplied value.protected void
assignValue(double value)
Properly assigns the value of the variable and remembers previous value without notifying any update observersjava.lang.String
asString()
Allows sub-classes to provide more detail than toString() to represent the ModelElement as a Stringprotected void
beforeExperiment()
This method should be overridden by subclasses that need logic to be performed prior to an experiment.double
getInitialValue()
Gets the initial value of the variabledouble
getLowerLimit()
The lower limit for the range of this random variabledouble
getPreviousTimeOfChange()
Gets the time associated with previous variable change.double
getPreviousValue()
Gets the previous number value that was assigned before the current valueboolean
getSetValueUpdateNotificationFlag()
Gets the value of the flag that indicates whether or not observers will be notified when the value changes.double
getTimeOfChange()
Gets the time associated with the last value observed.double
getUpperLimit()
The upper limit for the range of this random variabledouble
getValue()
Every Variable must implement the getValue method.double
getWeight()
Gets the weight associated with the last value observed.protected void
initialize()
This method should be overridden by subclasses that need actions performed to initialize prior to a replication.protected 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
setInitialValue(double value)
Sets the initial value of the variable.protected void
setTraceObserver(java.lang.String name, boolean header)
Can be overridden by subclasses to set the protected variable myVariableTraceTextReport for appropriate text tracingvoid
setValue(boolean value)
Maps true to 1.0 and false to 0.0void
setValue(double value)
Sets the value of the variable and notifies any observers of the changevoid
setValueUpdateNotificationFlag(boolean flag)
Turns off or on the notification of update observers for changes to the value of the variable.protected void
setWeight()
Sets the weightvoid
turnOffTrace()
Turns off the automatic tracing of this variable to a text file.void
turnOnTrace()
Turns on the automatic tracing of this variable to a text file with the default name and no headervoid
turnOnTrace(boolean header)
Turns on the automatic tracing of this variable to a text filevoid
turnOnTrace(java.lang.String fileName)
Turns on the automatic tracing of this variable to a text filevoid
turnOnTrace(java.lang.String name, boolean header)
Turns on the automatic tracing of this variable to a text fileprotected void
warmUp()
This method should be overridden by subclasses that need actions performed at the warm up event during each replication.-
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, afterReplication_, 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, notifyUpdateObservers, 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, timedUpdate_, toString, update, useControls, week
-
-
-
-
Field Detail
-
myLowerLimit
protected double myLowerLimit
Represents the lowest possible value allowed for this variable Attempts to set the value of the variable to < myLowerLimit will throw an exception
-
myUpperLimit
protected double myUpperLimit
Represents the lowest possible value allowed for this variable Attempts to set the value of the variable to > myUpperLimit will throw an exception
-
myValue
protected double myValue
The value of the variable.
-
myInitialValue
protected double myInitialValue
Holds the initial value of the variable.
-
myPrevValue
protected double myPrevValue
The previous value of the variable.
-
myNextValue
protected double myNextValue
The next value of the variable.
-
myTimeOfChange
protected double myTimeOfChange
The time that the variable changed
-
myPrevTimeOfChange
protected double myPrevTimeOfChange
The previous time that the variable changed
-
myWeight
protected double myWeight
The weight associated with the change
-
myVariableTraceTextReport
protected VariableTraceTextReport myVariableTraceTextReport
Holds a reference to an observer that will trace the variable's changes
-
-
Constructor Detail
-
Variable
public Variable(ModelElement parent)
Creates a Variable with the given parent with initial value 0.0 over the range [Double.NEGATIVE_INFINITY, Double.POSITIVE_INFINITY]- Parameters:
parent
- the variable's parent model element.
-
Variable
public Variable(ModelElement parent, double initialValue)
Creates a Variable with the given name and initial value over the range [Double.NEGATIVE_INFINITY, Double.POSITIVE_INFINITY]- Parameters:
parent
- the variable's parent model element.initialValue
- The initial value of the variable.
-
Variable
public Variable(ModelElement parent, java.lang.String name)
Creates a Variable with the given name and initial value, 0.0, over the range [Double.NEGATIVE_INFINITY, Double.POSITIVE_INFINITY]- Parameters:
parent
- the variable's parent model element.name
- The name of the variable.
-
Variable
public Variable(ModelElement parent, double initialValue, java.lang.String name)
Creates a Variable with the given name and initial value over the supplied range The default range is [Double.NEGATIVE_INFINITY, Double.POSITIVE_INFINITY]- Parameters:
parent
- the variable's parent model elementinitialValue
- The initial value of the variable.name
- The name of the variable.
-
Variable
public Variable(ModelElement parent, double initialValue, double lowerLimit, java.lang.String name)
Creates a Variable with the given name and initial value over the supplied range [lowerLimit, Double.POSITIVE_INFINITY]- Parameters:
parent
- the variable's parent model elementinitialValue
- The initial value of the variable.lowerLimit
- the lower limit on the range for the variable, must be < upperLimitname
- The name of the variable.
-
Variable
public Variable(ModelElement parent, double initialValue, double lowerLimit)
Creates a Variable with the initial value over the supplied range [lowerLimit, Double.POSITIVE_INFINITY]- Parameters:
parent
- the variable's parent model elementinitialValue
- The initial value of the variable.lowerLimit
- the lower limit on the range for the variable, must be < upperLimit
-
Variable
public Variable(ModelElement parent, double initialValue, double lowerLimit, double upperLimit)
Creates a Variable with the initial value over the supplied range [lowerLimit, upperLimit]- Parameters:
parent
- the variable's parent model elementinitialValue
- The initial value of the variable.lowerLimit
- the lower limit on the range for the variable, must be < upperLimitupperLimit
- the upper limit on the range for the variable
-
Variable
public Variable(ModelElement parent, double initialValue, double lowerLimit, double upperLimit, java.lang.String name)
Creates a Variable with the given name and initial value over the supplied range [lowerLimit, upperLimit]- Parameters:
parent
- the variable's parent model elementinitialValue
- The initial value of the variable. Must be within the range.lowerLimit
- the lower limit on the range for the variable, must be < upperLimitupperLimit
- the upper limit on the range for the variablename
- The name of the variable.
-
-
Method Detail
-
getInitialValue
public final double getInitialValue()
Gets the initial value of the variable- Specified by:
getInitialValue
in interfaceGetInitialValueIfc
- Returns:
- The initial value.
-
setInitialValue
public final void setInitialValue(double value)
Sets the initial value of the variable. Only relevant prior to each replication. Changing during a replication has no effect until the next replication.- Specified by:
setInitialValue
in interfaceSetInitialValueIfc
- Parameters:
value
- The initial value for the variable.
-
getLowerLimit
public final double getLowerLimit()
The lower limit for the range of this random variable- Returns:
- Returns the lowerLimit.
-
getUpperLimit
public final double getUpperLimit()
The upper limit for the range of this random variable- Returns:
- Returns the upperLimit.
-
setValue
public final void setValue(boolean value)
Maps true to 1.0 and false to 0.0- Parameters:
value
- true to 1.0 and false to 0.0
-
setValue
public void setValue(double value)
Sets the value of the variable and notifies any observers of the change- Specified by:
setValue
in interfaceSetValueIfc
- Parameters:
value
- The observation of the variable.
-
getValue
public double getValue()
Every Variable must implement the getValue method. By default this method simply returns the value of the variable.- Specified by:
getValue
in interfaceGetValueIfc
- Returns:
- The value of the variable.
-
getPreviousValue
public final double getPreviousValue()
Gets the previous number value that was assigned before the current value- Specified by:
getPreviousValue
in interfacePreviousValueIfc
- Returns:
- a double representing that was assigned before the current value
-
getWeight
public final double getWeight()
Gets the weight associated with the last value observed.- Specified by:
getWeight
in interfaceGetWeightIfc
- Returns:
- The weight for the value.
-
setWeight
protected void setWeight()
Sets the weight
-
getTimeOfChange
public final double getTimeOfChange()
Gets the time associated with the last value observed.- Specified by:
getTimeOfChange
in interfaceGetTimeOfChangeIfc
- Returns:
- The time of the last observation
-
getPreviousTimeOfChange
public final double getPreviousTimeOfChange()
Gets the time associated with previous variable change.- Specified by:
getPreviousTimeOfChange
in interfaceGetPreviousTimeOfChangeIfc
- Returns:
- The time of the previous change.
-
turnOnTrace
public final void turnOnTrace()
Turns on the automatic tracing of this variable to a text file with the default name and no header
-
turnOnTrace
public final void turnOnTrace(boolean header)
Turns on the automatic tracing of this variable to a text file- Parameters:
header
- if true a header will be the first line of the file
-
turnOnTrace
public final void turnOnTrace(java.lang.String fileName)
Turns on the automatic tracing of this variable to a text file- Parameters:
fileName
- the file name
-
turnOnTrace
public final void turnOnTrace(java.lang.String name, boolean header)
Turns on the automatic tracing of this variable to a text file- Parameters:
name
- Used to name the text fileheader
- if true a header will be the first line of the file
-
turnOffTrace
public final void turnOffTrace()
Turns off the automatic tracing of this variable to a text file.
-
assignInitialValue
protected void assignInitialValue(double value)
Assigns the value of the variable to the supplied value. Ensures that time of change is current time and previous value and previous time of change are the same as the current value and current time without notifying any update observers- Parameters:
value
- the initial value to assign
-
assignValue
protected final void assignValue(double value)
Properly assigns the value of the variable and remembers previous value without notifying any update observers- Parameters:
value
- the value to assign
-
setTraceObserver
protected void setTraceObserver(java.lang.String name, boolean header)
Can be overridden by subclasses to set the protected variable myVariableTraceTextReport for appropriate text tracing- Parameters:
name
- the file name of the reportheader
- the header, true means include the header
-
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()
Description copied from class:ModelElement
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- Overrides:
initialize
in classModelElement
-
warmUp
protected void warmUp()
Description copied from class:ModelElement
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.- Overrides:
warmUp
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
-
getSetValueUpdateNotificationFlag
public final boolean getSetValueUpdateNotificationFlag()
Gets the value of the flag that indicates whether or not observers will be notified when the value changes.- Returns:
- true means will be notified
-
setValueUpdateNotificationFlag
public final void setValueUpdateNotificationFlag(boolean flag)
Turns off or on the notification of update observers for changes to the value of the variable. For example, this is useful to save the execution time associated with the statistical collection, etc on the variable Once it is off, it remains off until turned on. Thus multiple executions of the same model will remember this setting- Parameters:
flag
- true means on
-
asString
public java.lang.String asString()
Description copied from class:ModelElement
Allows sub-classes to provide more detail than toString() to represent the ModelElement as a String- Overrides:
asString
in classModelElement
- Returns:
- a detailed String representation
-
-