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>myInitialListprotected 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 voidadd(int index, T element)booleanadd(T obj)booleanaddAll(int index, java.util.Collection<? extends T> c)booleanaddAll(java.util.Collection<? extends T> c)voidadvanceToNextSubstream()Positions the RNG at the beginning of its next substreamprotected voidafterReplication()after each replication reset the underlying random number generator to the next sub-streamprotected voidbeforeExperiment()before any replications reset the underlying random number generator to the starting streamvoidclear()booleancontains(java.lang.Object arg0)booleancontainsAll(java.util.Collection<?> arg0)Tget(int index)booleangetAntitheticOption()java.util.List<T>getList()TgetRandomElement()Returns an element randomly selected from the listbooleangetResetNextSubStreamOption()Gets the current reset next sub-stream option true means, that it is set to jump to the next sub-stream after each replicationbooleangetResetStartStreamOption()Gets the current Reset Start Stream OptionintindexOf(java.lang.Object arg0)protected voidinitialize()This method should be overridden by subclasses that need actions performed to initialize prior to a replication.protected voidinitializeList(java.util.List<T> list)booleanisEmpty()java.util.Iterator<T>iterator()intlastIndexOf(java.lang.Object o)java.util.ListIterator<T>listIterator()java.util.ListIterator<T>listIterator(int index)Tremove(int index)booleanremove(java.lang.Object obj)booleanremoveAll(java.util.Collection<?> c)protected voidremovedFromModel()This method should be overridden by subclasses that need actions performed when a model element is removed from a modelvoidresetStartStream()The resetStartStream method will position the RNG at the beginning of its stream.voidresetStartSubstream()Resets the position of the RNG at the start of the current substreambooleanretainAll(java.util.Collection<?> c)Tset(int index, T element)voidsetAntitheticOption(boolean flag)Tells the stream to start producing antithetic variatesvoidsetInitialList(java.util.List<T> list)Sets the initial list to be used to initialize the list at the beginning of each replicationvoidsetRandomList(RList<T> list)Allows the user to change the random list after it has been initialized by the initial list.voidsetResetNextSubStreamOption(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 replicationvoidsetResetStartStreamOption(boolean b)Sets the reset start stream option, true means that it will be reset to the starting streamintsize()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:ModelElementThis 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:
initializein classModelElement
-
removedFromModel
protected void removedFromModel()
Description copied from class:ModelElementThis method should be overridden by subclasses that need actions performed when a model element is removed from a model- Overrides:
removedFromModelin classModelElement
-
beforeExperiment
protected void beforeExperiment()
before any replications reset the underlying random number generator to the starting stream- Overrides:
beforeExperimentin classModelElement
-
afterReplication
protected void afterReplication()
after each replication reset the underlying random number generator to the next sub-stream- Overrides:
afterReplicationin 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:StreamOptionIfcGets the current Reset Start Stream Option- Specified by:
getResetStartStreamOptionin interfaceStreamOptionIfc- Returns:
- the option
-
setResetStartStreamOption
public final void setResetStartStreamOption(boolean b)
Description copied from interface:StreamOptionIfcSets the reset start stream option, true means that it will be reset to the starting stream- Specified by:
setResetStartStreamOptionin interfaceStreamOptionIfc- Parameters:
b- true means reset
-
getResetNextSubStreamOption
public final boolean getResetNextSubStreamOption()
Description copied from interface:StreamOptionIfcGets 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:
getResetNextSubStreamOptionin interfaceStreamOptionIfc- Returns:
- the option
-
setResetNextSubStreamOption
public final void setResetNextSubStreamOption(boolean b)
Description copied from interface:StreamOptionIfcSets 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:
setResetNextSubStreamOptionin 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:
addAllin 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:RElementIfcReturns an element randomly selected from the list- Specified by:
getRandomElementin interfaceRElementIfc<T>- Returns:
- a randomly selected element from the list
-
indexOf
public int indexOf(java.lang.Object arg0)
- Specified by:
indexOfin 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:
lastIndexOfin interfacejava.util.List<T>
-
listIterator
public java.util.ListIterator<T> listIterator()
- Specified by:
listIteratorin interfacejava.util.List<T>
-
listIterator
public java.util.ListIterator<T> listIterator(int index)
- Specified by:
listIteratorin 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:RNStreamControlIfcPositions the RNG at the beginning of its next substream- Specified by:
advanceToNextSubstreamin interfaceRNStreamControlIfc
-
resetStartStream
public void resetStartStream()
Description copied from interface:RNStreamControlIfcThe 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:
resetStartStreamin interfaceRNStreamControlIfc
-
resetStartSubstream
public void resetStartSubstream()
Description copied from interface:RNStreamControlIfcResets the position of the RNG at the start of the current substream- Specified by:
resetStartSubstreamin interfaceRNStreamControlIfc
-
retainAll
public boolean retainAll(java.util.Collection<?> c)
-
setAntitheticOption
public void setAntitheticOption(boolean flag)
Description copied from interface:RNStreamControlIfcTells the stream to start producing antithetic variates- Specified by:
setAntitheticOptionin interfaceRNStreamControlIfc- Parameters:
flag- true means that it produces antithetic variates.
-
getAntitheticOption
public final boolean getAntitheticOption()
- Specified by:
getAntitheticOptionin interfaceRNStreamControlIfc- Returns:
- true means on
-
size
public int size()
-
subList
public java.util.List<T> subList(int fromIndex, int toIndex)
- Specified by:
subListin interfacejava.util.List<T>
-
toArray
public java.lang.Object[] toArray()
-
-