Cbc JuMP set constraints

Hello, I am trying to create a simple optimization model using JuMP and Cbc.
My code is following:

using JuMP, Cbc
m = Model(Cbc.Optimizer)
@variable(m, x1)
@variable(m, x2)
@constraint(m, constraint1, x1 * x2 == 1)
@objective(m, Min, x1 + x2)

When I try to create the constraint, I get following error:
MOI.ScalarQuadraticFunction{Float64}-in-MOI.EqualTo{Float64} constraints are not supported and cannot be bridged into supported constrained variables and constraints.

How can I solve this?

Your constraint is non-linear. Have you tried the macro @NLconstraint instead of @constraint?

The section about non-linear modelling in the JuMP documentation is here. Let me remark my comment is just a guess, because I have never used JuMP for non-linear models.

1 Like

Thank you, with @NLconstraint it creates the constraint.
The optimization does not work because it is a linear solver (I guess from new error I got), but if I use a non linear solver it works. Thank you

I’ve opened an issue to improve the error message: https://github.com/jump-dev/JuMP.jl/issues/2680. The current error is confusing and isn’t good at explaining why this didn’t work.

Your problem is that Cbc does not support quadratic constraints.

Since your problem is a non-convex quadratic constraint, your options are Gurobi.jl or Ipopt.jl. In both cases the syntax you have is correct. No need for @NLconstraint.