mese79 / maze_solver

An implementation of Value Iteration algorithm

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Maze Solver

An implementation of value iteration algorithm to solve maze problem.


Requirements:

  • Python 3.x
  • numpy
  • matplotlib
  • texttable (included)

To run code:

python ./main.py

Help

To define your own maze create a list of strings which each element represent a row in maze.

Maze Symbols:
Symbol Description
# wall or obstacle (the maze is surrounded by walls as default)
. empty grid cell
* general goal
A-Z special goal/state
! pitfall
@ agent origin(starting state)

Example:

plan = [
    '...*...',
    '..!.#..',
    '..#.#..',
    '.#..A..',
    '.......',
]

Then you have to define your rewards or penalties by a dict like here:

rewards = {
    '*': 15.0,         # goal reward
    '!': -3.0,         # pitfall negative reward
    'A': 2.0,          # custom state reward
    'hit_wall': -1.0,  # hitting a wall negative reward
    'movement': -0.1   # each move negative reward(cost)
}

Finally run value iteration algorithm:

maze = SimpleMaze(plan=plan, rewards=rewards, action_prob=0.8)
maze.run_value_iteration(
    gamma=0.9, max_error=0.00001,
    max_iterations=1000, normal=False
)

sample output

About

An implementation of Value Iteration algorithm

License:MIT License


Languages

Language:Python 100.0%