1
votes

I am trying to run solve an optimization problem involving inverse of a matrix in one of its constraints. A simplified version is as follows:

a = [1 1e-3;1e-3 1]
n = 2
f(Q...) = inv(reshape(collect(Q), (n, n)))
g(x...) = reshape(collect(x), (n,n))
NSD = Model(with_optimizer(Ipopt.Optimizer))
@variable(NSD, Q[1:n, 1:n])
@variable(NSD, aux[1:n, 1:n])
register(NSD, :f, n*n, f, autodiff=true)
register(NSD, :g, n*n, g, autodiff=true)
@constraint(NSD, aux .== a)
@NLconstraint(NSD, invconst[i=1:n, j=1:n], f(Q...)[i,j] >= g(aux...)[i,j])
@objective(NSD, Max, 0)
optimize!(NSD)

However, this code keeps showing me the following error message which I am unable to resolve: LoadError: Cannot divide a quadratic expression by an aff. expression

Can someone please help me figure out the problem here?

1

1 Answers

2
votes

User-defined functions must return a single scalar. They cannot return a matrix.

What is n in your application? If n > 2, this is almost certainly not what you want to do.

If n = 2, just write out the inverse explicitly.

I'm adding an example that will be helpful to JuMP: https://github.com/jump-dev/JuMP.jl/pull/2379