from amplpy import AMPL

ampl = AMPL()
ampl.read("fractional2.mod")
ampl.option["solver"] = "highs"

LB, UB, EPS = 0.0, 1.0, 0.01
while True:
    theta = (UB + LB) / 2
    ampl.param["theta"] = theta
    ampl.solve(verbose=False)
    if ampl.solve_result == "solved":
        UB = theta
        best = (ampl.get_variable("x").value(),
                ampl.get_variable("y").value(),
                ampl.get_variable("z").value())
        if UB - LB <= EPS:
            break
    else:
        LB = theta

print("theta=", UB)
print("(x,y,z)=", best[0], best[1], best[2])
