linestack

# linestack.py
# ------------------------------------------------------------------------------

 
Classes
       
abcline.ABCLine()
LineStack(eventschtack.EventScheduleStack, abcline.ABCLine)
eventschtack.EventScheduleStack()
LineStack(eventschtack.EventScheduleStack, abcline.ABCLine)

 
class LineStack(eventschtack.EventScheduleStack, abcline.ABCLine)
    Class used for handling physical queues in discrete-event simulation (it 
might have been called "QueueStack" but Queue is a built-in class in 
Python...). LineStack inherits from the EventScheduleStack class but adds 
the organization of queues/lines including balking, reneging and the 
registration of waiting and service times using stack objects from the 
misclib.Stack class together with dicts and 'd' arrays. 
 
Besides the output from the methods of the class (including those of 
EventScheduleStack), the following attributes are available externally 
from each instance (but not directly assignable) at all times:
  instance.narriv      # Accumulated number of arrivers until present time
  instance.ninline     # Present number waiting in line
  instance.nfreeserv   # Present number of free servers
  instance.nbalked     # Accumulated number of balkers
  instance.nreneged    # Accumulated number of renegers  
  instance.nescaped    # = instance.nbalked + instance.nreneged
 
LineStack is notably less efficient (=slower) than Line, but the two classes 
care otherwise equivalent in principle. But just like EventScheduleStack is 
more general than EventSchedule, LineStack may be used when there are 
arrival time ties or when more complex queueing situations must be handled.
 
Multiple queues in parallel may be handled using multiple line objects 
and may be handled by using separate event schedules or one single event 
schedule, depending on what seems best in the situation at hand. Jockeying 
between queues/lines may be handled by letting customers renege from one 
queue/line and subsequently arrive at another. Special, separate care must 
be taken to record the  t o t a l  waiting time for jockeys.
 
NB  An excellent feature of Python allows you to add new attributes to
an object dynamically, so you are free to add your own data structures 
to a LineStack object to suit your needs in a given situation!
 
This class only adds the stuff that is specific to the LineStack class 
as compared to the Line class. Everything else is inherited from the 
ABCLine abstract base class. Always consult the docstring documentation 
of ABCLine before using this class!!
 
 
Method resolution order:
LineStack
eventschtack.EventScheduleStack
abcline.ABCLine

Methods defined here:
__init__(self, nserv, eventlist=[], timelist=[], sort=False)
Creates a heap for the event times and a dictionary to keep track
of the corresponding events. nserv is the initial number of servers. 
The events could for instance be desribed by strings. The times are 
(of course) floating-point numbers. The two input lists (if there are 
any) must be synchronized but not necessarily input in time order 
(will be sorted if sort=True). 
 
Creates deques, dicts and lists for keeping track of the attributes 
associated with the line/queue object.
prepare_to_renege(self, arrivaltime, renevent, drentime)
Used for all non-balkers when all servers are busy - if reneging is 
treated at all. The input 'drentime' is the time endured waiting in 
line before reneging and should be drawn from the appropriate
probability distribution. 
 
THE EVENT IS PLACED IN THE EVENT SCHEDULE WITH renevent AS THE EVENT 
TYPE AND drentime+arrivaltime AS THE EVENT (CLOCK) TIME!

Data and other attributes defined here:
__abstractmethods__ = frozenset([])

Methods inherited from eventschtack.EventScheduleStack:
get_next_event(self)
Method used to get the next stored event (the first in time) from the 
event schedule. The synchronized stacks eventstack and timestack are 
shifted in Perl fashion - i. e. the element that is returned is also 
removed from the stack. Returns None if the stacks are empty.
put_event(self, eventtype, eventtime)
Method used to place an event in the event schedule. The event is placed 
in temporal order in the synchronized stacks eventstack and timestack.
show_next_event(self)
Just look at the next event without touching the stack.
zap_events(self)
Method used to empty the schedule to allow for a restart.

Data descriptors inherited from eventschtack.EventScheduleStack:
__dict__
dictionary for instance variables (if defined)
__weakref__
list of weak references to the object (if defined)

Methods inherited from abcline.ABCLine:
__getattr__(self, attr_name)
This method overrides the built-in __getattr__ and makes the values
of the internal attributes externally available.
__setattr__(self, attr_name, value)
This method overrides the built-in __setattr__ and makes the values of 
the internal attributes externally available more difficult to screw 
up from the outside.
balker(self, tim)
Removes the arrival just placed last in line. Returns the arrival 
time of the balker.
 
NB. Balkers must first be placed in line - before balking!
Outputs:
--------
The arrival time of the balker
call_next_in_line(self, calltime)
Fetch the first arrival time at the front end of the line,
remove it from the line, and make one server busy.
 
Outputs:
--------
The arrival time at the front end of the line
idle_stats(self)
Returns a dict containing server statistics with the number of idle 
servers as keys and the corresponding times as values.
line_stats(self)
Returns a dict containing line length statistics with the line lengths 
as keys and the corresponding times as values.
place_first_in_line(self, times)
Add one or several arrival times at the front end of the line. 
The length of the expanded line is returned. 
 
NB The elements in an iterable will be placed so that the first 
will be the first in the line etc.
 
Arguments:
----------
times     single time or tuple/list of times
 
Outputs:
----------
The length of the expanded line
place_last_in_line(self, times)
Add one or several arrival times at the back end of the line. 
The length of the expanded line is returned. 
 
NB The elements in an iterable will be placed so that the last 
will be the last in the line etc.
 
Arguments:
----------
times     single time or tuple/list of times
 
Outputs:
----------
The number presently in the expanded line
remove_last_in_line(self, tim)
Fetch the last arrival time at the back end of the line and remove 
it from the line. To be used - for instance - when a customer that 
already has been placed in line balks (even balkers must first be 
placed in line - before balking!).
 
Outputs:
--------
The arrival time at the back end of the line
reneger(self, arentime)
To be used when a "renege" type event is picked up by get_next_event 
and removes the corresponding arrival time (arentime) in the line of 
arrival times GIVEN that it has not been removed already from calling 
call_next_in_line (the existence of the corresponding arrival time in 
the line is checked first).
server_freed_up(self, tim)
Adds '1' to the present number of free servers - 
to be used when a customer has been served.
May also be used to change the total number of servers 
during the course of a simulation.
system_stats(self)
Returns a dict containing statistics for the total number of customers 
in the system as keys and the corresponding times as values.
waiting_times_all(self)
Returns an unsorted 'd' array containing the waiting times 
for all served.
waiting_times_linedup(self)
Returns an unsorted 'd' array containing the waiting times 
only for those who had to wait in line before being served.