-
Notifications
You must be signed in to change notification settings - Fork 944
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix draw_network: Handle multiple agents per node correctly (#2691) #2693
base: main
Are you sure you want to change the base?
Fix draw_network: Handle multiple agents per node correctly (#2691) #2693
Conversation
Performance benchmarks:
|
715359f
to
fb5b53e
Compare
|
||
# Adjust positions for multiple agents per node | ||
adjusted_positions = [] | ||
for node in space.G.nodes: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This does not work for mesa.discrete_space.Network
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
hi @quaquel
Thanks for your review!
I have updated the code to ensure compatibility with mesa.discrete_space.Network by properly handling agent positions and preventing KeyError: None. Now, all 7 tests are passing. Let me know if further improvements are needed!
4bcc4f2
to
f777bba
Compare
for more information, see https://pre-commit.ci
@quaquel are you able to further review this PR? |
Summary
The draw_network() function previously failed when there were more agents than nodes in a network visualization. This PR fixes the issue by properly handling multiple agents at the same node, ensuring they are displayed correctly without overlapping.
Bug / Issue
Linked Issue: #2691
Problem:
Expected Behavior:
Actual Behavior (Before Fix):
Implementation
The fix introduces the following changes:
(1) Grouped agents per node manually
(2) Adjusted agent positions to prevent overlap
(3) Fixed IndexError by ensuring arguments["loc"] is always a 2D NumPy array
(4) Prevented _scatter() from failing on empty agent lists
Code Changes:
Testing
(1) Ran all tests in test_components_matplotlib.py
(2) Manually tested visualization with network models containing more agents than nodes
Additional Notes