I need to improve the efficiency of my code so I can create an Excel Spreadsheet and download it.
def find_pivot_largest_change(tableau):
M, N = tableau.shape
m = M-1 # Number of constraints
n = N-1 # Number of variables
# Largest Change Rule: find the column index that changes the objective function by the largest amount
s = np.argmin(tableau[0, 1:n+1])
delta_max = -np.inf
for j in range(1, n+1):
if tableau[0, j] < 0:
theta_star = min([tableau[i, 0] / tableau[i, j] for i in range(1, m+1) if tableau[i, j] > 0])
delta = -tableau[0, j] * theta_star
if delta > delta_max:
delta_max = delta
s = j
# Minimum ratio test plus Bland's rule:
# find the (first) row i minimizing b_i / a_{is}, a_{is} > 0
r = 0
theta_star = np.inf
for i in range(1, m+1):
if tableau[i, s] > 0:
if tableau[i, 0] / tableau[i, s] < theta_star:
r = i
theta_star = tableau[i, 0] / tableau[i, s]
return r, s