It would be desirable to make arbitrary changes to the state of a simulation according to a schedule. This is useful for simulating emergencies and disasters where the system has a change point where its behaviour changes substantially.
"""Scheduled changes implementation."""
from __future__ import annotations
from typing import Callable, Iterable, Tuple
import ciw
ScheduleItem = Tuple[float, Iterable[Callable[[ciw.Simulation], ciw.Simulation]]]
def scheduled_changes(sim: ciw.Simulation, sched: ScheduleItem) -> ciw.Simulation:
"""
Apply scheduled changes to simulation.
Parameters:
sim: Ciw Simulation
sched (tuple): tuple of times and functions
"""
for event in sched:
time_to, funcs = event
sim.simulate_until_max_time(sim.current_time + time_to)
for func in funcs:
sim = func(sim)
return simThe above is a rough prototype. It assumes that the time-to-events are constants fixed ahead of time, but I could see extension to this where the time-to-events change depending on what has happened in the simulation so far. Likewise, control flow to change the events that occur depending on the state might also be beneficial.