{ "cells": [ { "cell_type": "markdown", "id": "2f39414b", "metadata": {}, "source": [ "# Traveling Salesman\n", "\n", "### Problem definition\n", "\n", "Given a list of cities and the distance between each pair of cities, the problem asks for the\n", "shortest route starting at the first city, visiting each other city exactly once, then returning\n", "to the first city. This problem is a generalization of the Hamiltonian path problem, one of Karp's\n", "21 NP-complete problems.\n", "\n", "### Random problem generator\n", "\n", "The class `TravelingSalesmanGenerator` can be used to generate random instances of this\n", "problem. Initially, the generator creates $n$ cities $(x_1,y_1),\\ldots,(x_n,y_n) \\in \\mathbb{R}^2$,\n", "where $n, x_i$ and $y_i$ are sampled independently from the provided probability distributions `n`,\n", "`x` and `y`. For each pair of cities $(i,j)$, the distance $d_{i,j}$ between them is set to:\n", "$$\n", " d_{i,j} = \\gamma_{i,j} \\sqrt{(x_i-x_j)^2 + (y_i - y_j)^2}\n", "$$\n", "where $\\gamma_{i,j}$ is sampled from the distribution `gamma`.\n", "\n", "If `fix_cities=True` is provided, the list of cities is kept the same for all generated instances.\n", "The $gamma$ values, and therefore also the distances, are still different.\n", "\n", "By default, all distances $d_{i,j}$ are rounded to the nearest integer. If `round=False`\n", "is provided, this rounding will be disabled.\n", "\n", "### Challenge A\n", "\n", "* Fixed list of 350 cities in the $[0, 1000]^2$ square\n", "* $\\gamma_{i,j} \\sim U(0.95, 1.05)$\n", "* 500 training instances, 50 test instances" ] }, { "cell_type": "code", "execution_count": null, "id": "6b2c4ff9", "metadata": {}, "outputs": [], "source": [ "TravelingSalesmanGenerator(\n", " x=uniform(loc=0.0, scale=1000.0),\n", " y=uniform(loc=0.0, scale=1000.0),\n", " n=randint(low=350, high=351),\n", " gamma=uniform(loc=0.95, scale=0.1),\n", " fix_cities=True,\n", " round=True,\n", ")" ] }, { "cell_type": "code", "execution_count": null, "id": "cc125860", "metadata": {}, "outputs": [], "source": [] } ], "metadata": { "kernelspec": { "display_name": "miplearn", "language": "python", "name": "miplearn" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.8.10" } }, "nbformat": 4, "nbformat_minor": 5 }