hgv
hgv

Reputation: 237

Pyomo with ipopt Non-linear solver does not output an integer solution

I have a relatively simple non linear problem with I can not get a logical answer with pyomo and ipopt solver. Then I watered down to problem (way to much) to troubleshoot and still having problem . It outputs non integer values even this simple problem below. Can you please help

Problem reads as below

a= integer,

b= integer,

a*b <=20,

maximize a+b

from pyomo.opt import SolverFactory

model= pyomo.ConcreteModel()



##### Variables  ##################
model.a=pyomo.Var(within=pyomo.NonNegativeIntegers, initialize=1,bounds=(1,21))
model.b=pyomo.Var(within=pyomo.NonNegativeIntegers, initialize=1,bounds=(1,21))

###### Constraits #######################
model.eq1=pyomo.Constraint(expr= model.a*model.b <= 20)

########## OBJECTIVE ################
model.obj = pyomo.Objective(expr = model.a+model.b, sense = pyomo.maximize);

results=pyomo.SolverFactory('ipopt').solve(model)
# results.write()
print(model.obj())
print("a ",model.a())
print("b ",model.b())

--------------------
8.94427195221462
a  4.472135976087108
b  4.472135976127514

Upvotes: 0

Views: 473

Answers (1)

jsiirola
jsiirola

Reputation: 2634

Ipopt is a continuous nonlinear solver, and and does not honor discrete domains. It will automatically map discrete domains to their continuous counterparts. If you look at the solver output, e.g. with

results=pyomo.SolverFactory('ipopt').solve(model, tee=True)

you will see it begins with

Ipopt 3.13.2:
==> Warning: Treating 0 binary and 2 integer variables as continous.

Upvotes: 2

Related Questions