Example SimulationsEcology: Predator–Prey

Ecology: Predator–Prey

This scenario simulates a classic predator–prey ecosystem (e.g. rabbits and foxes). It’s useful for building intuition about cycles, stability, and cause → effect delays in biological systems.

What you’re simulating

  • Prey grows when conditions are favorable.
  • Predators increase when prey is abundant.
  • As predators rise, prey falls; when prey falls, predators later fall too.
  • This feedback loop often produces oscillations instead of a single “steady” outcome.

Run it (web UI)

  1. Open Examples
  2. Choose Ecology → Predator–Prey
  3. Click Run

Run it (local SimUI)

From the B‑Simulant library repo:

pip install "bsim[ui]"
python examples/ecology_simui_demo.py --mode predator-prey --port 8765

Open http://localhost:8765/ui/.

What results to expect

  • Population over time: prey and predator typically rise and fall in repeating waves.
  • Phase space (predator vs prey): often forms a loop (a “cycle”) rather than a straight line.

Parameter presets (and what they mean)

GoalStepsdtExpected resultWhat it means
Quick preview5000.1You’ll likely see the start of a rise/fall cycle.Enough to confirm “it’s alive”, not enough to judge long‑run stability.
Standard run2,0000.1Clear oscillations (waves) in prey and predator.Classic delayed negative feedback: predators lag prey.
Longer horizon10,0000.1Repeated cycles; you may see drift or damping depending on conditions.Shows whether the system is robust (persistent cycles) or converges to equilibrium/collapse.
Smoother curves5,0000.05Similar dynamics, but plots usually look smoother.Smaller dt reduces numerical artifacts; costs more compute.

What to try (and why)

  • Increase Steps: see whether cycles persist, dampen, or explode.
  • Change dt: smaller values can look smoother but run slower.

If your UI exposes additional domain controls (for example temperature), use them as “stress tests”. Moving conditions away from a population’s optimum can shrink oscillations, shift the cycle timing, or trigger collapse/extinction.