java.lang.Object
org.bzdev.devqsim.SimObject
org.bzdev.drama.generic.GenericSimObject<S,A,C,D,DM,F,G>
org.bzdev.drama.generic.GenericTaskObject<S,A,C,D,DM,F,G>
org.bzdev.drama.common.MessageRecipient<S,A,C,D,DM,F,G>
org.bzdev.drama.generic.GenericMsgRecipient<S,A,C,D,DM,F,G>
org.bzdev.drama.generic.GenericActor<DramaSimulation,Actor,Condition,Domain,DomainMember,DramaFactory,Group>
org.bzdev.drama.Actor
org.bzdev.bikeshare.HubWorker
- All Implemented Interfaces:
CondObserver<Condition,
,Actor> NamedObjectOps
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.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic interface
Interface for classes that generate a traversal order for hubs.static enum
Enumeration listing the Worker modes. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoid
addHubWorkerListener
(HubWorkerListener listener) Add a hub-worker listener to the current object.boolean
protected Object
clone()
final boolean
delete()
final boolean
protected void
fireChangedCount
(Hub hub, int oldCount, int newCount) Indicate that a worker's bicycle count has changed.protected void
fireEnteredHub
(Hub hub) Indicate that a worker has entered a hub.protected void
fireFixingOverflows
(Hub hub) Indicate that a worker has started to fix the overflow area.protected void
fireFixingPreferred
(Hub hub) Indicate that a worker has started to fix the preferred area.protected void
fireQueued
(Hub hub) Indicate that a worker has been queued.int
Get the current bicycle count at the preferred location.int
Get the capacity at the preferred location.Get the current hub.double
Get the simulation time at which this worker completed a move between storage hubsfinal String
getName()
protected Simulation
void
init
(int capacity, StorageHub shub, SysDomain domain, Hub currentHub) Initialize a hub worker.final boolean
boolean
boolean
isMoving()
Determine if a hub worker is being moved between storage hubs.boolean
Determine if a worker is running.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.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.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.void
printConfiguration
(String iPrefix, String prefix, boolean printName, PrintWriter out) Print the configuration for an instance of HubWorker.void
printState
(String iPrefix, String prefix, boolean printName, PrintWriter out) Print the state for an instance of HubWorker.void
removeHubWorkerListener
(HubWorkerListener listener) Remove a hub-worker listener from the current object.void
start
(HubWorker.Mode mode, HubWorker.HubSorter hubSorter, double wait, double offset) Start a hub worker.protected void
visit
(HubWorker.HubSorter hubSorter) Visit a sequence of hubs, adjusting the number of bicycles in the preferred area.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.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.Methods inherited from class org.bzdev.drama.Actor
doReceive, onConditionChange
Methods inherited from class org.bzdev.drama.generic.GenericActor
addCondition, conditionSet, domainSet, drainMessageQueue, findMsgFrwdngInfo, findMsgFrwdngInfo, findMsgFrwdngInfo, findMsgFrwdngInfo, findMsgFrwdngInfo, findMsgFrwdngInfo, findMsgFrwdngInfo, getChildDomains, getConditionChangeQMode, getCondObserverImpl, hasCondition, inDomain, joinDomain, joinDomain, leaveDomain, onConditionChange, onDelete, removeCondition, send, send, send, send, send, send, send, send, send, send, send, setConditionChangeQMode, setMessageQueueing, setSharedDomainMember
Methods inherited from class org.bzdev.drama.generic.GenericMsgRecipient
getGroups, inGroup, joinGroup, joinGroup, leaveGroup
Methods inherited from class org.bzdev.drama.generic.GenericTaskObject
cancelDefaultCall, cancelDefaultTask, defaultCall, defaultTask, scheduleDefaultCall, scheduleDefaultTask, scheduleDefaultTask
Methods inherited from class org.bzdev.drama.generic.GenericSimObject
getSimulation
Methods inherited from class org.bzdev.devqsim.SimObject
addSimulationListener, addTraceSet, bindCallable, bindCallable, bindCallable, bindCallable, bindRunnable, bindRunnable, bindRunnable, bindRunnable, callableObject, callableScript, callScriptFunction, callScriptMethod, clearTraceSets, evalScript, getEventListenerList, getScriptObject, getTraceSets, printConfiguration, printConfiguration, printConfiguration, printConfiguration, printConfiguration, printConfiguration, printState, printState, printState, printState, printState, printState, putScriptObject, removeSimulationListener, removeTraceSet, runnableObject, runnableScript, scheduleCall, scheduleCall, scheduleCall, scheduleCall, scheduleCallObject, scheduleScript, scheduleTask, scheduleTask, scheduleTask, scheduleTask, scheduleTaskObject, scheduleTaskScript, startImmediateTask, startImmediateTask, trace, trace, unscheduledTaskThread, unscheduledTaskThread, update, update, usesTraceSet
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface org.bzdev.obnaming.NamedObjectOps
canDelete, delete, deletePending, getName, isDeleted, isInterned
-
Constructor Details
-
HubWorker
Constructor.- Parameters:
sim
- the simulationname
- the name of this objectintern
- 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
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
-
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.
-
printConfiguration
Print the configuration for an instance of HubWorker. The documentation for methodSimObject.printState(String,String,boolean,java.io.PrintWriter)
contains a description of how this method is used and how to override it. The methodGenericSimObject.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 classGenericActor<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 stringprefix
- a prefix string (typically whitespace) to put at the start of each line other than the initial line that is printed when printName is trueprintName
- requests printing the name of an objectout
- the output print writer
-
printState
Print the state for an instance of HubWorker. The documentation for methodSimObject.printConfiguration(String,String,boolean,java.io.PrintWriter)
contains a description of how this method is used and how to override it. The methodGenericActor.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 classGenericSimObject<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 stringprefix
- a prefix string (typically whitespace) to put at the start of each line other than the initial line that is printed when printName is trueprintName
- requests printing the name of an objectout
- the output print writer
-
clone
- Overrides:
clone
in classObject
- Throws:
CloneNotSupportedException
-
isInterned
public boolean isInterned()- Specified by:
isInterned
in interfaceNamedObjectOps
-
getObjectNamer
-
getName
- Specified by:
getName
in interfaceNamedObjectOps
-
canDelete
public boolean canDelete()- Specified by:
canDelete
in interfaceNamedObjectOps
-
delete
public final boolean delete()- Specified by:
delete
in interfaceNamedObjectOps
-
isDeleted
public final boolean isDeleted()- Specified by:
isDeleted
in interfaceNamedObjectOps
-
deletePending
public final boolean deletePending()- Specified by:
deletePending
in interfaceNamedObjectOps
-