1

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 Answers2

1

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

Philippe Couronne
  • 826
  • 1
  • 5
  • 6
0

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

Tyler2P
  • 2,324
  • 26
  • 22
  • 31