XCSF  1.4.7
XCSF learning classifier system
env_maze.c File Reference

The discrete maze problem environment module. More...

#include "env_maze.h"
#include "param.h"
#include "utils.h"
Include dependency graph for env_maze.c:

Go to the source code of this file.

Macros

#define MAX_PAYOFF   (1.)
 The payoff provided at a food position. More...
 

Functions

static double env_maze_sensor (const struct XCSF *xcsf, const char s)
 Returns a float encoding of a sensor perception. More...
 
void env_maze_init (struct XCSF *xcsf, const char *filename)
 Initialises a maze environment from a specified file. More...
 
void env_maze_free (const struct XCSF *xcsf)
 Frees the maze environment. More...
 
void env_maze_reset (const struct XCSF *xcsf)
 Resets the animat to a random empty position in the maze. More...
 
bool env_maze_is_done (const struct XCSF *xcsf)
 Returns whether the maze is in a terminal state. More...
 
const double * env_maze_get_state (const struct XCSF *xcsf)
 Returns the current animat perceptions in the maze. More...
 
double env_maze_execute (const struct XCSF *xcsf, const int action)
 Executes the specified action and returns the payoff. More...
 
double env_maze_maxpayoff (const struct XCSF *xcsf)
 Returns the maximum payoff value possible in the maze. More...
 
bool env_maze_multistep (const struct XCSF *xcsf)
 Returns whether the environment is a multistep problem. More...
 

Variables

static const int x_moves [] = { 0, +1, +1, +1, 0, -1, -1, -1 }
 Maze x-axis moves. More...
 
static const int y_moves [] = { -1, -1, 0, +1, +1, +1, 0, -1 }
 Maze y-axis moves. More...
 

Detailed Description

The discrete maze problem environment module.

Author
Richard Preen rpree.nosp@m.n@gm.nosp@m.ail.c.nosp@m.om
Date
2015–2020.

Reads in the chosen maze from a file where each entry specifies a distinct position in the maze. The maze is toroidal and if the animat reaches one edge it can reenter the maze from the other side. Obstacles are coded as 'O' and 'Q', empty positions as '*', and food as 'F' or 'G'. The 8 adjacent cells are perceived (encoded as reals) and 8 movements are possible to the adjacent cells (if not blocked.) The animat is initially placed at a random empty position. The goal is to find the shortest path to the food.

Some mazes require a form of memory to be solved optimally. The optimal average number of steps for each maze is:

Woods 1: 1.7
Woods 2: 1.7
Woods 14: 9.5
Maze 4: 3.5
Maze 5: 4.61
Maze 6: 5.19
Maze 7: 4.33
Maze 10: 5.11
Woods 101: 2.9
Woods 101 1/2: 3.1
Woods 102: 3.31
Maze F1: 1.8
Maze F2: 2.5
Maze F3: 3.375
Maze F4: 4.5

Definition in file env_maze.c.

Macro Definition Documentation

◆ MAX_PAYOFF

#define MAX_PAYOFF   (1.)

The payoff provided at a food position.

Definition at line 55 of file env_maze.c.

Function Documentation

◆ env_maze_execute()

double env_maze_execute ( const struct XCSF xcsf,
const int  action 
)

Executes the specified action and returns the payoff.

Parameters
[in]xcsfThe XCSF data structure.
[in]actionThe action to perform.
Returns
The payoff from performing the action.

Definition at line 217 of file env_maze.c.

References EnvMaze::done, MAX_PAYOFF, EnvMaze::maze, x_moves, EnvMaze::xpos, EnvMaze::xsize, y_moves, EnvMaze::ypos, and EnvMaze::ysize.

◆ env_maze_free()

void env_maze_free ( const struct XCSF xcsf)

Frees the maze environment.

Parameters
[in]xcsfThe XCSF data structure.

Definition at line 147 of file env_maze.c.

References EnvMaze::state.

◆ env_maze_get_state()

const double* env_maze_get_state ( const struct XCSF xcsf)

Returns the current animat perceptions in the maze.

Parameters
[in]xcsfThe XCSF data structure.
Returns
The current animat perceptions.

Definition at line 187 of file env_maze.c.

References env_maze_sensor(), EnvMaze::maze, EnvMaze::state, EnvMaze::xpos, EnvMaze::xsize, EnvMaze::ypos, and EnvMaze::ysize.

Here is the call graph for this function:

◆ env_maze_init()

void env_maze_init ( struct XCSF xcsf,
const char *  filename 
)

Initialises a maze environment from a specified file.

Parameters
[in]xcsfThe XCSF data structure.
[in]filenameThe file name of the specified maze environment.

Definition at line 100 of file env_maze.c.

References MAX_SIZE, EnvMaze::maze, param_init(), EnvMaze::state, EnvMaze::xsize, and EnvMaze::ysize.

Referenced by env_init().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ env_maze_is_done()

bool env_maze_is_done ( const struct XCSF xcsf)

Returns whether the maze is in a terminal state.

Parameters
[in]xcsfThe XCSF data structure.
Returns
Whether the maze is in a terminal state.

Definition at line 175 of file env_maze.c.

References EnvMaze::done.

◆ env_maze_maxpayoff()

double env_maze_maxpayoff ( const struct XCSF xcsf)

Returns the maximum payoff value possible in the maze.

Parameters
[in]xcsfThe XCSF data structure.
Returns
The maximum payoff.

Definition at line 259 of file env_maze.c.

References MAX_PAYOFF.

◆ env_maze_multistep()

bool env_maze_multistep ( const struct XCSF xcsf)

Returns whether the environment is a multistep problem.

Parameters
[in]xcsfThe XCSF data structure.
Returns
True

Definition at line 271 of file env_maze.c.

◆ env_maze_reset()

void env_maze_reset ( const struct XCSF xcsf)

Resets the animat to a random empty position in the maze.

Parameters
[in]xcsfThe XCSF data structure.

Definition at line 159 of file env_maze.c.

References EnvMaze::done, EnvMaze::maze, rand_uniform_int(), EnvMaze::xpos, EnvMaze::xsize, EnvMaze::ypos, and EnvMaze::ysize.

Here is the call graph for this function:

◆ env_maze_sensor()

static double env_maze_sensor ( const struct XCSF xcsf,
const char  s 
)
static

Returns a float encoding of a sensor perception.

Parameters
[in]xcsfThe XCSF data structure.
[in]sThe char value of the sensor.
Returns
A float encoding of the sensor.

Definition at line 74 of file env_maze.c.

Referenced by env_maze_get_state().

Here is the caller graph for this function:

Variable Documentation

◆ x_moves

const int x_moves[] = { 0, +1, +1, +1, 0, -1, -1, -1 }
static

Maze x-axis moves.

Definition at line 60 of file env_maze.c.

Referenced by env_maze_execute().

◆ y_moves

const int y_moves[] = { -1, -1, 0, +1, +1, +1, 0, -1 }
static

Maze y-axis moves.

Definition at line 65 of file env_maze.c.

Referenced by env_maze_execute().