Skip to content

Commit

Permalink
Simplify logic for generating new sequence.
Browse files Browse the repository at this point in the history
  • Loading branch information
tturocy committed Sep 13, 2024
1 parent a5efee6 commit 9c9686f
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 29 deletions.
38 changes: 11 additions & 27 deletions src/solvers/enumpoly/sfg.cc
Original file line number Diff line number Diff line change
Expand Up @@ -64,23 +64,18 @@ Sfg::Sfg(const BehaviorSupportProfile &S) : support(S), m_dim(support.GetGame()-
sequences.try_emplace(player, Array<std::shared_ptr<SequenceRep>>());
sequences[player].push_back(std::make_shared<SequenceRep>(nullptr, nullptr, 1));

E.try_emplace(player, infoset_row[player].size() + 1, m_dim[player->GetNumber()]);
E.try_emplace(player, infoset_row[player].size() + 1, m_actionParents[player].size() + 1);
E.at(player)(1, 1) = Rational(1);

parent[player] = sequences.at(player).front();
last_infoset[player] = nullptr;
}

{
std::set<GameInfoset> visited;
MakeSequenceForm(support.GetGame()->GetRoot(), Rational(1), one, last_infoset, parent,
visited);
}
MakeSequenceForm(support.GetGame()->GetRoot(), Rational(1), one, last_infoset, parent);
}

void Sfg::MakeSequenceForm(const GameNode &n, const Rational &prob, const Array<int> &seq,
std::map<GamePlayer, GameInfoset> iset, PureSequenceProfile parent,
std::set<GameInfoset> &p_visited)
std::map<GamePlayer, GameInfoset> iset, PureSequenceProfile parent)
{
if (n->GetOutcome()) {
for (int pl = 1; pl <= seq.Length(); pl++) {
Expand All @@ -94,40 +89,29 @@ void Sfg::MakeSequenceForm(const GameNode &n, const Rational &prob, const Array<
for (auto action : n->GetInfoset()->GetActions()) {
MakeSequenceForm(n->GetChild(action),
prob * static_cast<Rational>(n->GetInfoset()->GetActionProb(action)), seq,
iset, parent, p_visited);
iset, parent);
}
}
else {
int pl = n->GetPlayer()->GetNumber();
iset[n->GetPlayer()] = n->GetInfoset();
int isetnum = n->GetInfoset()->GetNumber();
Array<int> snew(seq);
snew[pl] = 1;
for (int i = 1; i < isetnum; i++) {
if (infoset_row.at(n->GetPlayer()).find(n->GetPlayer()->GetInfoset(i)) !=
infoset_row.at(n->GetPlayer()).end()) {
snew[pl] += support.NumActions(pl, i);
}
}

E.at(n->GetPlayer())(infoset_row[n->GetPlayer()][n->GetInfoset()], seq[pl]) = Rational(1);
std::shared_ptr<SequenceRep> myparent(parent[n->GetPlayer()]);

bool flag = false;
if (p_visited.find(n->GetInfoset()) == p_visited.end()) {
p_visited.insert(n->GetInfoset());
flag = true;
}
Array<int> snew(seq);
for (auto action : support.GetActions(n->GetInfoset())) {
snew[pl] += 1;
if (flag) {
auto child_seq = std::make_shared<SequenceRep>(action, myparent, snew[pl]);
if (m_sequenceColumns[n->GetPlayer()].find(action) ==
m_sequenceColumns[n->GetPlayer()].end()) {
auto child_seq = std::make_shared<SequenceRep>(
action, myparent, m_sequenceColumns[n->GetPlayer()].size() + 1);
parent[n->GetPlayer()] = child_seq;
sequences.at(n->GetPlayer()).push_back(child_seq);
m_sequenceColumns[n->GetPlayer()][action] = m_sequenceColumns[n->GetPlayer()].size() + 1;
}
snew[pl] = m_sequenceColumns[n->GetPlayer()][action];
E.at(n->GetPlayer())(infoset_row[n->GetPlayer()][n->GetInfoset()], snew[pl]) = Rational(-1);
MakeSequenceForm(n->GetChild(action), prob, snew, iset, parent, p_visited);
MakeSequenceForm(n->GetChild(action), prob, snew, iset, parent);
}
}
}
Expand Down
3 changes: 1 addition & 2 deletions src/solvers/enumpoly/sfg.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,7 @@ class Sfg {
std::map<GamePlayer, std::map<GameAction, GameAction>> m_actionParents;

void MakeSequenceForm(const GameNode &, const Rational &, const Array<int> &,
std::map<GamePlayer, GameInfoset>, PureSequenceProfile,
std::set<GameInfoset> &);
std::map<GamePlayer, GameInfoset>, PureSequenceProfile);

void ComputeNumSequences(const GameNode &, std::map<GamePlayer, GameAction> &);

Expand Down

0 comments on commit 9c9686f

Please sign in to comment.