Class ResourcePool
- java.lang.Object
- 
- jsl.simulation.ModelElement
- 
- jsl.modeling.resource.ResourcePool
 
 
- 
- All Implemented Interfaces:
- RandomElementIfc,- ObservableIfc,- StreamOptionIfc,- GetNameIfc,- IdentityIfc,- GetRandomNumberStreamIfc,- RNStreamControlIfc,- SetRandomNumberStreamIfc
 - Direct Known Subclasses:
- ResourcePoolWithQ
 
 public class ResourcePool extends ModelElement implements RandomElementIfc A ResourcePool represents a list of ResourceUnits from which a single unit can be selected.ResourceUnits are selected according to a ResourceSelectionRule. The assumption is that any of the resource units within the pool may be used to fill the request. If no selection rule is supplied the pool selects the first idle resource by default. Statistics on the number of units idle and busy are automatically collected. Statistics on number inactive and number failed in the pool can be collected by specifying the statistics option, which is false by default. Inactive and failure statistics will be collected regardless of whether or not the units in the pool can be failed or inactive. Sub-classes may override the methods unitbecameIdle(), unitbecameBusy(), unitFailed(), unitBecameInactive() in order to react to state changes on individual resource units. The utilization of the pool is defined as the average number busy divided by the average number active. The average number active is the number of units minus the average number of inactive units and average number of failed units. Thus, we assume that resources cannot be busy if they are failed or inactive. 
- 
- 
Nested Class SummaryNested Classes Modifier and Type Class Description static classResourcePool.DescendingByNumIdleComparatorprotected classResourcePool.ResourceUnitObserver- 
Nested classes/interfaces inherited from class jsl.simulation.ModelElementModelElement.EventBuilderIfc<T>, ModelElement.EventScheduler<T>, ModelElement.ModelElementComparator, ModelElement.RequestBuilder, ModelElement.RequestDurationIfc, ModelElement.RequestTimeIfc, ModelElement.RequestUsingIfc, ModelElement.TimedUpdateEventAction, ModelElement.TimeUnitIfc<T>, ModelElement.WarmUpEventAction
 
- 
 - 
Field SummaryFields Modifier and Type Field Description protected TimeWeightedmyNumBusyprotected TimeWeightedmyNumFailedprotected TimeWeightedmyNumIdleprotected TimeWeightedmyNumInactiveprotected booleanmyResetNextSubStreamOptionprotected booleanmyResetStartStreamOptionprotected java.util.List<ResourceUnit>myResourcesprotected ResourcePool.ResourceUnitObservermyRUObserverprotected ResponseVariablemyUtilization- 
Fields inherited from class jsl.simulation.ModelElementAFTER_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 SummaryConstructors Constructor Description ResourcePool(ModelElement parent, java.util.List<ResourceUnit> units)Statistics option is false by defaultResourcePool(ModelElement parent, java.util.List<ResourceUnit> units, boolean statOption)ResourcePool(ModelElement parent, java.util.List<ResourceUnit> units, boolean statOption, java.lang.String name)ResourcePool(ModelElement parent, java.util.List<ResourceUnit> units, java.lang.String name)Statistics option is false by default
 - 
