Gym-Routing aims at offering a suite of Gymnasium environments tailored for training Reinforcement Learning (RL) agents to tackle various routing problems.
- Pip install the package
gym_routing
defined in the repo
pip install git+https://github.com/PierreCounathe/gym-routing
- Import
gym_routing
and make the gym environment
import gym_routing
import gymnasium as gym
from gymnasium.wrappers import FlattenObservation
env = gym.make("gym_routing/TSP-v0") # use "gym_routing/ActionMaskedTSP-v0" to use the action masked environment
env = FlattenObservation(env)
- (TSP) Vanilla Traveling Salesman Problem
- Action Masked TSP
- (VRP) Vehicle Routing Problem
- (CVRP) Capacitated Vehicle Routing Problem
import gym_routing
import gymnasium as gym
from gymnasium.wrappers import FlattenObservation
from stable_baselines3 import PPO
# Define the environment
env = gym.make("gym_routing/TSP-v0")
env = FlattenObservation(env)
# Define and train the agent
ppo = PPO("MlpPolicy", env, verbose=1, tensorboard_log="./ppo_tsp_tensorboard/")
ppo.learn(total_timesteps=5_000, progress_bar=True)
To ensure clean and consistent code, this repo uses pre-commit hooks (black, flake8, mypy, isort), that can be installed the following way:
pip install pre-commit
pre-commit install