From f4c29f4cc2dd961799857debbc0d447400693133 Mon Sep 17 00:00:00 2001 From: Aryan Tailor Date: Sun, 3 May 2026 00:09:39 +0530 Subject: [PATCH 1/2] 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 From 21b0795e86f78c59f82c04a07a54123701aae3c5 Mon Sep 17 00:00:00 2001 From: Aryan Tailor Date: Sun, 3 May 2026 00:25:26 +0530 Subject: [PATCH 2/2] Update simplex.py --- linear_programming/simplex.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/linear_programming/simplex.py b/linear_programming/simplex.py index 6762d4449506..835b42d4ce5e 100644 --- a/linear_programming/simplex.py +++ b/linear_programming/simplex.py @@ -302,10 +302,11 @@ def run_simplex(self) -> dict[Any, Any]: self.tableau = self.change_stage() else: self.tableau = self.pivot(row_idx, col_idx) - raise ValueError( + message = ( f"Simplex did not converge within {Tableau.maxiter} iterations. " "The problem may be cycling or unbounded." ) + raise ValueError(message) def interpret_tableau(self) -> dict[str, float]: """Given the final tableau, add the corresponding values of the basic