Skip to content

Commit

Permalink
Integrate benchmarks and example models (#2473)
Browse files Browse the repository at this point in the history
This PR integrates the benchmark models into the example models and runs the benchmarks on the example models.

The first commit moves over the benchmark scripts to run on the example models, the following commits merge the benchmark models into the example models one-by-one.

* benchmarks: Use official example models

Use the official example models for the benchmarks

* wolf_sheep: Merge benchmark model into example model

Key changes and improvements in this merged version:

1. Used the experimental cell space features:
   - Switched to the more efficient `OrthogonalVonNeumannGrid`
   - Leveraged `CellAgent` and `FixedAgent` base classes
   - Used the cell's neighborhood property for movement

2. Implemented discrete event scheduling for grass regrowth:
   - Used the experimental `ABMSimulator` for event scheduling
   - Replaced the countdown-based grass regrowth with scheduled events

3. Modern Mesa practices:
   - Used `agents_by_type` for agent management
   - Employed `shuffle_do()` for efficient random activation
   - Proper initialization of the Model class with `super().__init__()`
   - Clear data collection setup with dedicated model reporters

4. Code organization:
   - Maintained separation between agents and model
   - Added detailed docstrings
   - Used property decorators for grass state management
   - Consistent style and naming conventions

5. Additional improvements:
   - Made grass optional while keeping full functionality
   - Improved type hints and property usage
   - More efficient agent selection and movement
   - Better encapsulation of agent behaviors

* schelling: Merge benchmark model into example model

* flocking: Merge benchmark model into example model

The merged implementation includes several improvements:

1. Code Organization:
   - Separated into agents.py and model.py following Mesa best practices
   - Clear docstrings and comments throughout
   - Consistent code style

2. Modern Mesa Features:
   - Uses AgentSet's shuffle_do() for random activation
   - Proper initialization using super().__init__()
   - Direct access to model.agents

3. Improvements to the Boid Implementation:
   - Better vector normalization handling
   - Added tracking of average heading for statistics
   - More robust neighbor handling
   - Cleaner separation of the three flocking behaviors
   - Added parameter validation and documentation

4. Key Changes:
   - Simplified the step() method using AgentSet
   - Improved documentation and type hints
   - Added model statistics tracking
   - Made parameter names more descriptive
   - Better default parameters for stable flocking

* boltzmann: Merge benchmark model into example model

Merged the two implementations with the following improvements and best practices:

1. Code Organization:
   - Separated model and agent code into distinct files
   - Added comprehensive docstrings following Google style
   - Improved code organization and readability

2. Model Implementation:
   - Used Mesa 3.0's automatic agent management via `model.agents`
   - Used `shuffle_do()` for random agent activation

3. Agent Implementation:
   - Simplified agent code while maintaining functionality
   - Improved method documentation
   - Added clear separation of responsibilities between methods

4. Latest Mesa Best Practices:
   - Proper model initialization using `super().__init__(seed=seed)`
   - Use of `model.agents` instead of a scheduler
   - Clear attribute definitions and typing
   - Consistent code style following Mesa conventions

5. Performance Considerations:
   - Efficient use of list operations
   - Minimal object creation during runtime
   - Direct access to model properties

This implementation maintains all the core functionality while being more organized, better documented, and following current Mesa best practices. It uses only stable features and avoids experimental ones.

The main changes from the original implementations:
1. Unified the different versions of the Gini coefficient calculation
2. Added proper docstrings throughout
3. Removed duplicate code
4. Added the optional run_model method from one version
5. Simplified some method implementations
  • Loading branch information
EwoutH authored Nov 9, 2024
1 parent 22784df commit 88a8d89
Show file tree
Hide file tree
Showing 22 changed files with 377 additions and 840 deletions.
1 change: 0 additions & 1 deletion benchmarks/BoltzmannWealth/__init__.py

This file was deleted.

112 changes: 0 additions & 112 deletions benchmarks/BoltzmannWealth/boltzmann_wealth.py

This file was deleted.

1 change: 0 additions & 1 deletion benchmarks/Flocking/__init__.py

This file was deleted.

156 changes: 0 additions & 156 deletions benchmarks/Flocking/flocking.py

This file was deleted.

1 change: 0 additions & 1 deletion benchmarks/Schelling/__init__.py

This file was deleted.

113 changes: 0 additions & 113 deletions benchmarks/Schelling/schelling.py

This file was deleted.

1 change: 0 additions & 1 deletion benchmarks/WolfSheep/__init__.py

This file was deleted.

Loading

0 comments on commit 88a8d89

Please sign in to comment.