Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

parameter change not detected #234

Closed
stumarcus314 opened this issue Sep 14, 2018 · 1 comment · Fixed by #478
Closed

parameter change not detected #234

stumarcus314 opened this issue Sep 14, 2018 · 1 comment · Fixed by #478

Comments

@stumarcus314
Copy link

stumarcus314 commented Sep 14, 2018

I am trying to solve two problems, one after the other, by varying a single parameter p. But, according to Convex.jl, the solution to the second problem is the same as the first, which I know should not be the case, so Convex.jl is not detecting the parameter change when it solves the problem the second time. That is, in the two problems below, Convex.jl reports the solution to be 4; but for the second problem the solution should be 5.

lam = Convex.Variable(9,1)
p = 4 # p is a parameter.
convex_problem = minimize( p*sum(lam)+p , [lam >= 0])
Convex.solve!(convex_problem,GurobiSolver())
println("p: $p. Convex Status: $(convex_problem.status). Objective Value of Lagrangian Relaxation: $(convex_problem.optval).")
p += 1 # Increment the parameter p.
Convex.solve!(convex_problem,GurobiSolver(),warmstart=true)
println("p: $p. Convex Status: $(convex_problem.status). Objective Value of Lagrangian Relaxation: $(convex_problem.optval).")

@ericphanson
Copy link
Collaborator

The problem is that in the call minimize( p*sum(lam)+p , [lam >= 0]), when p = 4 is just a value, internally Convex forgets that name p and simply uses the value 4 in its formulation of the problem. Instead, you can make a variable p, and then fix! it's value. In your case, that would be

using Convex, SCS
lam = Convex.Variable(9,1)
p = Variable()
fix!(p, 4)
convex_problem = minimize( p*sum(lam)+p , [lam >= 0])
Convex.solve!(convex_problem,SCSSolver(verbose=0))
println("p: $p. Convex Status: $(convex_problem.status). Objective Value of Lagrangian Relaxation: $(convex_problem.optval).")
fix!(p,5)
Convex.solve!(convex_problem,SCSSolver(verbose=0),warmstart=true)
println("p: $p. Convex Status: $(convex_problem.status). Objective Value of Lagrangian Relaxation: $(convex_problem.optval).")

(I used SCS instead of Gurobi, since I don't have Gurobi installed on this computer, but it should be the same).

I believe the problem is with the documentation. The example in https://convexjl.readthedocs.io/en/stable/advanced.html#warmstarting is exactly like your problem, and it incorrectly does not set lambda to be a parameter. In that case, one needs to use

lambda = Variable(Positive())

instead of lambda = Variable() since the problem is only DCP when lambda > 0, and fix! does not update the sign of the variable (which maybe should be changed).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
2 participants