Home / Computer science / Traveling salesman problem (TSP) / Computation: Python, SAT + NN, permutation
Auxiliary variables: Subscripts
# Create auxiliary variables for subscripts with flattened distance indexes.
s = [model.new_int_var(0, (n * n) - 1, f"s_{i}") for i in range(n)]
# Constrain the values of the subscripts.
for i in range(n):
j = i + 1 if i < n - 1 else 0 # close the cycle
model.add(s[i] == x[i] * n + x[j])