From 298de066dfb0ea8e2e3e565f7f33728f04645fa7 Mon Sep 17 00:00:00 2001 From: QBatista Date: Sat, 25 Nov 2017 14:59:55 +0900 Subject: [PATCH 1/5] FEAT: Add option to choose LP solver to repeated_game.jl --- src/repeated_game.jl | 43 +++++++++++++++++++++++++++---------------- 1 file changed, 27 insertions(+), 16 deletions(-) diff --git a/src/repeated_game.jl b/src/repeated_game.jl index 9e21af48..11516537 100644 --- a/src/repeated_game.jl +++ b/src/repeated_game.jl @@ -227,13 +227,17 @@ Given a constraint w ∈ W, this finds the worst possible payoff for agent i. - `H::Array{Float64, 2}` : The subgradients used to approximate the value set. - `C::Array{Float64, 1}` : The array containing the hyperplane levels. - `i::Int` : The player of interest. +- `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 - `out::Float64` : Worst possible payoff for player i. """ function worst_value_i(rpd::RepGame2, H::Array{Float64, 2}, - C::Array{Float64, 1}, i::Int) + C::Array{Float64, 1}, i::Int, lp_solver=ClpSolver()) # Objective depends on which player we are minimizing c = zeros(2) c[i] = 1.0 @@ -242,7 +246,7 @@ function worst_value_i(rpd::RepGame2, H::Array{Float64, 2}, lb = [-Inf, -Inf] ub = [Inf, Inf] - lpout = linprog(c, H, '<', C, lb, ub, ClpSolver()) + lpout = linprog(c, H, '<', C, lb, ub, lp_solver) if lpout.status == :Optimal out = lpout.sol[i] else @@ -253,14 +257,15 @@ function worst_value_i(rpd::RepGame2, H::Array{Float64, 2}, end "See worst_value_i for documentation" -worst_value_1(rpd::RepGame2, H::Array{Float64, 2}, C::Array{Float64, 1}) = - worst_value_i(rpd, H, C, 1) +worst_value_1(rpd::RepGame2, H::Array{Float64, 2}, C::Array{Float64, 1}, + lp_solver=ClpSolver()) = worst_value_i(rpd, H, C, 1) "See worst_value_i for documentation" -worst_value_2(rpd::RepGame2, H::Array{Float64, 2}, C::Array{Float64, 1}) = - worst_value_i(rpd, H, C, 2) +worst_value_2(rpd::RepGame2, H::Array{Float64, 2}, C::Array{Float64, 1}, + lp_solver=ClpSolver()) = worst_value_i(rpd, H, C, 2) "See worst_value_i for documentation" -worst_values(rpd::RepGame2, H::Array{Float64, 2}, C::Array{Float64, 1}) = - (worst_value_1(rpd, H, C), worst_value_2(rpd, H, C)) +worst_values(rpd::RepGame2, H::Array{Float64, 2}, C::Array{Float64, 1}, + lp_solver=ClpSolver()) = (worst_value_1(rpd, H, C), + worst_value_2(rpd, H, C)) # # Outer Hyper Plane Approximation @@ -268,7 +273,8 @@ worst_values(rpd::RepGame2, H::Array{Float64, 2}, C::Array{Float64, 1}) = """ outerapproximation(rpd; nH=32, tol=1e-8, maxiter=500, check_pure_nash=true, verbose=false, nskipprint=50, - plib=getlibraryfor(2, Float64)) + plib=getlibraryfor(2, Float64), + lp_solver=ClpSolver()) Approximates the set of equilibrium value set for a repeated game with the outer hyperplane approximation described by Judd, Yeltekin, Conklin 2002. @@ -287,16 +293,21 @@ outer hyperplane approximation described by Judd, Yeltekin, Conklin 2002. - `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 SimplePolyhedraLibrary. + 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, - plib=getlibraryfor(2, Float64)) + plib=getlibraryfor(2, Float64), + lp_solver=ClpSolver()) # Long unpacking of stuff sg, delta = unpack(rpd) p1, p2 = sg.players @@ -331,8 +342,8 @@ function outerapproximation(rpd::RepGame2; nH=32, tol=1e-8, maxiter=500, iter, dist = 0, 10.0 while (iter < maxiter) & (dist > tol) # Compute the current worst values for each agent - _w1 = worst_value_1(rpd, H, C) - _w2 = worst_value_2(rpd, H, C) + _w1 = worst_value_1(rpd, H, C, lp_solver) + _w2 = worst_value_2(rpd, H, C, lp_solver) # Update all set constraints -- Copies elements 1:nH of C into b copy!(b, 1, C, 1, nH) @@ -364,7 +375,7 @@ function outerapproximation(rpd::RepGame2; nH=32, tol=1e-8, maxiter=500, (1-delta)*best_dev_payoff_2(rpd, a1) - delta*_w2 # Solve corresponding linear program - lpout = linprog(c, A, '<', b, lb, ub, ClpSolver()) + lpout = linprog(c, A, '<', b, lb, ub, lp_solver) if lpout.status == :Optimal # Pull out optimal value and compute w_sol = lpout.sol From f69bbe75e87b5e47a14b2d619be13103a354714a Mon Sep 17 00:00:00 2001 From: QBatista Date: Thu, 30 Nov 2017 17:22:43 +0900 Subject: [PATCH 2/5] FIX: Add type declaration for lp_solver --- src/repeated_game.jl | 26 +++++++++++++++++++------- 1 file changed, 19 insertions(+), 7 deletions(-) diff --git a/src/repeated_game.jl b/src/repeated_game.jl index 11516537..a906c26c 100644 --- a/src/repeated_game.jl +++ b/src/repeated_game.jl @@ -237,7 +237,8 @@ Given a constraint w ∈ W, this finds the worst possible payoff for agent i. - `out::Float64` : Worst possible payoff for player i. """ function worst_value_i(rpd::RepGame2, H::Array{Float64, 2}, - C::Array{Float64, 1}, i::Int, lp_solver=ClpSolver()) + C::Array{Float64, 1}, i::Int, + lp_solver::MathProgBase.AbstractMathProgSolver) # Objective depends on which player we are minimizing c = zeros(2) c[i] = 1.0 @@ -256,16 +257,27 @@ function worst_value_i(rpd::RepGame2, H::Array{Float64, 2}, return out end +worst_value_i(rpd::RepGame2, H::Array{Float64, 2}, C::Array{Float64, 1}, + i::Int) = worst_value_i(rpd, H, C, i, ClpSolver()) + "See worst_value_i for documentation" worst_value_1(rpd::RepGame2, H::Array{Float64, 2}, C::Array{Float64, 1}, - lp_solver=ClpSolver()) = worst_value_i(rpd, H, C, 1) + lp_solver::MathProgBase.AbstractMathProgSolver) = + worst_value_i(rpd, H, C, 1, lp_solver) +worst_value_1(rpd::RepGame2, H::Array{Float64, 2}, C::Array{Float64, 1}) = + worst_value_1(rpd, H, C, ClpSolver()) "See worst_value_i for documentation" worst_value_2(rpd::RepGame2, H::Array{Float64, 2}, C::Array{Float64, 1}, - lp_solver=ClpSolver()) = worst_value_i(rpd, H, C, 2) + lp_solver::MathProgBase.AbstractMathProgSolver) = + worst_value_i(rpd, H, C, 2, lp_solver) +worst_value_2(rpd::RepGame2, H::Array{Float64, 2}, C::Array{Float64, 1}) = + worst_value_2(rpd, H, C, 2, ClpSolver()) "See worst_value_i for documentation" worst_values(rpd::RepGame2, H::Array{Float64, 2}, C::Array{Float64, 1}, - lp_solver=ClpSolver()) = (worst_value_1(rpd, H, C), - worst_value_2(rpd, H, C)) + lp_solver::MathProgBase.AbstractMathProgSolver) = + (worst_value_1(rpd, H, C, lp_solver), worst_value_2(rpd, H, C, lp_solver)) +worst_values(rpd::RepGame2, H::Array{Float64, 2}, C::Array{Float64, 1}) = + (worst_value_1(rpd, H, C), worst_value_2(rpd, H, C)) # # Outer Hyper Plane Approximation @@ -307,7 +319,8 @@ outer hyperplane approximation described by Judd, Yeltekin, Conklin 2002. function outerapproximation(rpd::RepGame2; nH=32, tol=1e-8, maxiter=500, check_pure_nash=true, verbose=false, nskipprint=50, plib=getlibraryfor(2, Float64), - lp_solver=ClpSolver()) + lp_solver::MathProgBase.AbstractMathProgSolver= + ClpSolver()) # Long unpacking of stuff sg, delta = unpack(rpd) p1, p2 = sg.players @@ -438,4 +451,3 @@ function outerapproximation(rpd::RepGame2; nH=32, tol=1e-8, maxiter=500, return vertices end - From 3f898f72aba172d853686c39ec98c280ea85bac8 Mon Sep 17 00:00:00 2001 From: QBatista Date: Thu, 7 Dec 2017 21:49:15 +0900 Subject: [PATCH 3/5] RFC: Remove some unused functions --- src/repeated_game.jl | 13 ------------- 1 file changed, 13 deletions(-) diff --git a/src/repeated_game.jl b/src/repeated_game.jl index a906c26c..d1fc55e6 100644 --- a/src/repeated_game.jl +++ b/src/repeated_game.jl @@ -257,27 +257,14 @@ function worst_value_i(rpd::RepGame2, H::Array{Float64, 2}, return out end -worst_value_i(rpd::RepGame2, H::Array{Float64, 2}, C::Array{Float64, 1}, - i::Int) = worst_value_i(rpd, H, C, i, ClpSolver()) - "See worst_value_i for documentation" worst_value_1(rpd::RepGame2, H::Array{Float64, 2}, C::Array{Float64, 1}, lp_solver::MathProgBase.AbstractMathProgSolver) = worst_value_i(rpd, H, C, 1, lp_solver) -worst_value_1(rpd::RepGame2, H::Array{Float64, 2}, C::Array{Float64, 1}) = - worst_value_1(rpd, H, C, ClpSolver()) "See worst_value_i for documentation" worst_value_2(rpd::RepGame2, H::Array{Float64, 2}, C::Array{Float64, 1}, lp_solver::MathProgBase.AbstractMathProgSolver) = worst_value_i(rpd, H, C, 2, lp_solver) -worst_value_2(rpd::RepGame2, H::Array{Float64, 2}, C::Array{Float64, 1}) = - worst_value_2(rpd, H, C, 2, ClpSolver()) -"See worst_value_i for documentation" -worst_values(rpd::RepGame2, H::Array{Float64, 2}, C::Array{Float64, 1}, - lp_solver::MathProgBase.AbstractMathProgSolver) = - (worst_value_1(rpd, H, C, lp_solver), worst_value_2(rpd, H, C, lp_solver)) -worst_values(rpd::RepGame2, H::Array{Float64, 2}, C::Array{Float64, 1}) = - (worst_value_1(rpd, H, C), worst_value_2(rpd, H, C)) # # Outer Hyper Plane Approximation From ecfa1e092b745c71e677adf85cbb0c98eb8cb45a Mon Sep 17 00:00:00 2001 From: QBatista Date: Fri, 8 Dec 2017 11:32:21 +0900 Subject: [PATCH 4/5] FIX: Set ClpSolver() as default solver --- src/repeated_game.jl | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/repeated_game.jl b/src/repeated_game.jl index d1fc55e6..96ce9769 100644 --- a/src/repeated_game.jl +++ b/src/repeated_game.jl @@ -238,7 +238,8 @@ Given a constraint w ∈ W, this finds the worst possible payoff for agent i. """ function worst_value_i(rpd::RepGame2, H::Array{Float64, 2}, C::Array{Float64, 1}, i::Int, - lp_solver::MathProgBase.AbstractMathProgSolver) + lp_solver::MathProgBase.AbstractMathProgSolver= + ClpSolver()) # Objective depends on which player we are minimizing c = zeros(2) c[i] = 1.0 @@ -259,11 +260,11 @@ end "See worst_value_i for documentation" worst_value_1(rpd::RepGame2, H::Array{Float64, 2}, C::Array{Float64, 1}, - lp_solver::MathProgBase.AbstractMathProgSolver) = + lp_solver::MathProgBase.AbstractMathProgSolver=ClpSolver()) = worst_value_i(rpd, H, C, 1, lp_solver) "See worst_value_i for documentation" worst_value_2(rpd::RepGame2, H::Array{Float64, 2}, C::Array{Float64, 1}, - lp_solver::MathProgBase.AbstractMathProgSolver) = + lp_solver::MathProgBase.AbstractMathProgSolver=ClpSolver()) = worst_value_i(rpd, H, C, 2, lp_solver) # From 6a038f2f2a30d37296fd7889514149a94de3662c Mon Sep 17 00:00:00 2001 From: QBatista Date: Fri, 8 Dec 2017 14:55:57 +0900 Subject: [PATCH 5/5] FIX: Reverse change in doc --- src/repeated_game.jl | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/repeated_game.jl b/src/repeated_game.jl index 96ce9769..5d414f6d 100644 --- a/src/repeated_game.jl +++ b/src/repeated_game.jl @@ -293,8 +293,7 @@ outer hyperplane approximation described by Judd, Yeltekin, Conklin 2002. - `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) + docs for more info). By default, it chooses to use SimplePolyhedraLibrary. - `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().