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

Quadratics as NLconstraints #1870

Closed
coreysharris opened this issue Feb 18, 2019 · 3 comments
Closed

Quadratics as NLconstraints #1870

coreysharris opened this issue Feb 18, 2019 · 3 comments
Labels
Type: Error Messages Can be fixed with better error message

Comments

@coreysharris
Copy link
Contributor

coreysharris commented Feb 18, 2019

(JuMP v18.5)

I am trying to solve a MIQCP with Bonmin. The problem has several quadratic constraints, but JuMP tells me that I can not use @constraint because

ERROR: LoadError: Solver does not support quadratic constraints

If I enter the quadratic expression "by hand", I can get it to work. Like so:

using JuMP, AmplNLWriter
m = Model(solver=AmplNLSolver("bonmin"))

@variable(m, a, Int)
@variable(m, b, Int)
@variable(m, s >= 0 )
@variable(m, t >= 0 )

@NLconstraint(m, 2*x+(a+b)*y >= 0)

But I actually I have an array of linear forms in a and b, and I'd like to create many constraints from them.

My first try

M = [2 a-b; a+b 3]
v = [s t]

for j = 1:2
    @NLconstraint(m, sum(M[i,j]*v[i] for i=1:2) == 0)
end

fails at the @NLconstraint: Unexpected object 2 in nonlinear expression. Ok, so I use the @NLexpression macro. This fails on the first line (same error).

M = @NLexpression(m, [i=1:2,j=1:2], [2 a-b; a+b 3][i,j])
v = @NLexpression(m, [i=1:2], [s t][i])

for j = 1:2
    @NLconstraint(m, sum(M[i,j]*v[i] for i=1:2) == 0)
end

What am I doing wrong?

@odow
Copy link
Member

odow commented Feb 18, 2019

Reproducible on JuMP 0.19

model = Model()
@variable(model, x)
A = [x]
B = [2, x]
@NLconstraint(model, A[1] * B[1] == 0)

The problem is that B = [2, x] promotes 2 to an AffExpr, which are not allowed in @NL macros. Take a read of the syntax notes.

A quick fix is to type B as Any.

model = Model()
@variable(model, x)
A = [x]
B = Any[2, x]
@NLconstraint(model, A[1] * B[1] == 0)

This needs an improved error message.

@odow odow added the Type: Error Messages Can be fixed with better error message label Feb 18, 2019
@coreysharris
Copy link
Contributor Author

Ah, I see. In my case,

M = Any[2 a-b; a+b 3]

still generated the error at a-b, but that's obviously an AffExpr. My solution (in case it's useful for others):

@variable(m, aux[1:2,1:2])
M = [2 a-b; a+b 3]
@constraint(m, aux .== M)

I created #1872 to address the error message.

@mlubin
Copy link
Member

mlubin commented Feb 19, 2019

Closed by #1872. The underlying "quadratics not supported" issue is jump-dev/AmplNLWriter.jl#49.

@mlubin mlubin closed this as completed Feb 19, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Type: Error Messages Can be fixed with better error message
Development

No branches or pull requests

3 participants