Skip to content

Commit

Permalink
Modernise further the implementation of enumpoly on sequence forms
Browse files Browse the repository at this point in the history
This builds on previous work to bring the implementation of enumpoly on
extensive forms (via the sequence form) up-to-date.

This is a substantial refactoring that should improve the readability and
maintainability of these routines.

Further, the `GameSequenceForm` class has now moved towards being
ready to move to be part of the game representation library, which the goal
is to do in due course.
  • Loading branch information
tturocy committed Sep 20, 2024
1 parent 737dfe5 commit c2c77ed
Show file tree
Hide file tree
Showing 9 changed files with 554 additions and 501 deletions.
4 changes: 2 additions & 2 deletions Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -421,6 +421,8 @@ gambit_nashsupport_SOURCES = \
# For enumpoly, sources starting in 'pel' are from Pelican.
gambit_enumpoly_SOURCES = \
${core_SOURCES} ${game_SOURCES} ${gambit_nashsupport_SOURCES} \
src/solvers/enumpoly/gameseq.cc \
src/solvers/enumpoly/gameseq.h \
src/solvers/enumpoly/gpartltr.cc \
src/solvers/enumpoly/gpartltr.h \
src/solvers/enumpoly/gpartltr.imp \
Expand Down Expand Up @@ -464,8 +466,6 @@ gambit_enumpoly_SOURCES = \
src/solvers/enumpoly/linrcomb.h \
src/solvers/enumpoly/linrcomb.imp \
src/solvers/enumpoly/ndarray.h \
src/solvers/enumpoly/sfg.cc \
src/solvers/enumpoly/sfg.h \
src/solvers/enumpoly/odometer.cc \
src/solvers/enumpoly/odometer.h \
src/solvers/enumpoly/nfghs.cc \
Expand Down
15 changes: 15 additions & 0 deletions src/games/behavmixed.cc
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,21 @@ template <class T> MixedBehaviorProfile<T> MixedBehaviorProfile<T>::Normalize()
return norm;
}

template <class T> MixedBehaviorProfile<T> MixedBehaviorProfile<T>::ToFullSupport() const
{
CheckVersion();
MixedBehaviorProfile<T> full(GetGame());

for (auto player : m_support.GetGame()->GetPlayers()) {
for (auto infoset : player->GetInfosets()) {
for (auto action : infoset->GetActions()) {
full[action] = (m_support.Contains(action)) ? (*this)[action] : T(0);
}
}
}
return full;
}

//========================================================================
// MixedBehaviorProfile<T>: Interesting quantities
//========================================================================
Expand Down
2 changes: 2 additions & 0 deletions src/games/behavmixed.h
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,8 @@ template <class T> class MixedBehaviorProfile {

MixedStrategyProfile<T> ToMixedProfile() const;

/// @brief Converts the profile to one on the full support of the game
MixedBehaviorProfile<T> ToFullSupport() const;
//@}
};

Expand Down
13 changes: 3 additions & 10 deletions src/games/game.cc
Original file line number Diff line number Diff line change
Expand Up @@ -466,18 +466,11 @@ template <class T> MixedStrategyProfile<T> MixedStrategyProfile<T>::ToFullSuppor
CheckVersion();
MixedStrategyProfile<T> full(m_rep->m_support.GetGame()->NewMixedStrategyProfile(T(0)));

for (int pl = 1; pl <= m_rep->m_support.GetGame()->NumPlayers(); pl++) {
GamePlayer player = m_rep->m_support.GetGame()->GetPlayer(pl);
for (int st = 1; st <= player->NumStrategies(); st++) {
if (m_rep->m_support.Contains(player->GetStrategy(st))) {
full[player->GetStrategy(st)] = (*this)[player->GetStrategy(st)];
}
else {
full[player->GetStrategy(st)] = static_cast<T>(0);
}
for (auto player : m_rep->m_support.GetGame()->GetPlayers()) {
for (auto strategy : player->GetStrategies()) {
full[strategy] = (m_rep->m_support.Contains(strategy)) ? (*this)[strategy] : T(0);
}
}

return full;
}

Expand Down
Loading

0 comments on commit c2c77ed

Please sign in to comment.