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.2.tar.gz (8.4 kB view details)

Uploaded Source

Built Distribution

mini_maze-0.1.2-py3-none-any.whl (9.6 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: mini_maze-0.1.2.tar.gz
  • Upload date:
  • Size: 8.4 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.2.tar.gz
Algorithm Hash digest
SHA256 02d7ff57e35d321d86a3abcddbbb6158da4e034a734d83ab783a0ff587730d17
MD5 f9aac7baa2d5916666eefd1c2484d37f
BLAKE2b-256 a4d5b7003577a7704d36df569f75c1c1234773a4a14379a3a540a2e8cd07f224

See more details on using hashes here.

File details

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

File metadata

  • Download URL: mini_maze-0.1.2-py3-none-any.whl
  • Upload date:
  • Size: 9.6 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.2-py3-none-any.whl
Algorithm Hash digest
SHA256 74a8ead182374df7ccb10ce92b1aad40a6bddd68e2d829b1e6734be4e9eec999
MD5 f9435c373ba7cb4b6ad223b379c085c7
BLAKE2b-256 fc4fa2b1aff1768ff37a092b705a4e0c0eae61646a81a913278c7634ec7b7849

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