From e300cae3bec902200b5630d1ff49a9fb18224572 Mon Sep 17 00:00:00 2001 From: Bartolomeo Stellato Date: Sun, 10 Sep 2017 09:38:59 +0100 Subject: [PATCH] Minor changes for rho updating. Not working well yet --- interfaces/python/modulepurepy/_osqp.py | 27 ++++++++++++++------- interfaces/python/tests/general/big_prob.py | 2 +- 2 files changed, 19 insertions(+), 10 deletions(-) diff --git a/interfaces/python/modulepurepy/_osqp.py b/interfaces/python/modulepurepy/_osqp.py index f7ba7ab6b..0091615ed 100644 --- a/interfaces/python/modulepurepy/_osqp.py +++ b/interfaces/python/modulepurepy/_osqp.py @@ -1109,6 +1109,7 @@ def solve(self): # Initialize variables for printing # cos_vec = [] rho_new = self.work.settings.rho + res_ratio_vec = [] ratio_error = 0.0 ratio_error_int = 0.0 Kp = 0.01 @@ -1166,17 +1167,19 @@ def solve(self): dua_res = self.compute_dua_res(self.work.x, self.work.z, 0) / \ dua_res_normaliz ratio_error_prev = ratio_error - ratio_error = pri_res / dua_res - 1 - ratio_error_deriv = ratio_error - ratio_error_prev - ratio_error_int = ratio_error_int + ratio_error + res_ratio = pri_res / dua_res + res_ratio_vec.append(res_ratio) + # ratio_error = ratio_res - 1 + # ratio_error_deriv = ratio_error - ratio_error_prev + # ratio_error_int = ratio_error_int + ratio_error # Update rule - if iter % 100 == 0: - rho_new *= np.sqrt(pri_res / dua_res) - rho_new = np.minimum(np.maximum(rho_new, 1e-06), 1e06) - print("rho = %.2e | pri_res = %.2e, dua_res = %.2e" % - (rho_new, pri_res, dua_res)) - self.update_rho(rho_new) + # if iter % 100 == 0: + # rho_new *= np.sqrt(pri_res / dua_res) + # rho_new = np.minimum(np.maximum(rho_new, 1e-06), 1e06) + # print("rho = %.2e | pri_res = %.2e, dua_res = %.2e" % + # (rho_new, pri_res, dua_res)) + # self.update_rho(rho_new) # PID controller # rho_new = np.exp(Kp * ratio_error + @@ -1275,6 +1278,12 @@ def solve(self): # plt.plot(cos_vec) # plt.show(block=False) + # Plot residual ratio + import matplotlib.pylab as plt + plt.figure(0) + plt.semilogy(res_ratio_vec) + plt.show(block=False) + # Store results structure return results(self.work.solution, self.work.info) diff --git a/interfaces/python/tests/general/big_prob.py b/interfaces/python/tests/general/big_prob.py index 20888177c..87bc698dc 100644 --- a/interfaces/python/tests/general/big_prob.py +++ b/interfaces/python/tests/general/big_prob.py @@ -36,7 +36,7 @@ # rho=10.0 # q /= 100 # P *= 1000 -# q *= 10000 +q *= 10000 osqp_opts = {'rho': rho,