Skip to content

Commit

Permalink
Create concept of set of player's sequences
Browse files Browse the repository at this point in the history
  • Loading branch information
tturocy committed Sep 19, 2024
1 parent ad3b73c commit 3403966
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 37 deletions.
37 changes: 16 additions & 21 deletions src/solvers/enumpoly/efgpoly.cc
Original file line number Diff line number Diff line change
Expand Up @@ -64,13 +64,12 @@ gPoly<double> BuildSequenceVariable(ProblemData &p_data, const GameSequence &p_s
}

gPoly<double> equation(p_data.Space, p_data.Lex);
for (auto seq = p_data.SF.cbegin_sequences(p_sequence.player);
seq != p_data.SF.cend_sequences(p_sequence.player); seq++) {
if (*seq == p_sequence) {
for (auto seq : p_data.SF.GetSequences(p_sequence.player)) {
if (seq == p_sequence) {
break;
}
if (int constraint_coef = p_data.SF.GetConstraintEntry(infoset, seq->action)) {
equation += double(constraint_coef) * BuildSequenceVariable(p_data, *seq, var);
if (int constraint_coef = p_data.SF.GetConstraintEntry(infoset, seq.action)) {
equation += double(constraint_coef) * BuildSequenceVariable(p_data, seq, var);
}
}
return equation;
Expand All @@ -82,19 +81,17 @@ ProblemData::ProblemData(const BehaviorSupportProfile &p_support)
Lex(new term_order(Space, lex))
{
for (auto player : p_support.GetGame()->GetPlayers()) {
for (auto sequence = std::next(SF.cbegin_sequences(player));
sequence != SF.cend_sequences(player); sequence++) {
if (p_support.GetIndex(sequence->action) <
p_support.NumActions(sequence->action->GetInfoset())) {
var[*sequence] = var.size() + 1;
for (auto sequence : SF.GetSequences(player)) {
if (sequence.action && (p_support.GetIndex(sequence.action) <
p_support.NumActions(sequence.action->GetInfoset()))) {
var[sequence] = var.size() + 1;
}
}
}

for (auto player : p_support.GetGame()->GetPlayers()) {
for (auto sequence = SF.cbegin_sequences(player); sequence != SF.cend_sequences(player);
sequence++) {
variables.emplace(*sequence, BuildSequenceVariable(*this, *sequence, var));
for (auto sequence : SF.GetSequences(player)) {
variables.emplace(sequence, BuildSequenceVariable(*this, sequence, var));
}
}
}
Expand Down Expand Up @@ -152,12 +149,11 @@ gPolyList<double> LastActionProbPositiveInequalities(ProblemData &p_data)
gPolyList<double> equations(p_data.Space, p_data.Lex);

for (auto player : p_data.support.GetGame()->GetPlayers()) {
for (auto sequence = p_data.SF.cbegin_sequences(player);
sequence != p_data.SF.cend_sequences(player); ++sequence) {
int action_number = (sequence->action) ? p_data.support.GetIndex(sequence->action) : 0;
for (auto sequence : p_data.SF.GetSequences(player)) {
int action_number = (sequence.action) ? p_data.support.GetIndex(sequence.action) : 0;
if (action_number > 1 &&
action_number == p_data.support.NumActions(sequence->action->GetInfoset())) {
equations += p_data.variables.at({player, sequence->action});
action_number == p_data.support.NumActions(sequence.action->GetInfoset())) {
equations += p_data.variables.at({player, sequence.action});
}
}
}
Expand All @@ -183,9 +179,8 @@ std::map<GameSequence, double> ToSequenceProbs(const ProblemData &p_data, const
{
std::map<GameSequence, double> x;
for (auto player : p_data.support.GetGame()->GetPlayers()) {
for (auto sequence = p_data.SF.cbegin_sequences(player);
sequence != p_data.SF.cend_sequences(player); sequence++) {
x[*sequence] = p_data.variables.at(*sequence).Evaluate(v);
for (auto sequence : p_data.SF.GetSequences(player)) {
x[sequence] = p_data.variables.at(sequence).Evaluate(v);
}
}
return x;
Expand Down
44 changes: 28 additions & 16 deletions src/solvers/enumpoly/sfg.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,12 +64,35 @@ class SequenceForm {
Rational &GetMatrixEntry(const PureSequenceProfile &, const GamePlayer &);

public:
class contingencies {
class PlayerSequences {
private:
const SequenceForm *m_sfg;
GamePlayer m_player;

public:
contingencies(const SequenceForm *p_sfg) : m_sfg(p_sfg) {}
PlayerSequences(const SequenceForm *p_sfg, const GamePlayer &p_player)
: m_sfg(p_sfg), m_player(p_player)
{
}

size_t size() const { return m_sfg->m_sequences.at(m_player).size(); }

std::vector<GameSequence>::const_iterator begin() const
{
return m_sfg->m_sequences.at(m_player).begin();
}
std::vector<GameSequence>::const_iterator end() const
{
return m_sfg->m_sequences.at(m_player).end();
}
};

class Contingencies {
private:
const SequenceForm *m_sfg;

public:
Contingencies(const SequenceForm *p_sfg) : m_sfg(p_sfg) {}

class iterator {
private:
Expand Down Expand Up @@ -133,23 +156,12 @@ class SequenceForm {

~SequenceForm() = default;

int NumSequences(const GamePlayer &p_player) const
{
return m_sequenceColumns.at(p_player).size();
}

std::vector<GameSequence>::const_iterator cbegin_sequences(const GamePlayer &p_player) const
{
return m_sequences.at(p_player).cbegin();
}
std::vector<GameSequence>::const_iterator cend_sequences(const GamePlayer &p_player) const
PlayerSequences GetSequences(const GamePlayer &p_player) const
{
return m_sequences.at(p_player).cend();
return PlayerSequences(this, p_player);
}

contingencies GetContingencies() const { return contingencies(this); }

const Array<int> &NumSequences() const { return SF.GetIndexDimension(); }
Contingencies GetContingencies() const { return Contingencies(this); }

int TotalNumSequences() const
{
Expand Down

0 comments on commit 3403966

Please sign in to comment.