Class HubWorker

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

public class HubWorker extends Actor
Class representing a hub worker. Hub workers either wait in queues or move between hubs and adjust the number of bicycles in each one. An enumeration type HubWorker.Mode determines what the workers do at each node and whether they visit a sequence of nodes once or repeatedly.

Each worker is assigned to a storage hub, which in turn maintains a queue of available workers, some of which are preassigned to perform particular tasks repeatedly and some of which are used on demand.

Hub workers are started when a hub balancer calls the method start(HubWorker.Mode, HubWorker.HubSorter,double,double). For modes whose names contain the string LOOP, the worker will loop between hubs repeatedly, trying to start at fixed intervals. Otherwise the worker will visit a series of hubs and return to the worker's storage hub, placing themselves back into the storage hub's worker queue.

  • Constructor Details

    • HubWorker

      public HubWorker(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

    • getBikeCount

      public int getBikeCount()
      Get the current bicycle count at the preferred location.
      Returns:
      the current bicycle count at the preferred location
    • getCapacity

      public int getCapacity()
      Get the capacity at the preferred location. The capacity is that maximum number of bicycles that can be stored at the preferred location of this hub.
      Returns:
      the capacity at the preferred location for this hub
    • getCurrentHub

      public Hub getCurrentHub()
      Get the current hub.
      Returns:
      the current hub; null if none has been set.
    • isMoving

      public boolean isMoving()
      Determine if a hub worker is being moved between storage hubs.
      Returns:
      true of the worker is being moved; false otherwise
    • getMoveCompletionTime

      public double getMoveCompletionTime()
      Get the simulation time at which this worker completed a move between storage hubs
      Returns:
      the time in seconds from the start of the simulation
    • init

      public void init(int capacity, StorageHub shub, SysDomain domain, Hub currentHub)
      Initialize a hub worker.
      Parameters:
      capacity - the number of bicycles a hub worker can carry
      shub - the storage hub to which a hub worker is assigned
      domain - the hub worker's system domain
      currentHub - the hub at which the hub worker is initially located (this may be the hub worker's storage hub)
    • isRunning

      public boolean isRunning()
      Determine if a worker is running. Running implies that the worker is not in a queue and is actively processing various hubs.
      Returns:
      true if the worker is running; false otherwise.
    • addHubWorkerListener

      public void addHubWorkerListener(HubWorkerListener listener)
      Add a hub-worker listener to the current object.
      Parameters:
      listener - the listener to add
    • removeHubWorkerListener

      public void removeHubWorkerListener(HubWorkerListener listener)
      Remove a hub-worker listener from the current object.
      Parameters:
      listener - the listener to remove
    • fireEnteredHub

      protected void fireEnteredHub(Hub hub)
      Indicate that a worker has entered a hub.
      Parameters:
      hub - the hub at which this event occurred
    • fireFixingOverflows

      protected void fireFixingOverflows(Hub hub)
      Indicate that a worker has started to fix the overflow area.
      Parameters:
      hub - the hub at which this event occurred
    • fireFixingPreferred

      protected void fireFixingPreferred(Hub hub)
      Indicate that a worker has started to fix the preferred area.
      Parameters:
      hub - the hub at which this event occurred
    • fireQueued

      protected void fireQueued(Hub hub)
      Indicate that a worker has been queued.
      Parameters:
      hub - the hub at which this event occurred
    • fireChangedCount

      protected void fireChangedCount(Hub hub, int oldCount, int newCount)
      Indicate that a worker's bicycle count has changed.
      Parameters:
      hub - the hub at which this event occurred
      oldCount - the old value of the bicycle count
      newCount - the new value fo the bicycle count
    • start

      public void start(HubWorker.Mode mode, HubWorker.HubSorter hubSorter, double wait, double offset)
      Start a hub worker. The worker's behavior depends on worker mode as described by the documentation for HubWorker.Mode. The second argument is an array. Hubs will be "visited" in the order provided by the array. For worker mode's whose name contains the string LOOP, the hubs in the array will be visited an unlimited number of times.

      The specified wait will be ignore if the time needed to traverse a loop is more than the wait time.

      Parameters:
      mode - the worker mode to use
      hubSorter - the hub sorter
      wait - the desired time in seconds to wait after starting one loop before starting the next (used for modes that loop)
      offset - an initial offset in seconds before starting a loop (ignored for on-demand workers)
    • loop

      protected void loop(HubWorker.HubSorter hubSorter, long period, long loffset)
      Visit a sequence of hubs repeatedly, adjusting the number of bicycles in the preferred area.
      Parameters:
      hubSorter - the hub sorter
      period - the period in simulation ticks
      loffset - the initial wait in simulation ticks before starting the first loop
    • visit

      protected void visit(HubWorker.HubSorter hubSorter)
      Visit a sequence of hubs, adjusting the number of bicycles in the preferred area.
      Parameters:
      hubSorter - the hub seror
    • loopWithPickup

      protected void loopWithPickup(HubWorker.HubSorter hubSorter, long period, long loffset)
      Visit a sequence of hubs repeatedly, picking up bicycles from the overflow area and adjusting the number of bicycles in the preferred area.
      Parameters:
      hubSorter - the hub seror
      period - the period in simulation ticks
      loffset - the initial wait in simulation ticks before starting the first loop
    • visitWithPickup

      protected void visitWithPickup(HubWorker.HubSorter hubSorter)
      Visit a sequence of hubs, picking up bicycles from the overflow area and adjusting the number of bicycles in the preferred area.
      Parameters:
      hubSorter - the hub seror
    • loopToFixOverflows

      protected void loopToFixOverflows(HubWorker.HubSorter hubSorter, long period, long loffset)
      Visit a sequence of hubs repeatedly, picking up bicycles from the overflow area and putting as many as possible into the preferred area.
      Parameters:
      hubSorter - the hub seror
      period - the period in simulation ticks
      loffset - the initial wait in simulation ticks before starting the first loop
    • visitToFixOverflows

      protected void visitToFixOverflows(HubWorker.HubSorter hubSorter)
      Visit a sequence of hubs, picking up bicycles from the overflow area and putting as many as possible into the preferred area.
      Parameters:
      hubSorter - the hub seror
    • printConfiguration

      public void printConfiguration(String iPrefix, String prefix, boolean printName, PrintWriter out)
      Print the configuration for an instance of HubWorker. 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 HubWorker:

      • the capacity of this worker (the number of bicycles the worker can move at one time).
      • the storage hub to which this worker is assigned.
      Overrides:
      printConfiguration in class GenericActor<DramaSimulation,Actor,Condition,Domain,DomainMember,DramaFactory,Group>
      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 HubWorker. 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 HubWorker:

      • the number of bicycles this worker is carrying.
      • the hub this worker is currently visiting.
      • whether or not the worker is running.
      • the current value of the worker mode for this worker.
      • when the worker is running, a list of the hubs being visited.
      Overrides:
      printState in class GenericSimObject<DramaSimulation,Actor,Condition,Domain,DomainMember,DramaFactory,Group>
      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