Skip to content

Commit

Permalink
Pre-construct polynomial representations of probabilities.
Browse files Browse the repository at this point in the history
  • Loading branch information
tturocy committed Jul 18, 2024
1 parent 362d09f commit 60b6218
Showing 1 changed file with 17 additions and 33 deletions.
50 changes: 17 additions & 33 deletions src/solvers/enumpoly/nfgpoly.cc
Original file line number Diff line number Diff line change
Expand Up @@ -42,15 +42,15 @@ class PolEnumModule {
// in a solution is inferred by the sum-to-one constraint.
std::map<GameStrategy, int> strategy_vars;
std::list<GameStrategy> strategy_omit;
// The polynomial representation of each strategy probability, substituting in
// the sum-to-one equation for the probability of the last strategy for each player
std::map<GameStrategy, gPoly<double>> strategy_poly;
gSpace Space;
term_order Lex;
int num_vars;
List<MixedStrategyProfile<double>> solutions;
bool is_singular{false};

// p_i_j as a gPoly, with last prob in terms of previous probs
gPoly<double> Prob(const GameStrategy &strategy) const;

// equation for when player i sets strat1 = strat2
// with last probs for each player substituted out.
gPoly<double> IndifferenceEquation(const GameStrategy &s1, const GameStrategy &s2) const;
Expand Down Expand Up @@ -81,14 +81,25 @@ PolEnumModule::PolEnumModule(const StrategySupportProfile &S)
num_vars(support.MixedProfileLength() - S.GetGame()->NumPlayers())
{
int index = 1;
Vector<int> exps(num_vars);

for (auto player : support.GetGame()->GetPlayers()) {
auto strategies = support.GetStrategies(player);
exps = 0;
gPoly<double> residual(&Space, gMono<double>(1, exp_vect(&Space, exps)), &Lex);
for (auto strategy : strategies) {
if (strategy != strategies.back()) {
strategy_vars[strategy] = index++;
strategy_vars[strategy] = index;
exps = 0;
exps[index] = 1;
auto poly = gPoly<double>(&Space, gMono<double>(1, exp_vect(&Space, exps)), &Lex);
strategy_poly.emplace(strategy, poly);
residual -= strategy_poly.at(strategy);
index++;
}
else {
strategy_omit.push_back(strategy);
strategy_poly.emplace(strategy, residual);
}
}
}
Expand Down Expand Up @@ -126,33 +137,6 @@ int PolEnumModule::SaveSolutions(const List<Vector<double>> &list)
return solutions.size();
}

gPoly<double> PolEnumModule::Prob(const GameStrategy &strategy) const
{
gPoly<double> equation(&Space, &Lex);
Vector<int> exps(num_vars);

auto var_mapping = strategy_vars.find(strategy);

if (var_mapping != strategy_vars.end()) {
exps = 0;
exps[var_mapping->second] = 1;
equation += gPoly<double>(&Space, gMono<double>(1, exp_vect(&Space, exps)), &Lex);
}
else {
for (auto strat : support.GetStrategies(strategy->GetPlayer())) {
var_mapping = strategy_vars.find(strat);
if (var_mapping != strategy_vars.end()) {
exps = 0;
exps[var_mapping->second] = 1;
equation += gPoly<double>(&Space, gMono<double>(-1, exp_vect(&Space, exps)), &Lex);
}
}
exps = 0;
equation += gPoly<double>(&Space, gMono<double>(1, exp_vect(&Space, exps)), &Lex);
}
return equation;
}

gPoly<double> PolEnumModule::IndifferenceEquation(const GameStrategy &s1,
const GameStrategy &s2) const
{
Expand All @@ -162,7 +146,7 @@ gPoly<double> PolEnumModule::IndifferenceEquation(const GameStrategy &s1,
gPoly<double> term(&Space, 1, &Lex);
for (auto player : support.GetGame()->GetPlayers()) {
if (player != s1->GetPlayer()) {
term *= Prob((*A)->GetStrategy(player));
term *= strategy_poly.at((*A)->GetStrategy(player));
}
}
term *= (*A)->GetPayoff(s1->GetPlayer()) - (*B)->GetPayoff(s1->GetPlayer());
Expand All @@ -185,7 +169,7 @@ void PolEnumModule::IndifferenceEquations(gPolyList<double> &equations) const
void PolEnumModule::LastActionProbPositiveInequalities(gPolyList<double> &equations) const
{
for (auto strategy : strategy_omit) {
equations += Prob(strategy);
equations += strategy_poly.at(strategy);
}
}

Expand Down

0 comments on commit 60b6218

Please sign in to comment.