Package jsl.modeling.elements.station
Class SResource
- java.lang.Object
-
- jsl.simulation.ModelElement
-
- jsl.simulation.SchedulingElement
-
- jsl.modeling.elements.station.SResource
-
- All Implemented Interfaces:
ObservableIfc
,GetNameIfc
,IdentityIfc
public class SResource extends SchedulingElement
A SResource represents a simple resource that can have units become busy. A resource is considered busy when it has 1 or more units busy. A resource is considered idle when all available units are idle. A resource has an initial capacity, which represents the units that can be allocated. The capacity of the resource represents the maximum number of units available for use. For example, if the resource has capacity 3, it may have 2 units busy and 1 unit idle. A resource cannot have more units busy than the capacity.
-
-
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 static int
RELEASE
Indicates that the resource was released for state change purposes That is, units of resource became idle.static int
SEIZE
Indicates that the resource was seized for state change purposes That is, units of the resource became busy.-
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 SResource(ModelElement parent)
The capacity is set to 1SResource(ModelElement parent, int capacity)
The capacity represents the maximum number of units available to use when the resource is idle.SResource(ModelElement parent, int capacity, java.lang.String name)
The capacity represents the maximum number of units available to use when the resource is idle.SResource(ModelElement parent, java.lang.String name)
The capacity is set to 1
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description java.lang.String
asString()
Allows sub-classes to provide more detail than toString() to represent the ModelElement as a Stringvoid
attachStateChangeListener(SResourceStateChangeListenerIfc listener)
void
detachStateChangeListener(SResourceStateChangeListenerIfc listener)
int
getCapacity()
The current capacity of the resource.double
getFractionBusy()
The fraction of the capacity that is currently busyint
getInitialCapacity()
Gets the initial capacity of the resourceStatisticAccessorIfc
getNBAcrossReplicationStatistic()
Across replication statistics on the number busyint
getNumberAvailable()
Returns the number of units that are currently available for useint
getNumberTimesReleased()
Returns how many times the resource has had units returned from use.int
getNumberTimesSeized()
Returns how many times the resource has had units used.int
getNumBusy()
The number of units that are currently busyprotected ModelElementState
getPreviousState()
StatisticAccessorIfc
getUtilAcrossReplicationStatistic()
Across replication statistics on the utilizationboolean
hasAvailableUnits()
Returns true if getNumberAvailable() > 0protected void
initialize()
This method should be overridden by subclasses that need actions performed to initialize prior to a replication.boolean
isBusy()
Checks to see if the resource is busy.boolean
isIdle()
Checks if the resource is idle.protected void
notifyStateChangeListeners()
void
release()
Releases 1 unit of the resource.void
release(int amt)
Releases amt units of the resource.void
seize()
Seizes 1 unit of the resource.void
seize(int amt)
Seizes amt units of the resource.void
setInitialCapacity(int capacity)
Sets the initial capacity of the resource.protected void
setPreviousState(ModelElementState state)
protected void
setState(ModelElementState state)
protected void
updateState(int change)
-
Methods inherited from class jsl.simulation.SchedulingElement
cancelEvent, rescheduleEvent, rescheduleEvent, rescheduleEvent, rescheduleEvent, scheduleEvent, scheduleEvent, scheduleEvent, scheduleEvent, scheduleEvent, scheduleEvent, scheduleEvent, scheduleEvent, scheduleEvent, scheduleEvent
-
Methods inherited from class jsl.simulation.ModelElement
addObserver, addObserverToModelElements, afterExperiment, afterExperiment_, afterReplication, afterReplication_, beforeExperiment, 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_, removedFromModel, 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
-
-
-
-
Field Detail
-
SEIZE
public static final int SEIZE
Indicates that the resource was seized for state change purposes That is, units of the resource became busy.
-
RELEASE
public static final int RELEASE
Indicates that the resource was released for state change purposes That is, units of resource became idle.
-
-
Constructor Detail
-
SResource
public SResource(ModelElement parent)
The capacity is set to 1- Parameters:
parent
- the parent model element
-
SResource
public SResource(ModelElement parent, java.lang.String name)
The capacity is set to 1- Parameters:
parent
- the parent model elementname
- a unique name for the resource
-
SResource
public SResource(ModelElement parent, int capacity)
The capacity represents the maximum number of units available to use when the resource is idle.- Parameters:
parent
- the parent model elementcapacity
- the initial capacity of the resource
-
SResource
public SResource(ModelElement parent, int capacity, java.lang.String name)
The capacity represents the maximum number of units available to use when the resource is idle.- Parameters:
parent
- the parent model elementcapacity
- the initial capacity of the resourcename
- a unique name for the resource
-
-
Method Detail
-
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
-
getNumberTimesSeized
public final int getNumberTimesSeized()
Returns how many times the resource has had units used.- Returns:
- how many times the resource has had units used.
-
getNumberTimesReleased
public final int getNumberTimesReleased()
Returns how many times the resource has had units returned from use.- Returns:
- how many times the resource has had units returned from use
-
getFractionBusy
public final double getFractionBusy()
The fraction of the capacity that is currently busy- Returns:
- fraction of the capacity that is currently busy
-
getNumBusy
public final int getNumBusy()
The number of units that are currently busy- Returns:
- number of units that are currently busy
-
seize
public final void seize()
Seizes 1 unit of the resource. If the resource has no units available, then an exception occurs. If getNumberAvailable() = 0 then an exception occurs.
-
seize
public void seize(int amt)
Seizes amt units of the resource. If amt = 0, then an exception occurs. If the resource has no units available, then an exception occurs. If the amt > getNumberAvailable() then an exception occurs.- Parameters:
amt
- the amount to seize
-
updateState
protected void updateState(int change)
-
release
public final void release()
Releases 1 unit of the resource. If the number busy is zero, then an exception occurs.
-
release
public void release(int amt)
Releases amt units of the resource. If amt is 0 then an exception occurs. If the amt is > getNumBusy() then an exception occurs- Parameters:
amt
- the amount to release
-
asString
public java.lang.String asString()
Description copied from class:ModelElement
Allows sub-classes to provide more detail than toString() to represent the ModelElement as a String- Overrides:
asString
in classModelElement
- Returns:
- a detailed String representation
-
isIdle
public final boolean isIdle()
Checks if the resource is idle. The resource is idle if all available units are idle.- Returns:
- true if idle, false otherwise
-
isBusy
public final boolean isBusy()
Checks to see if the resource is busy. The resource is busy if 1 or more of its units are busy.- Returns:
- true if busy
-
getCapacity
public final int getCapacity()
The current capacity of the resource.- Returns:
- the capacity
-
getNumberAvailable
public int getNumberAvailable()
Returns the number of units that are currently available for use- Returns:
- the number of units that are currently available for use
-
hasAvailableUnits
public final boolean hasAvailableUnits()
Returns true if getNumberAvailable() > 0- Returns:
- true if getNumberAvailable() > 0
-
getInitialCapacity
public final int getInitialCapacity()
Gets the initial capacity of the resource- Returns:
- the initial capacity of the resource
-
setInitialCapacity
public final void setInitialCapacity(int capacity)
Sets the initial capacity of the resource. This only changes it for when the resource is initialized.- Parameters:
capacity
- the initial capacity of the resource
-
detachStateChangeListener
public void detachStateChangeListener(SResourceStateChangeListenerIfc listener)
-
attachStateChangeListener
public void attachStateChangeListener(SResourceStateChangeListenerIfc listener)
-
notifyStateChangeListeners
protected void notifyStateChangeListeners()
-
setState
protected void setState(ModelElementState state)
-
getPreviousState
protected ModelElementState getPreviousState()
-
setPreviousState
protected void setPreviousState(ModelElementState state)
-
getNBAcrossReplicationStatistic
public final StatisticAccessorIfc getNBAcrossReplicationStatistic()
Across replication statistics on the number busy- Returns:
-
getUtilAcrossReplicationStatistic
public final StatisticAccessorIfc getUtilAcrossReplicationStatistic()
Across replication statistics on the utilization- Returns:
-
-