Skip to content

Commit

Permalink
FIX: Resolve merge conflicts
Browse files Browse the repository at this point in the history
  • Loading branch information
QBatista committed Dec 8, 2017
2 parents 6e09b76 + 86a3b89 commit 3926a4a
Show file tree
Hide file tree
Showing 5 changed files with 84 additions and 53 deletions.
5 changes: 3 additions & 2 deletions docs/Structure
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
Order: Base Types and Methods, Computing Nash Equilibria, Repeated Games
Base Types and Methods: normal_form_game, random
Order: Base Types and Methods, Game Generators, Computing Nash Equilibria, Repeated Games
Base Types and Methods: normal_form_game
Game Generators: random
Computing Nash Equilibria: pure_nash, support_enumeration
Repeated Games: repeated_game_util, repeated_game
2 changes: 1 addition & 1 deletion docs/src/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ g = NormalFormGame((player1, player2))
or by passing a payoff matrix directly.

```@example 1
payoff_bimatrix = Array(Int, 2, 2, 2)
payoff_bimatrix = Array{Int}(2, 2, 2)
payoff_bimatrix[1, 1, :] = [3, 2]
payoff_bimatrix[1, 2, :] = [1, 1]
payoff_bimatrix[2, 1, :] = [0, 0]
Expand Down
36 changes: 36 additions & 0 deletions src/Games.jl
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,47 @@ using QuantEcon
using Polyhedra

# Type aliases #

"""
PureAction
Alias for `Integer`.
"""
const PureAction = Integer

"""
MixedAction{T}
Alias for Vector{T} where `T<:Real`.
"""
MixedAction{T<:Real} = Vector{T}

"""
Action{T}
Alias for `Union{PureAction,MixedAction{T}}` where `T<:Real`.
"""
Action{T<:Real} = Union{PureAction,MixedAction{T}}

"""
PureActionProfile{N,T}
Alias for `NTuple{N,T}` where `T<:PureAction`.
"""
PureActionProfile{N,T<:PureAction} = NTuple{N,T}

"""
MixedActionProfile{T,N}
Alias for `NTuple{N,MixedAction{T}}` where `T<:Real`.
"""
MixedActionProfile{T<:Real,N} = NTuple{N,MixedAction{T}}

"""
ActionProfile
Alias for `Union{PureActionProfile,MixedActionProfile}`.
"""
const ActionProfile = Union{PureActionProfile,MixedActionProfile}

# package code goes here
Expand Down
56 changes: 25 additions & 31 deletions src/normal_form_game.jl
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@ Authors: Daisuke Oyama

const opponents_actions_docstring = """
`opponents_actions::Union{Action,ActionProfile,Void}` : Profile of N-1
opponents' actions. If N=2, then it must be a vector of reals (in which case
it is treated as the opponent's mixed action) or a scalar of integer (in which
case it is treated as the opponent's pure action). If N>2, then it must be a
tuple of N-1 integers (pure actions) or N-1 vectors of reals (mixed actions).
(For the degenerate case N=1, it must be `nothing`.)"""
opponents' actions. If N=2, then it must be a vector of reals (in which case
it is treated as the opponent's mixed action) or a scalar of integer (in which
case it is treated as the opponent's pure action). If N>2, then it must be a
tuple of N-1 integers (pure actions) or N-1 vectors of reals (mixed actions).
(For the degenerate case N=1, it must be `nothing`.)"""


# Player #
Expand All @@ -21,15 +21,10 @@ tuple of N-1 integers (pure actions) or N-1 vectors of reals (mixed actions).
Type representing a player in an N-player normal form game.
# Arguments
- `payoff_array::Array{T<:Real}` : Array representing the player's payoff
function.
# Fields
- `payoff_array::Array{T<:Real}` : Array representing the player's payoff
function.
function.
"""
struct Player{N,T<:Real}
payoff_array::Array{T,N}
Expand Down Expand Up @@ -66,7 +61,7 @@ each own action, given a tuple of the opponents' pure actions.
- `player::Player` : Player instance.
- `opponents_actions::PureActionProfile` : Tuple of N-1 opponents' pure
actions.
actions.
# Returns
Expand Down Expand Up @@ -94,7 +89,7 @@ each own action, given a tuple of the opponents' mixed actions.
- `player::Player` : Player instance.
- `opponents_actions::MixedActionProfile` : Tuple of N-1 opponents' mixed
actions.
actions.
# Returns
Expand Down Expand Up @@ -207,7 +202,7 @@ Return True if `own_action` is a best response to `opponents_actions`.
# Returns
- `::Bool` : True if `own_action` is a best response to `opponents_actions`;
valse otherwise.
false otherwise.
"""
function is_best_response(player::Player,
own_action::PureAction,
Expand All @@ -233,7 +228,7 @@ Return true if `own_action` is a best response to `opponents_actions`.
# Returns
- `::Bool` : True if `own_action` is a best response to `opponents_actions`;
false otherwise.
false otherwise.
"""
function is_best_response(player::Player,
own_action::MixedAction,
Expand All @@ -260,7 +255,7 @@ Return all the best response actions to `opponents_actions`.
# Returns
- `best_responses::Vector{Int}` : Vector containing all the best response
actions.
actions.
"""
function best_responses(player::Player,
opponents_actions::Union{Action,ActionProfile,Void};
Expand All @@ -281,14 +276,14 @@ Return a best response action to `opponents_actions`.
- `player::Player` : Player instance.
- $(opponents_actions_docstring)
- `tie_breaking::AbstractString("smallest")` : Control how to break a tie (see
Returns for details).
Returns for details).
- `tol::Float64` : Tolerance to be used to determine best response actions.
# Returns
- `::Int` : If tie_breaking="smallest", returns the best response action with
the smallest index; if tie_breaking="random", returns an action randomly chosen
from the best response actions.
the smallest index; if tie_breaking="random", returns an action randomly
chosen from the best response actions.
"""
function best_response(player::Player,
opponents_actions::Union{Action,ActionProfile,Void};
Expand Down Expand Up @@ -318,8 +313,8 @@ Return the perturbed best response to `opponents_actions`.
- `player::Player` : Player instance.
- $(opponents_actions_docstring)
- `payoff_perturbation::Vector{Float64}` : Vector of length equal to the number
of actions of the player containing the values ("noises") to be added to the
payoffs in determining the best response.
of actions of the player containing the values ("noises") to be added to the
payoffs in determining the best response.
# Returns
Expand Down Expand Up @@ -364,7 +359,7 @@ function NormalFormGame(::Tuple{}) # To resolve definition ambiguity
end

"""
NormalFormGame{N}(T, nums_actions)
NormalFormGame(T, nums_actions)
Constructor of an N-player NormalFormGame, consisting of payoffs all 0.
Expand All @@ -386,7 +381,7 @@ NormalFormGame(nums_actions::NTuple{N,Int}) where {N} =
NormalFormGame(Float64, nums_actions)

"""
NormalFormGame{N,T}(players::NTuple{N,Player{N,T}})
NormalFormGame(players)
Constructor of an N-player NormalFormGame.
Expand All @@ -410,8 +405,7 @@ function NormalFormGame(players::NTuple{N,Player{N,T}}) where {N,T}
end

"""
NormalFormGame{N,T}(players::Vector{Player{N,T}}) =
NormalFormGame(tuple(players...)::NTuple{N,Player{N,T}})
NormalFormGame(players)
Constructor of an N-player NormalFormGame.
Expand All @@ -423,7 +417,7 @@ NormalFormGame(players::Vector{Player{N,T}}) where {N,T} =
NormalFormGame(tuple(players...)::NTuple{N,Player{N,T}})

"""
NormalFormGame{N,T}(players::Player{N,T}...)
NormalFormGame(players...)
Constructor of an N-player NormalFormGame.
Expand All @@ -444,7 +438,7 @@ function NormalFormGame(players::Player{N,T}...) where {N,T}
end

"""
NormalFormGame{T<:Real,M}(payoffs::Array{T,M})
NormalFormGame(payoffs)
Construct an N-player NormalFormGame for N>=2 with an array `payoffs` of M=N+1
dimensions, where `payoffs[a_1, a_2, ..., a_N, :]` contains a profile of N
Expand Down Expand Up @@ -474,7 +468,7 @@ function NormalFormGame(payoffs::Array{T,M}) where {T<:Real,M}
end

"""
NormalFormGame{T<:Real}(payoffs::Matrix{T})
NormalFormGame(payoffs)
Construct a symmetric 2-player NormalFormGame with a square matrix.
Expand Down Expand Up @@ -593,7 +587,7 @@ Return true if `action_profile` is a Nash equilibrium.

# Trivial game with 1 player
"""
is_nash(g, action) = is_best_response(g.players[1], action, nothing)
is_nash(g, action)
Return true if `action` is a Nash equilibrium of a trivial game with 1 player.
Expand Down Expand Up @@ -663,7 +657,7 @@ for (f, op) = ((:is_pareto_efficient, pareto_inferior_to),
end

@doc """
is_pareto_efficient(g::NormalFormGame, action_profile::PureActionProfile)
is_pareto_efficient(g, action_profile)
Return true if `action_profile` is Pareto efficient for game `g`.
Expand All @@ -678,7 +672,7 @@ Return true if `action_profile` is Pareto efficient for game `g`.
""" is_pareto_efficient

@doc """
is_pareto_dominant(g::NormalFormGame, action_profile::PureActionProfile)
is_pareto_dominant(g, action_profile)
Return true if `action_profile` is Pareto dominant for game `g`.
Expand Down
38 changes: 19 additions & 19 deletions src/repeated_game.jl
Original file line number Diff line number Diff line change
Expand Up @@ -281,28 +281,28 @@ outer hyperplane approximation described by Judd, Yeltekin, Conklin 2002.
# Arguments
- `rpd::RepGame2` : Two player repeated game.
- `nH` : Number of subgradients used for the approximation.
- `tol` : Tolerance in differences of set.
- `maxiter` : Maximum number of iterations.
- `verbose` : Whether to display updates about iterations and distance.
- `nskipprint` : Number of iterations between printing information
(assuming verbose=true).
- `check_pure_nash`: Whether to perform a check about whether a pure Nash
equilibrium exists.
- `plib`: Allows users to choose a particular package for the geometry
computations.
(See [Polyhedra.jl](https://github.com/JuliaPolyhedra/Polyhedra.jl)
docs for more info). By default, it chooses to use
[CDDLib.jl](https://github.com/JuliaPolyhedra/CDDLib.jl)
- `lp_solver` : Allows users to choose a particular solver for linear
programming problems. Options include ClpSolver(), CbcSolver(),
GLPKSolverLP() and GurobiSolver(). By default, it choooses ClpSolver().
- `rpd::RepGame2` : Two player repeated game.
- `nH` : Number of subgradients used for the approximation.
- `tol` : Tolerance in differences of set.
- `maxiter` : Maximum number of iterations.
- `verbose` : Whether to display updates about iterations and distance.
- `nskipprint` : Number of iterations between printing information
(assuming verbose=true).
- `check_pure_nash`: Whether to perform a check about whether a pure Nash
equilibrium exists.
- `plib`: Allows users to choose a particular package for the geometry
computations.
(See [Polyhedra.jl](https://github.com/JuliaPolyhedra/Polyhedra.jl)
docs for more info). By default, it chooses to use
[CDDLib.jl](https://github.com/JuliaPolyhedra/CDDLib.jl)
- `lp_solver` : Allows users to choose a particular solver for linear
programming problems. Options include ClpSolver(), CbcSolver(),
GLPKSolverLP() and GurobiSolver(). By default, it choooses ClpSolver().
# Returns
- `vertices::Array{Float64}` : Vertices of the outer approximation of the
value set.
- `vertices::Array{Float64}` : Vertices of the outer approximation of the
value set.
"""
function outerapproximation(rpd::RepGame2; nH=32, tol=1e-8, maxiter=500,
check_pure_nash=true, verbose=false, nskipprint=50,
Expand Down

0 comments on commit 3926a4a

Please sign in to comment.