Skip to main content

A mini-maze environment for reinforcement learning experiments

Project description

Mini-Maze

Mini-Maze is an open-source reinforcement learning (RL) environment based on the Minigrid package. Its primary goal is to simplify the development and testing of RL algorithms by enabling users to generate random mazes that guarantee a feasible path to the goal, as well as define mazes through a straightforward 0-1 matrix representation.

Installation

To install Mini-Maze, you will need Python 3.6 or later. It is recommended to use a virtual environment. Install Mini-Maze using pip:

pip install mini-maze

Quickstart

Below is a step-by-step guide to help you get started with Mini-Maze, showcasing two fundamental ways to work with mazes: defining a custom maze using a 0-1 matrix and generating a maze randomly.

Defining a Custom Maze

First, we demonstrate how to manually define a maze using a 0-1 matrix, where 0 represents an open path and 1 represents an obstacle, and then initialize the environment with custom start and target positions.

from mini_maze import MiniMazeEnv

# Define a 5x5 maze using a 0-1 matrix (0 represents an open path, 1 represents an obstacle)
maze = [
    [0, 1, 0, 0, 0],
    [0, 1, 0, 1, 0],
    [0, 0, 0, 1, 0],
    [0, 1, 1, 1, 0],
    [0, 0, 0, 0, 0]
]

# Initialize the environment with the defined maze, start position, and target position
env = MiniMazeEnv(maze=maze, start_pos=(0,0), target_pos=(4,4))

# Reset the environment to start a new episode
observation = env.reset()
done = False
while not done:
    # The action space of Mini-Maze is discrete, ranging from 0 to 3 (up, right, down, left)
    action = env.action_space.sample()  # Replace with your RL algorithm's action
    observation, reward, done, info = env.step(action)
    env.render()
# Close the environment
env.close()

Generating a Random Maze

For those looking to dive into experimentation on the generalization capabilities of reinforcement learning algorithms, Mini-Maze offers a convenient function to generate random mazes. This method ensures the generation of a solvable maze, along with randomly positioned start and target locations.

from mini_maze import generate_random_maze

maze, start_pos, target_pos = generate_random_maze(size=(5,5)) 
print(maze)

Here is an example output:

[
 [1, 1, 1, 1, 1], 
 [1, 0, 1, 0, 1], 
 [1, 0, 1, 0, 1], 
 [1, 0, 0, 0, 1], 
 [1, 1, 1, 1, 1]
] 

Built-In Optimal Policy

Mini-Maze provides a built-in optimal policy for each generated maze. This feature allows you to compare the performance of your RL algorithm against the optimal solution. To access the optimal policy, simply call the .get_optimal_action() method on the environment object:

from mini_maze import MiniMazeEnv, generate_random_maze 
# Generate a random maze
maze, start_pos, target_pos = generate_random_maze(size=(33, 33)) 
env = MiniMazeEnv(maze=maze, start_pos=start_pos, target_pos=target_pos, render_mode="human")

# Reset the environment to start a new episode
observation, _ = env.reset()
done = False
while not done:
    # Get the optimal action for the current state
    action = env.get_optimal_action()

    # Take the optimal action
    next_state, reward, done, truncated, info = env.step(action)

# Close the environment
env.close()

License

Mini-Maze is open source and licensed under the MIT license. See the LICENSE file for more details.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

mini_maze-0.1.3.tar.gz (8.3 kB view details)

Uploaded Source

Built Distribution

mini_maze-0.1.3-py3-none-any.whl (9.5 kB view details)

Uploaded Python 3

File details

Details for the file mini_maze-0.1.3.tar.gz.

File metadata

  • Download URL: mini_maze-0.1.3.tar.gz
  • Upload date:
  • Size: 8.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.0.0 CPython/3.8.6

File hashes

Hashes for mini_maze-0.1.3.tar.gz
Algorithm Hash digest
SHA256 90ef631dbadfb0bd42d8cf72fb1bac1446040357ba8807449bf60c6b1df95b79
MD5 004b519e9c6378852536cffaf7c8590b
BLAKE2b-256 35a2758cb9dcca2acc4002950e35708b79441431b67817dc6a82852867768f85

See more details on using hashes here.

File details

Details for the file mini_maze-0.1.3-py3-none-any.whl.

File metadata

  • Download URL: mini_maze-0.1.3-py3-none-any.whl
  • Upload date:
  • Size: 9.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.0.0 CPython/3.8.6

File hashes

Hashes for mini_maze-0.1.3-py3-none-any.whl
Algorithm Hash digest
SHA256 acebc08bd2740de5601748c75414991e1889c580b403e05c00b68bae7d9b4fd2
MD5 f9179ff3405991f6a6f44d059ba35815
BLAKE2b-256 09ef26b1774a0a2ed4678efcaba1c8e1c4643fb66bd71ad25a43e9339b15feee

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page