How to warm start convex Quadratic Programs after changing objective function
AnsweredI am trying to use gurobipy to solve lasso-like problems. After solving the problem, I want to change one term in the linear part of the objective function and resolve using warm starts. I tried to do that by saving the VBasis, and CBasis, and then setting then after updating the model. However, Gurobi still does not use warm start in the resolve. I am wondering if am not doing things correctly, or is it just the case that warm start is not possible after changing the objective function?
def boxed_lasso_resolve(X, y, c, M, k):
n, p = X.shape
XtX = X.T @ X
ytX = y.T @ X
LASSO = gp.Model()
beta = LASSO.addMVar(p, lb=-gp.GRB.INFINITY)
x = LASSO.addVars(p)
LASSO.setObjective(0.5 * beta.T @ XtX @ beta - ytX @ beta + 0.5 * np.dot(y, y) + gp.quicksum(c[i]*x[i] for i in range(p)), sense=gp.GRB.MINIMIZE)
# constraints x[i]=|beta[i]|
c1 = LASSO.addConstrs(-beta[j] <= x[j] for j in range(p))
c2 = LASSO.addConstrs(beta[j] <= x[j] for j in range(p))
# constraints -M<=beta[i]<=M
c3 = LASSO.addConstrs(-beta[j] <= M for j in range(p))
c4 = LASSO.addConstrs(beta[j] <= M for j in range(p))
LASSO.Params.Method = 0 # 0=primal simplex, 1=dual simplex
LASSO.optimize()
# save VBasis
VB_beta = beta.VBasis
VB_x = [x[i].VBasis for i in range(p)]
# save CBasis
CB_c1 = [c1[i].CBasis for i in range(p)]
CB_c2 = [c2[i].CBasis for i in range(p)]
CB_c3 = [c3[i].CBasis for i in range(p)]
CB_c4 = [c4[i].CBasis for i in range(p)]
# modify objective
c[k] = 0
LASSO.setObjective(0.5 * beta.T @ XtX @ beta - ytX @ beta + 0.5 * np.dot(y, y) + gp.quicksum(c[i] * x[i] for i in range(p)), sense=gp.GRB.MINIMIZE)
# load VBasis
beta.VBasis = VB_beta
for i in range(p):
x[i].VBasis = VB_x[i]
# load CBasis
for i in range(p):
c1[i].CBasis = CB_c1[i]
c2[i].CBasis = CB_c2[i]
c3[i].CBasis = CB_c3[i]
c4[i].CBasis = CB_c4[i]
LASSO.setParam("LPWarmStart", 1)
LASSO.update()
LASSO.optimize()
-
Hi Ruofeng,
I suspect the issue is the update() causing the CBasis and VBasis to be discarded. You can test this theory by inserting `print(LASSO.VBasis)` after the update() call.
Can you reposition the update() after setting the new objective, but before setting the basis information and see if it resolves your issue?
- Riley
0 -
This solves my problem! Thank you very much!
0
Please sign in to leave a comment.
Comments
2 comments