Home / Computer science / Traveling salesman problem (TSP) / Computation: Python, SAT, MTZ (with NN)
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: 108234.0 Tour: [0, 22, 21, 20, 24, 23, 45, 44, 43, 47, 46, 68, 67, 69, 66, 49, 48, 50, 65, 64, 70, 71, 72, 63, 62, 61, 60, 40, 59, 58, 57, 56, 55, 54, 51, 52, 53, 41, 42, 27, 26, 25, 28, 29, 19, 18, 30, 31, 32, 34, 33, 39, 38, 37, 35, 36, 17, 16, 15, 14, 73, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 74, 75]