MAEnvs4VRP Quickstart

Welcome to the MAEnvs4VRP Quickstart guide! This tutorial demonstrates the basic usage of the library through the CVRPTW environment example.

If you prefer interactive examples, you can also explore the corresponding Jupyter notebooks in 01: Quickstart.

Basic Usage

Let’s walk through a simple example using the CVRPTW environment to understand the main components of MAEnvs4VRP.

Import Libraries

Start by importing all the core modules needed for creating and interacting with an environment. Here, we exclude benchmarking and toy instance generators for simplicity.

from maenvs4vrp.environments.cvrptw.env import Environment
from maenvs4vrp.environments.cvrptw.env_agent_selector import AgentSelector
from maenvs4vrp.environments.cvrptw.observations import Observations
from maenvs4vrp.environments.cvrptw.instances_generator import InstanceGenerator
from maenvs4vrp.environments.cvrptw.env_agent_reward import DenseReward

%load_ext autoreload
%autoreload 2

Generate Instances and Create the Environment

Now, let’s generate instances and assemble the environment. We first create each individual component — instance generator, observations, agent selector, and reward evaluator — and then combine them into a complete environment.

gen = InstanceGenerator(batch_size=8)
obs = Observations()
sel = AgentSelector()
rew = DenseReward()

env = Environment(
    instance_generator_object=gen,
    obs_builder_object=obs,
    agent_selector_object=sel,
    reward_evaluator=rew,
    seed=0
)

Reset the Environment

Before simulation, the environment must be reset. This initializes the problem with the specified number of agents and nodes.

td = env.reset(batch_size=8, num_agents=4, num_nodes=16)

Run Simulation Steps

Once the environment is initialized, agents can begin performing actions. The simulation proceeds until all agents have completed their tasks and returned to the depot.

while not td["done"].all():
    td = env.sample_action(td)  # This is where your policy interacts with the environment
    td = env.step(td)

Continue Learning

This Quickstart provides a foundation for understanding how MAEnvs4VRP operates. You can find more hands-on examples and advanced topics in the following notebooks:

Notebook

Description

Colab

01: Quickstart

Learning MAEnvs4VRP basic usage.

Google Colab Badge

02: MAEnvs4VRP Library

Exploring MAEnvs4VRP functionality and challenges.

Google Colab Badge

03: Multi-Tasking Environments

Understanding multi-tasking behavior across environments.

Google Colab Badge

04: Stochastic Environments

Extending deterministic environments into stochastic versions.

Google Colab Badge

05: PyVRP

Integrating PyVRP to solve MAEnvs4VRP instances.

Google Colab Badge