import itertools
n = 3
ampl.param["n"] = n
solution = [
[1, 2, 3, 4, 5, 6, 7, 8, 9],
[4, 5, 6, 7, 8, 9, 1, 2, 3],
[7, 8, 9, 1, 2, 3, 4, 5, 6],
[2, 3, 1, 5, 6, 4, 8, 9, 7],
[5, 6, 4, 8, 9, 7, 2, 3, 1],
[8, 9, 7, 2, 3, 1, 5, 6, 4],
[3, 1, 2, 6, 4, 5, 9, 7, 8],
[6, 4, 5, 9, 7, 8, 3, 1, 2],
[9, 7, 8, 3, 1, 2, 6, 4, 5],
]
rows = range(1, n * n + 1) # 1..n^2
ampl.param["T"] = {
(i, j): solution[i - 1][j - 1] for i, j in itertools.product(rows, rows)
}
ampl.option["solver"] = "highs"
ampl.solve()