Skip to content

Commit

Permalink
Remove some unneeded or unused classes and functions.
Browse files Browse the repository at this point in the history
This removes the DVector container class, which is no longer needed
now that we have re-implemented MixedBehaviorProfile.

A follow-on from this is that we can remove the NumActions() and NumMembers() functions on games and
behavior supports, as those were only providing the shapes
to create the underlying DVectors.
  • Loading branch information
tturocy committed Nov 21, 2024
1 parent c524945 commit a6fcf5a
Show file tree
Hide file tree
Showing 16 changed files with 28 additions and 314 deletions.
3 changes: 0 additions & 3 deletions Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -251,8 +251,6 @@ core_SOURCES = \
src/core/vector.imp \
src/core/pvector.h \
src/core/pvector.imp \
src/core/dvector.h \
src/core/dvector.imp \
src/core/recarray.h \
src/core/matrix.h \
src/core/matrix.imp \
Expand All @@ -264,7 +262,6 @@ core_SOURCES = \
src/core/rational.h \
src/core/vector.cc \
src/core/pvector.cc \
src/core/dvector.cc \
src/core/matrix.cc \
src/core/sqmatrix.cc \
src/core/function.cc \
Expand Down
27 changes: 0 additions & 27 deletions src/core/dvector.cc

This file was deleted.

69 changes: 0 additions & 69 deletions src/core/dvector.h

This file was deleted.

115 changes: 0 additions & 115 deletions src/core/dvector.imp

This file was deleted.