Method SummaryAll Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description protected booleanadd(ResourceUnit unit)protected voidaddAll(java.util.List<ResourceUnit> units)voidadvanceToNextSubstream()Positions the RNG at the beginning of its next substreamprotected voidafterReplication()after each replication reset the underlying random number generator to the next substreamprotected voidbeforeExperiment()before any replications reset the underlying random number generator to the starting streamprotected voidcollectStateStatistics(ResourceUnit ru)Collects pool statistics based on change of state of contained resource unitsbooleancontains(ResourceUnit unit)ResourceUnitfindFirstIdle()java.util.List<ResourceUnit>findIdleResourceUnits()booleangetAntitheticOption()static java.util.Comparator<ResourcePool>getDescendingByNumIdleComparator()booleangetFailureDelayOption()booleangetInactivePeriodDelayOption()intgetNumBusy()intgetNumFailed()intgetNumIdle()intgetNumInactive()intgetNumUnits()RNStreamIfcgetRandomNumberStream()booleangetResetNextSubStreamOption()Gets the current reset next substream option true means, that it is set to jump to the next substream after each replicationbooleangetResetStartStreamOption()Gets the current Reset Start Stream Optionjava.util.Optional<ResourceUnitSelectionRuleIfc>getSelectionRule()java.util.List<ResourceUnit>getUnits()booleanhasAllUnitsBusy()booleanhasAllUnitsFailed()booleanhasAllUnitsIdle()booleanhasAllUnitsInactive()booleanhasBusyUnits()booleanhasFailedUnits()booleanhasFailureProcesses()Returns false if ALL units do not have failure processesbooleanhasIdleUnits()booleanhasInactiveUnits()booleanhasSchedules()Returns false if ALL units do not have any schedules attachedbooleanisPooledStatsOptionOn()booleanisPreemptionRuleCompatible(Request request)Checks if the preemption rule of the request is compatible with the failure delay option.ResourceUnitrandomlySelectResourceUnit()Randomly selects an idle resource unit if availableprotected voidreplicationEnded()This method should be overridden by subclasses that need actions performed when the replication ends and prior to the calling of afterReplication() .voidresetStartStream()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 substreamprotected voidresourceUnitChanged(ResourceUnit ru)Partials out unit changes to unitBecameIdle(), unitBecameBusy(), unitFailed(), unitBecameInactive()ResourceUnitselectResourceUnit()Selects a resource unit according to the selection rule.voidsetAntitheticOption(boolean flag)Tells the stream to start producing antithetic variatesvoidsetRandomNumberStream(RNStreamIfc stream)Sets the underlying random number streamvoidsetResetNextSubStreamOption(boolean b)Sets the current reset next substream option true means, that it is set to jump to the next substream after each replicationvoidsetResetStartStreamOption(boolean b)Sets the reset start stream option, true means that it will be reset to the starting streamvoidsetSelectionRule(ResourceUnitSelectionRuleIfc rule)protected voidunitBecameBusy(ResourceUnit ru)Called when one of the units becomes busyprotected voidunitBecameIdle(ResourceUnit ru)Called when one of the units becomes idleprotected voidunitBecameInactive(ResourceUnit ru)Called when one of the units becomes inactiveprotected voidunitFailed(ResourceUnit ru)Called when one of the units becomes failedvoiduseSchedule(Schedule schedule)Tells all ResourceUnits in the pool that are not already using a Schedule to use the supplied schedule- 
Methods inherited from class jsl.simulation.ModelElementaddObserver, 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, 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_, removedFromModel, removeFromModel, 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.Objectclone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 - 
Methods inherited from interface jsl.utilities.random.rng.GetRandomNumberStreamIfcgetStreamNumber
 - 
Methods inherited from interface jsl.utilities.random.rng.SetRandomNumberStreamIfcsetRandomNumberStream
 
- 
 
- 
- 
- 
Field Detail- 
myResourcesprotected final java.util.List<ResourceUnit> myResources 
 - 
myRUObserverprotected final ResourcePool.ResourceUnitObserver myRUObserver 
 - 
myNumBusyprotected final TimeWeighted myNumBusy 
 - 
myNumIdleprotected final TimeWeighted myNumIdle 
 - 
myNumFailedprotected TimeWeighted myNumFailed 
 - 
myNumInactiveprotected TimeWeighted myNumInactive 
 - 
myResetStartStreamOptionprotected boolean myResetStartStreamOption 
 - 
myResetNextSubStreamOptionprotected boolean myResetNextSubStreamOption 
 - 
myUtilizationprotected final ResponseVariable myUtilization 
 
- 
 - 
Constructor Detail- 
ResourcePoolpublic ResourcePool(ModelElement parent, java.util.List<ResourceUnit> units) Statistics option is false by default- Parameters:
- parent- the parent model element
- units- a list of ResourceUnits. Must not contain nulls and must not contain duplicates
 
 - 
ResourcePoolpublic ResourcePool(ModelElement parent, java.util.List<ResourceUnit> units, java.lang.String name) Statistics option is false by default- Parameters:
- parent- the parent model element
- units- a list of ResourceUnits. Must not contain nulls and must not contain duplicates
- name- the name of the pool
 
 - 
ResourcePoolpublic ResourcePool(ModelElement parent, java.util.List<ResourceUnit> units, boolean statOption) - Parameters:
- parent- the parent model element
- units- a list of ResourceUnits. Must not contain nulls and must not contain duplicates
- statOption- true means collect statistics on inactive and failure states
 
 - 
ResourcePoolpublic ResourcePool(ModelElement parent, java.util.List<ResourceUnit> units, boolean statOption, java.lang.String name) - Parameters:
- parent- the parent model element
- units- a list of ResourceUnits. Must not contain nulls and must not contain duplicates
- statOption- true means collect statistics on inactive and failure states
- name- the name of the pool
 
 
- 
 - 
Method Detail- 
getNumUnitspublic final int getNumUnits() - Returns:
- number of units in the pool
 
 - 
