"""実行不可能・非有界の判定（1.9 節）."""
from amplpy import AMPL

ampl = AMPL()
ampl.read("lo_infeas.mod")
ampl.option["solver"] = "highs"
ampl.solve(verbose=False)

if ampl.solve_result == "solved":
    print("Opt. Value=", ampl.get_objective("Obj").value())
    print(ampl.get_variable("x1").value(), ampl.get_variable("x2").value())
elif ampl.solve_result == "infeasible":
    print("Infeasible")
elif ampl.solve_result == "unbounded":
    # 端線だけを検出して非有界と報告するソルバーがあるので、
    # 目的関数を定数 0 に取り替えて解き直し、実行可能性そのものを確かめる。
    ampl.eval("objective Zero;")
    ampl.solve(verbose=False)
    print("Unbounded" if ampl.solve_result == "solved" else "Infeasible")
else:
    print("Solver finished with:", ampl.solve_result)
