Pyomo / pyomo

An object-oriented algebraic modeling language in Python for structured optimization problems.
https://www.pyomo.org
Other
1.97k stars 505 forks source link

error in recuperated results from mindtpy #2621

Closed Layebuniv closed 1 year ago

Layebuniv commented 1 year ago

Summary

I have coded the pressure veessel problem using pyomo. the results obtain are not in the right order, k1, and k2 are Integer x1: 7.0 x2: 0.4375 x3: 13.0 x4: 0.8125 k1: 42.09844611396906 k2: 176.63658709460654

the right order for the solution k1: 7.0 x1: 0.4375 k2: 13.0 x2: 0.8125 x3: 42.09844611396906 x4: 176.63658709460654

Steps to reproduce the issue

$ command1 [options]
$ command2 [options]
...
# example.py
import pyomo.environ
...# Pressure Vessel Design Problem with pyomo and integer constraints
# abdesslem Layeb
from pyomo.environ import *
import math

m = ConcreteModel()
m.x1 = Var(bounds=(0,99),initialize=0.0)
m.x2 = Var(bounds=(0,99),initialize=0.0,)
m.x3 = Var(bounds=(10,200),initialize=20.0)
m.x4 = Var(bounds=(10,200),initialize=20.0)
m.k1 = Var(domain=PositiveIntegers,initialize=1) # i have added  k1 and k2 to force x1 nad x2 to pultiple of 0.0625
m.k2 = Var(domain=PositiveIntegers,initialize=1)

m.c1 = Constraint(expr=-m.x1+0.0625*m.k1==0) # x1 is multiple of 0.0625
m.c2 = Constraint(expr=-m.x2+0.0625*m.k2==0)  # x2 is multiple of 0.0625
m.c3 = Constraint(expr=-m.x1+0.0193*m.x3<=0)
m.c4 = Constraint(expr=-m.x2+0.00954*m.x3<=0) 
m.c5 = Constraint(expr=-m.x4-240<=0)
m.c6 = Constraint(expr=-math.pi*m.x3**2 *m.x4 - 4/3*math.pi*m.x3**3 + 1296000<=0)
def funobj(m):
    return ((0.6224*m.x1*m.x3*m.x4)+(1.7781*m.x2*m.x3**2) + (3.1661*m.x1**2*m.x4)+(19.84*m.x1**2*m.x3))

m.Obj=Objective(rule=funobj,sense=minimize) # Objective

solver = SolverFactory('mindtpy')
result=solver.solve(m,
                tee=True)
# solver = SolverFactory('mindtpy').solve(m,
#                                    strategy='OA',
#                                    time_limit=3600,
#                                    mip_solver='cplex',
#                                    mip_solver_args=dict(solver='cplex', warmstart=True),
#                                    nlp_solver='ipopt',
#                                    tee=True)

print()
print('*** Solution *** :')
print('fonction objectif:', value(m.Obj))
print('x1:', value(m.x1))
print('x2:', value(m.x2))
print('x3:', value(m.x3))
print('x4:', value(m.x4))
print('k1:', value(m.k1))
print('k2:', value(m.k2))

Error Message

$ # Output message here, including entire stack trace, if available

Information on your system

Pyomo version: Python version: Operating system: How Pyomo was installed (PyPI, conda, source): Solver (if applicable):

Additional information

mrmundt commented 1 year ago

Thanks, @Layebuniv - can you please supply your Python/Pyomo/OS information for us?

Layebuniv commented 1 year ago

python 3.9/Pyomo 6.4.2/win10 (anaconda )

Thanks, @Layebuniv - can you please supply your Python/Pyomo/OS information for us?

blnicho commented 1 year ago

@bernalde or @ZedongPeng could you take a look at this issue?

ZedongPeng commented 1 year ago

This bug has already been fixed here. #2587

Layebuniv commented 1 year ago

thank you

Le mer. 23 nov. 2022 à 18:58, Zedong @.***> a écrit :

This bug has already been fixed here. #2587 https://github.com/Pyomo/pyomo/pull/2587

— Reply to this email directly, view it on GitHub https://github.com/Pyomo/pyomo/issues/2621#issuecomment-1325457736, or unsubscribe https://github.com/notifications/unsubscribe-auth/AS3DBDZH7JYCULVJV4QMYYDWJZLMFANCNFSM6AAAAAASH3JP3E . You are receiving this because you were mentioned.Message ID: @.***>