Commit 40cb6dae authored by Stefan Scherfke's avatar Stefan Scherfke
Browse files

Updated the api ref. for simpy.rt.

parent c7467ce0
......@@ -11,10 +11,11 @@ components.
simpy
simpy.core
simpy.monitoring
simpy.resources
simpy.resources.base
simpy.resources.container
simpy.resources.resource
simpy.resources.store
simpy.monitoring
simpy.rt
simpy.util
======================================
``simpy.rt`` --- Real-time simulations
======================================
.. automodule:: simpy.rt
.. autoclass:: RealtimeEnvironment
:members:
.. autoclass:: RealtimeScheduler
:members:
......@@ -16,7 +16,23 @@ Infinity = float('inf')
class RealtimeScheduler(Scheduler):
def __init__(self, env, initial_time, factor, strict):
"""This :class:`~simpy.core.Scheduler` delays the :meth:`pop()` operation
to adjust to the wallclock time.
The arguments *env* and an *initial_time* are passed to
:class:`~simpy.core.Scheduler`.
A simulation time step will take *factor* seconds of real time (one second
by default), e.g. if you simulate from ``0`` until ``3`` with
``factor=0.5``, the :func:`~simpy.core.simulate()` call will take at least
1.5 seconds.
If the processing of the events for a time step takes too long,
a :exc:`RuntimeError` is raised by :meth:`pop()`. You can disable this
behavior by setting *strict* to ``False``.
"""
def __init__(self, env, initial_time, factor=1.0, strict=True):
Scheduler.__init__(self, env, initial_time)
self.sim_start = initial_time
self.real_start = time()
......@@ -24,6 +40,15 @@ class RealtimeScheduler(Scheduler):
self.strict = strict
def pop(self):
"""Return the next event from the schedule.
The call is delayed corresponding to the real-time *factor* of the
scheduler.
If the events of a simulation time step are processed to slowly for the
given *factor* and if *strict* is enabled, raise a :exc:`RuntimeError`.
"""
event = super(RealtimeScheduler, self).pop()
sim_delta = self.now - self.sim_start
......@@ -41,15 +66,11 @@ class RealtimeScheduler(Scheduler):
class RealtimeEnvironment(Environment):
"""
A simulation time step in this environment will take *factor* seconds of
real time (one second by default), e.g. if you simulate from ``0`` until
``3`` with ``factor=0.5``, the call will take at least 1.5 seconds. If the
processing of the events for a time step takes too long, a
:exc:`RuntimeError` is raised. You can disable this behavior by setting
*strict* to ``False``.
"""
"""This :class:`~simpy.core.Environment` uses a :class:`RealtimeScheduler`
by default, so a simulation time step will take *factor* seconds of real
time (see :class:`RealtimeScheduler` for more information).
"""
def __init__(self, initial_time=0, factor=1.0, strict=True):
Environment.__init__(self, initial_time, RealtimeScheduler(
self, initial_time, factor, strict))
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment