Class BoundedDelay
- All Implemented Interfaces:
Serializable
,Named
,Parented
,ProvidesBarData
,Receiver
,Resettable
,sim.engine.Steppable
,sim.portrayal.Portrayal
,sim.portrayal.Portrayal2D
- An initial start time
- A maximum delay step length (an integer > 0)
- A delay interval (an integer > 0)
The point of BoundedDelay is that it can do many things that you would ordinarily use a Delay for, but it has an O(1) operation rather than an O(lg n) operation, often resulting in dramatic increases in efficiency for some models.
When a BoundedDelay accepts a Resource, it must first compute the delay length. If you are using a fixed delay time, this delay time must be greater than 0 and less than or equal to the maximum delay time, which is equal to the delay step length times the delay interval. If you are using a distribution, then BoundedDelay will try up to MAX_DELAY_TRIES times to pull a value from the distribution and take the absolute value, until it finds a result that is within these bounds. If it cannot find a valid result, it will issue an exception -- you don't want that. So use a distribution which does the job properly.
Once the BoundedDelay has a valid delay length, it adds the Resource to its delay array.
BoundedDelay should be stepped by the Schedule at multiples of the delay step length starting at some initial time. You should probably do this by calling autoScheduleAt(...). If the BoundedDelay is stepped at other intervals or times, it will not work properly.
- See Also:
-
Field Summary
Fields inherited from class sim.des.Middleman
totalReceivedResource
Fields inherited from class sim.des.Provider
entities, OFFER_ORDER_FIFO, OFFER_ORDER_LIFO, OFFER_POLICY_BACKWARD, OFFER_POLICY_FORWARD, OFFER_POLICY_RANDOM, OFFER_POLICY_ROUND_ROBIN, OFFER_POLICY_SELECT, OFFER_POLICY_SHUFFLE, resource, state, totalAcceptedOfferResource
Fields inherited from class sim.portrayal.simple.InternalPortrayal2D
portrayal
Fields inherited from class sim.portrayal.SimplePortrayal2D
TYPE_HIT_OBJECT, TYPE_SELECTED_OBJECT
-
Constructor Summary
ConstructorDescriptionBoundedDelay
(sim.engine.SimState state, double delayTime, Resource typical, int maxDelaySteps) Creates a BoundedDelay with a 0 ordering, the given delay time, max delay time, a delay interval of 1, and typical resource.BoundedDelay
(sim.engine.SimState state, double delayTime, Resource typical, int maxDelaySteps, int delayInterval) Creates a BoundedDelay with a 0 ordering, the given max delay time, delay interval, and typical resource.BoundedDelay
(sim.engine.SimState state, Resource typical, int maxDelaySteps) Creates a Delay with a 0 ordering, a delay time of 1.0, max delay time, a delay interval of 1, and typical resource.BoundedDelay
(sim.engine.SimState state, Resource typical, int maxDelaySteps, int delayInterval) Creates a Delay with a 0 ordering, a delay time of 1.0, max delay time, delay interval, and typical resource. -
Method Summary
Modifier and TypeMethodDescriptionboolean
Accepts up to CAPACITY of the given resource and places it in the delay, then auto-reschedules the delay if that feature is on.void
autoScheduleAt
(double time) A convenience method which calls setAutoSchedules(true), then schedules the BoundedDelay on the Schedule using the current rescheduleOrdering.protected void
Builds the delay structure.void
clear()
Clears all resources currently in the SimpleDelay.protected double
Returns the appropriate delay value for the given provider and resource amount.Returns in an array all the Resources currently being delayed and not yet ready to provide, along with their timestamps (when they are due to become available), combined as a DelayNode.int
double
getSize()
Returns the number of items currently being delayed.boolean
Returns whether the delay is cumulative.void
reset
(sim.engine.SimState state) Resets the received (and accepted) resource amount to 0, among other possible things.void
setCumulative
(boolean val) Returns whether the delay is cumulative.void
setDelayInterval
(int val) void
setDelayTime
(double delayTime) Sets the delay time.toString()
protected void
update()
Deletes exiting available resources, then checks the delay pipeline to determine if any resources have come available, and makes them available to registered receivers in zero time.Methods inherited from class sim.des.Delay
getDelayDistribution, getLastDelay, getLastDelayTime, getRefusesOffers, getUsesLastDelay, hideDelayedResources, setDelayDistribution, setLastDelay, setRefusesOffers, setUsesLastDelay
Methods inherited from class sim.des.SimpleDelay
buildDefaultPortrayal, callSlackProvider, drop, getAutoSchedules, getCapacity, getDataBars, getDataLabels, getDataValues, getDelayed, getDelayedPlusAvailable, getDelayTime, getDropsResourcesBeforeUpdate, getIncludesAvailableResourcesInTotal, getRescheduleOrdering, getSlackProvider, getSlackReceiver, getUsesLookup, hideAutoSchedules, hideDelayTime, hideRescheduleOrdering, lookup, offerReceivers, setAutoSchedules, setCapacity, setDropsResourcesBeforeUpdate, setIncludesAvailableResourcesInTotal, setRescheduleOrdering, setSlackProvider, setSlackReceiver, setUsesLookup, step
Methods inherited from class sim.des.Middleman
getReceiverResourceRate, getTotalReceivedResource, getTypicalReceived, performTransaction, throwUnequalReceivedTypeException, transact, transact
Methods inherited from class sim.des.Provider
addReceiver, getAvailable, getDrawState, getEntities, getEntity, getLastAcceptedOfferReceivers, getLastAcceptedOffers, getLastAcceptedOfferTime, getLastOfferTime, getMakesOffers, getName, getOfferDistribution, getOfferOrder, getOfferPolicy, getOfferResourceRate, getOffersAllEntities, getOffersTakeItOrLeaveIt, getParent, getReceivers, getState, getTotalAcceptedOfferResource, getTypicalProvided, hideDataBars, hideDataLabels, hideDataValues, hideDrawState, hideEntities, hideOfferDistribution, hideOfferOrder, hideOfferPolicy, hideOffersTakeItOrLeaveIt, hidePositiveNonNaN, hidePositiveOrZeroNonNaN, isOffering, isPositiveNonNaN, isPositiveOrZeroNonNaN, offerReceiver, offerReceiver, offerReceivers, provide, provide, removeReceiver, requestEntity, selectedOfferAccepted, selectReceiver, setMakesOffers, setName, setOfferDistribution, setOfferDistribution, setOfferOrder, setOfferPolicy, setOffersAllEntities, setOffersTakeItOrLeaveIt, setParent, throwCyclicOffers, throwDoesNotProvideEntities, throwInvalidAtLeastAtMost, throwInvalidEntityNumber, throwInvalidMinMax, throwUnequalTypeException
Methods inherited from class sim.des.portrayal.DESPortrayal
buildDefaultImagePortrayal, buildPortrayal, getFillPaint, getImagePath, getStrokePaint, getStrokeWidth, getUsesGlobalImageClass, hideFillPaint, hideImagePath, hideStrokePaint, hideStrokeWidth, providePortrayal, setFillPaint, setImage, setStrokePaint, setStrokeWidth
Methods inherited from class sim.portrayal.simple.InternalPortrayal2D
draw, getInspector, getName, handleMouseEvent, hitObject, setSelected
Methods inherited from class sim.portrayal.SimplePortrayal2D
getStatus
-
Field Details
-
MAX_DELAY_TRIES
public static final double MAX_DELAY_TRIES- See Also:
-
-
Constructor Details
-
BoundedDelay
public BoundedDelay(sim.engine.SimState state, double delayTime, Resource typical, int maxDelaySteps, int delayInterval) Creates a BoundedDelay with a 0 ordering, the given max delay time, delay interval, and typical resource. -
BoundedDelay
public BoundedDelay(sim.engine.SimState state, double delayTime, Resource typical, int maxDelaySteps) Creates a BoundedDelay with a 0 ordering, the given delay time, max delay time, a delay interval of 1, and typical resource. -
BoundedDelay
public BoundedDelay(sim.engine.SimState state, Resource typical, int maxDelaySteps, int delayInterval) Creates a Delay with a 0 ordering, a delay time of 1.0, max delay time, delay interval, and typical resource. -
BoundedDelay
Creates a Delay with a 0 ordering, a delay time of 1.0, max delay time, a delay interval of 1, and typical resource.
-
-
Method Details
-
buildDelay
protected void buildDelay()Description copied from class:SimpleDelay
Builds the delay structure.- Overrides:
buildDelay
in classDelay
-
getDelayedResources
Description copied from class:Delay
Returns in an array all the Resources currently being delayed and not yet ready to provide, along with their timestamps (when they are due to become available), combined as a DelayNode. Note that this is a different set of Resources than Provider.getEntities() returns. You can modify the array (it's yours), but do not modify the DelayNodes nor the Resources stored inside them, as they are the actual Resources being delayed.- Overrides:
getDelayedResources
in classDelay
-
getSize
public double getSize()Description copied from class:SimpleDelay
Returns the number of items currently being delayed. -
getDelayInterval
public int getDelayInterval() -
setDelayInterval
public void setDelayInterval(int val) -
clear
public void clear()Description copied from class:SimpleDelay
Clears all resources currently in the SimpleDelay. -
setDelayTime
public void setDelayTime(double delayTime) Description copied from class:Delay
Sets the delay time. Unlike a SimpleDelay, a Delay does not also clear its delay queue when setting the delay time: and so you are free to call this method any time you need to without issues. The default delay time is 1.0. Delay times may not be negative or NaN.- Overrides:
setDelayTime
in classDelay
-
getDelay
Description copied from class:Delay
Returns the appropriate delay value for the given provider and resource amount. You can override this as you see fit, though the defaults should work fine in most cases. The defaults are: if getUsesLastDelay(), and there has been at least one previous resource entered into the Delay already, then the most recent previous delay time is used. Otherwise if the delay distribution has been set, it is queried and its absolute value is used to produce a random delay time under the distribution (delay times may not be negative or NaN). Otherwise the fixed delay time is used (which defaults to 1.0). Override this to provide a custom delay given the provider and resource amount or type. -
isCumulative
public boolean isCumulative()Description copied from class:Delay
Returns whether the delay is cumulative. When you submit a Resource to a Delay, its final delay time is computed. Normally this is an absolute time: for example, if the current time is 9.2, and the relative delay interval is computed as 2.3 steps, then the Resource will become available at 11.5. However, another "cumulative" option is to compute the final delay time relative to the last delay time used. For example, if the final delay time of the previous Resource entered was 13.4, and the relative delay interval is 2.3 steps, then the new Resource will become available at 15.6. This makes it easy to compute each Resource as "processed" over a period of time after the previous Resource was processed.For the first Resource, or after you reset the Delay, or after you restart the simulation, or if the Delay is empty, the delay time will be relative to the current time, or the Simulation Epoch, whichever is later.
- Overrides:
isCumulative
in classDelay
-
setCumulative
public void setCumulative(boolean val) Description copied from class:Delay
Returns whether the delay is cumulative. When you submit a Resource to a Delay, its final delay time is computed. Normally this is an absolute time: for example, if the current time is 9.2, and the relative delay interval is computed as 2.3 steps, then the Resource will become available at 11.5. However, another "cumulative" option is to compute the final delay time relative to the last delay time used. For example, if the final delay time of the previous Resource entered was 13.4, and the relative delay interval is 2.3 steps, then the new Resource will become available at 15.6. This makes it easy to compute each Resource as "processed" over a period of time after the previous Resource was processed.For the first Resource, or after you reset the Delay, or after you restart the simulation, or if the Delay is empty, the delay time will be relative to the current time, or the Simulation Epoch, whichever is later.
- Overrides:
setCumulative
in classDelay
-
accept
Description copied from class:SimpleDelay
Accepts up to CAPACITY of the given resource and places it in the delay, then auto-reschedules the delay if that feature is on. -
autoScheduleAt
public void autoScheduleAt(double time) A convenience method which calls setAutoSchedules(true), then schedules the BoundedDelay on the Schedule using the current rescheduleOrdering. The BoundedDelay is initially scheduled at the given time. -
reset
public void reset(sim.engine.SimState state) Description copied from interface:Receiver
Resets the received (and accepted) resource amount to 0, among other possible things. -
update
protected void update()Description copied from class:SimpleDelay
Deletes exiting available resources, then checks the delay pipeline to determine if any resources have come available, and makes them available to registered receivers in zero time. -
toString
-