from newton_interior_points import mPI_Newton problem = 'adlittle' solution = 2.2549496316E+05 print('---------------------------------------------', 'Problema {}:'.format(problem), '---------------------------------------------', sep='\n') problem_path = 'test_problems/{}.mat'.format(problem) file = sio.loadmat(problem_path) A = file['A'] b = file['b'].flatten() c = file['c'].flatten() A = scipy.sparse.csr_matrix.todense(A) b = b.reshape(b.shape[0], 1) c = c.reshape(c.shape[0], 1) ans = mPI_Newton(A, b, c, warm_initial_solution=False ) #See also with warm_initial_solution = True :) print('- - - - - - - - - - - - - - - - - - - - - - -', 'Nuestra solución: {} '.format(ans['óptimo']), 'Solución oficial: {}'.format(solution), 'Número de iteraciones: {}'.format(ans['iter']), 'Valor de ||diag(x)z||_inf: {}'.format( norm(np.dot(np.diag(ans['x'].T[0]), ans['z']), np.inf)), '- - - - - - - - - - - - - - - - - - - - - - -\n', sep='\n')
c = np.concatenate((c, np.zeros(m))) return (A, b, c) m = [10, 12, 14, 16] for i in m: A, b, c = genera_klee_minty(i) b = b.reshape(b.shape[0], 1) c = c.reshape(c.shape[0], 1) ans = mPI_Newton(A, b, c, warm_initial_solution=True, show_iteration_and_norm=False) print('-----------------------------------------------------------------') print('Klee-Minty con m =', i, "(iniciando con una 'warm solution')") print('Nuestra solución:', ans['óptimo']) print('Solución teorica:', -((2**i) - 1)) print('Número de iteraciones:', ans['iter']) ans = mPI_Newton(A, b, c, show_iteration_and_norm=False) print('\nKlee-Minty con m =', i, "(sin iniciar con una 'warm solution')") print('Nuestra solución:', ans['óptimo']) print('Solución teorica:', -((2**i) - 1)) print('Número de iteraciones:', ans['iter'])