本文整理匯總了Python中pyomo.core.ConcreteModel.e方法的典型用法代碼示例。如果您正苦於以下問題:Python ConcreteModel.e方法的具體用法?Python ConcreteModel.e怎麽用?Python ConcreteModel.e使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類pyomo.core.ConcreteModel
的用法示例。
在下文中一共展示了ConcreteModel.e方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: test_clone_without_expression_components
# 需要導入模塊: from pyomo.core import ConcreteModel [as 別名]
# 或者: from pyomo.core.ConcreteModel import e [as 別名]
def test_clone_without_expression_components(self):
m = ConcreteModel()
m.x = Var(initialize=5)
m.y = Var(initialize=3)
m.e = Expression(expr=m.x**2 + m.x - 1)
base = m.x**2 + 1
test = clone_without_expression_components(base, {})
self.assertIs(base, test)
self.assertEqual(base(), test())
test = clone_without_expression_components(base, {id(m.x): m.y})
self.assertEqual(3**2+1, test())
base = m.e
test = clone_without_expression_components(base, {})
self.assertIsNot(base, test)
self.assertEqual(base(), test())
self.assertIsInstance(base, _ExpressionData)
self.assertIsInstance(test, EXPR.SumExpression)
test = clone_without_expression_components(base, {id(m.x): m.y})
self.assertEqual(3**2+3-1, test())
base = m.e + m.x
test = clone_without_expression_components(base, {})
self.assertIsNot(base, test)
self.assertEqual(base(), test())
self.assertIsInstance(base, EXPR.SumExpression)
self.assertIsInstance(test, EXPR.SumExpression)
self.assertIsInstance(base.arg(0), _ExpressionData)
self.assertIsInstance(test.arg(0), EXPR.SumExpression)
test = clone_without_expression_components(base, {id(m.x): m.y})
self.assertEqual(3**2+3-1 + 3, test())
示例2: test_mc_2d
# 需要導入模塊: from pyomo.core import ConcreteModel [as 別名]
# 或者: from pyomo.core.ConcreteModel import e [as 別名]
def test_mc_2d(self):
m = ConcreteModel()
m.x = Var(bounds=(pi / 6, pi / 3), initialize=pi / 4)
m.e = Expression(expr=cos(pow(m.x, 2)) * sin(pow(m.x, -3)))
mc_ccVals, mc_cvVals, aff_cc, aff_cv = make2dPlot(m.e.expr, 50)
self.assertAlmostEqual(mc_ccVals[1], 0.6443888590411435)
self.assertAlmostEqual(mc_cvVals[1], 0.2328315489072924)
self.assertAlmostEqual(aff_cc[1], 0.9674274332870583)
self.assertAlmostEqual(aff_cv[1], -1.578938503009686)
示例3: test_mc_3d
# 需要導入模塊: from pyomo.core import ConcreteModel [as 別名]
# 或者: from pyomo.core.ConcreteModel import e [as 別名]
def test_mc_3d(self):
m = ConcreteModel()
m.x = Var(bounds=(-2, 1), initialize=-1)
m.y = Var(bounds=(-1, 2), initialize=0)
m.e = Expression(expr=m.x * pow(exp(m.x) - m.y, 2))
ccSurf, cvSurf, ccAffine, cvAffine = make3dPlot(m.e.expr, 30)
self.assertAlmostEqual(ccSurf[48], 11.5655473482574)
self.assertAlmostEqual(cvSurf[48], -15.28102124928224)
self.assertAlmostEqual(ccAffine[48], 11.565547348257398)
self.assertAlmostEqual(cvAffine[48], -23.131094696514797)