本文整理汇总了Python中pyomo.environ.ConcreteModel.b方法的典型用法代码示例。如果您正苦于以下问题:Python ConcreteModel.b方法的具体用法?Python ConcreteModel.b怎么用?Python ConcreteModel.b使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pyomo.environ.ConcreteModel
的用法示例。
在下文中一共展示了ConcreteModel.b方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_induced_linearity_case2
# 需要导入模块: from pyomo.environ import ConcreteModel [as 别名]
# 或者: from pyomo.environ.ConcreteModel import b [as 别名]
def test_induced_linearity_case2(self):
m = ConcreteModel()
m.x = Var([0], bounds=(-3, 8))
m.y = Var(RangeSet(4), domain=Binary)
m.z = Var(domain=Integers, bounds=(-1, 2))
m.constr = Constraint(
expr=m.x[0] == m.y[1] + 2 * m.y[2] + m.y[3] + 2 * m.y[4] + m.z)
m.logical = ConstraintList()
m.logical.add(expr=m.y[1] + m.y[2] == 1)
m.logical.add(expr=m.y[3] + m.y[4] == 1)
m.logical.add(expr=m.y[2] + m.y[4] <= 1)
m.b = Var(bounds=(-2, 7))
m.c = Var()
m.bilinear = Constraint(
expr=(m.x[0] - 3) * (m.b + 2) - (m.c + 4) * m.b +
exp(m.b ** 2) * m.x[0] <= m.c)
TransformationFactory('contrib.induced_linearity').apply_to(m)
xfrmed_blk = m._induced_linearity_info.x0_b_bilinear
self.assertSetEqual(
set(xfrmed_blk.valid_values), set([1, 2, 3, 4, 5]))
select_one_repn = generate_standard_repn(
xfrmed_blk.select_one_value.body)
self.assertEqual(
ComponentSet(select_one_repn.linear_vars),
ComponentSet(xfrmed_blk.x_active[i] for i in xfrmed_blk.valid_values))
示例2: test_contains
# 需要导入模块: from pyomo.environ import ConcreteModel [as 别名]
# 或者: from pyomo.environ.ConcreteModel import b [as 别名]
def test_contains(self):
model=ConcreteModel()
model.a=Set(initialize=[1,2,3])
model.b=Constraint(model.a)
self.assertEqual(2 in model.b,False)
tmp=[]
for i in model.b:
tmp.append(i)
self.assertEqual(len(tmp),0)
示例3: test_no_column_ordering_linear
# 需要导入模块: from pyomo.environ import ConcreteModel [as 别名]
# 或者: from pyomo.environ.ConcreteModel import b [as 别名]
def test_no_column_ordering_linear(self):
model = ConcreteModel()
model.a = Var()
model.b = Var()
model.c = Var()
terms = [model.a, model.b, model.c]
model.obj = Objective(expr=self._gen_expression(terms))
model.con = Constraint(expr=self._gen_expression(terms) <= 1)
self._check_baseline(model)
示例4: test_unary_expressions
# 需要导入模块: from pyomo.environ import ConcreteModel [as 别名]
# 或者: from pyomo.environ.ConcreteModel import b [as 别名]
def test_unary_expressions(self):
m = ConcreteModel()
m.x = Var()
m.y = Var()
m.z = Var()
m.a = Var()
m.b = Var()
m.c = Var()
m.d = Var()
m.c1 = Constraint(expr=0 <= sin(m.x))
m.c2 = Constraint(expr=0 <= cos(m.y))
m.c3 = Constraint(expr=0 <= tan(m.z))
m.c4 = Constraint(expr=0 <= asin(m.a))
m.c5 = Constraint(expr=0 <= acos(m.b))
m.c6 = Constraint(expr=0 <= atan(m.c))
m.c7 = Constraint(expr=0 <= sqrt(m.d))
m.o = Objective(expr=m.x)
self.assertTrue(satisfiable(m) is not False)
示例5: test_detect_effectively_discrete_vars
# 需要导入模块: from pyomo.environ import ConcreteModel [as 别名]
# 或者: from pyomo.environ.ConcreteModel import b [as 别名]
def test_detect_effectively_discrete_vars(self):
m = ConcreteModel()
m.x = Var()
m.y = Var(domain=Binary)
m.z = Var(domain=Integers)
m.constr = Constraint(expr=m.x == m.y + m.z)
m.ignore_inequality = Constraint(expr=m.x <= m.y + m.z)
m.ignore_nonlinear = Constraint(expr=m.x ** 2 == m.y + m.z)
m.a = Var()
m.b = Var(domain=Binary)
m.c = Var(domain=Integers)
m.disj = Disjunct()
m.disj.constr = Constraint(expr=m.a == m.b + m.c)
effectively_discrete = detect_effectively_discrete_vars(m, 1E-6)
self.assertEqual(len(effectively_discrete), 1)
self.assertEqual(effectively_discrete[m.x], [m.constr])
effectively_discrete = detect_effectively_discrete_vars(m.disj, 1E-6)
self.assertEqual(len(effectively_discrete), 1)
self.assertEqual(effectively_discrete[m.a], [m.disj.constr])