"""Solve an LP file through the CLI backend from Python."""

from pathlib import Path

from alleria import solve_file


path = Path(__file__).with_name("model.lp")
result = solve_file(
    path, backend="cli", preset="exact", include_primal=True
)
print(f"status: {result.status}")
if result.status != "optimal" or result.incumbent_primal is None:
    raise RuntimeError("This small example should have an optimal solution.")
print(f"objective: {result.objective:g}")
# File parsers can reorder columns. Pair values with the returned names.
solution = dict(zip(result.column_names, result.incumbent_primal))
for name in sorted(solution):
    print(f"{name}: {solution[name]:g}")
