All Projects → wouterkool → Attention Learn To Route

wouterkool / Attention Learn To Route

Licence: mit
Attention based model for learning to solve different routing problems

Projects that are alternatives of or similar to Attention Learn To Route

Orion
A machine learning library for detecting anomalies in signals.
Stars: ✭ 445 (-0.89%)
Mutual labels:  jupyter-notebook
D2 Net
D2-Net: A Trainable CNN for Joint Description and Detection of Local Features
Stars: ✭ 448 (-0.22%)
Mutual labels:  jupyter-notebook
Practical Pytorch
Go to https://github.com/pytorch/tutorials - this repo is deprecated and no longer maintained
Stars: ✭ 4,329 (+864.14%)
Mutual labels:  jupyter-notebook
Face Image Motion Model
Face Image Motion Model (Photo-2-Video) based on "first-order-model" repository.
Stars: ✭ 446 (-0.67%)
Mutual labels:  jupyter-notebook
Pytorch Fastcampus
PyTorch로 시작하는 딥러닝 입문 CAMP (2017.7~2017.12) 강의자료
Stars: ✭ 447 (-0.45%)
Mutual labels:  jupyter-notebook
Ipython Soccer Predictions
Sample iPython notebook with soccer predictions
Stars: ✭ 447 (-0.45%)
Mutual labels:  jupyter-notebook
Deeplearning Ahem Detector
Stars: ✭ 444 (-1.11%)
Mutual labels:  jupyter-notebook
Worldmodelsexperiments
World Models Experiments
Stars: ✭ 450 (+0.22%)
Mutual labels:  jupyter-notebook
Pytorch advanced
書籍「つくりながら学ぶ! PyTorchによる発展ディープラーニング」の実装コードを配置したリポジトリです
Stars: ✭ 448 (-0.22%)
Mutual labels:  jupyter-notebook
Cocoapi
COCO API - Dataset @ http://cocodataset.org/
Stars: ✭ 4,776 (+963.7%)
Mutual labels:  jupyter-notebook
Jupyter tensorboard
Start Tensorboard in Jupyter Notebook
Stars: ✭ 446 (-0.67%)
Mutual labels:  jupyter-notebook
Rl Portfolio Management
Attempting to replicate "A Deep Reinforcement Learning Framework for the Financial Portfolio Management Problem" https://arxiv.org/abs/1706.10059 (and an openai gym environment)
Stars: ✭ 447 (-0.45%)
Mutual labels:  jupyter-notebook
Course V4
Please use fastbook's /clean folder instead of this
Stars: ✭ 449 (+0%)
Mutual labels:  jupyter-notebook
3dmol.js
WebGL accelerated JavaScript molecular graphics library
Stars: ✭ 443 (-1.34%)
Mutual labels:  jupyter-notebook
Fastai
The fastai deep learning library
Stars: ✭ 21,718 (+4736.97%)
Mutual labels:  jupyter-notebook
Swiftai
Swift for TensorFlow's high-level API, modeled after fastai
Stars: ✭ 445 (-0.89%)
Mutual labels:  jupyter-notebook
Course Resources Ml With Experts Budgets
Further student resources for DrivenData's 'Machine Learning with the Experts: School Budgets' DataCamp course.
Stars: ✭ 447 (-0.45%)
Mutual labels:  jupyter-notebook
Pytorch tutorial
PyTorch Tutorial (1.7)
Stars: ✭ 450 (+0.22%)
Mutual labels:  jupyter-notebook
Food Recipe Cnn
food image to recipe with deep convolutional neural networks.
Stars: ✭ 448 (-0.22%)
Mutual labels:  jupyter-notebook
Tpu
Reference models and tools for Cloud TPUs.
Stars: ✭ 4,580 (+920.04%)
Mutual labels:  jupyter-notebook

Attention, Learn to Solve Routing Problems!

