本文整理汇总了Python中pyomo.environ.ConcreteModel.logical方法的典型用法代码示例。如果您正苦于以下问题:Python ConcreteModel.logical方法的具体用法?Python ConcreteModel.logical怎么用?Python ConcreteModel.logical使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pyomo.environ.ConcreteModel
的用法示例。
在下文中一共展示了ConcreteModel.logical方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_induced_linearity_case2
# 需要导入模块: from pyomo.environ import ConcreteModel [as 别名]
# 或者: from pyomo.environ.ConcreteModel import logical [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_bilinear_in_disjuncts
# 需要导入模块: from pyomo.environ import ConcreteModel [as 别名]
# 或者: from pyomo.environ.ConcreteModel import logical [as 别名]
def test_bilinear_in_disjuncts(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.v = Var([1, 2])
m.v[1].setlb(-2)
m.v[1].setub(7)
m.v[2].setlb(-4)
m.v[2].setub(5)
m.bilinear = Constraint(
expr=(m.x[0] - 3) * (m.v[1] + 2) - (m.v[2] + 4) * m.v[1] +
exp(m.v[1] ** 2) * m.x[0] <= m.v[2])
m.disjctn = Disjunction(expr=[
[m.x[0] * m.v[1] <= 4],
[m.x[0] * m.v[2] >= 6]
])
TransformationFactory('contrib.induced_linearity').apply_to(m)
self.assertEqual(
m.disjctn.disjuncts[0].constraint[1].body.polynomial_degree(), 1)
self.assertEqual(
m.disjctn.disjuncts[1].constraint[1].body.polynomial_degree(), 1)
示例3: test_determine_valid_values
# 需要导入模块: from pyomo.environ import ConcreteModel [as 别名]
# 或者: from pyomo.environ.ConcreteModel import logical [as 别名]
def test_determine_valid_values(self):
m = ConcreteModel()
m.x = Var()
m.y = Var(RangeSet(4), domain=Binary)
m.z = Var(domain=Integers, bounds=(-1, 2))
m.constr = Constraint(
expr=m.x == 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)
var_to_values_map = determine_valid_values(
m, detect_effectively_discrete_vars(m, 1E-6), Bunch(
equality_tolerance=1E-6,
pruning_solver='glpk'))
valid_values = set([1, 2, 3, 4, 5])
self.assertEqual(set(var_to_values_map[m.x]), valid_values)
示例4: test_induced_linear_in_disjunct
# 需要导入模块: from pyomo.environ import ConcreteModel [as 别名]
# 或者: from pyomo.environ.ConcreteModel import logical [as 别名]
def test_induced_linear_in_disjunct(self):
m = ConcreteModel()
m.x = Var([0], bounds=(-3, 8))
m.y = Var(RangeSet(2), domain=Binary)
m.logical = ConstraintList()
m.logical.add(expr=m.y[1] + m.y[2] == 1)
m.v = Var([1])
m.v[1].setlb(-2)
m.v[1].setub(7)
m.bilinear_outside = Constraint(
expr=m.x[0] * m.v[1] >= 2)
m.disjctn = Disjunction(expr=[
[m.x[0] * m.v[1] == 3,
2 * m.x[0] == m.y[1] + m.y[2]],
[m.x[0] * m.v[1] == 4]
])
TransformationFactory('contrib.induced_linearity').apply_to(m)
self.assertEqual(
m.disjctn.disjuncts[0].constraint[1].body.polynomial_degree(), 1)
self.assertEqual(
m.bilinear_outside.body.polynomial_degree(), 2)
self.assertEqual(
m.disjctn.disjuncts[1].constraint[1].body.polynomial_degree(), 2)