Feature Request: Periodic Processes

Issue #3 invalid
Forrest Iandola
created an issue

Periodic Processes.

Currently, can be implemented at the user level by launching several instances of a process that contain different values of arrivalTime in activate(..., processInstance.execute(), at=arrivalTime). However, there are a couple of caveats:

  • It's necessary to know how long the simulation will run, so that we can launch the right number of Process instances with the appropriate arrival times.
  • The user must create his/her own scheme for handling process IDs for multiple instances of a periodic Process.

Neither of these caveats are that hard to deal with. But, given how many systems use periodic processes, I think this feature would see widespread use.

Implementation idea: Expose a "period=..." parameter in the activate() function. In the SimPy core code, we would use the planned simulation stop time to calculate the number of invocations of this Process to launch. For each Process invocation, we do activate(...,at=time), where time=(invocationID*period+[any offset needed]). Deciding how to handle Process IDs for periodic tasks is an open question.

Comments (13)

  1. Stefan Scherfke

    This should solve your problem. I’ll discuss if we add such a starter process to simpy.utils.

    def process(env):
        yield env.timeout(1)
    def starter(proc, count, interval):
        for delay in range(0, count * interval, interval):
            util.start_delayed(proc, delay)
    starter(process(env), count=5, delay=3)
  2. luensdorf

    I don' t see a reason for adding a convenience function for just two lines of code. That isn't really convenient :) I wouldn't add it, but I won't complain otherwise. However I think this is more readable:

    for period in range(count):
        util.start_delayed(proc, period * interval)
  3. Stefan Scherfke

    @Forrest Iandola We decided that a two-lines helper is just not worth to be added, so I thought of just making an example for this. However, I couldn’t come up with a good scenario where the implementation shown above would make sence. It would be nice if you could provide a small example or a use case at least. :-)

  4. Log in to comment