import math, random
from amplpy import AMPL

def make_data(n):
    V = list(range(1, n+1))
    px = {i: random.random() for i in V}
    py = {i: random.random() for i in V}
    c = {(i,j): math.hypot(px[i]-px[j], py[i]-py[j])
         for i in V for j in V if i != j}
    return n, c

def load(mod, n, c):
    ampl = AMPL()
    ampl.read(mod)
    ampl.param["n"] = n
    ampl.param["c"] = c
    ampl.option["solver"] = "highs"
    return ampl

random.seed(1)
n, c = make_data(10)
for mod in ["mtz.mod", "scf.mod", "mcf.mod"]:
    a = load(mod, n, c)
    a.solve(verbose=False)
    print("%-9s %-8s %.4f" % (mod, a.solve_result, a.get_objective("Length").value()))
