Skip to content

Commit

Permalink
Minor changes for rho updating. Not working well yet
Browse files Browse the repository at this point in the history
  • Loading branch information
bstellato committed Sep 10, 2017
1 parent f722678 commit e300cae
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 10 deletions.
27 changes: 18 additions & 9 deletions interfaces/python/modulepurepy/_osqp.py
Expand Up @@ -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
Expand Down Expand Up @@ -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 +
Expand Down Expand Up @@ -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)

Expand Down
2 changes: 1 addition & 1 deletion interfaces/python/tests/general/big_prob.py
Expand Up @@ -36,7 +36,7 @@
# rho=10.0
# q /= 100
# P *= 1000
# q *= 10000
q *= 10000


osqp_opts = {'rho': rho,
Expand Down

0 comments on commit e300cae

Please sign in to comment.