Dynamic Behavior Patterns
Explore common system behaviors: exponential growth, goal-seeking decay, overshoot-and-collapse, and S-curve saturation.
Explore Dynamic Behavior Patternssimulation.py
Watching a population grow logistically
This classic model starts with a small population that grows almost exponentially. Growth then slows as the number of individuals nudges up against the carrying capacity of the environment.
from tys import probe, progress
Simulate logistic population growth.
def simulate(cfg: dict):
import simpy
env = simpy.Environment()
population = cfg["initial_pop"]
r = cfg["growth_rate"]
K = cfg["carrying_capacity"]
steps = cfg["steps"]
done = env.event()
Evolve the population using the logistic equation.
def run():
nonlocal population
for t in range(steps):
growth = r * population * (1 - population / K)
population += growth
probe("population", env.now, population)
probe("growth", env.now, growth)
progress(int(100 * (t + 1) / steps))
yield env.timeout(1)
done.succeed({"final_population": population})
env.process(run())
env.run(until=done)
return done.value
def requirements():
return {
"builtin": ["micropip", "pyyaml"],
"external": ["simpy==4.1.1"],
}
config.yaml
initial_pop: 10
growth_rate: 0.2
carrying_capacity: 100
steps: 40