Skip to content

Commit d615373

Browse files
committed
Remove "frozen" strategies in contingencies; handle in support profiles instead.
1 parent b93ef41 commit d615373

4 files changed

Lines changed: 30 additions & 54 deletions

File tree

src/games/stratpure.h

Lines changed: 8 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -122,39 +122,26 @@ class PureStrategyProfile {
122122

123123
class StrategyContingencies {
124124
StrategySupportProfile m_support;
125-
std::vector<GamePlayer> m_unfrozen;
126-
std::vector<GameStrategy> m_frozen;
127125

128126
public:
129127
class iterator {
130128
StrategyContingencies *m_cont;
131129
bool m_atEnd{false};
132-
133-
// One index per unfrozen player (odometer digits)
134130
std::vector<size_t> m_pos;
135-
136-
// Current pure-strategy profile
137131
PureStrategyProfile m_profile;
138132

139133
public:
140-
iterator(StrategyContingencies *cont, bool end)
141-
: m_cont(cont), m_atEnd(end), m_profile(cont->m_support.GetGame()->NewPureStrategyProfile())
134+
iterator(StrategyContingencies *cont, bool p_end)
135+
: m_cont(cont), m_atEnd(p_end),
136+
m_profile(cont->m_support.GetGame()->NewPureStrategyProfile())
142137
{
143138
if (m_atEnd) {
144139
return;
145140
}
146-
147-
// Apply frozen strategies
148-
for (const auto &s : m_cont->m_frozen) {
149-
m_profile->SetStrategy(s);
150-
}
151-
152-
// Initialise odometer
153-
const size_t n = m_cont->m_unfrozen.size();
141+
const size_t n = m_cont->m_support.GetPlayers().size();
154142
m_pos.assign(n, 0);
155-
156143
for (size_t i = 0; i < n; ++i) {
157-
const GamePlayer player = m_cont->m_unfrozen[i];
144+
const GamePlayer player = m_cont->m_support.GetGame()->GetPlayer(i + 1);
158145
auto support = m_cont->m_support.GetStrategies(player);
159146
m_profile->SetStrategy(support[0]);
160147
}
@@ -163,23 +150,18 @@ class StrategyContingencies {
163150
iterator &operator++()
164151
{
165152
const size_t n = m_pos.size();
166-
167153
for (size_t i = 0; i < n; ++i) {
168-
const GamePlayer player = m_cont->m_unfrozen[i];
154+
const GamePlayer player = m_cont->m_support.GetGame()->GetPlayer(i + 1);
169155
auto support = m_cont->m_support.GetStrategies(player);
170-
171156
++m_pos[i];
172157
if (m_pos[i] < support.size()) {
173158
m_profile->SetStrategy(support[m_pos[i]]);
174159
return *this;
175160
}
176-
177-
// rollover this dimension
178161
m_pos[i] = 0;
179162
m_profile->SetStrategy(support[0]);
180163
}
181164

182-
// overflow in all dimensions → end
183165
m_atEnd = true;
184166
return *this;
185167
}
@@ -201,31 +183,8 @@ class StrategyContingencies {
201183
const PureStrategyProfile &operator*() const { return m_profile; }
202184
};
203185

204-
explicit StrategyContingencies(const Game &p_game) : m_support(StrategySupportProfile(p_game))
205-
{
206-
for (const auto &player : p_game->GetPlayers()) {
207-
m_unfrozen.push_back(player);
208-
}
209-
}
210-
explicit StrategyContingencies(const StrategySupportProfile &support,
211-
const std::vector<GameStrategy> &frozen = {})
212-
: m_support(support), m_frozen(frozen)
213-
{
214-
// Determine unfrozen players
215-
auto players = m_support.GetPlayers();
216-
for (auto player : players) {
217-
bool is_frozen = false;
218-
for (const auto &s : m_frozen) {
219-
if (s->GetPlayer() == player) {
220-
is_frozen = true;
221-
break;
222-
}
223-
}
224-
if (!is_frozen) {
225-
m_unfrozen.push_back(player);
226-
}
227-
}
228-
}
186+
explicit StrategyContingencies(const Game &p_game) : m_support(StrategySupportProfile(p_game)) {}
187+
explicit StrategyContingencies(const StrategySupportProfile &support) : m_support(support) {}
229188

230189
iterator begin() { return {this, false}; }
231190
iterator end() { return {this, true}; }

src/games/stratspt.h

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,19 @@ class StrategySupportProfile {
193193
/// player, it is not removed. Returns true if the removal was
194194
/// executed, and false if not.
195195
bool RemoveStrategy(const GameStrategy &);
196+
197+
StrategySupportProfile RestrictTo(const GameStrategy &p_strategy) const
198+
{
199+
if (p_strategy->GetGame() != m_game) {
200+
throw MismatchException();
201+
}
202+
const GamePlayer player = p_strategy->GetPlayer();
203+
const size_t player_index = player->GetNumber() - 1;
204+
const int digit = p_strategy->GetNumber() - 1;
205+
StrategySupportProfile restricted(*this);
206+
restricted.m_strategies.m_allowedDigits[player_index].assign(1, digit);
207+
return restricted;
208+
}
196209
//@}
197210

198211
/// @name Identification of dominated strategies

src/games/writer.cc

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,10 @@ std::string WriteHTMLFile(const Game &p_game, const GamePlayer &p_rowPlayer,
3131
std::string theHtml;
3232
theHtml += "<center><h1>" + p_game->GetTitle() + "</h1></center>\n";
3333

34-
for (const auto &iter : StrategyContingencies(
35-
p_game, {p_rowPlayer->GetStrategies().front(), p_colPlayer->GetStrategies().front()})) {
34+
auto support = StrategySupportProfile(p_game)
35+
.RestrictTo(p_rowPlayer->GetStrategies().front())
36+
.RestrictTo(p_colPlayer->GetStrategies().front());
37+
for (const auto &iter : StrategyContingencies(support)) {
3638
if (p_game->NumPlayers() > 2) {
3739
theHtml += "<center><b>Subtable with strategies:</b></center>";
3840
for (auto player : p_game->GetPlayers()) {
@@ -99,8 +101,10 @@ std::string WriteLaTeXFile(const Game &p_game, const GamePlayer &p_rowPlayer,
99101
{
100102
std::string theHtml;
101103

102-
for (const auto &iter : StrategyContingencies(
103-
p_game, {p_rowPlayer->GetStrategies().front(), p_colPlayer->GetStrategies().front()})) {
104+
auto support = StrategySupportProfile(p_game)
105+
.RestrictTo(p_rowPlayer->GetStrategies().front())
106+
.RestrictTo(p_colPlayer->GetStrategies().front());
107+
for (const auto &iter : StrategyContingencies(support)) {
104108
theHtml += "\\begin{game}{";
105109
theHtml += std::to_string(p_rowPlayer->GetStrategies().size());
106110
theHtml += "}{";

src/solvers/enumpoly/nfgpoly.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ IndifferenceEquation(std::shared_ptr<VariableSpace> space, const StrategySupport
6363
{
6464
Polynomial<double> equation(space);
6565

66-
for (auto iter : StrategyContingencies(support, {s1})) {
66+
for (const auto &iter : StrategyContingencies(support.RestrictTo(s1))) {
6767
Polynomial<double> term(space, 1);
6868
for (auto player : support.GetGame()->GetPlayers()) {
6969
if (player != s1->GetPlayer()) {

0 commit comments

Comments
 (0)