public class GridWorldRewardFunction extends java.lang.Object implements RewardFunction
setReward(int, int, double)
method.
This reward function is useful for simple grid worlds without any location objects or worlds for which the rewards are independent of location objects. An alternative to this class is to define worlds with location objects and use the atLocation propositional function and location types to define rewards.
Modifier and Type | Field and Description |
---|---|
protected int |
height |
protected double[][] |
rewardMatrix |
protected int |
width |
Constructor and Description |
---|
GridWorldRewardFunction(int width,
int height)
Initializes the reward function for a grid world of size width and height and initializes the reward values everywhere to 0.
|
GridWorldRewardFunction(int width,
int height,
double initializingReward)
Initializes the reward function for a grid world of size width and height and initializes the reward values everywhere to initializingReward.
|
Modifier and Type | Method and Description |
---|---|
double |
getRewardForTransitionsTo(int x,
int y)
Returns the reward this reward function will return when the agent transitions to position x, y.
|
double[][] |
getRewardMatrix()
Returns the reward matrix this reward function uses.
|
protected void |
initialize(int width,
int height,
double initializingReward)
Initializes the reward matrix.
|
double |
reward(State s,
Action a,
State sprime)
Returns the reward received when action a is executed in state s and the agent transitions to state sprime.
|
void |
setReward(int x,
int y,
double r)
Sets the reward the agent will receive to transitioning to position x, y
|
protected double[][] rewardMatrix
protected int width
protected int height
public GridWorldRewardFunction(int width, int height, double initializingReward)
setReward(int, int, double)
method.width
- the width of the grid worldheight
- the height of the grid worldinitializingReward
- the reward to which all agent position transitions are initialized to return.public GridWorldRewardFunction(int width, int height)
setReward(int, int, double)
method.width
- the width of the grid worldheight
- the height of the grid worldprotected void initialize(int width, int height, double initializingReward)
width
- the width of the grid worldheight
- the height of the grid worldinitializingReward
- the reward to which all agent position transitions are initialized to return.public double[][] getRewardMatrix()
public void setReward(int x, int y, double r)
x
- the x positiony
- the y positionr
- the reward the agent will receive to transitioning to position x, ypublic double getRewardForTransitionsTo(int x, int y)
x
- the x positiony
- the y positionpublic double reward(State s, Action a, State sprime)
RewardFunction
reward
in interface RewardFunction
s
- the state in which the action was executeda
- the action executedsprime
- the state to which the agent transitioned