Class 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.

    • Constructor Detail

      • ResourcePool

        public 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
      • 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 element
        units - a list of ResourceUnits. Must not contain nulls and must not contain duplicates
        name - the name of the pool
      • ResourcePool

        public 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
      • ResourcePool

        public 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

      • 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
      • 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
      • 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: 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 interface RNStreamControlIfc
      • setAntitheticOption

        public void setAntitheticOption​(boolean flag)
        Description copied from interface: RNStreamControlIfc
        Tells the stream to start producing antithetic variates
        Specified by:
        setAntitheticOption in interface RNStreamControlIfc
        Parameters:
        flag - true means that it produces antithetic variates.
      • getResetStartStreamOption

        public final boolean getResetStartStreamOption()
        Gets the current Reset Start Stream Option
        Specified by:
        getResetStartStreamOption in interface StreamOptionIfc
        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:
        setResetStartStreamOption in interface StreamOptionIfc
        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:
        getResetNextSubStreamOption in interface StreamOptionIfc
        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:
        setResetNextSubStreamOption in interface StreamOptionIfc
        Parameters:
        b -
      • beforeExperiment

        protected void beforeExperiment()
        before any replications reset the underlying random number generator to the starting stream

        Overrides:
        beforeExperiment in class ModelElement
      • 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:
        replicationEnded in class ModelElement
      • afterReplication

        protected void afterReplication()
        after each replication reset the underlying random number generator to the next substream
        Overrides:
        afterReplication in class ModelElement
      • 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()