x, s, u = longpath1(A, b, c, c_form = 1, info = 1, ip = 0) dful = cent_meas(x, u, label = 'LPF', plot = 0) """ LPF2 """ # 13 it x, s, u, sigma_l2 = longpath2(A, b, c, c_form = 1, info = 1, ip = 1) dfc = cent_meas(x, u, label = 'LPF2', plot = 0) """ LPF predictor corrector """ # 14 iterations x, s, u, sigma_pc = longpathPC(A, b, c, c_form = 1, info = 1, ip = 0) dfpc = cent_meas(x, u, label = 'LPF PC', plot = 0) """ Mehrotra """ # 8 iterations x, s, u, sigma_m = mehrotra(A, b, c, c_form = 1, info = 1, ip = 1) dfm = cent_meas(x, u, label = 'Mehrotra', plot = 0) """ Recall the simplex method """ (A2, b2, c2) = ssteel2() P, u = SimplexMethod(A, b, c, rule = 1, c_form = 1) # 17!!! # Start phase II #Iteration: 12 #Current x: [ 75. 250. 568. 80.5 ... 24. 0. 0. 0. ] #P2, u2 = SimplexMethodI(A, b, c, rule = 0, c_form = 1) # 0 it # P, u = SimplexMethod(A2, b2, c2, rule = 0)
if __name__ == "__main__": (A, b, c) = tubprod() # canonical form! """ Affine """ # 29 it x, s, u = affine(A, b, c, ip=1) dfu = cent_meas(x, u, label='Affine', plot=0) """ LPF1 """ # IT DOESN'T WORK!!! # x_l, s_l, u_l = longpath1(A, b, c, info = 1, ip = 1) """ LPF2 """ # 21 it x, s, u, sigma_l2 = longpath2(A, b, c, info=1, ip=0) dfc = cent_meas(x, u, label='LPF2', plot=0) """ LPF predictor corrector """ # 20 iterations x, s, u, sigma_pc = longpathPC(A, b, c, info=1, ip=1) dfpc = cent_meas(x, u, label='LPF PC', plot=0) """ Mehrotra """ # 10 iterations start = time.time() x_m, s_m, u_m, sigma_m = mehrotra(A, b, c, info=1, ip=1) dfm = cent_meas(x_m, u_m, label='Mehrotra', plot=0) plt.plot(sigma_m) " Recall the simplex method " #P, u = SimplexMethod(A, b, c, rule = 1) # 51 it # it doesn't work with rule = 0 #dfu = pd.DataFrame(u) x = linprog(c, method='simplex', A_ub=A, b_ub=b) # Exact solution
time_lpf2 = time.time()-start print('Time of the algorithm is {} \n\n'.format("%2.2e"%time_lpf2)) dfc = cent_meas(x_c, u_c, label = 'LPF2', plot= 0) """ LPF predictor corrector """ # 12 iterations/ 14 iteraions start = time.time() x_pc, s_pc, u_pc, sigma_pc = longpathPC(A, b, c, c_form = 1, info = 1, ip = 0) time_lpfpc = time.time()-start print('Time of the algorithm is {} \n\n'.format("%2.2e"%time_lpfpc)) dfpc = cent_meas(x_pc, u_pc, label = 'LPF PC', plot = 0) """ Mehrotra """ # 7 iterations start = time.time() x_m, s_m, u_m, sigma_m = mehrotra(A, b, c, c_form = 1, info = 1, ip = 0) time_mer = time.time()-start print('Time of the algorithm is {} \n\n'.format("%2.2e"%time_mer)) dfm = cent_meas(x_m, u_m, label = 'Mehrotra', plot = 0) " Recall the simplex method " #P, u = SimplexMethod(A, b, c, rule = 1, c_form = 1) # BAD x = linprog(c, A_eq = A, b_eq = b) # Exact solution x = linprog(c, A, b) # BAD #plt.show()
For every method we obtain the optimal vector (x,s), a dataframe with all sequences time of the algorithm ''' if __name__ == "__main__": (A, b, c) = forest() # already in standard form IP = 0 """ Affine """ # 29 it x, s, u = affine(A, b, -c, c_form=1, ip=IP) dfu = cent_meas(x, u, label='Affine', plot=0) """ LPF1 """ # 183 it x, s, u = longpath1(A, b, -c, c_form=1, info=1, ip=IP) dful = cent_meas(x, u, label='LPF', plot=0) """ LPF2 """ # 15 it x_c, s_c, u_c, sigma_l2 = longpath2(A, b, -c, c_form=1, info=1, ip=IP) dfc = cent_meas(x_c, u_c, label='LPF2', plot=0) """ LPF predictor corrector """ # 19 iterations x, s, u, sigma_pc = longpathPC(A, b, -c, c_form=1, info=1, ip=IP) dfpc = cent_meas(x, u, label='LPF PC', plot=0) """ Mehrotra """ # 9 iterations x, s, u, sigma = mehrotra(A, b, -c, c_form=1, info=1, ip=IP) dfm = cent_meas(x, u, label='Mehrotra', plot=0) P1, u = SimplexMethod(A, b, -c, rule=0, c_form=1) # 45 iterations
# L2 regression of |Ax -b|_2 for LPF2 p = np.dot(np.linalg.pinv(A), P) y2 = p[0]*x + p[1] plt.plot(x, y2, c = 'blue', linewidth = 2) # L2 regression of |Ax -b|_2 for LPF pc t = np.dot(np.linalg.pinv(A), Z) yl = t[0]*x + t[1] plt.plot(x,yl, c = 'cyan', linewidth = 2) # L2 regression of |Ax -b|_2 for Simplex #p = np.dot(np.linalg.pinv(A), W) #ys = p[0]*x + p[1] #plt.plot(x,ys, c = 'red', linewidth = 2) #x = [-np.Inf, np.Inf] #%% # L1 regression of the function |Ax - b| r_A, c_A = np.shape(A) A1 = np.hstack((A, -np.identity(r_A))) A2 = np.hstack((-A, -np.identity(r_A))) A = np.vstack((A1, A2)) b = np.concatenate((-B, B)) c = np.concatenate((np.zeros(c_A),np.ones(r_A))) xm, sm, um, sigmam = mehrotra(A, b, c)