Skip to content

Commit

Permalink
Add error if no valid solution is found
Browse files Browse the repository at this point in the history
  • Loading branch information
ExcaliburZero committed Jul 7, 2024
1 parent 83b2a63 commit 78848fc
Showing 1 changed file with 14 additions and 5 deletions.
19 changes: 14 additions & 5 deletions ttdlgc/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import logging
import pathlib
import sys

import pulp
import typer
Expand Down Expand Up @@ -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",
Expand All @@ -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:")
Expand All @@ -72,7 +82,8 @@ def solve(

logging.info(f"Final LGC = {simulation.lgc}")

return SUCCESS
if failed:
sys.exit(1)


@app.command()
Expand All @@ -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",
Expand All @@ -104,8 +115,6 @@ def simulate(

logging.info(f"Final LGC = {simulation.lgc}")

return SUCCESS


def main_without_args() -> Any:
return app()

0 comments on commit 78848fc

Please sign in to comment.