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.Hub
org.bzdev.bikeshare.StorageHub
- All Implemented Interfaces:
CondObserver<Condition,
,Actor> NamedObjectOps
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:
-
Nested Class Summary
Nested classes/interfaces inherited from class org.bzdev.bikeshare.Hub
Hub.TripMessage
-
Field Summary
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoid
Add a hub to the hub table for all modes.boolean
addHub
(HubWorker.Mode mode, Hub hub) Add a hub to the hub table.void
Add a callable to a list whose first element will be removed and called when a new worker is queued.void
Add a worker to this storage hub.boolean
protected Object
clone()
int
decrBikeCount
(int decr) Decrement the number of bicycles at a storage hub.final boolean
delete()
final boolean
getHubs
(HubWorker.Mode mode) Get a set of the hubs for a specified worker mode.Hub[]
getHubsAsArray
(HubWorker.Mode mode) Get an array of the hubs for a specified worker mode.int
Get the initial number of workers that were requested.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.final String
getName()
protected Simulation
void
init
(int upperTrigger, int nominal, int lowerTrigger, int count, double x, double y, SysDomain domain) Initialize this object.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.final boolean
boolean
Take a worker off of the worker queue.void
printConfiguration
(String iPrefix, String prefix, boolean printName, PrintWriter out) Print the configuration for an instance of Hub.void
printState
(String iPrefix, String prefix, boolean printName, PrintWriter out) Print the state for an instance of Hub.void
queueWorker
(HubWorker worker) Put a worker onto the worker queue.void
Remove a hub from the hub table for all modes.boolean
removeHub
(HubWorker.Mode mode, Hub hub) Remove a hub from the hub table.void
removeWorker
(HubWorker worker) Remove a worker from this storage hub.void
setInitialNumberOfWorkers
(int nworkersNP, int nworkersWP, int nworkersFO, double intervalNP, double intervalWP, double intervalFO) Set the initial worker allocations.boolean
Determine if the worker queue is not usable.Methods inherited from class org.bzdev.bikeshare.Hub
addHubDataListener, addHubListener, excessBikes, fireHubDataListeners, fireHubListeners, getBikeCount, getCapacity, getInitialBikeCount, getLowerTrigger, getNominal, getOverflow, getSysDomain, getUpperTrigger, getUsrDomain, getX, getY, incrBikeCount, incrOverflow, needBikes, pickupOverflow, removeHubDataListener, removeHubListener, sendUsers, sendUsers
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
-
StorageHub
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
-
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 classHub
- 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_PICKUPnworkersWP
- 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_PICKUPnworkersFO
- 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_OVERFLOWSintervalNP
- 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)
-
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
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
Take a worker off of the worker queue.- Returns:
- a worker; null if no worker is available
-
printConfiguration
Print the configuration for an instance of Hub. 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
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).
- 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 classHub
- 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 Hub. 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
Hub
:- the bicycle count for this hub.
- the count of the number of bicycles in the overflow area for this hub.
- the worker-queue and its length, with workers in the queue listed by name.
- Overrides:
printState
in classHub
- 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