| | |
-
- EventSchedule
class EventSchedule() |
| |
The class defines a schedule of events in a general discrete-event
simulation. The event times are kept in a heap; the event types are
kept in a corresponding dictionary. Safest is, of course, to assure
there are no ties among the event times.
EventSchedule is notably more efficient (=faster) than EventScheduleStack
despite the crudeness of its implementation (might be better having an
event type list shadowing the event time heap in a specific implementation
of the Heap class that does not use the built-in heapq library, but this
has not been tried). But the two classes are otherwise equivalent in
principle. Since the misclib.Stack class only uses Python's own built-in
list class, all the methods of the list class are available for handling
the event types via EventScheduleStack, a feature which may be used for
creating subclasses to EventScheduleStack which can handle more complex
types of schedules than the ones handled by the dict-based EventSchedule.
But EventSchedule should normally be preferred!.
NB. TIES are only handled approximately in EventSchedule. The put_event
method looks for ties in the eventtimes/eventtypes dictionary. If a tie is
found, (2*machine epsilon)*abs(eventtime) will be added to eventtime
before placing it in the dict. If perfect handling of ties is required,
then EventScheduleStack must be used! |
| |
Methods defined here:
- __init__(self, eventlist=[], timelist=[], sort=False)
- Creates a heap for the event times and a dictionary to keep track of
of the corresponding events. The events could for instance be described
by strings. The event times are (of course) floating-point numbers.
The two input lists can be filled here. They must be synchronized but
not necessarily created in time order - sort=True will turn the input
time list into a bona fide heap if the inputs are not sorted beforehand.
- 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 defined here:
- __dict__
- dictionary for instance variables (if defined)
- __weakref__
- list of weak references to the object (if defined)
| |