##### https://github.com/cran/GPGame
Tip revision: cbe720d
getEquilibrium.Rd
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/getEquilibrium.R
\name{getEquilibrium}
\alias{getEquilibrium}
\title{Equilibrium computation of a discrete game for a given matrix with objectives values}
\usage{
getEquilibrium(
Z,
equilibrium = c("NE", "NKSE", "KSE", "CKSE"),
nobj = 2,
n.s,
expanded.indices = NULL,
return.design = FALSE,
sorted = FALSE,
cross = FALSE,
kweights = NULL,
calibcontrol = NULL
)
}
\arguments{
\item{Z}{is a matrix of size [\code{npts x nsim*nobj}] of objective values, see details,}

\item{equilibrium}{considered type, one of \code{"NE"}, \code{"NKSE"}, \code{"KSE"}, \code{"CKSE"}}

\item{nobj}{nb of objectives (or players)}

\item{n.s}{scalar of vector. If scalar, total number of strategies (to be divided equally among players),
otherwise number of strategies per player.}

\item{expanded.indices}{is a matrix containing the indices of the \code{integ.pts} on the grid, see \code{\link[GPGame]{generate_integ_pts}}}

\item{return.design}{Boolean; if \code{TRUE}, the index of the optimal strategy is returned (otherwise only the pay-off is returned)}

\item{sorted}{Boolean; if \code{TRUE}, the last column of expanded.indices is assumed to be sorted in increasing order. This provides a substantial efficiency gain.}

\item{cross}{Should the simulation be crossed? (For "NE" only - may be dropped in future versions)}

\item{kweights}{kriging weights for \code{CKS} (TESTING)}

\item{Nadir, Shadow}{optional vectors of size \code{nobj}. Replaces the nadir and/or shadow point for \code{KSE}. Some coordinates can be set to \code{Inf} (resp. -\code{Inf}).}

\item{calibcontrol}{an optional list for calibration problems, containing \code{target} a vector of target values for the objectives,
\code{log} a Boolean stating if a log transformation should be used or not and
\code{offset} a (small) scalar so that each objective is log(offset + (y-T^2)).}
}
\value{
A list with elements:
\itemize{
\item \code{NEPoff} vector of pay-offs at the equilibrium or matrix of pay-offs at the equilibria;
\item \code{NE} the corresponding design(s), if \code{return.design} is \code{TRUE}.
}
}
\description{
Computes the equilibrium of three types of games, given a matrix of objectives (or a set of matrices) and the structure of the strategy space.
}
\details{
If \code{nsim=1}, each line of \code{Z} contains the pay-offs of the different players for a given strategy s: [obj1(s), obj2(s), ...].
The position of the strategy \code{s} in the grid is given by the corresponding line of \code{expanded.indices}. If \code{nsim>1}, (vectorized call) \code{Z} contains
different trajectories for each pay-off: each line is [obj1_1(x), obj1_2(x), ... obj2_1(x), obj2_2(x), ...].
}
\examples{
\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)
}
}