Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/ISSUE_TEMPLATE/bug_report.yml
Original file line number Diff line number Diff line change
Expand Up @@ -47,4 +47,4 @@ body:
placeholder: Tell us what you see and provide a screenshot if appropriate.
value: "A bug happened!"
validations:
required: true
required: true
2 changes: 1 addition & 1 deletion .github/ISSUE_TEMPLATE/documentation_improvement.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,4 @@ body:
placeholder: Describe the documentation improvement in detail.
value: "A documentation improvement suggestion!"
validations:
required: true
required: true
2 changes: 1 addition & 1 deletion .github/ISSUE_TEMPLATE/feature_request.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,4 @@ body:
placeholder: Describe the feature or improvement in detail.
value: "A feature or improvement suggestion!"
validations:
required: true
required: true
11 changes: 6 additions & 5 deletions src/games/nash.cc
Original file line number Diff line number Diff line change
Expand Up @@ -165,8 +165,9 @@ MixedBehaviorProfile<T> BuildProfile(const Game &p_game, const SubgameSolution<T
}

template <class T>
List<MixedBehaviorProfile<T>> SolveBySubgames(const Game &p_game, BehaviorSolverType<T> p_solver,
BehaviorCallbackType<T> p_onEquilibrium)
std::list<MixedBehaviorProfile<T>> SolveBySubgames(const Game &p_game,
BehaviorSolverType<T> p_solver,
BehaviorCallbackType<T> p_onEquilibrium)
{
const Game efg = p_game->CopySubgame(p_game->GetRoot());

Expand All @@ -185,18 +186,18 @@ List<MixedBehaviorProfile<T>> SolveBySubgames(const Game &p_game, BehaviorSolver
}

auto results = SolveSubgames(efg->GetRoot(), infoset_map, p_solver);
List<MixedBehaviorProfile<T>> solutions;
std::list<MixedBehaviorProfile<T>> solutions;
for (const auto &result : results) {
solutions.push_back(BuildProfile(p_game, result));
p_onEquilibrium(solutions.back(), "NE");
}
return solutions;
}

template List<MixedBehaviorProfile<double>>
template std::list<MixedBehaviorProfile<double>>
SolveBySubgames(const Game &p_game, BehaviorSolverType<double> p_solver,
BehaviorCallbackType<double> p_onEquilibrium);
template List<MixedBehaviorProfile<Rational>>
template std::list<MixedBehaviorProfile<Rational>>
SolveBySubgames(const Game &p_game, BehaviorSolverType<Rational> p_solver,
BehaviorCallbackType<Rational> p_onEquilibrium);

Expand Down
11 changes: 6 additions & 5 deletions src/games/nash.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,21 +47,22 @@ template <class T> void NullBehaviorCallback(const MixedBehaviorProfile<T> &, co
}

template <class T>
List<MixedBehaviorProfile<T>> ToMixedBehaviorProfile(const List<MixedStrategyProfile<T>> &p_list)
std::list<MixedBehaviorProfile<T>>
ToMixedBehaviorProfile(const std::list<MixedStrategyProfile<T>> &p_list)
{
List<MixedBehaviorProfile<T>> ret;
std::list<MixedBehaviorProfile<T>> ret;
for (const auto &profile : p_list) {
ret.push_back(MixedBehaviorProfile<T>(profile));
}
return ret;
}

template <class T>
using BehaviorSolverType = std::function<List<MixedBehaviorProfile<T>>(const Game &)>;
using BehaviorSolverType = std::function<std::list<MixedBehaviorProfile<T>>(const Game &)>;

template <class T>
List<MixedBehaviorProfile<T>> SolveBySubgames(const Game &, BehaviorSolverType<T> p_solver,
BehaviorCallbackType<T> p_onEquilibrium);
std::list<MixedBehaviorProfile<T>> SolveBySubgames(const Game &, BehaviorSolverType<T> p_solver,
BehaviorCallbackType<T> p_onEquilibrium);

//
// Exception raised when maximum number of equilibria to compute
Expand Down
36 changes: 18 additions & 18 deletions src/pygambit/gambit.pxd
Original file line number Diff line number Diff line change
Expand Up @@ -470,45 +470,45 @@ cdef extern from "util.h":


