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
- All Implemented Interfaces:
CondObserver<Condition,
,Actor> NamedObjectOps
- Direct Known Subclasses:
StorageHub
Class modeling a hub.
Hubs contain a bicycle-storage area, called the preferred area,
with a fixed capacity, and cover a geographic area. There is also
a second area called the overflow area. When the preferred
area is filled to capacity, new arrivals go to the overflow area.
New arrivals may, however, go the overflow area at any time: it
represents the immediate vicinity of the preferred area an thus
users may go directly to the overflow area as it may be slightly
closer to the actual destination.
In addition, workers (instances of HubWorker
), may move bicycles
from one hub to another. There are several values that control the
behavior of workers:
- the capacity of the hub's preferred area.
- the lower trigger for the hub.
- the nominal value for the hub.
- the upper trigger for the hub.
- the number of bicycles stored in the preferred area.
- the number of bicycles stored in the overflow area.
- a random variable giving the time it takes for a worker to pick up one bicycle from the overflow area.
Finally, each hub has an (X,Y) coordinate and is a member of a
user domain and a system domain.
Hubs are configured by the method
init
. There are two listeners that may be added to
a hub:
- HubListener. This is handled automatically for listeners used to notify instances of HubCondition of a change.
- HubDataListener. This is intended to be used for instrumenting a simulation.
sendUsers(Hub,int,boolean,Callable)
or
sendUsers(Hub,int,boolean,RealValuedFunctionTwo,Callable)
, however,
can be used as a higher-level interface for user operations.-
Nested Class Summary
Nested Classes -
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoid
addHubDataListener
(HubDataListener listener) Add a hub data listener to the current object.void
addHubListener
(HubListener listener) Add a hub listener to the current object.boolean
protected Object
clone()
int
decrBikeCount
(int decr) Decrement the number of bicycles at a hub's preferred location.final boolean
delete()
final boolean
int
Get the number of bicycles that must be removed from the hub's preferred location to reduce that number to the upper-trigger value.protected void
fireHubDataListeners
(int bikeCount, boolean newBikeCount, int overflowCount, boolean newOverflowCount) Notify each hub listener of a change.protected void
fireHubListeners
(int need, int excess, int overflow) Notify each hub listener of a change.int
Get the current bicycle count at the preferred location.int
Get the capacity at the preferred location.int
Get the initial bicycle count at the preferred location.int
Get the lower trigger for the number of bicycles stored at a hub's preferred location.final String
getName()
int
Get the nominal value for the number of bicycles that are stored at a hub's preferred location.protected Simulation
int
Get the number of bicycles in a hub's overflow area.Get the system domain for this hub.int
Get the upper trigger for the number of bicycles stored at a hub's preferred location.Get the user domain for this hub.double
getX()
Get this object's X coordinate.double
getY()
Get this object's Y coordinate.int
incrBikeCount
(int incr) Increment the number of bicycles at a hub's preferred location.void
incrOverflow
(int incr) Increment the number of bicycles in the overflow area of a hub.void
init
(int capacity, int lowerTrigger, int nominal, int upperTrigger, DoubleRandomVariable pickupTime, int count, int overCount, double x, double y, UsrDomain usrDomain, SysDomain sysDomain) Initialize this object.final boolean
boolean
int
Get the number of bicycles needed to raise the number of bicycles stored at a hub's preferred location to the lower-trigger value.long
pickupOverflow
(int n) Pickup bicycles from the overflow area.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
removeHubDataListener
(HubDataListener listener) Remove a hub data listener from the current object.void
removeHubListener
(HubListener listener) Remove a hub listener from the current object.Send users to another hub.sendUsers
(Hub dest, int m, boolean willOverflow, RealValuedFunctionTwo probFunction, Callable continuation) Send users to another hub using a probability function.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
-
Field Details
-
bikeCount
protected int bikeCountThe bicycle count. -
overflow
protected int overflowThe overflow count.
-
-
Constructor Details
-
Hub
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
-
getUsrDomain
Get the user domain for this hub.- Returns:
- this hub's user domain
-
getSysDomain
Get the system domain for this hub.- Returns:
- this hub's system domain
-
getX
public double getX()Get this object's X coordinate.- Returns:
- the X coordinate in units of meters
-
getY
public double getY()Get this object's Y coordinate.- Returns:
- the Y coordinate in units of meters
-
fireHubListeners
protected void fireHubListeners(int need, int excess, int overflow) Notify each hub listener of a change.- Parameters:
need
- the number of stored bicycles needed to reach this hub's lower triggerexcess
- the number of stored bicycles that have to be removed to reach this hub's upper triggeroverflow
- the number of bicycles stored elsewhere in the this hub
-
fireHubDataListeners
protected void fireHubDataListeners(int bikeCount, boolean newBikeCount, int overflowCount, boolean newOverflowCount) Notify each hub listener of a change.- Parameters:
bikeCount
- the new bike countnewBikeCount
- true if the bicycle count has changed during the event that invoked this listener; false otherwiseoverflowCount
- the new overflow countnewOverflowCount
- true if the overflow count has changed during the event that invoked this listener; false otherwise
-
needBikes
public int needBikes()Get the number of bicycles needed to raise the number of bicycles stored at a hub's preferred location to the lower-trigger value.- Returns:
- the number of bicycles needed to raise the number of bicycles stored at a hub's preferred location to the lower-trigger value; zero if no rebalancing is necessary
-
excessBikes
public int excessBikes()Get the number of bicycles that must be removed from the hub's preferred location to reduce that number to the upper-trigger value.- Returns:
- the number of bicycles that must be removed from the hub's preferred location to reduce that number to the upper-trigger value; zero if no rebalancing is necessary
-
getInitialBikeCount
public int getInitialBikeCount()Get the initial bicycle count at the preferred location.- Returns:
- the initial bicycle count at the preferred location
-
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
-
getOverflow
public int getOverflow()Get the number of bicycles in a hub's overflow area.- Returns:
- the number of bicycles in this hub's overflow area
-
getNominal
public int getNominal()Get the nominal value for the number of bicycles that are stored at a hub's preferred location. Load-balancing operations will try to adjust the number of bicycles at each hub to the nominal value for that hub.- Returns:
- the nominal value for the number of bicycles that are stored at this hub's preferred location
-
getLowerTrigger
public int getLowerTrigger()Get the lower trigger for the number of bicycles stored at a hub's preferred location. When the number of bicycles at the preferred location is smaller than this value, hub listeners will be notified.- Returns:
- the lower trigger
-
getUpperTrigger
public int getUpperTrigger()Get the upper trigger for the number of bicycles stored at a hub's preferred location. When the number of bicycles at the preferred location is larger than this value, hub listeners will be notified.- Returns:
- the upper trigger
-
pickupOverflow
Pickup bicycles from the overflow area. This method will reduce the count of bicycles in the overflow area for this hub.- Parameters:
n
- the number of bicycles to remove from the overflow area- Returns:
- the time it will take to pick up the specified number of bicycles
- Throws:
IllegalArgumentException
- the argument was larger than the number of bicycles in the overflow area or the argument was negative
-
decrBikeCount
public int decrBikeCount(int decr) Decrement the number of bicycles at a hub's preferred location. The value returned may differ from the argument as the number of bicycles at the current location cannot be negative or larger then the hub's capacity.- Parameters:
decr
- the decrement in the number of bicycles- Returns:
- the number of bicycles actually removed from the preferred location
-
incrOverflow
Increment the number of bicycles in the overflow area of a hub.- Parameters:
incr
- the increment- Throws:
IllegalArgumentException
- if the argument is negative
-
incrBikeCount
public int incrBikeCount(int incr) Increment the number of bicycles at a hub's preferred location. The value returned may differ from the argument as the number of bicycles at the current location cannot be negative or larger then the hub's capacity.- Parameters:
incr
- the increment in the number of bicycles- Returns:
- the number of bicycles actually added to the preferred location
-
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).
- 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 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.
- 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
-