def admm_phase2(x0, prob, rho, tol=1e-2, num_iters=1000, viol_lim=1e4):
logging.info("Starting ADMM phase 2 with rho %.3f", rho)
bestx = np.copy(x0)
z = np.copy(x0)
xs = [np.copy(x0) for i in range(prob.m)]
us = [np.zeros(prob.n) for i in range(prob.m)]
if prob.rho != rho:
prob.rho = rho
zlhs = 2*(prob.f0.P + rho*prob.m*sp.identity(prob.n)).tocsc()
prob.z_solver = SLA.factorized(zlhs)
last_z = None
for t in range(num_iters):
rhs = 2*rho*(sum(xs)-sum(us)) - prob.f0.qarray
z = prob.z_solver(rhs)
# TODO: parallel x/u-updates
for i in range(prob.m):
xs[i] = onecons_qcqp(z + us[i], prob.fi(i))
for i in range(prob.m):
us[i] += z - xs[i]
# TODO: termination condition
if last_z is not None and LA.norm(last_z - z) < tol:
break
last_z = z
maxviol = max(prob.violations(z))
logging.info("Iteration %d, violation %.3f", t, maxviol)
if maxviol > viol_lim: break
bestx = np.copy(prob.better(z, bestx))
return bestx
评论列表
文章目录