Attention based model for learning to solve the Travelling Salesman Problem (TSP) and the Vehicle Routing Problem (VRP), Orienteering Problem (OP) and (Stochastic) Prize Collecting TSP (PCTSP). Training with REINFORCE with greedy rollout baseline.

TSP100

Paper

For more details, please see our paper Attention, Learn to Solve Routing Problems! which has been accepted at ICLR 2019. If this code is useful for your work, please cite our paper:

@inproceedings{
    kool2018attention,
    title={Attention, Learn to Solve Routing Problems!},
    author={Wouter Kool and Herke van Hoof and Max Welling},
    booktitle={International Conference on Learning Representations},
    year={2019},
    url={https://openreview.net/forum?id=ByxBFsRqYm},
}

Dependencies

Quick start

For training TSP instances with 20 nodes and using rollout as REINFORCE baseline:

python run.py --graph_size 20 --baseline rollout --run_name 'tsp20_rollout'

Usage

Generating data

Training data is generated on the fly. To generate validation and test data (same as used in the paper) for all problems:

python generate_data.py --problem all --name validation --seed 4321
python generate_data.py --problem all --name test --seed 1234

Training

For training TSP instances with 20 nodes and using rollout as REINFORCE baseline and using the generated validation set:

python run.py --graph_size 20 --baseline rollout --run_name 'tsp20_rollout' --val_dataset data/tsp/tsp20_validation_seed4321.pkl

Multiple GPUs

By default, training will happen on all available GPUs. To disable CUDA at all, add the flag --no_cuda. Set the environment variable CUDA_VISIBLE_DEVICES to only use specific GPUs:

CUDA_VISIBLE_DEVICES=2,3 python run.py 

Note that using multiple GPUs has limited efficiency for small problem sizes (up to 50 nodes).

Warm start

You can initialize a run using a pretrained model by using the --load_path option:

python run.py --graph_size 100 --load_path pretrained/tsp_100/epoch-99.pt

The --load_path option can also be used to load an earlier run, in which case also the optimizer state will be loaded:

python run.py --graph_size 20 --load_path 'outputs/tsp_20/tsp20_rollout_{datetime}/epoch-0.pt'

The --resume option can be used instead of the --load_path option, which will try to resume the run, e.g. load additionally the baseline state, set the current epoch/step counter and set the random number generator state.

Evaluation

To evaluate a model, you can add the --eval-only flag to run.py, or use eval.py, which will additionally measure timing and save the results:

python eval.py data/tsp/tsp20_test_seed1234.pkl --model pretrained/tsp_20 --decode_strategy greedy

If the epoch is not specified, by default the last one in the folder will be used.

Sampling

To report the best of 1280 sampled solutions, use

python eval.py data/tsp/tsp20_test_seed1234.pkl --model pretrained/tsp_20 --decode_strategy sample --width 1280 --eval_batch_size 1

Beam Search (not in the paper) is also recently added and can be used using --decode_strategy bs --width {beam_size}.

To run baselines

Baselines for different problems are within the corresponding folders and can be ran (on multiple datasets at once) as follows

python -m problems.tsp.tsp_baseline farthest_insertion data/tsp/tsp20_test_seed1234.pkl data/tsp/tsp50_test_seed1234.pkl data/tsp/tsp100_test_seed1234.pkl

To run baselines, you need to install Compass by running the install_compass.sh script from within the problems/op directory and Concorde using the install_concorde.sh script from within problems/tsp. LKH3 should be automatically downloaded and installed when required. To use Gurobi, obtain a (free academic) license and follow the installation instructions.

Other options and help

python run.py -h
python eval.py -h

Example CVRP solution

See plot_vrp.ipynb for an example of loading a pretrained model and plotting the result for Capacitated VRP with 100 nodes.

CVRP100

Acknowledgements

Thanks to pemami4911/neural-combinatorial-rl-pytorch for getting me started with the code for the Pointer Network.

This repository includes adaptions of the following repositories as baselines:

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].