edu.princeton.repeatedgames.rgsolve.games
Class StageGameMethods

java.lang.Object
  extended by edu.princeton.repeatedgames.rgsolve.games.StageGameMethods

public class StageGameMethods
extends java.lang.Object

This class contains helper methods for manipulating games and performing basic operations on them


Field Summary
static int PLAYER_1
          index for player 1 in best response methods
static int PLAYER_2
          index for player 2 in best response methods
static int[] PLAYERS
          indexes for players
 
Constructor Summary
private StageGameMethods()
          private constructor
 
Method Summary
static java.util.List<GameExtremePoint> getFeasibleSetHull(Game gm, AlgoParameters params, boolean doMultiThread)
          Computes and returns the convex hull of the set of feasible stage payoffs in the game gm.
static Fraction[][][] getFractionalPayoffs(Game game)
          Converts game payoffs into Fractions (from reals/doubles)
static Point getMaximumPayoffs(Game game)
           
static Point getMinimumPayoffs(Game game)
          Returns the minimum feasible payoffs to each player as a Point of the game game
static Point getMinMax(Game game)
          Returns the minmax payoffs as a Point of the game game
static double[][][] getPayoffArray(Game game)
          Returns a double[][][] representation of the stage payoffs, with [i-1][a1][a2] denoting the payoff to player i in {PLAYER_1, PLAYER_2} given action (a1,a2)
static Point[] getPointArray(Game game)
          Returns an array of points representing the feasible payoffs in this game.
static int[] getStaticBestResponse(Game gm, int player, boolean doMulti)
          Returns the static best response vector for player i, where BR[a] is the best response of i to action a by player j = (-i).
private static void getStaticBestResponseFrom(Game gm, int start, int end, int player, int[] BR)
          Helper method that calculates the best responses for player player in the game game in response to actions start through end of the other player, and stores them in the array BR/ Note: there could be multiple BRs, but we only care about BRs for defection payoffs and therefore choose a unique BR.
static boolean[][] getUsableActions(Game game)
          Converts the BitSet of usable actions in the game game to a boolean[][] representation
static void showLatexTable(java.lang.String gameName, Game gm)
          Shows a JFrame with the game in LaTeX table format
static BimatrixGame toBimatrixGame(Game gm)
          This method converts any subclass of Game into a BimatrixGame, storing payoffs as double[][] arrays.
static BimatrixGame toBimatrixGame(Game gm, int m1, int m2)
          Converts the game gm to an m1 x m2 dimension BimatrixGame, truncating or padding gm as necessary.
static java.lang.String toLatexTable(Game gm, int numDigits)
          Returns the stage game as a normal-form table in LaTeX format
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

PLAYER_1

public static final int PLAYER_1
index for player 1 in best response methods

See Also:
Constant Field Values

PLAYER_2

public static final int PLAYER_2
index for player 2 in best response methods

See Also:
Constant Field Values

PLAYERS

public static final int[] PLAYERS
indexes for players

Constructor Detail

StageGameMethods

private StageGameMethods()
private constructor

Method Detail

getPointArray

public static Point[] getPointArray(Game game)
Returns an array of points representing the feasible payoffs in this game.

Parameters:
game -
Returns:
feasible payoffs as Point array

getMinMax

public static Point getMinMax(Game game)
Returns the minmax payoffs as a Point of the game game

Parameters:
game -
Returns:
minmax payoffs

getMinimumPayoffs

public static Point getMinimumPayoffs(Game game)
Returns the minimum feasible payoffs to each player as a Point of the game game

Parameters:
game -
Returns:
the minimum payoffs

getFractionalPayoffs

public static Fraction[][][] getFractionalPayoffs(Game game)
Converts game payoffs into Fractions (from reals/doubles)

Parameters:
game -
Returns:
game payoffs are array of fractions

getPayoffArray

public static double[][][] getPayoffArray(Game game)
Returns a double[][][] representation of the stage payoffs, with [i-1][a1][a2] denoting the payoff to player i in {PLAYER_1, PLAYER_2} given action (a1,a2)

Parameters:
game -
Returns:
the array of payoffs

getUsableActions

public static boolean[][] getUsableActions(Game game)
Converts the BitSet of usable actions in the game game to a boolean[][] representation

Parameters:
game -
Returns:
a boolean[][] representing usable actions in this game

toBimatrixGame

public static BimatrixGame toBimatrixGame(Game gm)
This method converts any subclass of Game into a BimatrixGame, storing payoffs as double[][] arrays.

Parameters:
gm - the game to be converted
Returns:
the BimatrixGame representation of gm

toBimatrixGame

public static BimatrixGame toBimatrixGame(Game gm,
                                          int m1,
                                          int m2)
Converts the game gm to an m1 x m2 dimension BimatrixGame, truncating or padding gm as necessary.

Parameters:
gm - the game
m1 - number of player 1 actions
m2 - number of player 2 actions
Returns:
the BimatrixGame representation of gm

getFeasibleSetHull

public static java.util.List<GameExtremePoint> getFeasibleSetHull(Game gm,
                                                                  AlgoParameters params,
                                                                  boolean doMultiThread)
                                                           throws java.lang.Exception
Computes and returns the convex hull of the set of feasible stage payoffs in the game gm. Returns an ArrayList of GameExtremePoints sorted counter-clockwise.

Parameters:
gm - the game
params - parameters to use in convex hull operation
doMultiThread - whether the method should try to parallelize the task
Returns:
a ArrayList of extreme points of the feasible stage payoff set
Throws:
java.lang.Exception

getStaticBestResponse

public static int[] getStaticBestResponse(Game gm,
                                          int player,
                                          boolean doMulti)
Returns the static best response vector for player i, where BR[a] is the best response of i to action a by player j = (-i). Note: there could be multiple BRs, but we only care about BRs for defection payoffs and therefore choose a unique BR.

Parameters:
gm - the game
player - the player to calculate best responses for (PLAYER_1 is player 1, etc.)
doMulti - should the method try to multi-thread?
Returns:
best response action vector

getStaticBestResponseFrom

private static void getStaticBestResponseFrom(Game gm,
                                              int start,
                                              int end,
                                              int player,
                                              int[] BR)
Helper method that calculates the best responses for player player in the game game in response to actions start through end of the other player, and stores them in the array BR/ Note: there could be multiple BRs, but we only care about BRs for defection payoffs and therefore choose a unique BR.

Parameters:
gm -
start -
end -
player -
BR -

toLatexTable

public static java.lang.String toLatexTable(Game gm,
                                            int numDigits)
Returns the stage game as a normal-form table in LaTeX format

Parameters:
gm - the game
numDigits - output digits
Returns:
LaTeX table

showLatexTable

public static void showLatexTable(java.lang.String gameName,
                                  Game gm)
Shows a JFrame with the game in LaTeX table format

Parameters:
gameName - the name of the game
gm - the game
numDigits - output digits

getMaximumPayoffs

public static Point getMaximumPayoffs(Game game)
Parameters:
game -
Returns:
the maximum payoff feasible to each player