Open
Description
# =================
# Import Statements
# =================
import numpy as np
import pyomo.environ as pyo
from pyomo.contrib.edi import Formulation
from pyomo.contrib.edi import BlackBoxFunctionModel
from pyomo.contrib.edi.solvers.solver import cvxopt_solve
f = Formulation()
cst = f.Constant(name = 'c', value = 3.0, units = '-', size = 0, description = 'A constant')
c2 = f.Constant(name = 'c2', value = 2, units = '-', size = 0, description = 'A constant')
x = f.Variable(name = 'x', guess = 1.0, units = '-', size = 0, description = 'The X variable')
y = f.Variable(name = 'y', guess = 2.0, units = '-', size = 0, description = 'The Y variable')
f.Objective( x**2 + 4*y**c2 +1 + x*y )
f.ConstraintList(
[
x >= 1,
y >= 1,
x + 1/(1+y*x) >= cst,
]
)
res = cvxopt_solve(f)
print(res)
print(res['x'])