cdef extern from "solvers/enumpure/enumpure.h":
c_List[c_MixedStrategyProfile[c_Rational]] EnumPureStrategySolve(c_Game) except +RuntimeError
c_List[c_MixedBehaviorProfile[c_Rational]] EnumPureAgentSolve(c_Game) except +RuntimeError
stdlist[c_MixedStrategyProfile[c_Rational]] EnumPureStrategySolve(c_Game) except +RuntimeError
stdlist[c_MixedBehaviorProfile[c_Rational]] EnumPureAgentSolve(c_Game) except +RuntimeError

cdef extern from "solvers/enummixed/enummixed.h":
c_List[c_MixedStrategyProfile[T]] EnumMixedStrategySolve[T](c_Game) except +RuntimeError
stdlist[c_MixedStrategyProfile[T]] EnumMixedStrategySolve[T](c_Game) except +RuntimeError

cdef extern from "solvers/lcp/lcp.h":
c_List[c_MixedStrategyProfile[T]] LcpStrategySolve[T](
stdlist[c_MixedStrategyProfile[T]] LcpStrategySolve[T](
c_Game, int p_stopAfter, int p_maxDepth
) except +RuntimeError
c_List[c_MixedBehaviorProfile[T]] LcpBehaviorSolve[T](
stdlist[c_MixedBehaviorProfile[T]] LcpBehaviorSolve[T](
c_Game, int p_stopAfter, int p_maxDepth
) except +RuntimeError

cdef extern from "solvers/lp/lp.h":
c_List[c_MixedStrategyProfile[T]] LpStrategySolve[T](c_Game) except +RuntimeError
c_List[c_MixedBehaviorProfile[T]] LpBehaviorSolve[T](c_Game) except +RuntimeError
stdlist[c_MixedStrategyProfile[T]] LpStrategySolve[T](c_Game) except +RuntimeError
stdlist[c_MixedBehaviorProfile[T]] LpBehaviorSolve[T](c_Game) except +RuntimeError

cdef extern from "solvers/liap/liap.h":
c_List[c_MixedStrategyProfile[double]] LiapStrategySolve(
stdlist[c_MixedStrategyProfile[double]] LiapStrategySolve(
c_MixedStrategyProfile[double], double p_maxregret, int p_maxitsN
) except +RuntimeError
c_List[c_MixedBehaviorProfile[double]] LiapBehaviorSolve(
stdlist[c_MixedBehaviorProfile[double]] LiapBehaviorSolve(
c_MixedBehaviorProfile[double], double p_maxregret, int p_maxitsN
) except +RuntimeError

cdef extern from "solvers/simpdiv/simpdiv.h":
c_List[c_MixedStrategyProfile[c_Rational]] SimpdivStrategySolve(
stdlist[c_MixedStrategyProfile[c_Rational]] SimpdivStrategySolve(
c_MixedStrategyProfile[c_Rational] start, c_Rational p_maxregret, int p_gridResize,
int p_leashLength
) except +RuntimeError

cdef extern from "solvers/ipa/ipa.h":
c_List[c_MixedStrategyProfile[double]] IPAStrategySolve(
stdlist[c_MixedStrategyProfile[double]] IPAStrategySolve(
c_MixedStrategyProfile[double]
) except +RuntimeError

cdef extern from "solvers/gnm/gnm.h":
c_List[c_MixedStrategyProfile[double]] GNMStrategySolve(
stdlist[c_MixedStrategyProfile[double]] GNMStrategySolve(
c_MixedStrategyProfile[double], double p_endLambda, int p_steps,
int p_localNewtonInterval, int p_localNewtonMaxits
) except +RuntimeError
Expand All @@ -521,10 +521,10 @@ cdef extern from "solvers/nashsupport/nashsupport.h":
) except +RuntimeError

cdef extern from "solvers/enumpoly/enumpoly.h":
c_List[c_MixedStrategyProfile[double]] EnumPolyStrategySolve(
stdlist[c_MixedStrategyProfile[double]] EnumPolyStrategySolve(
c_Game, int, float
) except +RuntimeError
c_List[c_MixedBehaviorProfile[double]] EnumPolyBehaviorSolve(
stdlist[c_MixedBehaviorProfile[double]] EnumPolyBehaviorSolve(
c_Game, int, float
) except +RuntimeError

Expand All @@ -551,10 +551,10 @@ cdef extern from "solvers/logit/logit.h":


cdef extern from "nash.h":
c_List[c_MixedBehaviorProfile[double]] LogitBehaviorSolveWrapper(
stdlist[c_MixedBehaviorProfile[double]] LogitBehaviorSolveWrapper(
c_Game, double, double, double
) except +
c_List[c_LogitQREMixedBehaviorProfile] LogitBehaviorPrincipalBranchWrapper(
stdlist[c_LogitQREMixedBehaviorProfile] LogitBehaviorPrincipalBranchWrapper(
c_Game, double, double, double
) except +
stdlist[shared_ptr[c_LogitQREMixedBehaviorProfile]] LogitBehaviorAtLambdaWrapper(
Expand All @@ -563,10 +563,10 @@ cdef extern from "nash.h":
shared_ptr[c_LogitQREMixedBehaviorProfile] LogitBehaviorEstimateWrapper(
shared_ptr[c_MixedBehaviorProfile[double]], bool, double, double
) except +
c_List[c_MixedStrategyProfile[double]] LogitStrategySolveWrapper(
stdlist[c_MixedStrategyProfile[double]] LogitStrategySolveWrapper(
c_Game, double, double, double
) except +
c_List[c_LogitQREMixedStrategyProfile] LogitStrategyPrincipalBranchWrapper(
stdlist[c_LogitQREMixedStrategyProfile] LogitStrategyPrincipalBranchWrapper(
c_Game, double, double, double
) except +
stdlist[shared_ptr[c_LogitQREMixedStrategyProfile]] LogitStrategyAtLambdaWrapper(
Expand Down
30 changes: 16 additions & 14 deletions src/pygambit/nash.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,21 +26,22 @@
using namespace std;
using namespace Gambit;

List<MixedBehaviorProfile<double>> LogitBehaviorSolveWrapper(const Game &p_game, double p_regret,
double p_firstStep, double p_maxAccel)
std::list<MixedBehaviorProfile<double>> LogitBehaviorSolveWrapper(const Game &p_game,
double p_regret,
double p_firstStep,
double p_maxAccel)
{
List<MixedBehaviorProfile<double>> ret;
std::list<MixedBehaviorProfile<double>> ret;
ret.push_back(LogitBehaviorSolve(LogitQREMixedBehaviorProfile(p_game), p_regret, 1.0,
p_firstStep, p_maxAccel)
.back()
.GetProfile());
return ret;
}

inline List<LogitQREMixedBehaviorProfile> LogitBehaviorPrincipalBranchWrapper(const Game &p_game,
double p_regret,
double p_firstStep,
double p_maxAccel)
inline std::list<LogitQREMixedBehaviorProfile>
LogitBehaviorPrincipalBranchWrapper(const Game &p_game, double p_regret, double p_firstStep,
double p_maxAccel)
{
return LogitBehaviorSolve(LogitQREMixedBehaviorProfile(p_game), p_regret, 1.0, p_firstStep,
p_maxAccel);
Expand All @@ -66,21 +67,22 @@ LogitBehaviorAtLambdaWrapper(const Game &p_game, const std::list<double> &p_targ
return ret;
}

List<MixedStrategyProfile<double>> LogitStrategySolveWrapper(const Game &p_game, double p_regret,
double p_firstStep, double p_maxAccel)
std::list<MixedStrategyProfile<double>> LogitStrategySolveWrapper(const Game &p_game,
double p_regret,
double p_firstStep,
double p_maxAccel)
{
List<MixedStrategyProfile<double>> ret;
std::list<MixedStrategyProfile<double>> ret;
ret.push_back(LogitStrategySolve(LogitQREMixedStrategyProfile(p_game), p_regret, 1.0,
p_firstStep, p_maxAccel)
.back()
.GetProfile());
return ret;
}

inline List<LogitQREMixedStrategyProfile> LogitStrategyPrincipalBranchWrapper(const Game &p_game,
double p_regret,
double p_firstStep,
double p_maxAccel)
inline std::list<LogitQREMixedStrategyProfile>
LogitStrategyPrincipalBranchWrapper(const Game &p_game, double p_regret, double p_firstStep,
double p_maxAccel)
{
return LogitStrategySolve(LogitQREMixedStrategyProfile(p_game), p_regret, 1.0, p_firstStep,
p_maxAccel);
Expand Down
32 changes: 16 additions & 16 deletions src/pygambit/nash.pxi
Original file line number Diff line number Diff line change
Expand Up @@ -22,41 +22,42 @@
import cython
from libcpp.memory cimport shared_ptr, make_shared
from cython.operator cimport dereference as deref
from libcpp.list cimport list as stdlist


import typing


@cython.cfunc
def _convert_mspd(
inlist: c_List[c_MixedStrategyProfile[float]]
inlist: stdlist[c_MixedStrategyProfile[float]]
) -> typing.List[MixedStrategyProfile[double]]:
return [MixedStrategyProfileDouble.wrap(copyitem_list_mspd(inlist, i+1))
for i in range(inlist.size())]
return [MixedStrategyProfileDouble.wrap(profile)
for profile in make_list_of_pointer(inlist)]


@cython.cfunc
def _convert_mspr(
inlist: c_List[c_MixedStrategyProfile[c_Rational]]
inlist: stdlist[c_MixedStrategyProfile[c_Rational]]
) -> typing.List[MixedStrategyProfile[c_Rational]]:
return [MixedStrategyProfileRational.wrap(copyitem_list_mspr(inlist, i+1))
for i in range(inlist.size())]
return [MixedStrategyProfileRational.wrap(profile)
for profile in make_list_of_pointer(inlist)]


@cython.cfunc
def _convert_mbpd(
inlist: c_List[c_MixedBehaviorProfile[float]]
inlist: stdlist[c_MixedBehaviorProfile[float]]
) -> typing.List[MixedBehaviorProfile[double]]:
return [MixedBehaviorProfileDouble.wrap(copyitem_list_mbpd(inlist, i+1))
for i in range(inlist.size())]
return [MixedBehaviorProfileDouble.wrap(profile)
for profile in make_list_of_pointer(inlist)]


@cython.cfunc
def _convert_mbpr(
inlist: c_List[c_MixedBehaviorProfile[c_Rational]]
inlist: stdlist[c_MixedBehaviorProfile[c_Rational]]
) -> typing.List[MixedBehaviorProfile[c_Rational]]:
return [MixedBehaviorProfileRational.wrap(copyitem_list_mbpr(inlist, i+1))
for i in range(inlist.size())]
return [MixedBehaviorProfileRational.wrap(profile)
for profile in make_list_of_pointer(inlist)]


def _enumpure_strategy_solve(game: Game) -> typing.List[MixedStrategyProfile[c_Rational]]:
Expand Down Expand Up @@ -279,8 +280,7 @@ def _logit_strategy_branch(game: Game,
first_step: float,
max_accel: float):
solns = LogitStrategyPrincipalBranchWrapper(game.game, maxregret, first_step, max_accel)
return [LogitQREMixedStrategyProfile.wrap(copyitem_list_qrem(solns, i+1))
for i in range(solns.size())]
return [LogitQREMixedStrategyProfile.wrap(profile) for profile in make_list_of_pointer(solns)]


@cython.cclass
Expand Down Expand Up @@ -366,8 +366,8 @@ def _logit_behavior_branch(game: Game,
max_accel: float):
solns = LogitBehaviorPrincipalBranchWrapper(game.game, maxregret, first_step, max_accel)
ret = []
for i in range(solns.size()):
for profile_ptr in make_list_of_pointer(solns):
p = LogitQREMixedBehaviorProfile()
p.thisptr = copyitem_list_qreb(solns, i+1)
p.thisptr = profile_ptr
ret.append(p)
return ret
9 changes: 6 additions & 3 deletions src/solvers/enummixed/enummixed.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,15 @@ template <class T> class EnumMixedStrategySolution {
~EnumMixedStrategySolution() = default;

const Game &GetGame() const { return m_game; }
const List<MixedStrategyProfile<T>> &GetExtremeEquilibria() const { return m_extremeEquilibria; }
const std::list<MixedStrategyProfile<T>> &GetExtremeEquilibria() const
{
return m_extremeEquilibria;
}

List<List<MixedStrategyProfile<T>>> GetCliques() const;

Game m_game;
List<MixedStrategyProfile<T>> m_extremeEquilibria;
std::list<MixedStrategyProfile<T>> m_extremeEquilibria;

/// Representation of the graph connecting the extreme equilibria
///@{
Expand All @@ -64,7 +67,7 @@ EnumMixedStrategySolveDetailed(const Game &p_game,
StrategyCallbackType<T> p_onEquilibrium = NullStrategyCallback<T>);

template <class T>
List<MixedStrategyProfile<T>>
std::list<MixedStrategyProfile<T>>
EnumMixedStrategySolve(const Game &p_game,
StrategyCallbackType<T> p_onEquilibrium = NullStrategyCallback<T>)
{
Expand Down
4 changes: 2 additions & 2 deletions src/solvers/enumpoly/efgpoly.cc
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ std::list<MixedBehaviorProfile<double>> SolveSupport(const BehaviorSupportProfil

namespace Gambit::Nash {

List<MixedBehaviorProfile<double>>
std::list<MixedBehaviorProfile<double>>
EnumPolyBehaviorSolve(const Game &p_game, int p_stopAfter, double p_maxregret,
EnumPolyMixedBehaviorObserverFunctionType p_onEquilibrium,
EnumPolyBehaviorSupportObserverFunctionType p_onSupport)
Expand All @@ -204,7 +204,7 @@ EnumPolyBehaviorSolve(const Game &p_game, int p_stopAfter, double p_maxregret,
p_maxregret *= scale;
}

List<MixedBehaviorProfile<double>> ret;
std::list<MixedBehaviorProfile<double>> ret;
auto possible_supports = PossibleNashBehaviorSupports(p_game);

for (auto support : possible_supports->m_supports) {
Expand Down
4 changes: 2 additions & 2 deletions src/solvers/enumpoly/enumpoly.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ inline void EnumPolyNullStrategySupportObserver(const std::string &,
{
}

List<MixedStrategyProfile<double>> EnumPolyStrategySolve(
std::list<MixedStrategyProfile<double>> EnumPolyStrategySolve(
const Game &p_game, int p_stopAfter, double p_maxregret,
EnumPolyMixedStrategyObserverFunctionType p_onEquilibrium = EnumPolyNullMixedStrategyObserver,
EnumPolyStrategySupportObserverFunctionType p_onSupport = EnumPolyNullStrategySupportObserver);
Expand All @@ -60,7 +60,7 @@ inline void EnumPolyNullBehaviorSupportObserver(const std::string &,
{
}

List<MixedBehaviorProfile<double>> EnumPolyBehaviorSolve(
std::list<MixedBehaviorProfile<double>> EnumPolyBehaviorSolve(
const Game &, int p_stopAfter, double p_maxregret,
EnumPolyMixedBehaviorObserverFunctionType p_onEquilibrium = EnumPolyNullMixedBehaviorObserver,
EnumPolyBehaviorSupportObserverFunctionType p_onSupport = EnumPolyNullBehaviorSupportObserver);
Expand Down
4 changes: 2 additions & 2 deletions src/solvers/enumpoly/nfgpoly.cc
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ EnumPolyStrategySupportSolve(const StrategySupportProfile &support, bool &is_sin
return solutions;
}

List<MixedStrategyProfile<double>>
std::list<MixedStrategyProfile<double>>
EnumPolyStrategySolve(const Game &p_game, int p_stopAfter, double p_maxregret,
EnumPolyMixedStrategyObserverFunctionType p_onEquilibrium,
EnumPolyStrategySupportObserverFunctionType p_onSupport)
Expand All @@ -148,7 +148,7 @@ EnumPolyStrategySolve(const Game &p_game, int p_stopAfter, double p_maxregret,
p_maxregret *= scale;
}

List<MixedStrategyProfile<double>> ret;
std::list<MixedStrategyProfile<double>> ret;
auto possible_supports = PossibleNashStrategySupports(p_game);

for (auto support : possible_supports->m_supports) {
Expand Down
Loading
Loading