Package sim.des

Class BoundedDelay

java.lang.Object
sim.portrayal.SimplePortrayal2D
sim.portrayal.simple.InternalPortrayal2D
All Implemented Interfaces:
Serializable, Named, Parented, ProvidesBarData, Receiver, Resettable, sim.engine.Steppable, sim.portrayal.Portrayal, sim.portrayal.Portrayal2D

public class BoundedDelay extends Delay
A delay pipeline where all delay amounts must be multiples of integers > 0 and less than or equal to a certain maximum bound, which is equal to a delay step length times the integer multiple. A BoundedDelay must be auto-scheduled at a certain time to start it. Thus we have:
  • 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 Details

  • 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

      public 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.
  • Method Details

    • buildDelay

      protected void buildDelay()
      Description copied from class: SimpleDelay
      Builds the delay structure.
      Overrides:
      buildDelay in class Delay
    • getDelayedResources

      public DelayNode[] 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 class Delay
    • getSize

      public double getSize()
      Description copied from class: SimpleDelay
      Returns the number of items currently being delayed.
      Overrides:
      getSize in class Delay
    • 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.
      Overrides:
      clear in class Delay
    • 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 class Delay
    • getDelay

      protected double getDelay(Provider provider, Resource amount)
      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.
      Overrides:
      getDelay in class Delay
    • 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 class Delay
    • 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 class Delay
    • accept

      public boolean accept(Provider provider, Resource amount, double atLeast, double atMost)
      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.
      Specified by:
      accept in interface Receiver
      Overrides:
      accept in class Delay
    • 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.
      Specified by:
      reset in interface Receiver
      Specified by:
      reset in interface Resettable
      Overrides:
      reset in class Delay
    • 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.
      Overrides:
      update in class Delay
    • toString

      public String toString()
      Overrides:
      toString in class Delay