Package jsl.modeling.elements
Class RandomList<T>
- java.lang.Object
-
- jsl.simulation.ModelElement
-
- jsl.modeling.elements.RandomList<T>
-
- Type Parameters:
T
-
- All Implemented Interfaces:
java.lang.Iterable<T>
,java.util.Collection<T>
,java.util.List<T>
,RandomElementIfc
,ObservableIfc
,StreamOptionIfc
,GetNameIfc
,IdentityIfc
,GetRandomNumberStreamIfc
,RNStreamControlIfc
,SetRandomNumberStreamIfc
,RElementIfc<T>
,RListIfc<T>
public abstract class RandomList<T> extends ModelElement implements RListIfc<T>, RandomElementIfc
Allows for random selection from a list of objects as supplied by the RList<T> The list is created empty unless a List<T> is supplied upon construction. Thus, if the user does not supply an initial list then there will not be any elements to select from during the replication. By default the list is cleared prior to each replication. If a List<T> is supplied to initialize the list at the beginning of each replication, then it will be used to set up the elements in the list Note: The underlying streams for the random selection process are controlled by the replication, see RandomVariable Note: If the user calls setRandomList() or calls any mutator methods on the list, during the replication the list will be changed; however, the supplied initial list will not have been changed and will be used to reinitialize the list at the beginning of each replication. If the user does not want this behavior, then overwrite the initialize() method or turn off automatic initialization via the ModelElement interface, setInitializationOption(false). Warning: If the user uses ANY mutator methods (e.g. add() etc) prior to the start of a replication, then the list will be CLEARED prior to the the replication (or set to the supplied initialization list). If the user does not want the list cleared or initialize use setInitializationOption(false). Warning: If the user changes the supplied initial list during or between replications, then each replication may not start under the same conditions. Warning: There may not be elements in the list, thus a call to getRandomElement() may return null The default RList is DUniformList, equally likely selection over the elements in the list
-
-
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 java.util.List<T>
myInitialList
protected RList<T>
myRList
-
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 RandomList(ModelElement parent)
Creates an empty list.RandomList(ModelElement parent, java.util.List<T> initialList)
The initial list is used to initialize the list prior to each replication.RandomList(ModelElement parent, java.util.List<T> initialList, java.lang.String name)
The initial list is used to initialize the list prior to each replication.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
add(int index, T element)
boolean
add(T obj)
boolean
addAll(int index, java.util.Collection<? extends T> c)
boolean
addAll(java.util.Collection<? extends T> c)
void
advanceToNextSubstream()
Positions the RNG at the beginning of its next substreamprotected void
afterReplication()
after each replication reset the underlying random number generator to the next sub-streamprotected void
beforeExperiment()
before any replications reset the underlying random number generator to the starting streamvoid
clear()
boolean
contains(java.lang.Object arg0)
boolean
containsAll(java.util.Collection<?> arg0)
T
get(int index)
boolean
getAntitheticOption()
java.util.List<T>
getList()
T
getRandomElement()
Returns an element randomly selected from the listboolean
getResetNextSubStreamOption()
Gets the current reset next sub-stream option true means, that it is set to jump to the next sub-stream after each replicationboolean
getResetStartStreamOption()
Gets the current Reset Start Stream Optionint
indexOf(java.lang.Object arg0)
protected void
initialize()
This method should be overridden by subclasses that need actions performed to initialize prior to a replication.protected void
initializeList(java.util.List<T> list)
boolean
isEmpty()
java.util.Iterator<T>
iterator()
int
lastIndexOf(java.lang.Object o)
java.util.ListIterator<T>
listIterator()
java.util.ListIterator<T>
listIterator(int index)
T
remove(int index)
boolean
remove(java.lang.Object obj)
boolean
removeAll(java.util.Collection<?> c)
protected void
removedFromModel()
This method should be overridden by subclasses that need actions performed when a model element is removed from a modelvoid
resetStartStream()
The resetStartStream method will position the RNG at the beginning of its stream.void
resetStartSubstream()
Resets the position of the RNG at the start of the current substreamboolean
retainAll(java.util.Collection<?> c)
T
set(int index, T element)
void
setAntitheticOption(boolean flag)
Tells the stream to start producing antithetic variatesvoid
setInitialList(java.util.List<T> list)
Sets the initial list to be used to initialize the list at the beginning of each replicationvoid
setRandomList(RList<T> list)
Allows the user to change the random list after it has been initialized by the initial list.void
setResetNextSubStreamOption(boolean b)
Sets the current reset next sub-stream option true means, that it is set to jump to the next sub-stream after each replicationvoid
setResetStartStreamOption(boolean b)
Sets the reset start stream option, true means that it will be reset to the starting streamint
size()
java.util.List<T>
subList(int fromIndex, int toIndex)
java.lang.Object[]
toArray()
<T> T[]
toArray(T[] a)
-
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, initialize_, 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, warmUp, warmUp_, week
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface jsl.utilities.random.rng.GetRandomNumberStreamIfc
getRandomNumberStream, getStreamNumber
-
Methods inherited from interface jsl.utilities.random.rng.SetRandomNumberStreamIfc
setRandomNumberStream, setRandomNumberStream
-
-
-
-
Constructor Detail
-
RandomList
public RandomList(ModelElement parent)
Creates an empty list. Elements must be added to it for random selection to be possible.- Parameters:
parent
-
-
RandomList
public RandomList(ModelElement parent, java.util.List<T> initialList)
The initial list is used to initialize the list prior to each replication. The supplied list is copied.- Parameters:
parent
-
-
RandomList
public RandomList(ModelElement parent, java.util.List<T> initialList, java.lang.String name)
The initial list is used to initialize the list prior to each replication. The supplied list is copied.- Parameters:
parent
-initialList
-name
-
-
-
Method Detail
-
initializeList
protected void initializeList(java.util.List<T> list)
-
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
-
removedFromModel
protected void removedFromModel()
Description copied from class:ModelElement
This method should be overridden by subclasses that need actions performed when a model element is removed from a model- Overrides:
removedFromModel
in classModelElement
-
beforeExperiment
protected void beforeExperiment()
before any replications reset the underlying random number generator to the starting stream- Overrides:
beforeExperiment
in classModelElement
-
afterReplication
protected void afterReplication()
after each replication reset the underlying random number generator to the next sub-stream- Overrides:
afterReplication
in classModelElement
-
setRandomList
public void setRandomList(RList<T> list)
Allows the user to change the random list after it has been initialized by the initial list. The supplied list will be used directly instead of the current list- Parameters:
list
-
-
setInitialList
public void setInitialList(java.util.List<T> list)
Sets the initial list to be used to initialize the list at the beginning of each replication- Parameters:
list
-
-
getResetStartStreamOption
public final boolean getResetStartStreamOption()
Description copied from interface:StreamOptionIfc
Gets the current Reset Start Stream Option- Specified by:
getResetStartStreamOption
in interfaceStreamOptionIfc
- Returns:
- the option
-
setResetStartStreamOption
public final void setResetStartStreamOption(boolean b)
Description copied from interface:StreamOptionIfc
Sets the reset start stream option, true means that it will be reset to the starting stream- Specified by:
setResetStartStreamOption
in interfaceStreamOptionIfc
- Parameters:
b
- true means reset
-
getResetNextSubStreamOption
public final boolean getResetNextSubStreamOption()
Description copied from interface:StreamOptionIfc
Gets the current reset next sub-stream option true means, that it is set to jump to the next sub-stream after each replication- Specified by:
getResetNextSubStreamOption
in interfaceStreamOptionIfc
- Returns:
- the option
-
setResetNextSubStreamOption
public final void setResetNextSubStreamOption(boolean b)
Description copied from interface:StreamOptionIfc
Sets the current reset next sub-stream option true means, that it is set to jump to the next sub-stream after each replication- Specified by:
setResetNextSubStreamOption
in interfaceStreamOptionIfc
- Parameters:
b
- true means reset
-
add
public boolean add(T obj)
-
addAll
public boolean addAll(java.util.Collection<? extends T> c)
-
addAll
public boolean addAll(int index, java.util.Collection<? extends T> c)
- Specified by:
addAll
in interfacejava.util.List<T>
-
clear
public void clear()
-
contains
public boolean contains(java.lang.Object arg0)
-
containsAll
public boolean containsAll(java.util.Collection<?> arg0)
-
getList
public java.util.List<T> getList()
- Returns:
- See Also:
RList.getList()
-
getRandomElement
public T getRandomElement()
Description copied from interface:RElementIfc
Returns an element randomly selected from the list- Specified by:
getRandomElement
in interfaceRElementIfc<T>
- Returns:
- a randomly selected element from the list
-
indexOf
public int indexOf(java.lang.Object arg0)
- Specified by:
indexOf
in interfacejava.util.List<T>
-
isEmpty
public boolean isEmpty()
-
iterator
public java.util.Iterator<T> iterator()
-
lastIndexOf
public int lastIndexOf(java.lang.Object o)
- Specified by:
lastIndexOf
in interfacejava.util.List<T>
-
listIterator
public java.util.ListIterator<T> listIterator()
- Specified by:
listIterator
in interfacejava.util.List<T>
-
listIterator
public java.util.ListIterator<T> listIterator(int index)
- Specified by:
listIterator
in interfacejava.util.List<T>
-
remove
public boolean remove(java.lang.Object obj)
-
removeAll
public boolean removeAll(java.util.Collection<?> c)
-
advanceToNextSubstream
public void advanceToNextSubstream()
Description copied from interface:RNStreamControlIfc
Positions the RNG at the beginning of its next substream- Specified by:
advanceToNextSubstream
in interfaceRNStreamControlIfc
-
resetStartStream
public void resetStartStream()
Description copied from interface:RNStreamControlIfc
The resetStartStream method will position the RNG at the beginning of its stream. This is the same location in the stream as assigned when the RNG was created and initialized.- Specified by:
resetStartStream
in interfaceRNStreamControlIfc
-
resetStartSubstream
public void resetStartSubstream()
Description copied from interface:RNStreamControlIfc
Resets the position of the RNG at the start of the current substream- Specified by:
resetStartSubstream
in interfaceRNStreamControlIfc
-
retainAll
public boolean retainAll(java.util.Collection<?> c)
-
setAntitheticOption
public void setAntitheticOption(boolean flag)
Description copied from interface:RNStreamControlIfc
Tells the stream to start producing antithetic variates- Specified by:
setAntitheticOption
in interfaceRNStreamControlIfc
- Parameters:
flag
- true means that it produces antithetic variates.
-
getAntitheticOption
public final boolean getAntitheticOption()
- Specified by:
getAntitheticOption
in interfaceRNStreamControlIfc
- Returns:
- true means on
-
size
public int size()
-
subList
public java.util.List<T> subList(int fromIndex, int toIndex)
- Specified by:
subList
in interfacejava.util.List<T>
-
toArray
public java.lang.Object[] toArray()
-
-