Class StorageHub

All Implemented Interfaces:
CondObserver<Condition,Actor>, NamedObjectOps

public class StorageHub extends Hub
Class representing a storage hub. A storage hub has a set of workers associated with it, a worker queue for idle hub workers, and a table that associates a set of hubs with a worker mode. The table's key is an enum constant whose type is HubWorker.Mode. A storage hub is initialized by providing its (X,Y) coordinates and its system domain. One will also set the the number of workers that loop between sets of hubs repeatedly. The modes for these loops are HubWorker.Mode.LOOP, HubWorker.Mode.LOOP_WITH_PICKUP, and HubWorker.Mode.LOOP_TO_FIX_OVERFLOWS. One will also provide the storage hub with the hubs that can be visited by hub workers for each mode (all modes, not just the ones associated with loops). There should be at least as many workers as are allocated to the three modes listed above. Additional workers will be used on demand (e.g., when a condition requiring an immediate adjustment is detected). While a storage hub specifies allocations, workers are actually started by hub balancers.
See Also:
  • Constructor Details

    • StorageHub

      public StorageHub(DramaSimulation sim, String name, boolean intern)
      Constructor.
      Parameters:
      sim - the simulation
      name - the name of this object
      intern - true if this object should be interned in the simulation's name table; false otherwise
  • Method Details

    • init

      public void init(int upperTrigger, int nominal, int lowerTrigger, int count, double x, double y, SysDomain domain)
      Initialize this object. Each instance of this object has an X and Y coordinate and a system domain, but no user domain.

      As with the Hub class, the X and Y coordinates are used to determine the delays for traveling between two hubs. As a storage domain, however, the only objects traveling to or from a storage domain are hub workers, and the travel time for these is determined by a system domain.

      Parameters:
      count - the initial number of bicycles stored at this hub; -1 to use the nominal value
      lowerTrigger - the lower-trigger value; -1 for the default (0)
      nominal - the nominal value; -1 for the default (0)
      upperTrigger - the upper-trigger value; -1 for the default (Integer.MAX_VALUE)
      x - the X coordinate in meters
      y - the Y coordinate in meters
      domain - the system domain for this storage hub
    • init

      public void init(int capacity, int lowerTrigger, int nominal, int upperTrigger, DoubleRandomVariable pickupTime, int count, int overCount, double x, double y, UsrDomain usrDomain, SysDomain sysDomain)
      Superclass initializer. This is overridden to disable the method. It should not be called except in factories, as it will do nothing. Use init(int,int,int,int,double,double,SysDomain) instead.
      Overrides:
      init in class Hub
      Parameters:
      capacity - a non-negative integer giving the capacity for this hub (the number of bicycles that can be stored at the hub's preferred location)
      lowerTrigger - the lower trigger for the number of bicycles at the preferred location
      nominal - the preferred number of bicycles at this hub's preferred location
      upperTrigger - the upper trigger for the number of bicycles at the preferred location
      pickupTime - a random variable providing the time it takes to pick up a bicycle that is at this hub but not at the hub's preferred location
      count - the initial number of bicycles stored at the preferred location of this hub
      overCount - the initial number of bicycles that are stored at this hub but not at this hub's preferred location
      x - the X value in meters of the preferred location for this hub
      y - the Y value in meters of the preferred location for this hub
      usrDomain - the user domain for this hub
      sysDomain - the system domain for his hub
    • decrBikeCount

      public int decrBikeCount(int decr)
      Decrement the number of bicycles at a storage hub. The value returned may differ from the argument as the number of bicycles at the current location cannot be negative.
      Overrides:
      decrBikeCount in class Hub
      Parameters:
      decr - the decrement in the number of bicycles
      Returns:
      the number of bicycles actually removed from the preferred location
    • setInitialNumberOfWorkers

      public void setInitialNumberOfWorkers(int nworkersNP, int nworkersWP, int nworkersFO, double intervalNP, double intervalWP, double intervalFO)
      Set the initial worker allocations. The initial allocations are desired values. Enough workers must be available for these desired values to be met or the actual number allocated will be less.
      Parameters:
      nworkersNP - the number of workers that will loop between hubs, ignoring the overflow areas but handling the preferred areas, corresponding to the worker mode LOOP_NO_PICKUP
      nworkersWP - the number of workers that will loop between hubs, handling the overflow areas as well as the preferred areas, corresponding to the worker mode LOOP_WITH_PICKUP
      nworkersFO - the number of workers that will pickup bicycles from the overflow areas and deposit these bicycles in the preferred areas, but that will not remove bicycles from the preferred area, corresponding to the worker mode LOOP_TO_FIX_OVERFLOWS
      intervalNP - the desired time interval in units of seconds from the start of one loop to the start of the next for the nworkersNP case (worker mode LOOP_NO_PICKUP)
      intervalWP - the desired time interval in units of seconds from the start of one loop to the start of the next for the nworkersWP case (worker mode LOOP_WITH_PICKUP)
      intervalFO - the desired time interval in units of seconds from the start of one loop to the start of the next for the nworkersFO case (worker mode LOOP_TO_FIX_OVERFLOWS)
    • getInitialNumberOfWorkers

      public int getInitialNumberOfWorkers(HubWorker.Mode mode)
      Get the initial number of workers that were requested. The worker modes that produce non-zero values are LOOP, LOOP_WITH_PICKUP, and LOOP_TO_FIX_OVERFLOWS, and correspond to arguments of the method setInitialNumberOfWorkers(int,int,int,double,double,double).
      Parameters:
      mode - the worker mode for the allocation
      Returns:
      the initial number of workers that were requested for the given mode
    • getInterval

      public double getInterval(HubWorker.Mode mode)
      Get the desired time interval interval from the start of one loop to the start of the next for hub workers with various modes.
      Parameters:
      mode - the mode
      Returns:
      the interval in seconds
    • addHub

      public void addHub(Hub hub)
      Add a hub to the hub table for all modes. If the hub is a storage hub, the hub will not be added
      Parameters:
      hub - the hub to add
    • removeHub

      public void removeHub(Hub hub)
      Remove a hub from the hub table for all modes.
      Parameters:
      hub - the hub to remove
    • addHub

      public boolean addHub(HubWorker.Mode mode, Hub hub)
      Add a hub to the hub table. The hub table assigns an ordered set of hubs to a worker mode. The set is ordered by the order of insertion and indicates the order in which hubs will be visited for each worker mode.

      Storage hubs cannot be added to the hub table.

      Parameters:
      mode - the worker mode; null for all modes
      hub - the hub to add
      Returns:
      true if the hub was added sucessfully and was not previously in the table; false otherwise.
    • removeHub

      public boolean removeHub(HubWorker.Mode mode, Hub hub)
      Remove a hub from the hub table. The hub table assigns an ordered set of hubs to a worker mode. The set is ordered by the order of insertion and indicates the order in which hubs will be visited for each worker mode.
      Parameters:
      mode - the worker mode
      hub - the hub to add
      Returns:
      true if the hub was removed; false if it could not be removed or was already removed
    • getHubs

      public List<Hub> getHubs(HubWorker.Mode mode)
      Get a set of the hubs for a specified worker mode. These are the hubs that a worker will "visit" for the specified mode.
      Parameters:
      mode - the worker mode
      Returns:
      a list of the corresponding hubs, ordered by the sequence in which they were inserted into the hub table
    • getHubsAsArray

      public Hub[] getHubsAsArray(HubWorker.Mode mode)
      Get an array of the hubs for a specified worker mode. These are the hubs that a worker will "visit" for the specified mode.
      Parameters:
      mode - the worker mode
      Returns:
      an array of the corresponding hubs, ordered by the sequence in which they were inserted into the hub table
    • addWorker

      public void addWorker(HubWorker worker)
      Add a worker to this storage hub. This method also inserts the worker into this storage hub's worker queue.

      Note: when a worker is initialized, it will automatically be added to its storage hub. This method would only be used explicitly in the case where a worker is moved from one storage hub to another. In that case, the worker must be queued - not running and not in the process of being moved from one hub to another

      Parameters:
      worker - the worker to add
      Throws:
      IllegalStateException - addWorker was called before a previously scheduled addWorker call could complete or if an addWorker call was made while a worker was running
      See Also:
    • removeWorker

      public void removeWorker(HubWorker worker)
      Remove a worker from this storage hub. This method also removes the worker from this storage hub's worker queue.
      Parameters:
      worker - the worker to remove
    • workerQueueNotUseable

      public boolean workerQueueNotUseable()
      Determine if the worker queue is not usable. A worker queue is not use-able if all its entries are in permanent use. I.e., they were started with a worker mode that causes the worker to loop indefinitely.
      Returns:
      true if the queue is not use-able; false otherwise
    • addOnQueueCallable

      public void addOnQueueCallable(Callable c)
      Add a callable to a list whose first element will be removed and called when a new worker is queued.

      A typical use of this is to delay some action that requires a worker. In this case, the Callable's call method will call pollWorkers() to get a worker and then perform some action with that worker.

      Parameters:
      c - the Callable to add.
    • pollWorkers

      public HubWorker pollWorkers()
      Take a worker off of the worker queue.
      Returns:
      a worker; null if no worker is available
    • queueWorker

      public void queueWorker(HubWorker worker)
      Put a worker onto the worker queue.
      Parameters:
      worker - the worker to insert into the worker queue
    • printConfiguration

      public void printConfiguration(String iPrefix, String prefix, boolean printName, PrintWriter out)
      Print the configuration for an instance of Hub. The documentation for method SimObject.printConfiguration(String,String,boolean,java.io.PrintWriter) contains a description of how this method is used and how to override it. The method GenericActor.printConfiguration(String,String,boolean,java.io.PrintWriter) describes the data that will be printed for the superclass of this class. The data that will be printed when this method is called are the following.

      For class Hub:

      • the X coordinate of this hub in meters.
      • the Y coordinate of this hub in meters.
      • the initial bicycle count.
      • the capacity of this hub.
      • the lower trigger for this hub.
      • the upper trigger for this hub.
      • the user domain for this hub.
      • the system domain for this hub.
      • the pickup time for this hub (the random variable that determines the time in seconds it takes to pickup a bicycle from the overflow area).
      Defined for class StorageHub:
      • the permanent worker allocations. These include:
        • the number of workers that should loop, only visiting a hub's preferred area, and the period in seconds at which successive loops are run.
        • the number of workers that should loop, picking up bicycles from the overflow area and visiting the preferred area, , and the period in seconds at which successive loops are run.
        • the number of workers that should loop, picking up bicycles in the overflow area and moving them to the same hub's preferred area, , and the period in seconds at which successive loops are run.
      • The number of assigned workers plus a list of those workers, listed by name.
      • The hub table. Each "row" in this table consists of a the worker mode and a list of the hubs that a worker with that mode will visit, with the list in the order in which hubs are visited.
      Overrides:
      printConfiguration in class Hub
      Parameters:
      iPrefix - the prefix to use for an initial line when printName is true with null treated as an empty string
      prefix - a prefix string (typically whitespace) to put at the start of each line other than the initial line that is printed when printName is true
      printName - requests printing the name of an object
      out - the output print writer
    • printState

      public void printState(String iPrefix, String prefix, boolean printName, PrintWriter out)
      Print the state for an instance of Hub. The documentation for method SimObject.printState(String,String,boolean,java.io.PrintWriter) contains a description of how this method is used and how to override it. The method GenericSimObject.printState(String,String,boolean,java.io.PrintWriter) describes the data that will be printed for the superclass of this class. The data that will be printed when this method is called are the following.

      For class Hub:

      • the bicycle count for this hub.
      • the count of the number of bicycles in the overflow area for this hub.
      Defined for class StorageHub:
      • the worker-queue and its length, with workers in the queue listed by name.
      Overrides:
      printState in class Hub
      Parameters:
      iPrefix - the prefix to use for an initial line when printName is true with null treated as an empty string
      prefix - a prefix string (typically whitespace) to put at the start of each line other than the initial line that is printed when printName is true
      printName - requests printing the name of an object
      out - the output print writer
    • clone

      protected Object clone() throws CloneNotSupportedException
      Overrides:
      clone in class Object
      Throws:
      CloneNotSupportedException
    • isInterned

      public boolean isInterned()
      Specified by:
      isInterned in interface NamedObjectOps
    • getObjectNamer

      protected Simulation getObjectNamer()
    • getName

      public final String getName()
      Specified by:
      getName in interface NamedObjectOps
    • canDelete

      public boolean canDelete()
      Specified by:
      canDelete in interface NamedObjectOps
    • delete

      public final boolean delete()
      Specified by:
      delete in interface NamedObjectOps
    • isDeleted

      public final boolean isDeleted()
      Specified by:
      isDeleted in interface NamedObjectOps
    • deletePending

      public final boolean deletePending()
      Specified by:
      deletePending in interface NamedObjectOps