0
Follow
0
View

How to solve an abstract model using Pyomo in Google Colab

demon909 注册会员
2023-01-26 05:45
!pip install pyomo 
from pyomo.environ import *
import matplotlib.pyplot as plt
!wget -N -q "https://ampl.com/dl/open/ipopt/ipopt-linux64.zip"
!unzip -o -q ipopt-linux64

model = AbstractModel()
model.x = Var(bounds=(0,1.2), within=Reals)
model.obj1 = Objective(expr=model.x**2, sense=maximize)
#opt = SolverFactory('ipopt')
opt=SolverFactory('ipopt', executable='/content/ipopt')
instance = model.create_instance()
results = opt.solve(instance) # solves and updates instance
print('OF= ',value(instance.obj1))

About the Author

Question Info

Publish Time
2023-01-26 05:45
Update Time
2023-01-26 05:45