Skip to content

Commit

Permalink
[Example] CVRPLib update
Browse files Browse the repository at this point in the history
  • Loading branch information
fedebotu committed Oct 24, 2024
1 parent 74b18bd commit 7a16b64
Showing 1 changed file with 38 additions and 14 deletions.
52 changes: 38 additions & 14 deletions examples/datasets/2-test-on-cvrplib.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,13 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"# Test Model on VRPLib\n",
"# Testing Model on VRPLib\n",
"\n",
"In this notebook, we will test the trained model's performance on the VRPLib benchmark. We will use the trained model from the previous notebook.\n",
"In this notebook, we will test the trained model's performance on the VRPLib benchmark.\n",
"\n",
"[VRPLIB](http://vrp.galgos.inf.puc-rio.br/index.php/en/) is a collection of instances related to the CVRP, which is a classic optimization challenge in the field of logistics and transportation. \n",
"[VRPLib](http://vrp.galgos.inf.puc-rio.br/index.php/en/) is a collection of instances related to the CVRP, which is a classic optimization challenge in the field of logistics and transportation. \n",
"\n",
"<a href=\"https://colab.research.google.com/github/ai4co/rl4co/blob/main/examples/datasets/2-test-on-cvrplib.ipynb\"><img src=\"https://colab.research.google.com/assets/colab-badge.svg\" alt=\"Open In Colab\"></a>\n",
"\n",
"## Before we start\n",
"\n",
"To use the VRPLib, we strongly recomment to use the Python `vrplib` tool:\n",
"\n",
"[VRPLib](https://github.com/leonlan/VRPLIB) is a Python package for working with Vehicle Routing Problem (VRP) instances. This tool can help us easily load the VRPLib instances and visualize the results."
"<a href=\"https://colab.research.google.com/github/ai4co/rl4co/blob/main/examples/datasets/2-test-on-cvrplib.ipynb\"><img src=\"https://colab.research.google.com/assets/colab-badge.svg\" alt=\"Open In Colab\"></a>"
]
},
{
Expand All @@ -32,11 +26,12 @@
},
{
"cell_type": "code",
"execution_count": 1,
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# !pip install rl4co[graph] # include torch-geometric\n",
"# !pip install vrplib # for reading instance files\n",
"\n",
"## NOTE: to install latest version from Github (may be unstable) install from source instead:\n",
"# !pip install git+https://github.com/ai4co/rl4co.git"
Expand Down Expand Up @@ -299,7 +294,7 @@
},
{
"cell_type": "code",
"execution_count": 9,
"execution_count": null,
"metadata": {},
"outputs": [
{
Expand Down Expand Up @@ -336,15 +331,22 @@
"source": [
"# Plot some instances\n",
"env.render(tds[0], actions[0].cpu())\n",
"env.render(tds[-2], actions[-2].cpu())git\n",
"env.render(tds[-2], actions[-2].cpu())\n",
"env.render(tds[-1], actions[-1].cpu())"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Train"
"### Train\n",
"\n",
"We will train for few steps just to show the effects of training a model.\n",
"Alternatively, we can load the a pretrained checkpoint, e.g. with:\n",
"\n",
"```python\n",
"model = AttentionModel.load_from_checkpoint(checkpoint_path, load_baseline=False)\n",
"```\n"
]
},
{
Expand Down Expand Up @@ -482,6 +484,13 @@
"trainer.fit(model)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Test trained model"
]
},
{
"cell_type": "code",
"execution_count": 11,
Expand Down Expand Up @@ -593,6 +602,21 @@
"env.render(tds[-2], actions[-2].cpu())\n",
"env.render(tds[-1], actions[-1].cpu())"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Great! We can see that the performance vastly improved even with just few minutes of training.\n",
"\n",
"There are several ways to improve the model's performance further, such as:\n",
"- Training for more steps\n",
"- Using a different model architecture\n",
"- Using a different training algorithm\n",
"- Using a different hyperparameters\n",
"- Using a different `Generator` \n",
"- ... and many more!"
]
}
],
"metadata": {
Expand Down

0 comments on commit 7a16b64

Please sign in to comment.