import math, random
from amplpy import AMPL

random.seed(3)
n = 8
V = list(range(1, n+1))
px = {i: random.random()*100 for i in V}
py = {i: random.random()*100 for i in V}
c = {(i,j): round(math.hypot(px[i]-px[j], py[i]-py[j]), 1)
     for i in V for j in V if i != j}
e = {1: 0}; l = {1: 1000}
for i in V[1:]:
    e[i] = random.randint(0, 200)
    l[i] = e[i] + random.randint(200, 600)

for mod, has_u in [("mtz2tw.mod", True), ("tsptw2.mod", True)]:
    a = AMPL(); a.read(mod)
    a.param["n"] = n; a.param["c"] = c; a.param["e"] = e; a.param["l"] = l
    a.option["solver"] = "highs"
    a.solve(verbose=False)
    print("%-11s %-9s %s" % (mod, a.solve_result,
          round(a.get_objective("Length").value(), 2) if a.solve_result=="solved" else "-"))
