Docplex (cplex) fails solve a simple quadratic optimization problem

123 Views Asked by At

I'm trying to solve the following problem using the docplex:

min (x+10)**2

its obvious answer is x = -10. I used the following code to solve it in docplex:

=============================================== from docplex.mp.model import Model

model = Model('Quadratic Optimization')

x = model.continuous_var(name='x')

quad_expr = (x + 10)**2

obj = model.minimize(quad_expr)

model.solve()

=================================================

but surprisingly, it gives the soulution x=0! I also tried it with AdvModel but still the same results. Can anyone help me on that?

Thanks

try: from docplex.mp.model import Model

model = Model('Quadratic Optimization')

x = model.continuous_var(name='x')

quad_expr = (x + 10)**2

obj = model.minimize(quad_expr)

model.solve()

==========

expect: x = -10

==========

result: x = 0

2

There are 2 best solutions below

0
Ehsan Rezaei On

It seems that Model.continuous_var lower bound is zero. Change it to model.continuous_var(name='x', lb=-10e10) and the problem was solved

0
Philippe Couronne On

The default lower bound for all types of variables (integer, continuous), is zero. To allow negative values, you have to set an explicit negative lower bound