Skip to content

Update alliance formation mode#3075

Merged
tpike3 merged 3 commits intomesa:mainfrom
quaquel:speed_up_shapley
Jan 5, 2026
Merged

Update alliance formation mode#3075
tpike3 merged 3 commits intomesa:mainfrom
quaquel:speed_up_shapley

Conversation

@quaquel
Copy link
Copy Markdown
Member

@quaquel quaquel commented Jan 5, 2026

This PR updates the shapley value calculation in the alliance formation model.

The old implementation heavily relies on indexing on an agent set, which is painfully slow. In a benchmark on all example models, for 100 steps each, this one method was responsible for 15% of the total runtime, simply due to indexing on agentsets (i.e., model.agents[5]) being so slow.

This PR avoids the problem by destructing the list into the two agents and using these in all places were indexing was used.

I'll raise a separate issue about AgentSet.__getitem__ later.

@quaquel quaquel requested a review from tpike3 January 5, 2026 14:37
@quaquel quaquel added example Changes the examples or adds to them. performance Release notes label labels Jan 5, 2026
@github-actions
Copy link
Copy Markdown

github-actions bot commented Jan 5, 2026

Performance benchmarks:

Model Size Init time [95% CI] Run time [95% CI]
BoltzmannWealth small 🔵 -1.6% [-2.9%, -0.1%] 🔵 -2.6% [-2.8%, -2.4%]
BoltzmannWealth large 🔵 +0.3% [-1.6%, +2.0%] 🔵 -2.0% [-11.4%, +7.7%]
Schelling small 🔵 +2.4% [+1.1%, +3.9%] 🔴 +6.6% [+4.6%, +8.8%]
Schelling large 🔵 +2.5% [+1.2%, +3.9%] 🔵 +6.7% [+1.1%, +11.8%]
WolfSheep small 🔵 +3.7% [+2.9%, +4.5%] 🔴 +6.0% [+4.7%, +7.2%]
WolfSheep large 🔵 +2.0% [-4.2%, +9.2%] 🔵 +2.3% [-4.6%, +9.3%]
BoidFlockers small 🔵 +1.7% [+0.8%, +2.7%] 🔵 +1.6% [+1.1%, +2.3%]
BoidFlockers large 🔵 +0.3% [-0.5%, +1.2%] 🔵 +0.9% [+0.2%, +1.5%]

Copy link
Copy Markdown
Member

@tpike3 tpike3 left a comment

Choose a reason for hiding this comment

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

Thanks @quaquel !

@tpike3 tpike3 merged commit c003afb into mesa:main Jan 5, 2026
15 of 16 checks passed
@quaquel quaquel deleted the speed_up_shapley branch February 16, 2026 15:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

example Changes the examples or adds to them. performance Release notes label

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants