Skip to content

Render reduced-strategy labels lazily - #991

Open
d-kad wants to merge 4 commits into
gambitproject:masterfrom
d-kad:lazy-strategy-labels
Open

Render reduced-strategy labels lazily#991
d-kad wants to merge 4 commits into
gambitproject:masterfrom
d-kad:lazy-strategy-labels

Conversation

@d-kad

@d-kad d-kad commented Jul 20, 2026

Copy link
Copy Markdown
Contributor

Description of the changes in this PR

GamePlayerRep::MakeStrategy built a text label for every reduced strategy eagerly, scanning all of the
player's information sets with two map lookups each. The label is often never read, and its construction is
O(strategies × infosets) in time and allocations.

This PR makes it lazy. GameStrategyRep::m_label becomes a mutable std::optional<std::string>;
MakeStrategy leaves it empty and GetLabel() renders from m_behav on first access, then caches.
The rendered text is unchanged.

It also replaces operator[] with contains()/at() on the two paths that read m_behav
(the behavior-to-strategy profile constructor and TreePureStrategyProfileRep::GetPayoff).
operator[] inserted a zero for every absent information set, expanding each strategy's map on first read;
the const-correct access preserves the sparsity MakeStrategy produces.

No behavioral change.

d-kad added 4 commits July 18, 2026 20:31
…osen action, holding only the sets a strategy specifies

Render strategy labels lazily from the behaviour map
@d-kad

d-kad commented Jul 20, 2026

Copy link
Copy Markdown
Contributor Author

On 16.7.0, labels for all reduced strategies are constructed and held at generation time; for the binary tree at size 20 it exhausts memory and the kernel is killed.
Screenshot 2026-07-20 at 13 29 36
Rendering labels lazily removes that up-front allocation, so these sizes complete
Screenshot 2026-07-20 at 09 12 49

@d-kad
d-kad requested a review from tturocy July 20, 2026 12:48
@d-kad d-kad added this to the gambit-17.0.0 milestone Jul 20, 2026
@d-kad d-kad added the c++ Items which involve writing in C++ label Jul 20, 2026
@tturocy

tturocy commented Jul 20, 2026

Copy link
Copy Markdown
Member

This is a good idea, but let's trace the implications through even more thoroughly.

Would it make sense simply to have generate-on-demand for the strategic form above a given size? Random access via label is probably not going to be something that makes a lot of sense in a large game.

But also this is flagging up that we are abusing labels in reduced strategic forms to do multiple duties.

And - now that we are requiring labels for actions, the use of numbers for the auto-generated strategy labels is dubious when we could do something derived from the constituent actions.

We should discuss this in our upcoming catchup. We do definitely need to do something along these lines however.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

c++ Items which involve writing in C++

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants