Skip to content

Refactor MixedBehaviorProfile caching#703

Merged
tturocy merged 5 commits intomasterfrom
dev_mixedbehav
Dec 17, 2025
Merged

Refactor MixedBehaviorProfile caching#703
tturocy merged 5 commits intomasterfrom
dev_mixedbehav

Conversation

@tturocy
Copy link
Copy Markdown
Member

@tturocy tturocy commented Dec 15, 2025

This re-writes the cached quantity calculations for MixedBehaviorProfile:

  • Uses the preorder and postorder traversal of nodes provided by the game class;
  • Thereby avoids recursion to descend the tree
  • Cleanly separates the computation of each vector of quantities (which will be a help for further optimisation in future when we look at the data structures used to represent them)
  • Because there is a dependency order in the cached quantities, implements a slightly more sophisticated cache to compute only what is truly needed.

This re-writes the cached quantity calculations for MixedBehaviorProfile:

* Uses the preorder and postorder traversal of nodes provided by the game class;
* Thereby avoids recursion to descend the tree
* Cleanly separates the computation of each vector of quantities (which will be a help for
  further optimisation in future when we look at the data structures
  used to represent them)
* Because there is a dependency order in the cached quantities,
  implements a slightly more sophisticated cache to compute
  only what is truly needed.

Introduce cache object

Remove separate cache invalidation

Ensure only as much information as is required.
@tturocy
Copy link
Copy Markdown
Member Author

tturocy commented Dec 15, 2025

@rahulsavani I've completed my first go at rationalising the way we're doing caching in mixed behaviour profiles. I've still got a bit more to do, but this is advanced enough it is worth you having a look. All tests continue to pass, and also I checked a few of my standard extensive games in liap/logit and didn't notice any differences. Note that this is based on current master so it does not reflect yet the nomenclature changes for agent.

@d-kad I wanted to call your attention to this because I've implemented here a more sophisticated Cache object. This is something we should develop for the extensive game as well to manage all the information being computed there, especially your work. For the moment no action is required (in fact don't let it distract you from the thrust of your work) but we will circle around and refactor so we can track more carefully what's been computed.

And for both - note this new implementation uses both the preorder and postorder traversal versions of GetNodes() - and insofar as all tests pass it's further confirmation both now appear to be correct!

@tturocy tturocy marked this pull request as ready for review December 17, 2025 08:58
@tturocy tturocy merged commit 04a620d into master Dec 17, 2025
28 checks passed
@tturocy tturocy deleted the dev_mixedbehav branch December 17, 2025 09:00
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.

1 participant