本文整理汇总了Python中pyomo.environ.ConcreteModel.del_component方法的典型用法代码示例。如果您正苦于以下问题:Python ConcreteModel.del_component方法的具体用法?Python ConcreteModel.del_component怎么用?Python ConcreteModel.del_component使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pyomo.environ.ConcreteModel
的用法示例。
在下文中一共展示了ConcreteModel.del_component方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_non_supported_single_index
# 需要导入模块: from pyomo.environ import ConcreteModel [as 别名]
# 或者: from pyomo.environ.ConcreteModel import del_component [as 别名]
def test_non_supported_single_index(self):
# Can't simulate a model with no ContinuousSet
m = ConcreteModel()
with self.assertRaises(DAE_Error):
Simulator(m)
# Can't simulate a model with multiple ContinuousSets
m = ConcreteModel()
m.s = ContinuousSet(bounds=(0, 10))
m.t = ContinuousSet(bounds=(0, 5))
with self.assertRaises(DAE_Error):
Simulator(m)
# Can't simulate a model with no Derivatives
m = ConcreteModel()
m.t = ContinuousSet(bounds=(0, 10))
with self.assertRaises(DAE_Error):
Simulator(m)
# Can't simulate a model with multiple RHS for a derivative
m = self.m
def _diffeq(m, t):
return m.dv[t] == m.v[t]**2 + m.v[t]
m.con1 = Constraint(m.t, rule=_diffeq)
m.con2 = Constraint(m.t, rule=_diffeq)
with self.assertRaises(DAE_Error):
Simulator(m)
m.del_component('con1')
m.del_component('con2')
# Can't simulate a model with multiple derivatives in an
# equation
m = self.m
def _diffeq(m, t):
return m.dv[t] == m.dv[t] + m.v[t]**2
m.con1 = Constraint(m.t, rule=_diffeq)
with self.assertRaises(DAE_Error):
Simulator(m)
m.del_component('con1')
示例2: test_mutable_novalue_param_equality
# 需要导入模块: from pyomo.environ import ConcreteModel [as 别名]
# 或者: from pyomo.environ.ConcreteModel import del_component [as 别名]
def test_mutable_novalue_param_equality(self):
model = ConcreteModel()
model.x = Var()
model.p = Param(mutable=True)
model.p.value = None
model.c = Constraint(expr=model.x - model.p == 0)
self.assertEqual(model.c.equality, True)
model.del_component(model.c)
model.c = Constraint(expr=model.x == model.p)
self.assertTrue(model.c.upper is model.p)
self.assertEqual(model.c.equality, True)
model.del_component(model.c)
model.c = Constraint(expr=model.x + 1 == model.p)
self.assertEqual(model.c.equality, True)
model.del_component(model.c)
model.c = Constraint(expr=model.x + 1 == (model.p + 1)**2)
self.assertEqual(model.c.equality, True)
model.del_component(model.c)
model.c = Constraint(expr=model.x == model.p + 1)
self.assertEqual(model.c.equality, True)
model.del_component(model.c)
model.c = Constraint(expr=inequality(model.p, model.x, model.p))
self.assertTrue(model.c.upper is model.p)
# GH: Not sure if we are supposed to detect equality
# in this situation. I would rather us not, for
# the sake of making the code less complicated.
# Either way, I am not going to test for it here.
#self.assertEqual(model.c.equality, <blah>)
model.del_component(model.c)
model.c = Constraint(expr=(model.x, model.p))
self.assertTrue(model.c.upper is model.p)
self.assertEqual(model.c.equality, True)
model.del_component(model.c)
model.c = Constraint(expr=(model.p, model.x))
self.assertTrue(model.c.upper is model.p)
self.assertEqual(model.c.equality, True)
model.del_component(model.c)
示例3: test_mutable_novalue_param_upper_bound
# 需要导入模块: from pyomo.environ import ConcreteModel [as 别名]
# 或者: from pyomo.environ.ConcreteModel import del_component [as 别名]
def test_mutable_novalue_param_upper_bound(self):
model = ConcreteModel()
model.x = Var()
model.p = Param(mutable=True)
model.p.value = None
model.c = Constraint(expr=model.x - model.p <= 0)
self.assertEqual(model.c.equality, False)
model.del_component(model.c)
model.c = Constraint(expr=model.x <= model.p)
self.assertTrue(model.c.upper is model.p)
self.assertEqual(model.c.equality, False)
model.del_component(model.c)
model.c = Constraint(expr=model.x + 1 <= model.p)
self.assertEqual(model.c.equality, False)
model.del_component(model.c)
model.c = Constraint(expr=model.x <= model.p + 1)
self.assertEqual(model.c.equality, False)
model.del_component(model.c)
model.c = Constraint(expr=model.x <= (model.p + 1)**2)
self.assertEqual(model.c.equality, False)
model.del_component(model.c)
model.c = Constraint(expr=(model.p + 1, model.x, model.p))
self.assertEqual(model.c.equality, False)
model.del_component(model.c)
model.c = Constraint(expr=0 >= model.x - model.p)
self.assertEqual(model.c.equality, False)
model.del_component(model.c)
model.c = Constraint(expr=model.p >= model.x)
self.assertTrue(model.c.upper is model.p)
self.assertEqual(model.c.equality, False)
model.del_component(model.c)
model.c = Constraint(expr=model.p >= model.x + 1)
self.assertEqual(model.c.equality, False)
model.del_component(model.c)
model.c = Constraint(expr=model.p + 1 >= model.x)
self.assertEqual(model.c.equality, False)
model.del_component(model.c)
model.c = Constraint(expr=(model.p + 1)**2 >= model.x)
self.assertEqual(model.c.equality, False)
model.del_component(model.c)
model.c = Constraint(expr=(None, model.x, model.p))
self.assertTrue(model.c.upper is model.p)
self.assertEqual(model.c.equality, False)
model.del_component(model.c)
model.c = Constraint(expr=(None, model.x + 1, model.p))
self.assertEqual(model.c.equality, False)
model.del_component(model.c)
model.c = Constraint(expr=(None, model.x, model.p + 1))
self.assertEqual(model.c.equality, False)
model.del_component(model.c)
model.c = Constraint(expr=(1, model.x, model.p))
self.assertEqual(model.c.equality, False)
model.del_component(model.c)