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 Summary
Nested Classes Modifier and Type Class Description static classResourcePool.DescendingByNumIdleComparatorprotected classResourcePool.ResourceUnitObserver-
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 TimeWeightedmyNumBusyprotected TimeWeightedmyNumFailedprotected TimeWeightedmyNumIdleprotected TimeWeightedmyNumInactiveprotected booleanmyResetNextSubStreamOptionprotected booleanmyResetStartStreamOptionprotected java.util.List<ResourceUnit>myResourcesprotected ResourcePool.ResourceUnitObservermyRUObserverprotected ResponseVariablemyUtilization-
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 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 Summary
All 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.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, 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.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface jsl.utilities.random.rng.GetRandomNumberStreamIfc
getStreamNumber
-
Methods inherited from interface jsl.utilities.random.rng.SetRandomNumberStreamIfc
setRandomNumberStream
-
-
-
-
Field Detail
-
myResources
protected final java.util.List<ResourceUnit> myResources
-
myRUObserver
protected final ResourcePool.ResourceUnitObserver myRUObserver
-
myNumBusy
protected final TimeWeighted myNumBusy
-
myNumIdle
protected final TimeWeighted myNumIdle
-
myNumFailed
protected TimeWeighted myNumFailed
-
myNumInactive
protected TimeWeighted myNumInactive
-
myResetStartStreamOption
protected boolean myResetStartStreamOption
-
myResetNextSubStreamOption
protected boolean myResetNextSubStreamOption
-
myUtilization
protected final ResponseVariable myUtilization
-
-
Constructor Detail
-
ResourcePool
public ResourcePool(ModelElement parent, java.util.List<ResourceUnit> units)
Statistics option is false by default- Parameters:
parent- the parent model elementunits- a list of ResourceUnits. Must not contain nulls and must not contain duplicates
-
ResourcePool
public ResourcePool(ModelElement parent, java.util.List<ResourceUnit> units, java.lang.String name)
Statistics option is false by default- Parameters:
parent- the parent model elementunits- a list of ResourceUnits. Must not contain nulls and must not contain duplicatesname- the name of the pool
-
ResourcePool
public ResourcePool(ModelElement parent, java.util.List<ResourceUnit> units, boolean statOption)
- Parameters:
parent- the parent model elementunits- a list of ResourceUnits. Must not contain nulls and must not contain duplicatesstatOption- true means collect statistics on inactive and failure states
-
ResourcePool
public ResourcePool(ModelElement parent, java.util.List<ResourceUnit> units, boolean statOption, java.lang.String name)
- Parameters:
parent- the parent model elementunits- a list of ResourceUnits. Must not contain nulls and must not contain duplicatesstatOption- true means collect statistics on inactive and failure statesname- the name of the pool
-
-
Method Detail
-
getNumUnits
public final int getNumUnits()
- Returns:
- number of units in the pool
-
hasIdleUnits
public final boolean hasIdleUnits()
- Returns:
- true if at least one unit is idle
-
hasBusyUnits
public final boolean hasBusyUnits()
- Returns:
- true if at least one unit is busy
-
hasFailedUnits
public final boolean hasFailedUnits()
- Returns:
- true if at least one unit is failed
-
hasAllUnitsIdle
public final boolean hasAllUnitsIdle()
- Returns:
- true if all units are idle
-
hasAllUnitsBusy
public final boolean hasAllUnitsBusy()
- Returns:
- true if all units are busy
-
hasAllUnitsFailed
public final boolean hasAllUnitsFailed()
- Returns:
- true if all units are failed
-
hasAllUnitsInactive
public final boolean hasAllUnitsInactive()
- Returns:
- true if all units are inactive
-
hasInactiveUnits
public final boolean hasInactiveUnits()
- Returns:
- true if at least one unit is inactive
-
getNumIdle
public final int getNumIdle()
- Returns:
- the number of currently idle units
-
getNumBusy
public final int getNumBusy()
- Returns:
- the number of currently busy units
-
getNumFailed
public final int getNumFailed()
- Returns:
- the number of currently failed units
-
getNumInactive
public final int getNumInactive()
- Returns:
- the number of currently inactive units
-
getFailureDelayOption
public 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.
-
hasFailureProcesses
public 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
-
hasSchedules
public 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
-
getInactivePeriodDelayOption
public 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
-
isPreemptionRuleCompatible
public 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
-
isPooledStatsOptionOn
public final boolean isPooledStatsOptionOn()
- Returns:
- true if pooled statistics will be collected
-
contains
public final boolean contains(ResourceUnit unit)
- Parameters:
unit- the unit to test- Returns:
- true if in the pool
-
getUnits
public final java.util.List<ResourceUnit> getUnits()
- Returns:
- an unmodifiable list of the resource units
-
useSchedule
public 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
-
addAll
protected 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.
-
add
protected 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
-
getSelectionRule
public java.util.Optional<ResourceUnitSelectionRuleIfc> getSelectionRule()
- Returns:
- an Optional with the rule
-
setSelectionRule
public void setSelectionRule(ResourceUnitSelectionRuleIfc rule)
- Parameters:
rule- the supplied rule, may be null
-
selectResourceUnit
public 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
-
randomlySelectResourceUnit
public ResourceUnit randomlySelectResourceUnit()
Randomly selects an idle resource unit if available- Returns:
- the selected resource unit or null
-
getRandomNumberStream
public RNStreamIfc getRandomNumberStream()
- Specified by:
getRandomNumberStreamin interfaceGetRandomNumberStreamIfc- Returns:
- the random number stream reference
-
setRandomNumberStream
public void setRandomNumberStream(RNStreamIfc stream)
Description copied from interface:SetRandomNumberStreamIfcSets the underlying random number stream- Specified by:
setRandomNumberStreamin interfaceSetRandomNumberStreamIfc- Parameters:
stream- the reference to the random number stream, must not be null
-
findIdleResourceUnits
public java.util.List<ResourceUnit> findIdleResourceUnits()
- Returns:
- returns a list of idle resource units. It may be empty
-
findFirstIdle
public ResourceUnit findFirstIdle()
- Returns:
- the first idle resource found or null
-
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
-
advanceToNextSubstream
public void advanceToNextSubstream()
Description copied from interface:RNStreamControlIfcPositions the RNG at the beginning of its next substream- Specified by:
advanceToNextSubstreamin interfaceRNStreamControlIfc
-
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 boolean getAntitheticOption()
- Specified by:
getAntitheticOptionin interfaceRNStreamControlIfc- Returns:
- true means on
-
getResetStartStreamOption
public final boolean getResetStartStreamOption()
Gets the current Reset Start Stream Option- Specified by:
getResetStartStreamOptionin interfaceStreamOptionIfc- Returns:
-
setResetStartStreamOption
public 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 interfaceStreamOptionIfc- Parameters:
b-
-
getResetNextSubStreamOption
public 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 interfaceStreamOptionIfc- Returns:
-
setResetNextSubStreamOption
public 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 interfaceStreamOptionIfc- Parameters:
b-
-
beforeExperiment
protected void beforeExperiment()
before any replications reset the underlying random number generator to the starting stream- Overrides:
beforeExperimentin classModelElement
-
replicationEnded
protected 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 classModelElement
-
afterReplication
protected void afterReplication()
after each replication reset the underlying random number generator to the next substream- Overrides:
afterReplicationin classModelElement
-
resourceUnitChanged
protected void resourceUnitChanged(ResourceUnit ru)
Partials out unit changes to unitBecameIdle(), unitBecameBusy(), unitFailed(), unitBecameInactive()- Parameters:
ru- the unit that changed
-
collectStateStatistics
protected void collectStateStatistics(ResourceUnit ru)
Collects pool statistics based on change of state of contained resource units- Parameters:
ru- the resource unit that changed state
-
unitBecameIdle
protected void unitBecameIdle(ResourceUnit ru)
Called when one of the units becomes idle- Parameters:
ru- the unit that became idle
-
unitBecameBusy
protected void unitBecameBusy(ResourceUnit ru)
Called when one of the units becomes busy- Parameters:
ru- the unit that became busy
-
unitFailed
protected void unitFailed(ResourceUnit ru)
Called when one of the units becomes failed- Parameters:
ru- the unit that became failed
-
unitBecameInactive
protected void unitBecameInactive(ResourceUnit ru)
Called when one of the units becomes inactive- Parameters:
ru- the unit that became inactive
-
getDescendingByNumIdleComparator
public static java.util.Comparator<ResourcePool> getDescendingByNumIdleComparator()
-
-