Class Square

java.lang.Object
  |
  +--Square
All Implemented Interfaces:
Environment, java.io.Serializable

public class Square
extends java.lang.Object
implements Environment, java.io.Serializable

This class implements the problem to be solved by agents. It first generates randomly two values corresponding to the two parameters taken into account for the evaluation. Then, it calculates the value corresponding to the combination of these two variables. These two variables are then converted in a binary string that is the signal transmitted to the agent. It then calculates the reward, comparing the calculated output and the answer provided by the agent.

Since:
JDK 1.3
See Also:
Serialized Form

Field Summary
private  int bits
          the number of bits used to code the variables in binaries
private  int[] car
          The different variables are stored in an array of integers.
static int conLength
          Specifies the length of each presented problem.
private static XCSConstants cons
          Stores the relevant constants for XCS.
private  boolean correct
          Stores if the last classification was correct.
private  java.lang.String currentState
          Stores the current problem.
private  int edgeSquare
          Edge of the square problem
private  int maxPayoff
          Specifies the maximal payoff possible in this environment.
private  int nbVar
          The number of variables taken into account in the process of evaluation, i.e. in calculating the right action.
private  int nrActions
          In the square problem there are 6 possible classifications
static boolean payoffLandscape
          Defines if either a payoff landscape or a 1000/0 payoff is provided after the execution of a classification.
private  java.util.Random random
          Used to generate new situations randomly
private  boolean reset
          Is set to true after a classification was executed
private  int scale
          In the square problem, variables'values can rank from 0 to 3
 
Constructor Summary
Square(int payoffMap)
          Constructs the square problem according to the specified problem length and chosen payoff type.
 
Method Summary
 double computeDistance(java.lang.String string1, java.lang.String string2)
          Computes the distance between two points in the problem space.
 boolean doReset()
          Returns true after the current problem was classified
private  java.lang.String encode(int n)
          turn an integer into a binary
 double executeAction(int action)
          Executes the action and determines the reward.
private  int[] generateSituation()
          Generates the values of the variables constituting the current state
 int getConditionLength()
          Returns the problem length
 java.lang.String getCurrentState()
          Returns the current problem
 int getMaxPayoff()
          Returns the maximal payoff possible in the current multiplexer problem.
 int getNbVar()
          Returns the number of variables comprised in the problem
 int getNrActions()
          Returns the number of possible actions.
 double getProblemSurface()
          Returns the edge of the surface of the square problem space
 boolean isMultiStepProblem()
          Returns false since the square problem is a single step problem
 java.lang.String resetState()
          Generates a new random problem instance.
 boolean wasCorrect()
          Returns true if the last executed action was a correct classification
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

conLength

public static int conLength
Specifies the length of each presented problem.


payoffLandscape

public static boolean payoffLandscape
Defines if either a payoff landscape or a 1000/0 payoff is provided after the execution of a classification.


maxPayoff

private int maxPayoff
Specifies the maximal payoff possible in this environment.


edgeSquare

private int edgeSquare
Edge of the square problem


random

private java.util.Random random
Used to generate new situations randomly


currentState

private java.lang.String currentState
Stores the current problem.


cons

private static XCSConstants cons
Stores the relevant constants for XCS.

See Also:
XCSConstants

correct

private boolean correct
Stores if the last classification was correct.


reset

private boolean reset
Is set to true after a classification was executed


nrActions

private final int nrActions
In the square problem there are 6 possible classifications

See Also:
Constant Field Values

scale

private final int scale
In the square problem, variables'values can rank from 0 to 3

See Also:
Constant Field Values

bits

private int bits
the number of bits used to code the variables in binaries


nbVar

private final int nbVar
The number of variables taken into account in the process of evaluation, i.e. in calculating the right action.

See Also:
Constant Field Values

car

private int[] car
The different variables are stored in an array of integers. This array is used to generate the string passed to the agents and the value of the correct action

Constructor Detail

Square

public Square(int payoffMap)
Constructs the square problem according to the specified problem length and chosen payoff type. Essentially the relevant constants for the environment are calculated here. Moreover, the problem array is generated

Parameters:
payoffMap - Specifies if a payoff map should be provided or a 1000/0 payoff.
Method Detail

resetState

public java.lang.String resetState()
Generates a new random problem instance.

Specified by:
resetState in interface Environment
See Also:
generateSituation(), encode(int)

executeAction

public double executeAction(int action)
Executes the action and determines the reward. Distinguishes between the payoff landscape and the 0/1000 reward.

Specified by:
executeAction in interface Environment
Parameters:
action - Specifies the classification.

generateSituation

private int[] generateSituation()
Generates the values of the variables constituting the current state


encode

private java.lang.String encode(int n)
turn an integer into a binary

Parameters:
n - The integer to be turned into a binary string

wasCorrect

public boolean wasCorrect()
Returns true if the last executed action was a correct classification

Specified by:
wasCorrect in interface Environment

isMultiStepProblem

public boolean isMultiStepProblem()
Returns false since the square problem is a single step problem

Specified by:
isMultiStepProblem in interface Environment

doReset

public boolean doReset()
Returns true after the current problem was classified

Specified by:
doReset in interface Environment

getConditionLength

public int getConditionLength()
Returns the problem length

Specified by:
getConditionLength in interface Environment

getMaxPayoff

public int getMaxPayoff()
Returns the maximal payoff possible in the current multiplexer problem. The maximal payoff is determined out of the payoff type. If the payoff type 1000/0 is selected, this function will return 1000, otherwise the maximal value depends on the problem size.

Specified by:
getMaxPayoff in interface Environment

getNrActions

public int getNrActions()
Returns the number of possible actions. in the square problem there are six classifications possible

Specified by:
getNrActions in interface Environment

getNbVar

public int getNbVar()
Returns the number of variables comprised in the problem


getCurrentState

public java.lang.String getCurrentState()
Returns the current problem

Specified by:
getCurrentState in interface Environment

computeDistance

public double computeDistance(java.lang.String string1,
                              java.lang.String string2)
Computes the distance between two points in the problem space. The coordinates are written as binary strings. This method is used to compute the distance between the signal from the environment and the classifier most remote from it, in order to assess whether or not the signal is in the realm of competence of the agent (or XCS) to whom the signal is submitted.

Specified by:
computeDistance in interface Environment
Parameters:
string1 - Coordinates of the first position used in the comparison
string2 - Coordinates of the second position used in the comparison

getProblemSurface

public double getProblemSurface()
Returns the edge of the surface of the square problem space

Specified by:
getProblemSurface in interface Environment