Home / Computer science / Traveling salesman problem (TSP) / Computation: Python, SAT, MTZ
Solution
Find a solution in the given time.
solver = cp.CpSolver()
solver.parameters.max_time_in_seconds = 60 * 1
result = solver.solve(model)
y = solver.objective_value
tour = sorted(range(len(t)), key=lambda i: solver.value(t[i]))
print(f"Result: {result}")
print(f"Distance: {y}")
print(f"Tour: {tour}")
Result: 2 Distance: 110370.0 Tour: [0, 22, 21, 20, 24, 23, 45, 44, 43, 47, 46, 68, 67, 69, 66, 49, 48, 54, 55, 56, 57, 58, 59, 40, 60, 61, 62, 63, 72, 71, 70, 64, 65, 50, 51, 52, 53, 41, 42, 27, 26, 25, 19, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 73, 14, 15, 16, 17, 36, 35, 37, 38, 39, 33, 34, 32, 31, 28, 29, 30, 18, 3, 2, 1, 74, 75]