Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/lucidfrontier45/tsp_mip_example
Solve TSP as MIP with Rust
https://github.com/lucidfrontier45/tsp_mip_example
Last synced: about 4 hours ago
JSON representation
Solve TSP as MIP with Rust
- Host: GitHub
- URL: https://github.com/lucidfrontier45/tsp_mip_example
- Owner: lucidfrontier45
- License: apache-2.0
- Created: 2024-09-17T10:07:04.000Z (about 2 months ago)
- Default Branch: main
- Last Pushed: 2024-09-18T04:58:17.000Z (about 2 months ago)
- Last Synced: 2024-09-18T14:15:24.065Z (about 2 months ago)
- Language: Rust
- Size: 18.6 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Example program to solve TSP as mixed integer programming
## How to run
The project is managed by uv.
You can use the following command to automatically download dependencies and run the main program.```sh
uv run main.py berlin52.csv
```CP-SAT is used as the default solver. You can use `--solver` option to choose other solvers e.g. 'highs' and 'scip'.
## Problem structure
- $i$ : index of city
- $d_{ij}$ : distance between cities $i$ and $j$
- $x_{ij}$ : binary decision variable, indicates if edge between $i$ and $j$ is used or not.
- $u_i$ : integer auxiliary variable, indicates thata $i$ is visited at $u_i$th order.
- $D(x) = \sum_{i,j}d_{ij}x_{ij}$ : objective function, total distance
- $X_{i.} = \sum_j x_{ij} = 1$ : constraint, there must be one edge from $i$
- $X_{.j} = \sum_i x_{ij} = 1$ : constraint, there must be one edge to $j$
- if $x_{ij} = 1$ then $u_i - u_j = -1$ otherwise $u_i - u_j \leq M$, wher $M$ is a sufficiently large number. In this case, $M$ can be set to $N-1$ where $N$ is total number of cities. -> $u_i - u_j \leq (1-x_{ij})N -1$. This constraint, known as the Miller–Tucker–Zemlin (MTZ) formulation, is used for sub tour elimination.