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.HubBalancer
org.bzdev.bikeshare.BasicHubBalancer
- All Implemented Interfaces:
CondObserver<Condition,
,Actor> NamedObjectOps
Basic hub balancer class.
This class provides a simple implementation of a hub
balancer in which additional workers are scheduled based on
the fraction of hubs that are in the hub balancer's user domain
and that (1) have bicycles in their overflow areas, (2) have
more bicycles in their preferred areas than the value provided
by an upper trigger, or (3) have fewer bicycles in their preferred
areas than the value provided by a lower trigger. When this
fraction is larger than a threshold, an additional worker is
scheduled from each storage hub in the hub balancer's system domain.
In addition, a timer is started (the interval is called the quiet
period and is configurable). Additional workers will not be
scheduled until this timer expires.
Subclasses that change the behavior of this class only by
overriding
HubBalancer.getHubSorter(HubWorker.Mode,StorageHub,Hub[])
are
relatively simple extensions of this class. For more complex
changes, one will want to override startAdditionalWorkers()
as well, in which case it might be better to create a subclass
of HubBalancer
itself.
-
Constructor Summary
ConstructorsConstructorDescriptionBasicHubBalancer
(DramaSimulation sim, String name, boolean intern) Constructor. -
Method Summary
Modifier and TypeMethodDescriptionboolean
protected Object
clone()
final boolean
delete()
final boolean
getHubSorter
(HubWorker.Mode mode, StorageHub shub, Hub[] hubs) Get a hub sorter.final String
getName()
protected Simulation
long
Get the quiet period.double
Get the fraction of the number of hubs beyond which a worker may be scheduled.final boolean
boolean
void
printConfiguration
(String iPrefix, String prefix, boolean printName, PrintWriter out) Print the configuration for an instance of HubBalancer.void
printState
(String iPrefix, String prefix, boolean printName, PrintWriter out) Print the state for an instance of HubBalancer.void
setQuietPeriod
(double value) Set the quiet period.void
setThreshold
(double value) Set the fraction of the number of hubs beyond which a worker may be scheduled.protected void
Start additional works on an as-needed basis.Methods inherited from class org.bzdev.bikeshare.HubBalancer
getOverflowSet, getOverSet, getSysDomain, getUnderSet, initDomain, onConditionChangeImpl, startInitialWorkers
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
-
BasicHubBalancer
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
-
setQuietPeriod
public void setQuietPeriod(double value) Set the quiet period. If additional workers are scheduled at some simulation time t, the quiet period δ indicates that no more workers should be scheduled until the simulation time reaches t + δ.- Parameters:
value
- the quiet period in seconds
-
getQuietPeriod
public long getQuietPeriod()Get the quiet period. If additional workers are scheduled at some simulation time t, the quiet period δ indicates that no more workers should be scheduled until the simulation time reaches t + δ.- Returns:
- the quite period in units of simulation ticks
-
setThreshold
public void setThreshold(double value) Set the fraction of the number of hubs beyond which a worker may be scheduled. If the fraction of the number of hubs in the sets returned by the methodsHubBalancer.getUnderSet()
,HubBalancer.getOverSet()
, orHubBalancer.getOverflowSet()
, when compared to the total number of hubs, exceeds the threshold, one or more worker may be scheduled.- Parameters:
value
- the value of the threshold, which must be in the range [0, 1].
-
getThreshold
public double getThreshold()Get the fraction of the number of hubs beyond which a worker may be scheduled. If the fraction of the number of hubs in the sets returned by the methodsHubBalancer.getUnderSet()
,HubBalancer.getOverSet()
, orHubBalancer.getOverflowSet()
, when compared to the total number of hubs, exceeds the threshold, one or more worker may be scheduled.- Returns:
- the current value of the threshold
- See Also:
-
startAdditionalWorkers
protected void startAdditionalWorkers()Start additional works on an as-needed basis. This method may be called in response to a condition change. When a subclass implements this method, it is the responsibility of the subclass to determine the number of workers that should be used. This number may be zero. The classBasicHubBalancer
, for example, uses an implementation where there is a threshold for the number of hubs that can use an extra worker and a quiet period that prevents a large number of workers from being scheduled at once.This method uses a "quiet period" to prevent multiple workers from responding to the same event. It also uses a threshold that looks at the ratio of three counts to the total number of hubs for this hub balancer. These counts are:
- the number of hubs for which the number of bicycles stored the preferred area exceeds the upper limit.
- the number of hubs for which the number of bicycles stored the preferred area is below the lower limit.
- the number of hubs with bicycles in their overflow areas.
- Specified by:
startAdditionalWorkers
in classHubBalancer
-
printConfiguration
Print the configuration for an instance of HubBalancer. 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
HubBalancer
:- (No data associated with the HubBalancer class is printed.)
- the quiet period in seconds.
- the threshold (the fraction of the number of hubs beyond which a worker may be scheduled).
- Overrides:
printConfiguration
in classHubBalancer
- 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 HubBalancer. 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
HubBalancer
:- the over-trigger set (the hubs whose bicycle count is larger than its upper-trigger value).
- the under-trigger set (the hubs whose bicycle count is below its under-trigger value).
- the overflow set (the hubs that have bicycles in their overflow areas).
- parameters set as the simulation starts:
- initial bicycle count.
- nominal bicycle count.
- the number of hubs.
- Overrides:
printState
in classHubBalancer
- 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
-