21 changes: 5 additions & 16 deletions src/games/behavmixed.cc
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ namespace Gambit {

template <class T>
MixedBehaviorProfile<T>::MixedBehaviorProfile(const Game &p_game)
: m_probs(p_game->NumActions()), m_support(BehaviorSupportProfile(p_game)),
: m_probs(p_game->BehavProfileLength()), m_support(BehaviorSupportProfile(p_game)),
m_gameversion(p_game->GetVersion())
{
int index = 1;
Expand All @@ -51,7 +51,7 @@ MixedBehaviorProfile<T>::MixedBehaviorProfile(const Game &p_game)

template <class T>
MixedBehaviorProfile<T>::MixedBehaviorProfile(const BehaviorSupportProfile &p_support)
: m_probs(p_support.NumActions()), m_support(p_support),
: m_probs(p_support.BehaviorProfileLength()), m_support(p_support),
m_gameversion(p_support.GetGame()->GetVersion())
{
int index = 1;
Expand Down Expand Up @@ -127,20 +127,19 @@ void MixedBehaviorProfile<T>::RealizationProbs(const MixedStrategyProfile<T> &mp

template <class T>
MixedBehaviorProfile<T>::MixedBehaviorProfile(const MixedStrategyProfile<T> &p_profile)
: m_probs(p_profile.GetGame()->NumActions()), m_support(p_profile.GetGame()),
: m_probs(p_profile.GetGame()->BehavProfileLength()), m_support(p_profile.GetGame()),
m_gameversion(p_profile.GetGame()->GetVersion())
{
int index = 1;
for (const auto &player : p_profile.GetGame()->GetPlayers()) {
for (const auto &infoset : player->GetInfosets()) {
for (const auto &action : infoset->GetActions()) {
m_profileIndex[action] = index++;
m_profileIndex[action] = index;
m_probs[index++] = static_cast<T>(0);
}
}
}

static_cast<Vector<T> &>(m_probs) = T(0);

GameTreeNodeRep *root =
dynamic_cast<GameTreeNodeRep *>(m_support.GetGame()->GetRoot().operator->());

Expand Down Expand Up @@ -184,16 +183,6 @@ MixedBehaviorProfile<T>::operator=(const MixedBehaviorProfile<T> &p_profile)
return *this;
}

//========================================================================
// MixedBehaviorProfile<T>: Operator overloading
//========================================================================

template <class T>
bool MixedBehaviorProfile<T>::operator==(const MixedBehaviorProfile<T> &p_profile) const
{
return (m_support == p_profile.m_support && (DVector<T> &)*this == (DVector<T> &)p_profile);
}

//========================================================================
// MixedBehaviorProfile<T>: General data access
//========================================================================
Expand Down
15 changes: 9 additions & 6 deletions src/games/behavmixed.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ namespace Gambit {
///
template <class T> class MixedBehaviorProfile {
protected:
DVector<T> m_probs;
Vector<T> m_probs;
BehaviorSupportProfile m_support;
/// The index into the action profile for a action (-1 if not in support)
std::map<GameAction, int> m_profileIndex;
Expand Down Expand Up @@ -101,11 +101,14 @@ template <class T> class MixedBehaviorProfile {

/// @name Operator overloading
//@{
bool operator==(const MixedBehaviorProfile<T> &) const;
bool operator!=(const MixedBehaviorProfile<T> &x) const { return !(*this == x); }

bool operator==(const DVector<T> &x) const { return m_probs == x; }
bool operator!=(const DVector<T> &x) const { return m_probs != x; }
bool operator==(const MixedBehaviorProfile<T> &p_profile) const
{
return (m_support == p_profile.m_support && m_probs == p_profile.m_probs);
}
bool operator!=(const MixedBehaviorProfile<T> &p_profile) const
{
return (m_support != p_profile.m_support || m_probs != p_profile.m_probs);
}

const T &operator[](const GameAction &p_action) const
{
Expand Down
13 changes: 0 additions & 13 deletions src/games/behavspt.cc
Original file line number Diff line number Diff line change
Expand Up @@ -54,19 +54,6 @@ BehaviorSupportProfile::BehaviorSupportProfile(const Game &p_efg) : m_efg(p_efg)
// BehaviorSupportProfile: General information
//========================================================================

PVector<int> BehaviorSupportProfile::NumActions() const
{
PVector<int> answer(m_efg->NumInfosets());
for (const auto &player : m_efg->GetPlayers()) {
for (const auto &infoset : player->GetInfosets()) {
answer(player->GetNumber(), infoset->GetNumber()) =
static_cast<int>(m_actions.at(infoset).size());
}
}

return answer;
}

size_t BehaviorSupportProfile::BehaviorProfileLength() const
{
size_t answer = 0;
Expand Down
2 changes: 0 additions & 2 deletions src/games/behavspt.h
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,6 @@ class BehaviorSupportProfile {
/// Returns the game on which the support is defined.
Game GetGame() const { return m_efg; }

/// Returns the number of actions in the support for all information sets
PVector<int> NumActions() const;
/// Returns the total number of actions in the support
size_t BehaviorProfileLength() const;

Expand Down
6 changes: 1 addition & 5 deletions src/games/game.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
#include <set>
#include <random>

#include "core/dvector.h"
#include "core/pvector.h"
#include "number.h"
#include "gameobject.h"

Expand Down Expand Up @@ -485,10 +485,6 @@ class GameRep : public BaseGameRep {

/// @name Dimensions of the game
//@{
/// The number of actions in each information set
virtual PVector<int> NumActions() const = 0;
/// The number of members in each information set
virtual PVector<int> NumMembers() const = 0;
/// The number of strategies for each player
virtual Array<int> NumStrategies() const = 0;
/// Gets the i'th strategy in the game, numbered globally
Expand Down
4 changes: 0 additions & 4 deletions src/games/gameagg.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,6 @@ class GameAGGRep : public GameRep {
std::shared_ptr<agg::AGG> GetUnderlyingAGG() const { return aggPtr; }
/// @name Dimensions of the game
//@{
/// The number of actions in each information set
PVector<int> NumActions() const override { throw UndefinedException(); }
/// The number of members in each information set
PVector<int> NumMembers() const override { throw UndefinedException(); }
/// The number of strategies for each player
Array<int> NumStrategies() const override;
/// Gets the i'th strategy in the game, numbered globally
Expand Down
4 changes: 0 additions & 4 deletions src/games/gamebagg.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,6 @@ class GameBAGGRep : public GameRep {

/// @name Dimensions of the game
//@{
/// The number of actions in each information set
PVector<int> NumActions() const override { throw UndefinedException(); }
/// The number of members in each information set
PVector<int> NumMembers() const override { throw UndefinedException(); }
/// The number of strategies for each player
Array<int> NumStrategies() const override;
/// Gets the i'th strategy in the game, numbered globally
Expand Down
Loading

0 comments on commit a6fcf5a

Please sign in to comment.