Skip to content

Commit f4c29f4

Browse files
authored
Handle non-convergence in Simplex method
Raise ValueError if Simplex does not converge within max iterations.
1 parent 791deb4 commit f4c29f4

1 file changed

Lines changed: 4 additions & 1 deletion

File tree

linear_programming/simplex.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -302,7 +302,10 @@ def run_simplex(self) -> dict[Any, Any]:
302302
self.tableau = self.change_stage()
303303
else:
304304
self.tableau = self.pivot(row_idx, col_idx)
305-
return {}
305+
raise ValueError(
306+
f"Simplex did not converge within {Tableau.maxiter} iterations. "
307+
"The problem may be cycling or unbounded."
308+
)
306309

307310
def interpret_tableau(self) -> dict[str, float]:
308311
"""Given the final tableau, add the corresponding values of the basic

0 commit comments

Comments
 (0)