Skip to content

Commit e59b0b6

Browse files
StephenPasterisStephenPasteris
andauthored
Changed outputs of solvers to std::list (#558)
Closes #554 Co-authored-by: StephenPasteris <spasteris@turing.ac.uk>
1 parent 51855b0 commit e59b0b6

File tree

30 files changed

+174
-163
lines changed

30 files changed

+174
-163
lines changed

.github/ISSUE_TEMPLATE/bug_report.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,4 +47,4 @@ body:
4747
placeholder: Tell us what you see and provide a screenshot if appropriate.
4848
value: "A bug happened!"
4949
validations:
50-
required: true
50+
required: true

.github/ISSUE_TEMPLATE/documentation_improvement.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,4 @@ body:
1515
placeholder: Describe the documentation improvement in detail.
1616
value: "A documentation improvement suggestion!"
1717
validations:
18-
required: true
18+
required: true

.github/ISSUE_TEMPLATE/feature_request.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,4 +24,4 @@ body:
2424
placeholder: Describe the feature or improvement in detail.
2525
value: "A feature or improvement suggestion!"
2626
validations:
27-
required: true
27+
required: true

src/games/nash.cc

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -165,8 +165,9 @@ MixedBehaviorProfile<T> BuildProfile(const Game &p_game, const SubgameSolution<T
165165
}
166166

167167
template <class T>
168-
List<MixedBehaviorProfile<T>> SolveBySubgames(const Game &p_game, BehaviorSolverType<T> p_solver,
169-
BehaviorCallbackType<T> p_onEquilibrium)
168+
std::list<MixedBehaviorProfile<T>> SolveBySubgames(const Game &p_game,
169+
BehaviorSolverType<T> p_solver,
170+
BehaviorCallbackType<T> p_onEquilibrium)
170171
{
171172
const Game efg = p_game->CopySubgame(p_game->GetRoot());
172173

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

187188
auto results = SolveSubgames(efg->GetRoot(), infoset_map, p_solver);
188-
List<MixedBehaviorProfile<T>> solutions;
189+
std::list<MixedBehaviorProfile<T>> solutions;
189190
for (const auto &result : results) {
190191
solutions.push_back(BuildProfile(p_game, result));
191192
p_onEquilibrium(solutions.back(), "NE");
192193
}
193194
return solutions;
194195
}
195196

196-
template List<MixedBehaviorProfile<double>>
197+
template std::list<MixedBehaviorProfile<double>>
197198
SolveBySubgames(const Game &p_game, BehaviorSolverType<double> p_solver,
198199
BehaviorCallbackType<double> p_onEquilibrium);
199-
template List<MixedBehaviorProfile<Rational>>
200+
template std::list<MixedBehaviorProfile<Rational>>
200201
SolveBySubgames(const Game &p_game, BehaviorSolverType<Rational> p_solver,
201202
BehaviorCallbackType<Rational> p_onEquilibrium);
202203

src/games/nash.h

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -47,21 +47,22 @@ template <class T> void NullBehaviorCallback(const MixedBehaviorProfile<T> &, co
4747
}
4848

4949
template <class T>
50-
List<MixedBehaviorProfile<T>> ToMixedBehaviorProfile(const List<MixedStrategyProfile<T>> &p_list)
50+
std::list<MixedBehaviorProfile<T>>
51+
ToMixedBehaviorProfile(const std::list<MixedStrategyProfile<T>> &p_list)
5152
{
52-
List<MixedBehaviorProfile<T>> ret;
53+
std::list<MixedBehaviorProfile<T>> ret;
5354
for (const auto &profile : p_list) {
5455
ret.push_back(MixedBehaviorProfile<T>(profile));
5556
}
5657
return ret;
5758
}
5859

5960
template <class T>
60-
using BehaviorSolverType = std::function<List<MixedBehaviorProfile<T>>(const Game &)>;
61+
using BehaviorSolverType = std::function<std::list<MixedBehaviorProfile<T>>(const Game &)>;
6162

6263
template <class T>
63-
List<MixedBehaviorProfile<T>> SolveBySubgames(const Game &, BehaviorSolverType<T> p_solver,
64-
BehaviorCallbackType<T> p_onEquilibrium);
64+
std::list<MixedBehaviorProfile<T>> SolveBySubgames(const Game &, BehaviorSolverType<T> p_solver,
65+
BehaviorCallbackType<T> p_onEquilibrium);
6566

6667
//
6768
// Exception raised when maximum number of equilibria to compute

src/pygambit/gambit.pxd

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -470,45 +470,45 @@ cdef extern from "util.h":
470470

471471

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

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

479479
cdef extern from "solvers/lcp/lcp.h":
480-
c_List[c_MixedStrategyProfile[T]] LcpStrategySolve[T](
480+
stdlist[c_MixedStrategyProfile[T]] LcpStrategySolve[T](
481481
c_Game, int p_stopAfter, int p_maxDepth
482482
) except +RuntimeError
483-
c_List[c_MixedBehaviorProfile[T]] LcpBehaviorSolve[T](
483+
stdlist[c_MixedBehaviorProfile[T]] LcpBehaviorSolve[T](
484484
c_Game, int p_stopAfter, int p_maxDepth
485485
) except +RuntimeError
486486

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

491491
cdef extern from "solvers/liap/liap.h":
492-
c_List[c_MixedStrategyProfile[double]] LiapStrategySolve(
492+
stdlist[c_MixedStrategyProfile[double]] LiapStrategySolve(
493493
c_MixedStrategyProfile[double], double p_maxregret, int p_maxitsN
494494
) except +RuntimeError
495-
c_List[c_MixedBehaviorProfile[double]] LiapBehaviorSolve(
495+
stdlist[c_MixedBehaviorProfile[double]] LiapBehaviorSolve(
496496
c_MixedBehaviorProfile[double], double p_maxregret, int p_maxitsN
497497
) except +RuntimeError
498498

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

505505
cdef extern from "solvers/ipa/ipa.h":
506-
c_List[c_MixedStrategyProfile[double]] IPAStrategySolve(
506+
stdlist[c_MixedStrategyProfile[double]] IPAStrategySolve(
507507
c_MixedStrategyProfile[double]
508508
) except +RuntimeError
509509

510510
cdef extern from "solvers/gnm/gnm.h":
511-
c_List[c_MixedStrategyProfile[double]] GNMStrategySolve(
511+
stdlist[c_MixedStrategyProfile[double]] GNMStrategySolve(
512512
c_MixedStrategyProfile[double], double p_endLambda, int p_steps,
513513
int p_localNewtonInterval, int p_localNewtonMaxits
514514
) except +RuntimeError
@@ -521,10 +521,10 @@ cdef extern from "solvers/nashsupport/nashsupport.h":
521521
) except +RuntimeError
522522

523523
cdef extern from "solvers/enumpoly/enumpoly.h":
524-
c_List[c_MixedStrategyProfile[double]] EnumPolyStrategySolve(
524+
stdlist[c_MixedStrategyProfile[double]] EnumPolyStrategySolve(
525525
c_Game, int, float
526526
) except +RuntimeError
527-
c_List[c_MixedBehaviorProfile[double]] EnumPolyBehaviorSolve(
527+
stdlist[c_MixedBehaviorProfile[double]] EnumPolyBehaviorSolve(
528528
c_Game, int, float
529529
) except +RuntimeError
530530

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

552552

553553
cdef extern from "nash.h":
554-
c_List[c_MixedBehaviorProfile[double]] LogitBehaviorSolveWrapper(
554+
stdlist[c_MixedBehaviorProfile[double]] LogitBehaviorSolveWrapper(
555555
c_Game, double, double, double
556556
) except +
557-
c_List[c_LogitQREMixedBehaviorProfile] LogitBehaviorPrincipalBranchWrapper(
557+
stdlist[c_LogitQREMixedBehaviorProfile] LogitBehaviorPrincipalBranchWrapper(
558558
c_Game, double, double, double
559559
) except +
560560
stdlist[shared_ptr[c_LogitQREMixedBehaviorProfile]] LogitBehaviorAtLambdaWrapper(
@@ -563,10 +563,10 @@ cdef extern from "nash.h":
563563
shared_ptr[c_LogitQREMixedBehaviorProfile] LogitBehaviorEstimateWrapper(
564564
shared_ptr[c_MixedBehaviorProfile[double]], bool, double, double
565565
) except +
566-
c_List[c_MixedStrategyProfile[double]] LogitStrategySolveWrapper(
566+
stdlist[c_MixedStrategyProfile[double]] LogitStrategySolveWrapper(
567567
c_Game, double, double, double
568568
) except +
569-
c_List[c_LogitQREMixedStrategyProfile] LogitStrategyPrincipalBranchWrapper(
569+
stdlist[c_LogitQREMixedStrategyProfile] LogitStrategyPrincipalBranchWrapper(
570570
c_Game, double, double, double
571571
) except +
572572
stdlist[shared_ptr[c_LogitQREMixedStrategyProfile]] LogitStrategyAtLambdaWrapper(

src/pygambit/nash.h

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -26,21 +26,22 @@
2626
using namespace std;
2727
using namespace Gambit;
2828

29-
List<MixedBehaviorProfile<double>> LogitBehaviorSolveWrapper(const Game &p_game, double p_regret,
30-
double p_firstStep, double p_maxAccel)
29+
std::list<MixedBehaviorProfile<double>> LogitBehaviorSolveWrapper(const Game &p_game,
30+
double p_regret,
31+
double p_firstStep,
32+
double p_maxAccel)
3133
{
32-
List<MixedBehaviorProfile<double>> ret;
34+
std::list<MixedBehaviorProfile<double>> ret;
3335
ret.push_back(LogitBehaviorSolve(LogitQREMixedBehaviorProfile(p_game), p_regret, 1.0,
3436
p_firstStep, p_maxAccel)
3537
.back()
3638
.GetProfile());
3739
return ret;
3840
}
3941

40-
inline List<LogitQREMixedBehaviorProfile> LogitBehaviorPrincipalBranchWrapper(const Game &p_game,
41-
double p_regret,
42-
double p_firstStep,
43-
double p_maxAccel)
42+
inline std::list<LogitQREMixedBehaviorProfile>
43+
LogitBehaviorPrincipalBranchWrapper(const Game &p_game, double p_regret, double p_firstStep,
44+
double p_maxAccel)
4445
{
4546
return LogitBehaviorSolve(LogitQREMixedBehaviorProfile(p_game), p_regret, 1.0, p_firstStep,
4647
p_maxAccel);
@@ -66,21 +67,22 @@ LogitBehaviorAtLambdaWrapper(const Game &p_game, const std::list<double> &p_targ
6667
return ret;
6768
}
6869

69-
List<MixedStrategyProfile<double>> LogitStrategySolveWrapper(const Game &p_game, double p_regret,
70-
double p_firstStep, double p_maxAccel)
70+
std::list<MixedStrategyProfile<double>> LogitStrategySolveWrapper(const Game &p_game,
71+
double p_regret,
72+
double p_firstStep,
73+
double p_maxAccel)
7174
{
72-
List<MixedStrategyProfile<double>> ret;
75+
std::list<MixedStrategyProfile<double>> ret;
7376
ret.push_back(LogitStrategySolve(LogitQREMixedStrategyProfile(p_game), p_regret, 1.0,
7477
p_firstStep, p_maxAccel)
7578
.back()
7679
.GetProfile());
7780
return ret;
7881
}
7982

80-
inline List<LogitQREMixedStrategyProfile> LogitStrategyPrincipalBranchWrapper(const Game &p_game,
81-
double p_regret,
82-
double p_firstStep,
83-
double p_maxAccel)
83+
inline std::list<LogitQREMixedStrategyProfile>
84+
LogitStrategyPrincipalBranchWrapper(const Game &p_game, double p_regret, double p_firstStep,
85+
double p_maxAccel)
8486
{
8587
return LogitStrategySolve(LogitQREMixedStrategyProfile(p_game), p_regret, 1.0, p_firstStep,
8688
p_maxAccel);

src/pygambit/nash.pxi

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -22,41 +22,42 @@
2222
import cython
2323
from libcpp.memory cimport shared_ptr, make_shared
2424
from cython.operator cimport dereference as deref
25+
from libcpp.list cimport list as stdlist
2526

2627

2728
import typing
2829

2930

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

3738

3839
@cython.cfunc
3940
def _convert_mspr(
40-
inlist: c_List[c_MixedStrategyProfile[c_Rational]]
41+
inlist: stdlist[c_MixedStrategyProfile[c_Rational]]
4142
) -> typing.List[MixedStrategyProfile[c_Rational]]:
42-
return [MixedStrategyProfileRational.wrap(copyitem_list_mspr(inlist, i+1))
43-
for i in range(inlist.size())]
43+
return [MixedStrategyProfileRational.wrap(profile)
44+
for profile in make_list_of_pointer(inlist)]
4445

4546

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

5354

5455
@cython.cfunc
5556
def _convert_mbpr(
56-
inlist: c_List[c_MixedBehaviorProfile[c_Rational]]
57+
inlist: stdlist[c_MixedBehaviorProfile[c_Rational]]
5758
) -> typing.List[MixedBehaviorProfile[c_Rational]]:
58-
return [MixedBehaviorProfileRational.wrap(copyitem_list_mbpr(inlist, i+1))
59-
for i in range(inlist.size())]
59+
return [MixedBehaviorProfileRational.wrap(profile)
60+
for profile in make_list_of_pointer(inlist)]
6061

6162

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

285285

286286
@cython.cclass
@@ -366,8 +366,8 @@ def _logit_behavior_branch(game: Game,
366366
max_accel: float):
367367
solns = LogitBehaviorPrincipalBranchWrapper(game.game, maxregret, first_step, max_accel)
368368
ret = []
369-
for i in range(solns.size()):
369+
for profile_ptr in make_list_of_pointer(solns):
370370
p = LogitQREMixedBehaviorProfile()
371-
p.thisptr = copyitem_list_qreb(solns, i+1)
371+
p.thisptr = profile_ptr
372372
ret.append(p)
373373
return ret

src/solvers/enummixed/enummixed.h

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,12 +39,15 @@ template <class T> class EnumMixedStrategySolution {
3939
~EnumMixedStrategySolution() = default;
4040

4141
const Game &GetGame() const { return m_game; }
42-
const List<MixedStrategyProfile<T>> &GetExtremeEquilibria() const { return m_extremeEquilibria; }
42+
const std::list<MixedStrategyProfile<T>> &GetExtremeEquilibria() const
43+
{
44+
return m_extremeEquilibria;
45+
}
4346

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

4649
Game m_game;
47-
List<MixedStrategyProfile<T>> m_extremeEquilibria;
50+
std::list<MixedStrategyProfile<T>> m_extremeEquilibria;
4851

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

6669
template <class T>
67-
List<MixedStrategyProfile<T>>
70+
std::list<MixedStrategyProfile<T>>
6871
EnumMixedStrategySolve(const Game &p_game,
6972
StrategyCallbackType<T> p_onEquilibrium = NullStrategyCallback<T>)
7073
{

src/solvers/enumpoly/efgpoly.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,7 @@ std::list<MixedBehaviorProfile<double>> SolveSupport(const BehaviorSupportProfil
194194

195195
namespace Gambit::Nash {
196196

197-
List<MixedBehaviorProfile<double>>
197+
std::list<MixedBehaviorProfile<double>>
198198
EnumPolyBehaviorSolve(const Game &p_game, int p_stopAfter, double p_maxregret,
199199
EnumPolyMixedBehaviorObserverFunctionType p_onEquilibrium,
200200
EnumPolyBehaviorSupportObserverFunctionType p_onSupport)
@@ -204,7 +204,7 @@ EnumPolyBehaviorSolve(const Game &p_game, int p_stopAfter, double p_maxregret,
204204
p_maxregret *= scale;
205205
}
206206

207-
List<MixedBehaviorProfile<double>> ret;
207+
std::list<MixedBehaviorProfile<double>> ret;
208208
auto possible_supports = PossibleNashBehaviorSupports(p_game);
209209

210210
for (auto support : possible_supports->m_supports) {

0 commit comments

Comments
 (0)