hasIdleUnitspublic final boolean hasIdleUnits() - Returns:
- true if at least one unit is idle
 
 - 
hasBusyUnitspublic final boolean hasBusyUnits() - Returns:
- true if at least one unit is busy
 
 - 
hasFailedUnitspublic final boolean hasFailedUnits() - Returns:
- true if at least one unit is failed
 
 - 
hasAllUnitsIdlepublic final boolean hasAllUnitsIdle() - Returns:
- true if all units are idle
 
 - 
hasAllUnitsBusypublic final boolean hasAllUnitsBusy() - Returns:
- true if all units are busy
 
 - 
hasAllUnitsFailedpublic final boolean hasAllUnitsFailed() - Returns:
- true if all units are failed
 
 - 
hasAllUnitsInactivepublic final boolean hasAllUnitsInactive() - Returns:
- true if all units are inactive
 
 - 
hasInactiveUnitspublic final boolean hasInactiveUnits() - Returns:
- true if at least one unit is inactive
 
 - 
getNumIdlepublic final int getNumIdle() - Returns:
- the number of currently idle units
 
 - 
getNumBusypublic final int getNumBusy() - Returns:
- the number of currently busy units
 
 - 
getNumFailedpublic final int getNumFailed() - Returns:
- the number of currently failed units
 
 - 
getNumInactivepublic final int getNumInactive() - Returns:
- the number of currently inactive units
 
 - 
getFailureDelayOptionpublic final boolean getFailureDelayOption() - Returns:
- true if ALL units in the pool have true for their failure delay option. That is, all units allow failures to be delayed.
 
 - 
hasFailureProcessespublic final boolean hasFailureProcesses() Returns false if ALL units do not have failure processes- Returns:
- returns true if at least one of the units in the pool has a failure process
 
 - 
hasSchedulespublic final boolean hasSchedules() Returns false if ALL units do not have any schedules attached- Returns:
- returns true if at least one of the units in the pool has a schedule attached
 
 - 
getInactivePeriodDelayOptionpublic final boolean getInactivePeriodDelayOption() - Returns:
- true if ALL units in the pool have true for their inactive period option. That is, all units allows their inactive periods to be delayed
 
 - 
isPreemptionRuleCompatiblepublic boolean isPreemptionRuleCompatible(Request request) Checks if the preemption rule of the request is compatible with the failure delay option. If the request doesn't allow preemption and failures cannot be delayed, this means that the request will be rejected.- Parameters:
- request- the request to check
- Returns:
- true if compatible
 
 - 
isPooledStatsOptionOnpublic final boolean isPooledStatsOptionOn() - Returns:
- true if pooled statistics will be collected
 
 - 
containspublic final boolean contains(ResourceUnit unit) - Parameters:
- unit- the unit to test
- Returns:
- true if in the pool
 
 - 
getUnitspublic final java.util.List<ResourceUnit> getUnits() - Returns:
- an unmodifiable list of the resource units
 
 - 
useSchedulepublic final void useSchedule(Schedule schedule) Tells all ResourceUnits in the pool that are not already using a Schedule to use the supplied schedule- Parameters:
- schedule- the schedule to use
 
 - 
addAllprotected final void addAll(java.util.List<ResourceUnit> units) - Parameters:
- units- the list to add. Must not contain any nulls and must not have any units that are already in the pool.
 
 - 
addprotected final boolean add(ResourceUnit unit) - Parameters:
- unit- the unit to add. Must not be null. Must not already have been added
- Returns:
- true if added
 
 - 
getSelectionRulepublic java.util.Optional<ResourceUnitSelectionRuleIfc> getSelectionRule() - Returns:
- an Optional with the rule
 
 - 
setSelectionRulepublic void setSelectionRule(ResourceUnitSelectionRuleIfc rule) - Parameters:
- rule- the supplied rule, may be null
 
 - 
selectResourceUnitpublic ResourceUnit selectResourceUnit() Selects a resource unit according to the selection rule. If no selection rule is present, selects the first idle resource in the list of resources.- Returns:
- the selected resource unit or null
 
 - 
randomlySelectResourceUnitpublic ResourceUnit randomlySelectResourceUnit() Randomly selects an idle resource unit if available- Returns:
- the selected resource unit or null
 
 - 
getRandomNumberStreampublic RNStreamIfc getRandomNumberStream() - Specified by:
- getRandomNumberStreamin interface- GetRandomNumberStreamIfc
- Returns:
- the random number stream reference
 
 - 
