Skip to content

Commit

Permalink
Merge pull request #19 from QuantEcon/repeatedgames
Browse files Browse the repository at this point in the history
Add code for solving repeated games.
  • Loading branch information
cc7768 authored Jan 17, 2017
2 parents b9f6b59 + 06f5766 commit fd1c11d
Show file tree
Hide file tree
Showing 8 changed files with 500 additions and 7 deletions.
9 changes: 7 additions & 2 deletions REQUIRE
Original file line number Diff line number Diff line change
@@ -1,2 +1,7 @@
julia 0.4
Compat 0.8.4
julia 0.5
Clp
MathProgBase
QuantEcon
Polyhedra
CDDLib

17 changes: 16 additions & 1 deletion src/Games.jl
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
module Games

# Packages
using Clp
using MathProgBase
using QuantEcon

# Geometry packages
using Polyhedra
getlibraryfor(2, AbstractFloat)

# 0.5 compatibility
import Compat.view
Expand All @@ -16,6 +23,8 @@ typealias ActionProfile Union{PureActionProfile,MixedActionProfile}
# package code goes here
include("normal_form_game.jl")
include("pure_nash.jl")
include("repeated_game_util.jl")
include("repeated_game.jl")


export Player, NormalFormGame, # Types
Expand All @@ -31,6 +40,12 @@ export Player, NormalFormGame, # Types
num_players, num_actions, num_opponents,

# Nash Equilibrium
pure_nash
pure_nash,

# Repeated Games
RepeatedGame, unpack, flow_u_1, flow_u_2, flow_u, best_dev_i,
best_dev_1, best_dev_2, best_dev_payoff_i, best_dev_payoff_1,
best_dev_payoff_2, worst_value_i, worst_value_1, worst_value_2,
worst_values, outerapproximation

end # module
17 changes: 14 additions & 3 deletions src/pure_nash.jl
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ action Nash.
Currently uses a brute force algorithm, but that hopefully
will change in the future.
"""
function pure_nash(nfg::NormalFormGame)
function pure_nash(nfg::NormalFormGame; ntofind=Inf)
# Get number of players and their actions
np = num_players(nfg)
na = nfg.nums_actions
Expand All @@ -16,9 +16,20 @@ function pure_nash(nfg::NormalFormGame)

# For each action profile check whether it is NE
as = CartesianRange(na)
for a in as

# Create counter for how many to find and iterator for actions
nfound = 0
state = start(as)

while (nfound < ntofind) & !done(as, state)
# Get next action pair
a, state = next(as, state)
_a = a.I
is_nash(nfg, _a) ? push!(ne, _a) : nothing

if is_nash(nfg, _a)
push!(ne, _a)
nfound = nfound + 1
end
end

return ne
Expand Down
Loading

0 comments on commit fd1c11d

Please sign in to comment.