# Error in an optimization problem

Hello there!

I’m fairly new to Julia. I just made a problem to test and learn how to write the obj. function and restrictions. But i’m having some issues, if anyone can help me out, will be trully apreciated.

Here’s my code:

``````workspace()
using JuMP, AmplNLWriter, CoinOptServices

## Solve test problem
#
#  min   100 * (x5 - (0.5 + x4) ^ 2) ^ 2 + (1 - x4) ^ 2
#  s.t.  x4*x3 + x5*x1 <= 20
#        5x1 - 2x5 + 3x3 <= 17
#        x4, x5 binary
#        0 <= x1 <= 3
#        0 <= x2 <= 5
#        0 <= x3 <= 10
##

m = Model(solver=AmplNLSolver(CoinOptServices.couenne))

X_U = [3;5;10] # Superior Limits

@variable(m, 0 <= X[i=1:3] <= X_U[i])
@variable(m, x[i=4:5], Bin)

@NLobjective(m, Min, 100*(x - (0.5 + x)^2)^2 + (1 - x)^2)

@NLconstraint(m, x*X+x*X <= 20)
@constraint(m, 5*X-2*x+3*X <= 17)

print(m)

status = solve(m)

println("Objective value: ", getobjectivevalue(m))
println("x = ", getvalue(x))
println("X = ", getvalue(X))
``````

I’m using counne here, because later i’ll have to solve a Non-Convex MINLP.

Then, when i run the code, i get this:

``````Objective value: 0.24937733210128057
x = x: 1 dimensions:
 = 0.501244569130593
 = 1.0
X = [1.0, 2.5, 2.0]
``````

So, x4 should be a binary variable here, but from the solution it gives me 0.5012… Does anyone knows why this happens?

Seems like a bug. COUENNE appears to be aware of the right number of integrality constraints (`Variables: 5 (2 integer)`), but the constraint is clearly not being enforced.

BTW, I tried using https://github.com/rdeits/CouenneNL.jl instead, since it uses Couenne version 0.5.6 while CoinOptServices uses 0.5.4 (also, CouenneNL.jl just downloads a binary instead of building from scratch, which is nice). Unfortunately, that didn’t make a difference.

1 Like

I understand, thanks for the reply.

I tried another problem now, wich i found in the web:

``````workspace()
using JuMP, AmplNLWriter, CoinOptServices

## Solve test problem
#
#  min   2*x1 + 3*x2 + 1.5*y1 + 2*y2 - 0.5*y3
#  s.t.  x1^2 + y1 = 1.25
#        x2^1.5 + 1.5y2 = 3
#        x1 + y1 <= 1.6
#        1.333*x2 + y2 <= 3
#        -y1-y2+y3 <= 0
#        x1, x2 >= 0
#        y1, y2, y3 binary
##

m = Model(solver=AmplNLSolver(CoinOptServices.couenne))

@variable(m, X[i=1:2] >= 0)
@variable(m, y[i=1:3], Bin)

@NLobjective(m, Min, 2*X + 3*X + 1.5*y + 2*y - 0.5*y)

@NLconstraint(m,  X^2 + y == 1.25)
@NLconstraint(m, (X)^(3/2) + 1.5*y == 3)
@NLconstraint(m, X + y <= 1.6)
@NLconstraint(m, 1.333*X + y <= 3)
@NLconstraint(m, -y-y+y <= 0)

print(m)

status = solve(m)

println("Objective value: ", getobjectivevalue(m))
println("y = ", getvalue(y))
println("x = ", getvalue(X))
``````

But here i’m getting this error:

``````ANALYSIS TEST: Error evaluating constraint 2: can't evaluate pow"(0,1.5).
WARNING: Not solved to optimality, status: Error
Objective value: NaN
WARNING: Variable value not defined for component of y. Check that the model was properly solved.
y = [NaN, NaN, NaN]
WARNING: Variable value not defined for component of X. Check that the model was properly solved.
x = [NaN, NaN]
``````

So, Couenne doesn’t accept non-integers in the exponent of a constraint?

I actually don’t get the `Error evaluating constraint 2: can't evaluate pow"(0,1.5).` part, but I still get the rest of the warnings/errors. Changing `(X)^(3/2)` to `sqrt((X)^3)` doesn’t seem to change anything.

Bonmin returns the same solution for your first problem, so I think it’s likely to be a problem with the `.nl` file written by AmplNLWriter. I’d open an issue with AmplNLWriter.