From 2b59b5f486317a61408f7c093c53bcab9a41390d Mon Sep 17 00:00:00 2001 From: StephenPasteris Date: Tue, 2 Sep 2025 10:24:38 +0100 Subject: [PATCH] Changed outputs of solvers to std::list Closes #554 --- .github/ISSUE_TEMPLATE/bug_report.yml | 2 +- .../documentation_improvement.yml | 2 +- .github/ISSUE_TEMPLATE/feature_request.yml | 2 +- src/games/nash.cc | 11 +++--- src/games/nash.h | 11 +++--- src/pygambit/gambit.pxd | 36 +++++++++---------- src/pygambit/nash.h | 30 ++++++++-------- src/pygambit/nash.pxi | 32 ++++++++--------- src/solvers/enummixed/enummixed.h | 9 +++-- src/solvers/enumpoly/efgpoly.cc | 4 +-- src/solvers/enumpoly/enumpoly.h | 4 +-- src/solvers/enumpoly/nfgpoly.cc | 4 +-- src/solvers/enumpure/enumpure.h | 8 ++--- src/solvers/gnm/gnm.cc | 21 ++++++----- src/solvers/gnm/gnm.h | 4 +-- src/solvers/ipa/ipa.cc | 11 +++--- src/solvers/ipa/ipa.h | 4 +-- src/solvers/lcp/efglcp.cc | 19 +++++----- src/solvers/lcp/lcp.h | 4 +-- src/solvers/lcp/nfglcp.cc | 19 +++++----- src/solvers/liap/efgliap.cc | 8 ++--- src/solvers/liap/liap.h | 4 +-- src/solvers/liap/nfgliap.cc | 8 ++--- src/solvers/logit/efglogit.cc | 14 ++++---- src/solvers/logit/logit.h | 4 +-- src/solvers/logit/nfglogit.cc | 14 ++++---- src/solvers/lp/lp.cc | 28 +++++++-------- src/solvers/lp/lp.h | 4 +-- src/solvers/simpdiv/simpdiv.cc | 14 ++++---- src/solvers/simpdiv/simpdiv.h | 2 +- 30 files changed, 174 insertions(+), 163 deletions(-) diff --git a/.github/ISSUE_TEMPLATE/bug_report.yml b/.github/ISSUE_TEMPLATE/bug_report.yml index e83059645..9f4474bbe 100644 --- a/.github/ISSUE_TEMPLATE/bug_report.yml +++ b/.github/ISSUE_TEMPLATE/bug_report.yml @@ -47,4 +47,4 @@ body: placeholder: Tell us what you see and provide a screenshot if appropriate. value: "A bug happened!" validations: - required: true \ No newline at end of file + required: true diff --git a/.github/ISSUE_TEMPLATE/documentation_improvement.yml b/.github/ISSUE_TEMPLATE/documentation_improvement.yml index de50ae0f1..49ca95c07 100644 --- a/.github/ISSUE_TEMPLATE/documentation_improvement.yml +++ b/.github/ISSUE_TEMPLATE/documentation_improvement.yml @@ -15,4 +15,4 @@ body: placeholder: Describe the documentation improvement in detail. value: "A documentation improvement suggestion!" validations: - required: true \ No newline at end of file + required: true diff --git a/.github/ISSUE_TEMPLATE/feature_request.yml b/.github/ISSUE_TEMPLATE/feature_request.yml index fdcc7a98d..2dd8409ec 100644 --- a/.github/ISSUE_TEMPLATE/feature_request.yml +++ b/.github/ISSUE_TEMPLATE/feature_request.yml @@ -24,4 +24,4 @@ body: placeholder: Describe the feature or improvement in detail. value: "A feature or improvement suggestion!" validations: - required: true \ No newline at end of file + required: true diff --git a/src/games/nash.cc b/src/games/nash.cc index 8f61bb751..74596078a 100644 --- a/src/games/nash.cc +++ b/src/games/nash.cc @@ -165,8 +165,9 @@ MixedBehaviorProfile BuildProfile(const Game &p_game, const SubgameSolution -List> SolveBySubgames(const Game &p_game, BehaviorSolverType p_solver, - BehaviorCallbackType p_onEquilibrium) +std::list> SolveBySubgames(const Game &p_game, + BehaviorSolverType p_solver, + BehaviorCallbackType p_onEquilibrium) { const Game efg = p_game->CopySubgame(p_game->GetRoot()); @@ -185,7 +186,7 @@ List> SolveBySubgames(const Game &p_game, BehaviorSolver } auto results = SolveSubgames(efg->GetRoot(), infoset_map, p_solver); - List> solutions; + std::list> solutions; for (const auto &result : results) { solutions.push_back(BuildProfile(p_game, result)); p_onEquilibrium(solutions.back(), "NE"); @@ -193,10 +194,10 @@ List> SolveBySubgames(const Game &p_game, BehaviorSolver return solutions; } -template List> +template std::list> SolveBySubgames(const Game &p_game, BehaviorSolverType p_solver, BehaviorCallbackType p_onEquilibrium); -template List> +template std::list> SolveBySubgames(const Game &p_game, BehaviorSolverType p_solver, BehaviorCallbackType p_onEquilibrium); diff --git a/src/games/nash.h b/src/games/nash.h index 99ba4cb87..a22c3166b 100644 --- a/src/games/nash.h +++ b/src/games/nash.h @@ -47,9 +47,10 @@ template void NullBehaviorCallback(const MixedBehaviorProfile &, co } template -List> ToMixedBehaviorProfile(const List> &p_list) +std::list> +ToMixedBehaviorProfile(const std::list> &p_list) { - List> ret; + std::list> ret; for (const auto &profile : p_list) { ret.push_back(MixedBehaviorProfile(profile)); } @@ -57,11 +58,11 @@ List> ToMixedBehaviorProfile(const List -using BehaviorSolverType = std::function>(const Game &)>; +using BehaviorSolverType = std::function>(const Game &)>; template -List> SolveBySubgames(const Game &, BehaviorSolverType p_solver, - BehaviorCallbackType p_onEquilibrium); +std::list> SolveBySubgames(const Game &, BehaviorSolverType p_solver, + BehaviorCallbackType p_onEquilibrium); // // Exception raised when maximum number of equilibria to compute diff --git a/src/pygambit/gambit.pxd b/src/pygambit/gambit.pxd index 51bede716..e492d9c00 100644 --- a/src/pygambit/gambit.pxd +++ b/src/pygambit/gambit.pxd @@ -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 @@ -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 @@ -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( @@ -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( diff --git a/src/pygambit/nash.h b/src/pygambit/nash.h index a6b3755f6..92609a741 100644 --- a/src/pygambit/nash.h +++ b/src/pygambit/nash.h @@ -26,10 +26,12 @@ using namespace std; using namespace Gambit; -List> LogitBehaviorSolveWrapper(const Game &p_game, double p_regret, - double p_firstStep, double p_maxAccel) +std::list> LogitBehaviorSolveWrapper(const Game &p_game, + double p_regret, + double p_firstStep, + double p_maxAccel) { - List> ret; + std::list> ret; ret.push_back(LogitBehaviorSolve(LogitQREMixedBehaviorProfile(p_game), p_regret, 1.0, p_firstStep, p_maxAccel) .back() @@ -37,10 +39,9 @@ List> LogitBehaviorSolveWrapper(const Game &p_game, return ret; } -inline List LogitBehaviorPrincipalBranchWrapper(const Game &p_game, - double p_regret, - double p_firstStep, - double p_maxAccel) +inline std::list +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); @@ -66,10 +67,12 @@ LogitBehaviorAtLambdaWrapper(const Game &p_game, const std::list &p_targ return ret; } -List> LogitStrategySolveWrapper(const Game &p_game, double p_regret, - double p_firstStep, double p_maxAccel) +std::list> LogitStrategySolveWrapper(const Game &p_game, + double p_regret, + double p_firstStep, + double p_maxAccel) { - List> ret; + std::list> ret; ret.push_back(LogitStrategySolve(LogitQREMixedStrategyProfile(p_game), p_regret, 1.0, p_firstStep, p_maxAccel) .back() @@ -77,10 +80,9 @@ List> LogitStrategySolveWrapper(const Game &p_game, return ret; } -inline List LogitStrategyPrincipalBranchWrapper(const Game &p_game, - double p_regret, - double p_firstStep, - double p_maxAccel) +inline std::list +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); diff --git a/src/pygambit/nash.pxi b/src/pygambit/nash.pxi index 4ed8e90a2..9f8d73582 100644 --- a/src/pygambit/nash.pxi +++ b/src/pygambit/nash.pxi @@ -22,6 +22,7 @@ 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 @@ -29,34 +30,34 @@ 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]]: @@ -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 @@ -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 diff --git a/src/solvers/enummixed/enummixed.h b/src/solvers/enummixed/enummixed.h index 9ab1eaf9b..22d0fd201 100644 --- a/src/solvers/enummixed/enummixed.h +++ b/src/solvers/enummixed/enummixed.h @@ -39,12 +39,15 @@ template class EnumMixedStrategySolution { ~EnumMixedStrategySolution() = default; const Game &GetGame() const { return m_game; } - const List> &GetExtremeEquilibria() const { return m_extremeEquilibria; } + const std::list> &GetExtremeEquilibria() const + { + return m_extremeEquilibria; + } List>> GetCliques() const; Game m_game; - List> m_extremeEquilibria; + std::list> m_extremeEquilibria; /// Representation of the graph connecting the extreme equilibria ///@{ @@ -64,7 +67,7 @@ EnumMixedStrategySolveDetailed(const Game &p_game, StrategyCallbackType p_onEquilibrium = NullStrategyCallback); template -List> +std::list> EnumMixedStrategySolve(const Game &p_game, StrategyCallbackType p_onEquilibrium = NullStrategyCallback) { diff --git a/src/solvers/enumpoly/efgpoly.cc b/src/solvers/enumpoly/efgpoly.cc index 72d5a88a9..8ca2ac2fd 100644 --- a/src/solvers/enumpoly/efgpoly.cc +++ b/src/solvers/enumpoly/efgpoly.cc @@ -194,7 +194,7 @@ std::list> SolveSupport(const BehaviorSupportProfil namespace Gambit::Nash { -List> +std::list> EnumPolyBehaviorSolve(const Game &p_game, int p_stopAfter, double p_maxregret, EnumPolyMixedBehaviorObserverFunctionType p_onEquilibrium, EnumPolyBehaviorSupportObserverFunctionType p_onSupport) @@ -204,7 +204,7 @@ EnumPolyBehaviorSolve(const Game &p_game, int p_stopAfter, double p_maxregret, p_maxregret *= scale; } - List> ret; + std::list> ret; auto possible_supports = PossibleNashBehaviorSupports(p_game); for (auto support : possible_supports->m_supports) { diff --git a/src/solvers/enumpoly/enumpoly.h b/src/solvers/enumpoly/enumpoly.h index 46a3c0c1d..813573de8 100644 --- a/src/solvers/enumpoly/enumpoly.h +++ b/src/solvers/enumpoly/enumpoly.h @@ -42,7 +42,7 @@ inline void EnumPolyNullStrategySupportObserver(const std::string &, { } -List> EnumPolyStrategySolve( +std::list> EnumPolyStrategySolve( const Game &p_game, int p_stopAfter, double p_maxregret, EnumPolyMixedStrategyObserverFunctionType p_onEquilibrium = EnumPolyNullMixedStrategyObserver, EnumPolyStrategySupportObserverFunctionType p_onSupport = EnumPolyNullStrategySupportObserver); @@ -60,7 +60,7 @@ inline void EnumPolyNullBehaviorSupportObserver(const std::string &, { } -List> EnumPolyBehaviorSolve( +std::list> EnumPolyBehaviorSolve( const Game &, int p_stopAfter, double p_maxregret, EnumPolyMixedBehaviorObserverFunctionType p_onEquilibrium = EnumPolyNullMixedBehaviorObserver, EnumPolyBehaviorSupportObserverFunctionType p_onSupport = EnumPolyNullBehaviorSupportObserver); diff --git a/src/solvers/enumpoly/nfgpoly.cc b/src/solvers/enumpoly/nfgpoly.cc index a9e984525..35501eb37 100644 --- a/src/solvers/enumpoly/nfgpoly.cc +++ b/src/solvers/enumpoly/nfgpoly.cc @@ -138,7 +138,7 @@ EnumPolyStrategySupportSolve(const StrategySupportProfile &support, bool &is_sin return solutions; } -List> +std::list> EnumPolyStrategySolve(const Game &p_game, int p_stopAfter, double p_maxregret, EnumPolyMixedStrategyObserverFunctionType p_onEquilibrium, EnumPolyStrategySupportObserverFunctionType p_onSupport) @@ -148,7 +148,7 @@ EnumPolyStrategySolve(const Game &p_game, int p_stopAfter, double p_maxregret, p_maxregret *= scale; } - List> ret; + std::list> ret; auto possible_supports = PossibleNashStrategySupports(p_game); for (auto support : possible_supports->m_supports) { diff --git a/src/solvers/enumpure/enumpure.h b/src/solvers/enumpure/enumpure.h index 571651749..704933723 100644 --- a/src/solvers/enumpure/enumpure.h +++ b/src/solvers/enumpure/enumpure.h @@ -44,7 +44,7 @@ inline bool IsNash(const PureStrategyProfile &p_profile) /// Enumerate pure-strategy Nash equilibria of a game. By definition, /// pure-strategy equilibrium uses the strategic representation of a game. /// -inline List> EnumPureStrategySolve( +inline std::list> EnumPureStrategySolve( const Game &p_game, StrategyCallbackType p_onEquilibrium = NullStrategyCallback) { @@ -52,7 +52,7 @@ inline List> EnumPureStrategySolve( throw UndefinedException( "Computing equilibria of games with imperfect recall is not supported."); } - List> solutions; + std::list> solutions; for (auto citer : StrategyContingencies(p_game)) { if (IsNash(citer)) { solutions.push_back(citer->ToMixedStrategyProfile()); @@ -84,11 +84,11 @@ inline bool IsAgentNash(const PureBehaviorProfile &p_profile) /// set (rather than possible deviations by the same player at multiple /// information sets. /// -inline List> +inline std::list> EnumPureAgentSolve(const Game &p_game, BehaviorCallbackType p_onEquilibrium = NullBehaviorCallback) { - List> solutions; + std::list> solutions; const BehaviorSupportProfile support(p_game); for (auto citer : BehaviorContingencies(BehaviorSupportProfile(p_game))) { if (IsAgentNash(citer)) { diff --git a/src/solvers/gnm/gnm.cc b/src/solvers/gnm/gnm.cc index d463acdb9..c1737453a 100644 --- a/src/solvers/gnm/gnm.cc +++ b/src/solvers/gnm/gnm.cc @@ -30,7 +30,7 @@ using namespace Gambit::gametracer; namespace { -List> +std::list> Solve(const Game &p_game, const std::shared_ptr &p_rep, const cvector &p_pert, double p_lambdaEnd, int p_steps, int p_localNewtonInterval, int p_localNewtonMaxits, std::function &, const std::string &)> &p_callback) @@ -48,7 +48,7 @@ Solve(const Game &p_game, const std::shared_ptr &p_rep, const cvector & if (!nonzero) { throw UndefinedException("Perturbation vector must have at least one nonzero component."); } - List> eqa; + std::list> eqa; p_callback(ToProfile(p_game, p_pert), "pert"); cvector norm_pert = p_pert / p_pert.norm(); std::list answers; @@ -69,10 +69,10 @@ Solve(const Game &p_game, const std::shared_ptr &p_rep, const cvector & namespace Gambit::Nash { -List> GNMStrategySolve(const Game &p_game, double p_lambdaEnd, - int p_steps, int p_localNewtonInterval, - int p_localNewtonMaxits, - StrategyCallbackType p_callback) +std::list> GNMStrategySolve(const Game &p_game, double p_lambdaEnd, + int p_steps, int p_localNewtonInterval, + int p_localNewtonMaxits, + StrategyCallbackType p_callback) { if (!p_game->IsPerfectRecall()) { throw UndefinedException( @@ -92,11 +92,10 @@ List> GNMStrategySolve(const Game &p_game, double p p_localNewtonMaxits, p_callback); } -List> GNMStrategySolve(const MixedStrategyProfile &p_pert, - double p_lambdaEnd, int p_steps, - int p_localNewtonInterval, - int p_localNewtonMaxits, - StrategyCallbackType p_callback) +std::list> +GNMStrategySolve(const MixedStrategyProfile &p_pert, double p_lambdaEnd, int p_steps, + int p_localNewtonInterval, int p_localNewtonMaxits, + StrategyCallbackType p_callback) { if (!p_pert.GetGame()->IsPerfectRecall()) { throw UndefinedException( diff --git a/src/solvers/gnm/gnm.h b/src/solvers/gnm/gnm.h index 47ce0ff99..dbcb50d7e 100644 --- a/src/solvers/gnm/gnm.h +++ b/src/solvers/gnm/gnm.h @@ -33,14 +33,14 @@ const int GNM_LOCAL_NEWTON_INTERVAL_DEFAULT = 3; const int GNM_LOCAL_NEWTON_MAXITS_DEFAULT = 10; const int GNM_STEPS_DEFAULT = 100; -List> +std::list> GNMStrategySolve(const Game &p_game, double p_lambdaEnd, int p_steps, int p_localNewtonInterval, int p_localNewtonMaxits, StrategyCallbackType p_callback = NullStrategyCallback); /// @brief Compute the mixed strategy equilibria accessible via the initial ray determined /// by \p p_profile using the Global Newton method -List> +std::list> GNMStrategySolve(const MixedStrategyProfile &p_profile, double p_lambdaEnd, int p_steps, int p_localNewtonInterval, int p_localNewtonMaxits, StrategyCallbackType p_callback = NullStrategyCallback); diff --git a/src/solvers/ipa/ipa.cc b/src/solvers/ipa/ipa.cc index 227ea8afe..ead9a8ddd 100644 --- a/src/solvers/ipa/ipa.cc +++ b/src/solvers/ipa/ipa.cc @@ -29,8 +29,8 @@ using namespace Gambit::gametracer; namespace Gambit::Nash { -List> IPAStrategySolve(const Game &p_game, - StrategyCallbackType p_callback) +std::list> IPAStrategySolve(const Game &p_game, + StrategyCallbackType p_callback) { MixedStrategyProfile pert = p_game->NewMixedStrategyProfile(0.0); for (const auto &player : p_game->GetPlayers()) { @@ -44,8 +44,9 @@ List> IPAStrategySolve(const Game &p_game, return IPAStrategySolve(pert, p_callback); } -List> IPAStrategySolve(const MixedStrategyProfile &p_pert, - StrategyCallbackType p_callback) +std::list> +IPAStrategySolve(const MixedStrategyProfile &p_pert, + StrategyCallbackType p_callback) { if (!p_pert.GetGame()->IsPerfectRecall()) { throw UndefinedException( @@ -64,7 +65,7 @@ List> IPAStrategySolve(const MixedStrategyProfile> solutions; + std::list> solutions; solutions.push_back(ToProfile(p_pert.GetGame(), ans)); p_callback(solutions.back(), "NE"); return solutions; diff --git a/src/solvers/ipa/ipa.h b/src/solvers/ipa/ipa.h index c31183724..454fa13c8 100644 --- a/src/solvers/ipa/ipa.h +++ b/src/solvers/ipa/ipa.h @@ -27,11 +27,11 @@ namespace Gambit::Nash { -List> +std::list> IPAStrategySolve(const Game &p_game, StrategyCallbackType p_callback = NullStrategyCallback); -List> +std::list> IPAStrategySolve(const MixedStrategyProfile &p_pert, StrategyCallbackType p_callback = NullStrategyCallback); diff --git a/src/solvers/lcp/efglcp.cc b/src/solvers/lcp/efglcp.cc index 6c396cbd6..9b44b08e9 100644 --- a/src/solvers/lcp/efglcp.cc +++ b/src/solvers/lcp/efglcp.cc @@ -36,7 +36,7 @@ template class NashLcpBehaviorSolver { } ~NashLcpBehaviorSolver() = default; - List> Solve(const Game &) const; + std::list> Solve(const Game &) const; private: BehaviorCallbackType m_onEquilibrium; @@ -58,7 +58,7 @@ template class NashLcpBehaviorSolver::Solution { std::map infosetOffset; T eps; List> m_list; - List> m_equilibria; + std::list> m_equilibria; explicit Solution(const Game &); @@ -110,7 +110,7 @@ bool NashLcpBehaviorSolver::Solution::AddBFS(const linalg::LemkeTableau &t // as refined by Eaves for degenerate problems, starting from the primary ray. // template -List> NashLcpBehaviorSolver::Solve(const Game &p_game) const +std::list> NashLcpBehaviorSolver::Solve(const Game &p_game) const { if (p_game->NumPlayers() != 2) { throw UndefinedException("Method only valid for two-player games."); @@ -341,15 +341,16 @@ void NashLcpBehaviorSolver::GetProfile(const linalg::LemkeTableau &tab, } template -List> LcpBehaviorSolve(const Game &p_game, int p_stopAfter, int p_maxDepth, - BehaviorCallbackType p_onEquilibrium) +std::list> LcpBehaviorSolve(const Game &p_game, int p_stopAfter, + int p_maxDepth, + BehaviorCallbackType p_onEquilibrium) { return NashLcpBehaviorSolver(p_stopAfter, p_maxDepth, p_onEquilibrium).Solve(p_game); } -template List> LcpBehaviorSolve(const Game &, int, int, - BehaviorCallbackType); -template List> LcpBehaviorSolve(const Game &, int, int, - BehaviorCallbackType); +template std::list> LcpBehaviorSolve(const Game &, int, int, + BehaviorCallbackType); +template std::list> +LcpBehaviorSolve(const Game &, int, int, BehaviorCallbackType); } // end namespace Gambit::Nash diff --git a/src/solvers/lcp/lcp.h b/src/solvers/lcp/lcp.h index c84352cd2..302092d96 100644 --- a/src/solvers/lcp/lcp.h +++ b/src/solvers/lcp/lcp.h @@ -28,12 +28,12 @@ namespace Gambit::Nash { template -List> +std::list> LcpStrategySolve(const Game &p_game, int p_stopAfter, int p_maxDepth, StrategyCallbackType p_onEquilibrium = NullStrategyCallback); template -List> +std::list> LcpBehaviorSolve(const Game &p_game, int p_stopAfter, int p_maxDepth, BehaviorCallbackType p_onEquilibrium = NullBehaviorCallback); diff --git a/src/solvers/lcp/nfglcp.cc b/src/solvers/lcp/nfglcp.cc index 6271942c9..37956e3c0 100644 --- a/src/solvers/lcp/nfglcp.cc +++ b/src/solvers/lcp/nfglcp.cc @@ -118,7 +118,7 @@ template class NashLcpStrategySolver { } ~NashLcpStrategySolver() = default; - List> Solve(const Game &) const; + std::list> Solve(const Game &) const; private: StrategyCallbackType m_onEquilibrium; @@ -133,7 +133,7 @@ template class NashLcpStrategySolver { template class NashLcpStrategySolver::Solution { public: List> m_bfsList; - List> m_equilibria; + std::list> m_equilibria; bool Contains(const Gambit::linalg::BFS &p_bfs) const { return contains(m_bfsList, p_bfs); } void push_back(const Gambit::linalg::BFS &p_bfs) { m_bfsList.push_back(p_bfs); } @@ -241,7 +241,7 @@ void NashLcpStrategySolver::AllLemke(const Game &p_game, int j, linalg::LHTab } template -List> NashLcpStrategySolver::Solve(const Game &p_game) const +std::list> NashLcpStrategySolver::Solve(const Game &p_game) const { if (p_game->NumPlayers() != 2) { throw UndefinedException("Method only valid for two-player games."); @@ -278,15 +278,16 @@ List> NashLcpStrategySolver::Solve(const Game &p_game } template -List> LcpStrategySolve(const Game &p_game, int p_stopAfter, int p_maxDepth, - StrategyCallbackType p_onEquilibrium) +std::list> LcpStrategySolve(const Game &p_game, int p_stopAfter, + int p_maxDepth, + StrategyCallbackType p_onEquilibrium) { return NashLcpStrategySolver(p_stopAfter, p_maxDepth, p_onEquilibrium).Solve(p_game); } -template List> LcpStrategySolve(const Game &, int, int, - StrategyCallbackType); -template List> LcpStrategySolve(const Game &, int, int, - StrategyCallbackType); +template std::list> LcpStrategySolve(const Game &, int, int, + StrategyCallbackType); +template std::list> +LcpStrategySolve(const Game &, int, int, StrategyCallbackType); } // end namespace Gambit::Nash diff --git a/src/solvers/liap/efgliap.cc b/src/solvers/liap/efgliap.cc index ac048ebcd..2add29501 100644 --- a/src/solvers/liap/efgliap.cc +++ b/src/solvers/liap/efgliap.cc @@ -143,16 +143,16 @@ MixedBehaviorProfile EnforceNonnegativity(const MixedBehaviorProfile> LiapBehaviorSolve(const MixedBehaviorProfile &p_start, - double p_maxregret, int p_maxitsN, - BehaviorCallbackType p_callback) +std::list> +LiapBehaviorSolve(const MixedBehaviorProfile &p_start, double p_maxregret, int p_maxitsN, + BehaviorCallbackType p_callback) { if (!p_start.GetGame()->IsPerfectRecall()) { throw UndefinedException( "Computing equilibria of games with imperfect recall is not supported."); } - List> solutions; + std::list> solutions; MixedBehaviorProfile p(p_start); p_callback(p, "start"); diff --git a/src/solvers/liap/liap.h b/src/solvers/liap/liap.h index 2deb802c4..7760a89ed 100644 --- a/src/solvers/liap/liap.h +++ b/src/solvers/liap/liap.h @@ -27,11 +27,11 @@ namespace Gambit::Nash { -List> +std::list> LiapBehaviorSolve(const MixedBehaviorProfile &p_start, double p_maxregret, int p_maxitsN, BehaviorCallbackType p_callback = NullBehaviorCallback); -List> +std::list> LiapStrategySolve(const MixedStrategyProfile &p_start, double p_maxregret, int p_maxitsN, StrategyCallbackType p_callback = NullStrategyCallback); diff --git a/src/solvers/liap/nfgliap.cc b/src/solvers/liap/nfgliap.cc index 14bcb625e..f1fe4a11a 100644 --- a/src/solvers/liap/nfgliap.cc +++ b/src/solvers/liap/nfgliap.cc @@ -147,16 +147,16 @@ MixedStrategyProfile EnforceNonnegativity(const MixedStrategyProfile> LiapStrategySolve(const MixedStrategyProfile &p_start, - double p_maxregret, int p_maxitsN, - StrategyCallbackType p_callback) +std::list> +LiapStrategySolve(const MixedStrategyProfile &p_start, double p_maxregret, int p_maxitsN, + StrategyCallbackType p_callback) { if (!p_start.GetGame()->IsPerfectRecall()) { throw UndefinedException( "Computing equilibria of games with imperfect recall is not supported."); } - List> solutions; + std::list> solutions; MixedStrategyProfile p(p_start); p_callback(p, "start"); diff --git a/src/solvers/logit/efglogit.cc b/src/solvers/logit/efglogit.cc index dad6d5697..4b6c0d715 100644 --- a/src/solvers/logit/efglogit.cc +++ b/src/solvers/logit/efglogit.cc @@ -251,18 +251,18 @@ class TracingCallbackFunction { ~TracingCallbackFunction() = default; void AppendPoint(const Vector &p_point); - const List &GetProfiles() const { return m_profiles; } + const std::list &GetProfiles() const { return m_profiles; } private: Game m_game; MixedBehaviorObserverFunctionType m_observer; - List m_profiles; + std::list m_profiles; }; void TracingCallbackFunction::AppendPoint(const Vector &p_point) { const MixedBehaviorProfile profile(PointToProfile(m_game, p_point)); - m_profiles.push_back(LogitQREMixedBehaviorProfile(profile, p_point.back(), 1.0)); + m_profiles.emplace_back(profile, p_point.back(), 1.0); m_observer(m_profiles.back()); } @@ -308,10 +308,10 @@ void EstimatorCallbackFunction::EvaluatePoint(const Vector &p_point) namespace Gambit { -List LogitBehaviorSolve(const LogitQREMixedBehaviorProfile &p_start, - double p_regret, double p_omega, - double p_firstStep, double p_maxAccel, - MixedBehaviorObserverFunctionType p_observer) +std::list +LogitBehaviorSolve(const LogitQREMixedBehaviorProfile &p_start, double p_regret, double p_omega, + double p_firstStep, double p_maxAccel, + MixedBehaviorObserverFunctionType p_observer) { PathTracer tracer; tracer.SetMaxDecel(p_maxAccel); diff --git a/src/solvers/logit/logit.h b/src/solvers/logit/logit.h index 4d3c00951..8b940ec6d 100644 --- a/src/solvers/logit/logit.h +++ b/src/solvers/logit/logit.h @@ -84,7 +84,7 @@ using MixedStrategyObserverFunctionType = inline void NullMixedStrategyObserver(const LogitQREMixedStrategyProfile &) {} -List +std::list LogitStrategySolve(const LogitQREMixedStrategyProfile &p_start, double p_regret, double p_omega, double p_firstStep, double p_maxAccel, MixedStrategyObserverFunctionType p_observer = NullMixedStrategyObserver); @@ -107,7 +107,7 @@ using MixedBehaviorObserverFunctionType = inline void NullMixedBehaviorObserver(const LogitQREMixedBehaviorProfile &) {} -List +std::list LogitBehaviorSolve(const LogitQREMixedBehaviorProfile &p_start, double p_regret, double p_omega, double p_firstStep, double p_maxAccel, MixedBehaviorObserverFunctionType p_observer = NullMixedBehaviorObserver); diff --git a/src/solvers/logit/nfglogit.cc b/src/solvers/logit/nfglogit.cc index 9111c12bf..154673f37 100644 --- a/src/solvers/logit/nfglogit.cc +++ b/src/solvers/logit/nfglogit.cc @@ -169,18 +169,18 @@ class TracingCallbackFunction { ~TracingCallbackFunction() = default; void AppendPoint(const Vector &p_point); - const List &GetProfiles() const { return m_profiles; } + const std::list &GetProfiles() const { return m_profiles; } private: Game m_game; MixedStrategyObserverFunctionType m_observer; - List m_profiles; + std::list m_profiles; }; void TracingCallbackFunction::AppendPoint(const Vector &p_point) { const MixedStrategyProfile profile(PointToProfile(m_game, p_point)); - m_profiles.push_back(LogitQREMixedStrategyProfile(profile, p_point.back(), 1.0)); + m_profiles.emplace_back(profile, p_point.back(), 1.0); m_observer(m_profiles.back()); } @@ -225,10 +225,10 @@ void EstimatorCallbackFunction::EvaluatePoint(const Vector &p_point) } // namespace -List LogitStrategySolve(const LogitQREMixedStrategyProfile &p_start, - double p_regret, double p_omega, - double p_firstStep, double p_maxAccel, - MixedStrategyObserverFunctionType p_observer) +std::list +LogitStrategySolve(const LogitQREMixedStrategyProfile &p_start, double p_regret, double p_omega, + double p_firstStep, double p_maxAccel, + MixedStrategyObserverFunctionType p_observer) { PathTracer tracer; tracer.SetMaxDecel(p_maxAccel); diff --git a/src/solvers/lp/lp.cc b/src/solvers/lp/lp.cc index 5587b01aa..9e0a5e467 100644 --- a/src/solvers/lp/lp.cc +++ b/src/solvers/lp/lp.cc @@ -162,8 +162,8 @@ void SolveLP(const Matrix &A, const Vector &b, const Vector &c, int neq } template -List> LpBehaviorSolve(const Game &p_game, - BehaviorCallbackType p_onEquilibrium) +std::list> LpBehaviorSolve(const Game &p_game, + BehaviorCallbackType p_onEquilibrium) { if (p_game->NumPlayers() != 2) { throw UndefinedException("Method only valid for two-player games."); @@ -195,7 +195,7 @@ List> LpBehaviorSolve(const Game &p_game, c[data.ns2 + 1] = static_cast(-1); Array primal(A.NumColumns()), dual(A.NumRows()); - List> solution; + std::list> solution; SolveLP(A, b, c, p_game->GetPlayer(2)->GetInfosets().size() + 1, primal, dual); MixedBehaviorProfile profile(p_game); data.GetBehavior(profile, primal, dual, p_game->GetRoot(), 1, 1); @@ -205,14 +205,14 @@ List> LpBehaviorSolve(const Game &p_game, return solution; } -template List> LpBehaviorSolve(const Game &, - BehaviorCallbackType); -template List> LpBehaviorSolve(const Game &, - BehaviorCallbackType); +template std::list> LpBehaviorSolve(const Game &, + BehaviorCallbackType); +template std::list> LpBehaviorSolve(const Game &, + BehaviorCallbackType); template -List> LpStrategySolve(const Game &p_game, - StrategyCallbackType p_onEquilibrium) +std::list> LpStrategySolve(const Game &p_game, + StrategyCallbackType p_onEquilibrium) { if (p_game->NumPlayers() != 2) { throw UndefinedException("Method only valid for two-player games."); @@ -264,14 +264,14 @@ List> LpStrategySolve(const Game &p_game, eqm[p_game->GetPlayer(2)->GetStrategy(j)] = dual[j]; } p_onEquilibrium(eqm, "NE"); - List> solution; + std::list> solution; solution.push_back(eqm); return solution; } -template List> LpStrategySolve(const Game &, - StrategyCallbackType); -template List> LpStrategySolve(const Game &, - StrategyCallbackType); +template std::list> LpStrategySolve(const Game &, + StrategyCallbackType); +template std::list> LpStrategySolve(const Game &, + StrategyCallbackType); } // end namespace Gambit::Nash diff --git a/src/solvers/lp/lp.h b/src/solvers/lp/lp.h index 5fdc693d9..48581ed2c 100644 --- a/src/solvers/lp/lp.h +++ b/src/solvers/lp/lp.h @@ -28,12 +28,12 @@ namespace Gambit::Nash { template -List> +std::list> LpStrategySolve(const Game &p_game, StrategyCallbackType p_onEquilibrium = NullStrategyCallback); template -List> +std::list> LpBehaviorSolve(const Game &p_game, BehaviorCallbackType p_onEquilibrium = NullBehaviorCallback); diff --git a/src/solvers/simpdiv/simpdiv.cc b/src/solvers/simpdiv/simpdiv.cc index edff882f4..6049924b9 100644 --- a/src/solvers/simpdiv/simpdiv.cc +++ b/src/solvers/simpdiv/simpdiv.cc @@ -78,8 +78,9 @@ class NashSimpdivStrategySolver { } ~NashSimpdivStrategySolver() = default; - List> Solve(const MixedStrategyProfile &p_start) const; - List> Solve(const Game &p_game) const; + std::list> + Solve(const MixedStrategyProfile &p_start) const; + std::list> Solve(const Game &p_game) const; private: int m_gridResize, m_leashLength; @@ -528,7 +529,7 @@ inline Integer find_lcd(const Vector &vec) return lcd; } -List> +std::list> NashSimpdivStrategySolver::Solve(const MixedStrategyProfile &p_start) const { if (!p_start.GetGame()->IsPerfectRecall()) { @@ -551,7 +552,7 @@ NashSimpdivStrategySolver::Solve(const MixedStrategyProfile &p_start) } m_onEquilibrium(y, "NE"); - List> sol; + std::list> sol; sol.push_back(y); return sol; } @@ -568,7 +569,8 @@ NashSimpdivStrategySolver::Solve(const MixedStrategyProfile &p_start) /// to a long initial search before reaching a candidate neighborhood /// for an equilibrium. /// -List> NashSimpdivStrategySolver::Solve(const Game &p_game) const +std::list> +NashSimpdivStrategySolver::Solve(const Game &p_game) const { MixedStrategyProfile start = p_game->NewMixedStrategyProfile(Rational(0)); start = Rational(0); @@ -578,7 +580,7 @@ List> NashSimpdivStrategySolver::Solve(const Game return Solve(start); } -List> +std::list> SimpdivStrategySolve(const MixedStrategyProfile &p_start, const Rational &p_maxregret, int p_gridResize, int p_leashLength, StrategyCallbackType p_onEquilibrium) diff --git a/src/solvers/simpdiv/simpdiv.h b/src/solvers/simpdiv/simpdiv.h index 8745354de..954a5bf1a 100644 --- a/src/solvers/simpdiv/simpdiv.h +++ b/src/solvers/simpdiv/simpdiv.h @@ -32,7 +32,7 @@ namespace Gambit::Nash { /// mixed strategy solutions to general finite n-person games. It is based on /// van Der Laan, Talman and van Der Heyden, Math of Oper Res, 1987. /// -List> SimpdivStrategySolve( +std::list> SimpdivStrategySolve( const MixedStrategyProfile &p_start, const Rational &p_maxregret = Rational(1, 1000000), int p_gridResize = 2, int p_leashLength = 0,