Conversation
Adds a classic M/M/c queuing model as the first pure discrete event simulation example, demonstrating Mesa's new event scheduling API without using step().
This way python model.py works directly, and importlib.import_module("examples.mmc_queue.model") in the test harness also works. It's a common pattern for examples that need to function both standalone and as part of a package.
| rng: Random number generator seed. | ||
| """ | ||
|
|
||
| def __init__(self, arrival_rate=1.0, service_rate=0.5, n_servers=2, **kwargs): |
There was a problem hiding this comment.
consider using a scenario class here.
| ), | ||
| ) | ||
|
|
||
| def _customer_arrival(self): |
There was a problem hiding this comment.
this is a question beyond this example, but should this not become some seperate mesa base class we can use?
There was a problem hiding this comment.
Could very well be!
I mainly created this example to see if we supported everything to do it. The answer is yes, and for future potential Mesa improvements we could check if it simplifies this example or not.
| self.servers = [Server(self, service_rate) for _ in range(n_servers)] | ||
|
|
||
| # Disable default step schedule — pure DES | ||
| self._default_schedule.stop() |
There was a problem hiding this comment.
this also reveals something we have to fix more elegantly in mesa 4.
| interval=lambda m: m.rng.exponential(1.0 / m.arrival_rate), | ||
| start=0.0, | ||
| ), | ||
| ) |
There was a problem hiding this comment.
what about adding the new data collection to this example. Your use of properties should make this quite easy.
There was a problem hiding this comment.
Sounds cool, but let's make that a separate PR.
Summary
Adds a classic M/M/c queuing model as the first pure discrete event simulation example, demonstrating Mesa's new event scheduling API without using
step().Motive
Mesa 3.5 introduced public event scheduling and time advancement (mesa/mesa#3266), but we lack an example showing pure DES usage. The M/M/c queue is the "hello world" of discrete event simulation: simple, well-understood, and with analytical solutions for validation. It fills the gap between our ABM examples and the new DES capabilities.
Implementation
agents.py:Customer(created on arrival, removed after service) andServer(pulls from queue when idle — server-centric design).model.py:MMcQueuemodel usingschedule_recurringwith a callable interval for Poisson arrivals andschedule_event(after=...)for service completions. Disables the default step schedule via_default_schedule.stop().analytical_mmc.py: Erlang C steady-state solutions for validation.Usage Examples
Running
python model.pyprints a comparison table:Additional Notes
_default_schedule.stop(). This works but may warrant a more explicit opt-out mechanism for pure DES models (e.g. aModelparameter).