Skip to content

Commit

Permalink
Implement computing principal branch of agent QRE
Browse files Browse the repository at this point in the history
  • Loading branch information
tturocy committed Jun 4, 2024
1 parent 2c844a0 commit 575835f
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 3 deletions.
3 changes: 3 additions & 0 deletions src/pygambit/gambit.pxd
Original file line number Diff line number Diff line change
Expand Up @@ -395,6 +395,9 @@ cdef extern from "util.h":
shared_ptr[c_LogitQREMixedStrategyProfile] copyitem_list_qrem "sharedcopyitem"(
c_List[c_LogitQREMixedStrategyProfile], int
) except +
shared_ptr[c_LogitQREMixedBehaviorProfile] copyitem_list_qreb "sharedcopyitem"(
c_List[c_LogitQREMixedBehaviorProfile], int
) except +


cdef extern from "solvers/enumpure/enumpure.h":
Expand Down
20 changes: 18 additions & 2 deletions src/pygambit/nash.pxi
Original file line number Diff line number Diff line change
Expand Up @@ -264,8 +264,11 @@ def logit_strategy_atlambda(game: Game,
return ret


def logit_principal_branch(game: Game, first_step: float = .03, max_accel: float = 1.1):
solns = LogitStrategyPrincipalBranchWrapper(game.game, 1.0e-8, first_step, max_accel)
def _logit_strategy_branch(game: Game,
maxregret: float,
first_step: float,
max_accel: float):
solns = LogitStrategyPrincipalBranchWrapper(game.game, maxregret, first_step, max_accel)
ret = []
for i in range(solns.Length()):
p = LogitQREMixedStrategyProfile()
Expand Down Expand Up @@ -342,3 +345,16 @@ def logit_behavior_atlambda(game: Game,
ret = LogitQREMixedBehaviorProfile()
ret.thisptr = LogitBehaviorAtLambdaWrapper(game.game, lam, first_step, max_accel)
return ret


def _logit_behavior_branch(game: Game,
maxregret: float,
first_step: float,
max_accel: float):
solns = LogitBehaviorPrincipalBranchWrapper(game.game, maxregret, first_step, max_accel)
ret = []
for i in range(solns.Length()):
p = LogitQREMixedBehaviorProfile()
p.thisptr = copyitem_list_qreb(solns, i+1)
ret.append(p)
return ret
16 changes: 15 additions & 1 deletion src/pygambit/nash.py
Original file line number Diff line number Diff line change
Expand Up @@ -587,6 +587,20 @@ def logit_solve(
)


def logit_solve_branch(
game: libgbt.Game,
use_strategic: bool = False,
maxregret: float = 1.0e-8,
first_step: float = .03,
max_accel: float = 1.1,
):
if maxregret <= 0.0:
raise ValueError("logit_solve(): maxregret argument must be positive")
if not game.is_tree or use_strategic:
return libgbt._logit_strategy_branch(game, maxregret, first_step, max_accel)
else:
return libgbt._logit_behavior_branch(game, maxregret, first_step, max_accel)


logit_behavior_atlambda = libgbt.logit_behavior_atlambda
logit_strategy_atlambda = libgbt.logit_strategy_atlambda
logit_principal_branch = libgbt.logit_principal_branch

0 comments on commit 575835f

Please sign in to comment.