diff --git a/ttdlgc/main.py b/ttdlgc/main.py index 7797baa..972331a 100644 --- a/ttdlgc/main.py +++ b/ttdlgc/main.py @@ -2,6 +2,7 @@ import logging import pathlib +import sys import pulp import typer @@ -30,7 +31,9 @@ def solve( Optional[list[Constraint]], typer.Option(help="Constraints to add to the MILP.") ] = None, verbose: bool = False, -) -> int: +) -> None: + failed = False + logging.basicConfig( level=logging.DEBUG if verbose else logging.INFO, format="%(levelname)s> %(message)s", @@ -53,6 +56,13 @@ def solve( for vairable in problem.variables(): logging.debug(f"{vairable} = {vairable.varValue}") + logging.warn(f"{problem.status}") + if problem.status < 0: + logging.error("Failed to create a solution that satisfies all constraints.") + logging.error("The following is the solver's best attempt solution.") + + failed = True + solution = extract_solution(events, problem) logging.info("===============") logging.info("Choices:") @@ -72,7 +82,8 @@ def solve( logging.info(f"Final LGC = {simulation.lgc}") - return SUCCESS + if failed: + sys.exit(1) @app.command() @@ -86,7 +97,7 @@ def simulate( typer.Option(help="Filepath to CSV file of choices to load as input."), ], verbose: bool = False, -) -> int: +) -> None: logging.basicConfig( level=logging.DEBUG if verbose else logging.INFO, format="%(levelname)s> %(message)s", @@ -104,8 +115,6 @@ def simulate( logging.info(f"Final LGC = {simulation.lgc}") - return SUCCESS - def main_without_args() -> Any: return app()