setRandomNumberStreampublic void setRandomNumberStream(RNStreamIfc stream) Description copied from interface:SetRandomNumberStreamIfcSets the underlying random number stream- Specified by:
- setRandomNumberStreamin interface- SetRandomNumberStreamIfc
- Parameters:
- stream- the reference to the random number stream, must not be null
 
 - 
findIdleResourceUnitspublic java.util.List<ResourceUnit> findIdleResourceUnits() - Returns:
- returns a list of idle resource units. It may be empty
 
 - 
findFirstIdlepublic ResourceUnit findFirstIdle() - Returns:
- the first idle resource found or null
 
 - 
resetStartStreampublic 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 interface- RNStreamControlIfc
 
 - 
resetStartSubstreampublic void resetStartSubstream() Description copied from interface:RNStreamControlIfcResets the position of the RNG at the start of the current substream- Specified by:
- resetStartSubstreamin interface- RNStreamControlIfc
 
 - 
advanceToNextSubstreampublic void advanceToNextSubstream() Description copied from interface:RNStreamControlIfcPositions the RNG at the beginning of its next substream- Specified by:
- advanceToNextSubstreamin interface- RNStreamControlIfc
 
 - 
setAntitheticOptionpublic void setAntitheticOption(boolean flag) Description copied from interface:RNStreamControlIfcTells the stream to start producing antithetic variates- Specified by:
- setAntitheticOptionin interface- RNStreamControlIfc
- Parameters:
- flag- true means that it produces antithetic variates.
 
 - 
getAntitheticOptionpublic boolean getAntitheticOption() - Specified by:
- getAntitheticOptionin interface- RNStreamControlIfc
- Returns:
- true means on
 
 - 
getResetStartStreamOptionpublic final boolean getResetStartStreamOption() Gets the current Reset Start Stream Option- Specified by:
- getResetStartStreamOptionin interface- StreamOptionIfc
- Returns:
 
 - 
setResetStartStreamOptionpublic final void setResetStartStreamOption(boolean b) Sets the reset start stream option, true means that it will be reset to the starting stream- Specified by:
- setResetStartStreamOptionin interface- StreamOptionIfc
- Parameters:
- b-
 
 - 
getResetNextSubStreamOptionpublic final boolean getResetNextSubStreamOption() Gets the current reset next substream option true means, that it is set to jump to the next substream after each replication- Specified by:
- getResetNextSubStreamOptionin interface- StreamOptionIfc
- Returns:
 
 - 
setResetNextSubStreamOptionpublic final void setResetNextSubStreamOption(boolean b) Sets the current reset next substream option true means, that it is set to jump to the next substream after each replication- Specified by:
- setResetNextSubStreamOptionin interface- StreamOptionIfc
- Parameters:
- b-
 
 - 
beforeExperimentprotected void beforeExperiment() before any replications reset the underlying random number generator to the starting stream- Overrides:
- beforeExperimentin class- ModelElement
 
 - 
replicationEndedprotected void replicationEnded() This method should be overridden by subclasses that need actions performed when the replication ends and prior to the calling of afterReplication() . It is called when each replication ends and can be used to collect data from the the model element, etc.- Overrides:
- replicationEndedin class- ModelElement
 
 - 
afterReplicationprotected void afterReplication() after each replication reset the underlying random number generator to the next substream- Overrides:
- afterReplicationin class- ModelElement
 
 - 
resourceUnitChangedprotected void resourceUnitChanged(ResourceUnit ru) Partials out unit changes to unitBecameIdle(), unitBecameBusy(), unitFailed(), unitBecameInactive()- Parameters:
- ru- the unit that changed
 
 - 
collectStateStatisticsprotected void collectStateStatistics(ResourceUnit ru) Collects pool statistics based on change of state of contained resource units- Parameters:
- ru- the resource unit that changed state
 
 - 
unitBecameIdleprotected void unitBecameIdle(ResourceUnit ru) Called when one of the units becomes idle- Parameters:
- ru- the unit that became idle
 
 - 
unitBecameBusyprotected void unitBecameBusy(ResourceUnit ru) Called when one of the units becomes busy- Parameters:
- ru- the unit that became busy
 
 - 
unitFailedprotected void unitFailed(ResourceUnit ru) Called when one of the units becomes failed- Parameters:
- ru- the unit that became failed
 
 - 
unitBecameInactiveprotected void unitBecameInactive(ResourceUnit ru) Called when one of the units becomes inactive- Parameters:
- ru- the unit that became inactive
 
 - 
getDescendingByNumIdleComparatorpublic static java.util.Comparator<ResourcePool> getDescendingByNumIdleComparator() 
 
- 
 
-