# \donttest{
## Setup
fun <- function (x)
{
if (is.null(dim(x))) x <- matrix(x, nrow = 1)
b1 <- 15 * x[, 1] - 5
b2 <- 15 * x[, 2]
return(cbind((b2 - 5.1*(b1/(2*pi))^2 + 5/pi*b1 - 6)^2 + 10*((1 - 1/(8*pi)) * cos(b1) + 1),
-sqrt((10.5 - b1)*(b1 + 5.5)*(b2 + 0.5)) - 1/30*(b2 - 5.1*(b1/(2*pi))^2 - 6)^2-
1/3 * ((1 - 1/(8 * pi)) * cos(b1) + 1)))
}
d <- nobj <- 2
# Generate grid of strategies for Nash and Nash-Kalai-Smorodinsky
n.s <- c(11,11) # number of strategies per player
x.to.obj <- 1:2 # allocate objectives to players
integcontrol <- generate_integ_pts(n.s=n.s,d=d,nobj=nobj,x.to.obj=x.to.obj,gridtype="cartesian")
integ.pts <- integcontrol$integ.pts
expanded.indices <- integcontrol$expanded.indices
# Compute the pay-off on the grid
response.grid <- t(apply(integ.pts, 1, fun))
# Compute the Nash equilibrium (NE)
trueEq <- getEquilibrium(Z = response.grid, equilibrium = "NE", nobj = nobj, n.s = n.s,
return.design = TRUE, expanded.indices = expanded.indices,
sorted = !is.unsorted(expanded.indices[,2]))
# Pay-off at equilibrium
print(trueEq$NEPoff)
# Optimal strategy
print(integ.pts[trueEq$NE,])
# Index of the optimal strategy in the grid
print(expanded.indices[trueEq$NE,])
# Plots
oldpar <- par(mfrow = c(1,2))
plotGameGrid(fun = fun, n.grid = n.s, x.to.obj = x.to.obj, integcontrol=integcontrol,
equilibrium = "NE")
# Compute KS equilibrium (KSE)
trueKSEq <- getEquilibrium(Z = response.grid, equilibrium = "KSE", nobj = nobj,
return.design = TRUE, sorted = !is.unsorted(expanded.indices[,2]))
# Pay-off at equilibrium
print(trueKSEq$NEPoff)
# Optimal strategy
print(integ.pts[trueKSEq$NE,])
plotGameGrid(fun = fun, n.grid = n.s, integcontrol=integcontrol,
equilibrium = "KSE", fun.grid = response.grid)
# Compute the Nash equilibrium (NE)
trueNKSEq <- getEquilibrium(Z = response.grid, equilibrium = "NKSE", nobj = nobj, n.s = n.s,
return.design = TRUE, expanded.indices = expanded.indices,
sorted = !is.unsorted(expanded.indices[,2]))
# Pay-off at equilibrium
print(trueNKSEq$NEPoff)
# Optimal strategy
print(integ.pts[trueNKSEq$NE,])
# Index of the optimal strategy in the grid
print(expanded.indices[trueNKSEq$NE,])
# Plots
plotGameGrid(fun = fun, n.grid = n.s, x.to.obj = x.to.obj, integcontrol=integcontrol,
equilibrium = "NKSE")
par(oldpar)
# }
Run the code above in your browser using DataLab