Skip to content

Add Active Walker trail formation example#330

Open
som-or wants to merge 9 commits intomesa:mainfrom
som-or:trial
Open

Add Active Walker trail formation example#330
som-or wants to merge 9 commits intomesa:mainfrom
som-or:trial

Conversation

@som-or
Copy link

@som-or som-or commented Feb 17, 2026

Summary

This example implements an Active Walker model that simulates how informal pedestrian trails emerge in grassy open spaces. Agents move between predefined stops while gradually wearing down the grass. Worn areas become easier and more attractive to traverse, reinforcing frequently used routes.

Over time, stable paths form organically without explicit pathfinding. This model utilizes a continuous space and a custom property layer to track wear.

Motive

This example demonstrates agent–environment feedback dynamics in Mesa. It showcases how simple local movement rules combined with environmental modification can produce large-scale pattern formation.
In parks, campuses, and urban green spaces, informal footpaths often appear before any pavement is installed. These “desire paths” emerge because people tend to prefer routes that are already partially worn.

This example models that feedback loop:

  • Walking wears down grass
  • Worn grass becomes easier to traverse
  • Easier paths attract more walkers
  • Repeated use strengthens certain routes

Implementation

  • ActiveModel

    • Continuous 2D space
    • Configurable agent population
    • Staggered agent activation
    • Origin–destination cycling
  • WalkerAgent

    • Moves toward destinations
    • Direction influenced by wear gradient
    • Variable speed (normal distribution)
  • StepDeposit (PropertyLayer)

    • Tracks grass wear intensity
    • Diffusion-based spreading
    • Exponential decay (recovery)

Each simulation step:

  • Agents move according to combined destination and wear gradient
  • Wear is deposited spatially
  • The layer diffuses and decays over time
image

Usage Examples

  • Initialize the model with configurable population size and wear parameters.
  • Adjust print_strength, vision, or trail_dies_in to observe different trail formation dynamics.
  • Modify the number and positions of stops by editing the parameters in app.py to explore different origin–destination layouts.
  • Observe how stable paths emerge between frequently visited stops.

References

-This model is inspired by the Active Walker model described by Helbing et al. (1997): https://arxiv.org/abs/cond-mat/9806097.

self.G_layer.update()


class StepDeposit(PropertyLayer):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why are you using a property layer for this? Can't you simplify this to just use a numpy array directly?

Copy link
Author

@som-or som-or Feb 18, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the review, @quaquel !
I’ve updated the implementation to use a NumPy array as suggested.
I Initially chose property layers with potential continuous space support in mind, If there’s interest, extending property layers to continuous space could be explored separately in the future.

from agent import StopsAgent, WalkerAgent
from mesa.agent import AgentSet
from mesa.experimental.continuous_space import ContinuousSpace
from mesa.space import PropertyLayer
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is being deprecated, so either redesign it to not use it or import property layer from mesa.discrete_space.

@som-or
Copy link
Author

som-or commented Feb 24, 2026

I’ve updated the implementation to use a NumPy array as suggested.
I Initially chose property layers with potential continuous space support in mind, If there’s interest, extending property layers to continuous space could be explored separately in the future.

Hi @quaquel, just following up on this PR. I've implemented the suggested changes, let me know if there's anything else you need from my end to finalize this!

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