| | |
- abcline.ABCLine()
-
- Line(eventschedule.EventSchedule, abcline.ABCLine)
- eventschedule.EventSchedule()
-
- Line(eventschedule.EventSchedule, abcline.ABCLine)
class Line(eventschedule.EventSchedule, abcline.ABCLine) |
| |
Class used for handling physical queues in discrete-event simulation
(it might have been called "Queue" but Queue is a class in Python's
library...). Line inherits from the EventSchedule class but adds the
organization of queues/lines including balking, reneging and the
registration of waiting and service times using deque objects from
the misclib.Deque class together with dicts and 'd' arrays.
Besides the output from the methods of the class (including those of
EventSchedule), 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
Line is notably more efficient (=faster) than LineStack, but the two classes
are 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 Line object to suit your needs in a given situation!
This class only adds the stuff that is specific to the Line class as
compared to the LineStack 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:
- Line
- eventschedule.EventSchedule
- 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!
Ties are handled in a way so that the time placed in the event schedule
is incremented by TWOMACHEPS*(drentime+arrivaltime) for each consecutive
tie.
Data and other attributes defined here:
- __abstractmethods__ = frozenset([])
Methods inherited from eventschedule.EventSchedule:
- get_next_event(self)
- Get the next event (event type, event time) and remove it from
the schedule.
- put_event(self, eventtype, eventtime)
- Add an event to the schedule: place it in the eventtype/eventtime
dictionary and heap.
- show_next_event(self)
- Just look at the next event in the schedule (event type, event time)
without touching!
- zap_events(self)
- Empty the schedule to allow for a restart. Return the length of
the heap as it was before zapping.
Data descriptors inherited from eventschedule.EventSchedule:
- __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.
| |