Skip to content

feat: new "event based collisions" example#323

Open
rico-haas wants to merge 7 commits intomesa:mainfrom
rico-haas:colliding-discs
Open

feat: new "event based collisions" example#323
rico-haas wants to merge 7 commits intomesa:mainfrom
rico-haas:colliding-discs

Conversation

@rico-haas
Copy link
Contributor

@rico-haas rico-haas commented Feb 4, 2026

Summary

This is a playful example that makes use of Mesa's DEVSimulator event-based simulation capabilities on a continuous timeline. It features moving discs in a 2D environment that collide with the border and each other, using an event-based collision mechanism. With help of the simulator, discs will collide accurately, no matter how fast they are!

event_based_collisions

Motive

This provides an example usage of Mesa's DEVSimulator event-based simulation capabilities on a continuous timeline, see #124. This model has been explicitly designed to demonstrate that simulator feature, since without it, the model couldn't have the same accuracy guarantees (discs could pass through each other).

Implementation

  1. Discs are placed in the space with a random movement direction.
  2. At the beginning and whenever a disc changes its trajectory, the disc calculates when it could collide with an obstacle (other discs or the border) and schedules these as future events.
  3. When such an event occurs and the disc still has the same trajectory (it hasn't collided with something else) then it changes its trajectory based on its angle of incidence.
  4. Each full time step, all discs update their shown position based on their current trajectory. This doesn't update the actual model at all, it only queries the current state. Hence the simulation results are always the same, regardless of the timestep interval.

Usage Examples

  1. Set the disc speed to 1 and let the simulation run for let's say 100 time steps.
  2. Take a screenshot of where all the discs are after 100 steps.
  3. Turn the disc speed up to 10 and reset the simulation.
  4. Now let the simulation run only 10 time steps.
  5. Compare the result with your screenshot. It should be exactly the same!

Additional Notes

This example is based on my idea for a DEVS tutorial.

@Logende
Copy link
Contributor

Logende commented Feb 10, 2026

The tests are failing, but the failures seem unrelated to this PR. @EwoutH how to proceed?

@EwoutH
Copy link
Member

EwoutH commented Feb 12, 2026

This seems really cool! I toyed around in the days I was still using NetLogo with almost exactly a model like this.

I'm a bit busy, but I will try to review somewhere this weekend. Maybe @tpike3 or @quaquel might also find this interesting.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants