A pretrained model has learned parameters from an earlier dataset or task, so it can be applied without repeating the full training process. For TSP, this avoids the substantial code and data preprocessing required to train an ML model from scratch. section 11.7
Using a pretrained model for TSP involves:
- Selecting a dataset, batch size, sample count, graph-sparsification proportion, and nearest-neighbor strategy. section 11.7
- Loading the saved model, moving it to the selected CUDA or CPU device, choosing greedy decoding, and switching to evaluation mode. section 11.7
- Producing a feasible candidate tour from the model’s edge probability distribution; Gurobi can help eliminate subtours and calculate reduced costs. section 11.7
Listing 11.4 Solving TSP using supervised ML
import os import math import itertools import numpy as np import networkx as nx from scipy.spatial.distance import pdist, squareform import seaborn as sns import matplotlib.pyplot as plt import torch from torch.utils.data import DataLoader from torch.nn import DataParallel from learning_tsp.problems.tsp.problem_tsp import TSP from learning_tsp.utils import load_model, move_to from gurobipy import * os.environ["CUDA_DEVICE_ORDER"] = "PCI_BUS_ID" os.environ["CUDA_VISIBLE_DEVICES"] = "0"
Inspect the Python setup for loading and evaluating a pretrained model on TSP instances. section 11.7






