From 70c78680162e0f014f668e849b5591dc8b99eb85 Mon Sep 17 00:00:00 2001 From: MiniMax Agent Date: Mon, 27 Apr 2026 16:21:58 +0800 Subject: [PATCH] fix(simplex): raise ValueError instead of returning empty dict when max iterations reached Fixes #14584 The run_simplex() method now raises a descriptive ValueError when the maximum iteration limit (Tableau.maxiter) is reached, instead of silently returning an empty dict. This allows callers to distinguish between a converging solution and a cycling/unbounded problem. --- linear_programming/simplex.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/linear_programming/simplex.py b/linear_programming/simplex.py index a8affe1b72d2..e2557c1303dd 100644 --- a/linear_programming/simplex.py +++ b/linear_programming/simplex.py @@ -302,7 +302,13 @@ def run_simplex(self) -> dict[Any, Any]: self.tableau = self.change_stage() else: self.tableau = self.pivot(row_idx, col_idx) - return {} + + max_iterations = Tableau.maxiter + raise ValueError( + "Simplex did not converge within " + + str(max_iterations) + + " 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