From f4c29f4cc2dd961799857debbc0d447400693133 Mon Sep 17 00:00:00 2001 From: Aryan Tailor Date: Sun, 3 May 2026 00:09:39 +0530 Subject: [PATCH] Handle non-convergence in Simplex method Raise ValueError if Simplex does not converge within max iterations. --- linear_programming/simplex.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/linear_programming/simplex.py b/linear_programming/simplex.py index a8affe1b72d2..6762d4449506 100644 --- a/linear_programming/simplex.py +++ b/linear_programming/simplex.py @@ -302,7 +302,10 @@ def run_simplex(self) -> dict[Any, Any]: self.tableau = self.change_stage() else: self.tableau = self.pivot(row_idx, col_idx) - return {} + raise ValueError( + f"Simplex did not converge within {Tableau.maxiter} iterations. " + "The problem may be cycling or unbounded." + ) def interpret_tableau(self) -> dict[str, float]: """Given the final tableau, add the corresponding values of the basic