Rintarooo / VRP_DRL_MHA

"Attention, Learn to Solve Routing Problems!"[Kool+, 2019], Capacitated Vehicle Routing Problem solver

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

CVRP solver with Multi-Head Attention

TensorFlow2 and PyTorch implementation of ATTENTION, LEARN TO SOLVE ROUTING PROBLEMS!(Kool et al. 2019)(https://arxiv.org/pdf/1803.08475.pdf)

Description

Slide Share -- CVRP solver with Multi Heads Attention --

Dependencies

  • Python >= 3.6
  • TensorFlow >= 2.0
  • PyTorch = 1.5
  • tqdm
  • scipy
  • numpy
  • plotly (only for plotting)
  • matplotlib (only for plotting)

Usage

First move to PyTorch or TensorFlow2 dir.

cd PyTorch

Then, generate the pickle file contaning hyperparameter values by running the following command.

python config.py

you would see the pickle file in Pkl dir. now you can start training the model.

python train.py -p Pkl/***.pkl

Plot prediction of the pretrained model (in this example, batch size is 128, number of customer nodes is 50)

python plot.py -p Weights/***.pt(or ***.h5) -b 128 -n 50

You can change plot.py into plot_2opt.py.

2opt is a local search method, which improves a crossed route by swapping arcs.

If you want to verify your model, you can use opensource dataset in OpenData dir.

Opensource data is obtained from Augerat et al.(1995)

please refer to Capacitated VRP Instances by NEO Research Group

python plot.py -p Weights/***.pt -t ../OpenData/A-n***.txt -b 128

One example would be cd PyTorch && python plot.py -p Weights/VRP50_train_epoch19.pt -t ../OpenData/A-n45-k7.txt -d sampling -b 128

Reference

About

"Attention, Learn to Solve Routing Problems!"[Kool+, 2019], Capacitated Vehicle Routing Problem solver

License:MIT License


Languages

Language:Python 100.0%