@@ -163,14 +163,9 @@ def linprog_simplex(c, A_ub=np.empty((0, 0)), b_ub=np.empty((0,)),
163163
164164 # Phase 1
165165 success , status , num_iter_1 = \
166- solve_tableau (tableau , basis , max_iter , skip_aux = False ,
167- piv_options = piv_options )
166+ solve_phase_1 (tableau , basis , max_iter , piv_options = piv_options )
168167 num_iter += num_iter_1
169- if not success : # max_iter exceeded
170- return SimplexResult (x , lambd , fun , success , status , num_iter )
171- if tableau [- 1 , - 1 ] > piv_options .fea_tol : # Infeasible
172- success = False
173- status = 2
168+ if not success :
174169 return SimplexResult (x , lambd , fun , success , status , num_iter )
175170
176171 # Modify the criterion row for Phase 2
@@ -442,6 +437,50 @@ def solve_tableau(tableau, basis, max_iter=10**6, skip_aux=True,
442437 return success , status , num_iter
443438
444439
440+ @jit (nopython = True , cache = True )
441+ def solve_phase_1 (tableau , basis , max_iter = 10 ** 6 , piv_options = PivOptions ()):
442+ """
443+ Perform the simplex algorithm for Phase 1 on a given tableau in
444+ canonical form, by calling `solve_tableau` with `skip_aux=False`.
445+
446+ Parameters
447+ ----------
448+ See `solve_tableau`.
449+
450+ Returns
451+ -------
452+ See `solve_tableau`.
453+
454+ """
455+ L = tableau .shape [0 ] - 1
456+ nm = tableau .shape [1 ] - (L + 1 ) # n + m
457+
458+ success , status , num_iter_1 = \
459+ solve_tableau (tableau , basis , max_iter , skip_aux = False ,
460+ piv_options = piv_options )
461+
462+ if not success : # max_iter exceeded
463+ return success , status , num_iter_1
464+ if tableau [- 1 , - 1 ] > piv_options .fea_tol : # Infeasible
465+ success = False
466+ status = 2
467+ return success , status , num_iter_1
468+
469+ # Check artifial variables have been eliminated
470+ tol_piv = piv_options .tol_piv
471+ for i in range (L ):
472+ if basis [i ] >= nm : # Artifial variable not eliminated
473+ for j in range (nm ):
474+ if tableau [i , j ] < - tol_piv or \
475+ tableau [i , j ] > tol_piv : # Treated nonzero
476+ _pivoting (tableau , j , i )
477+ basis [i ] = j
478+ num_iter_1 += 1
479+ break
480+
481+ return success , status , num_iter_1
482+
483+
445484@jit (nopython = True , cache = True )
446485def _pivot_col (tableau , skip_aux , piv_options ):
447486 """
0 commit comments