from input_data import input_data from MehrotraMethod import mehrotra from MehrotraMethod2 import mehrotra2 from LPFMethod_PC import longpathPC from matplotlib.ticker import NullFormatter # useful for `logit` scale import pandas as pd # Export to excel import matplotlib.pyplot as plt # Create graphics from mpl_toolkits.mplot3d import Axes3D ''' _PLOT THE PATHs_ ''' # Recall lp istance with dimension 2 (A, b, c) = input_data(0) xm, sm, um = mehrotra2(A, b, c) #um = pd.DataFrame(um, columns = ['it', 'g', 'Current x', 'Current s', 'rb', 'rc']) xl, sl, ul = longpathPC(A, b, c) #ul = pd.DataFrame(ul, columns = ['it', 'g', 'Current x', 'Current s', 'rb', 'rc']) # Create 3d point x*s for mehrotra x1 = [] y1 = [] z1 = [] for i in range(len(um)): g = um[i][2] * um[i][3] x1.append(g[0].copy()) y1.append(g[1].copy()) z1.append(g[2].copy())
""" Affine """ # IP = 1 doesn't work x, s, u = affine(A, b, c, ip=IP) dfu = cent_meas(x, u, label='Affine', plot=0) # 29 it """ LPF1 """ # 307 iterations x, s, u = longpath1(A, b, c, c_form=0, info=1, ip=IP) dfu = cent_meas(x, u, label='LPF', plot=0) """ LPF2 """ # 16 it x, s, u, sigma_l2 = longpath2(A, b, c, c_form=0, info=1, ip=1) """ LPF predictor corrector """ # 41 iterations / 17 iterations ip = 1 x_pc, s_pc, u_pc, sigma_pc = longpathPC(A, b, c, c_form=0, info=0) x_pc, s_pc, u_pc, sigma_pc = longpathPC(A, b, c, c_form=0, info=0, ip=1) dfpc = cent_meas(x_pc, u_pc, label='LPF PC', plot=0) """ Mehrotra """ # 8 iterations x_m, s_m, u_m, sigma_m = mehrotra2(A, b, c, c_form=0, info=1) # Mehrotra1 doesn't work x_m, s_m, u_m, sigma_m1 = mehrotra2(A, b, c, c_form=0, info=1, ip=1) # Mehrotra1 doesn't work dfm = cent_meas(x_m, u_m, label='Mehrotra', plot=0) " Recall the simplex method " #P, u = SimplexMethod(A, b, c, c_form = 0, rule = 0, max_it = 200)
ax = fig.gca(projection='3d') #plt.xscale('logit') #plt.yscale('logit') ax.plot_trisurf(x, y, z, linewidth=0.2, cmap='viridis') ax.set_xlabel('x1s1') ax.set_ylabel('x2s2') ax.set_zlabel('x3s3') w = [] (A, b, c) = input_data(0) x, s, u = mehrotra2(A, b, c) x1, s1, u1 = longpath1(A, b, c) # Plot Mehrotra iterations for i in range(1, len(u)): t = u[i][2] * u[i][3] w.append(t.copy()) ax.scatter(t[0], t[1], t[2], linewidth=2, zorder=1, lw=3, linestyle='dashed', c="red") ax.text(t[0], t[1], t[2], "xs{}".format(len(u) - i))
""" it = [] B = [] a = [] Y = [] W = [] Z = [] O = [] P = [] q = np.log(2) for i in range(29): print(i) if not i in {4, 20, 23, 25}: (A, b, c) = input_data(i) x, s, u, sigma_m = mehrotra2(A, b, c, info=1) # x, v = SimplexMethod(A, b, c, rule = 0) x, s, o = longpath1(A, b, c, c_form=0, info=1, ip=0) x, s, p, sigma_2 = longpath2(A, b, c, c_form=0, info=1) x, s, z, sigma_pc = longpathPC(A, b, c, info=1) B.append(np.log(len(u) - 1)) # W.append(np.log(len(v))) Z.append(np.log(len(z) - 1)) O.append(np.log(len(o) - 1)) P.append(np.log(len(p) - 1)) r = sum(A.shape) a.append([q, np.log(r)]) Y.append(np.log(r)) it.append(i) for i in range(29, 34): # we compute the models