本文整理汇总了Python中pyomo.environ.ConcreteModel.c方法的典型用法代码示例。如果您正苦于以下问题:Python ConcreteModel.c方法的具体用法?Python ConcreteModel.c怎么用?Python ConcreteModel.c使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pyomo.environ.ConcreteModel
的用法示例。
在下文中一共展示了ConcreteModel.c方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_is_feasible_function
# 需要导入模块: from pyomo.environ import ConcreteModel [as 别名]
# 或者: from pyomo.environ.ConcreteModel import c [as 别名]
def test_is_feasible_function(self):
m = ConcreteModel()
m.x = Var(bounds=(0, 3), initialize=2)
m.c = Constraint(expr=m.x == 2)
self.assertTrue(is_feasible(m, GDPoptSolver.CONFIG()))
m.c2 = Constraint(expr=m.x <= 1)
self.assertFalse(is_feasible(m, GDPoptSolver.CONFIG()))
m = ConcreteModel()
m.x = Var(bounds=(0, 3), initialize=2)
m.c = Constraint(expr=m.x >= 5)
self.assertFalse(is_feasible(m, GDPoptSolver.CONFIG()))
m = ConcreteModel()
m.x = Var(bounds=(3, 3), initialize=2)
self.assertFalse(is_feasible(m, GDPoptSolver.CONFIG()))
m = ConcreteModel()
m.x = Var(bounds=(0, 1), initialize=2)
self.assertFalse(is_feasible(m, GDPoptSolver.CONFIG()))
m = ConcreteModel()
m.x = Var(bounds=(0, 1), initialize=2)
m.d = Disjunct()
with self.assertRaisesRegexp(NotImplementedError, "Found active disjunct"):
is_feasible(m, GDPoptSolver.CONFIG())
示例2: test_set_expr_inline
# 需要导入模块: from pyomo.environ import ConcreteModel [as 别名]
# 或者: from pyomo.environ.ConcreteModel import c [as 别名]
def test_set_expr_inline(self):
"""Test expr= option (inline expression)"""
model = ConcreteModel()
model.A = RangeSet(1,4)
model.x = Var(model.A,initialize=2)
model.c = Constraint(expr=(0, sum(model.x[i] for i in model.A), 1))
self.assertEqual(model.c(), 8)
self.assertEqual(value(model.c.body), 8)
示例3: test_set_expr_explicit_univariate
# 需要导入模块: from pyomo.environ import ConcreteModel [as 别名]
# 或者: from pyomo.environ.ConcreteModel import c [as 别名]
def test_set_expr_explicit_univariate(self):
"""Test expr= option (univariate expression)"""
model = ConcreteModel()
model.x = Var(initialize=2)
ans = model.x >= 0
ans = ans <= 1
model.c = Constraint(expr=ans)
self.assertEqual(model.c(), 2)
self.assertEqual(model.c.body(), 2)
self.assertEqual(value(model.c.body), 2)
示例4: test_setitem
# 需要导入模块: from pyomo.environ import ConcreteModel [as 别名]
# 或者: from pyomo.environ.ConcreteModel import c [as 别名]
def test_setitem(self):
m = ConcreteModel()
m.x = Var()
m.c = Constraint()
self.assertEqual(len(m.c), 0)
m.c = m.x**2 <= 4
self.assertEqual(len(m.c), 1)
self.assertEqual(list(m.c.keys()), [None])
self.assertEqual(m.c.upper, 4)
m.c = Constraint.Skip
self.assertEqual(len(m.c), 0)
示例5: test_set_expr_undefined_univariate
# 需要导入模块: from pyomo.environ import ConcreteModel [as 别名]
# 或者: from pyomo.environ.ConcreteModel import c [as 别名]
def test_set_expr_undefined_univariate(self):
"""Test expr= option (univariate expression)"""
model = ConcreteModel()
model.x = Var()
ans = model.x >= 0
ans = ans <= 1
model.c = Constraint(expr=ans)
#self.assertRaises(ValueError, model.c)
self.assertEqual(model.c(),None)
model.x = 2
self.assertEqual(model.c(), 2)
self.assertEqual(value(model.c.body), 2)
示例6: test_rule5
# 需要导入模块: from pyomo.environ import ConcreteModel [as 别名]
# 或者: from pyomo.environ.ConcreteModel import c [as 别名]
def test_rule5(self):
"""Test rule option"""
model = ConcreteModel()
model.B = RangeSet(1,4)
def f(model):
ans=0
for i in model.B:
ans = ans + model.x[i]
return (ans, 1)
model.x = Var(model.B, initialize=2)
model.c = Constraint(rule=f)
self.assertEqual(model.c(), 8)
self.assertEqual(value(model.c.body), 8)
示例7: test_set_expr_explicit_multivariate
# 需要导入模块: from pyomo.environ import ConcreteModel [as 别名]
# 或者: from pyomo.environ.ConcreteModel import c [as 别名]
def test_set_expr_explicit_multivariate(self):
"""Test expr= option (multivariate expression)"""
model = ConcreteModel()
model.A = RangeSet(1,4)
model.x = Var(model.A, initialize=2)
ans=0
for i in model.A:
ans = ans + model.x[i]
ans = ans >= 0
ans = ans <= 1
model.c = Constraint(expr=ans)
self.assertEqual(model.c(), 8)
self.assertEqual(model.c.body(), 8)
self.assertEqual(value(model.c.body), 8)
示例8: test_linear
# 需要导入模块: from pyomo.environ import ConcreteModel [as 别名]
# 或者: from pyomo.environ.ConcreteModel import c [as 别名]
def test_linear(self):
m = ConcreteModel()
m.x = Var()
m.c = Constraint(expr=5*m.x == 10)
calculate_variable_from_constraint(m.x, m.c)
self.assertEqual(value(m.x), 2)
示例9: build_model
# 需要导入模块: from pyomo.environ import ConcreteModel [as 别名]
# 或者: from pyomo.environ.ConcreteModel import c [as 别名]
def build_model(self):
m = ConcreteModel()
m.v1 = Var(initialize=1, bounds=(1, 8))
m.v2 = Var(initialize=2, bounds=(0, 3))
m.v3 = Var(initialize=3, bounds=(-7, 4))
m.v4 = Var(initialize=4, bounds=(2, 6))
m.c1 = Constraint(expr=m.v1 == m.v2)
m.c2 = Constraint(expr=m.v2 == m.v3)
m.c3 = Constraint(expr=m.v3 == m.v4)
m.v2.fix()
m.s = RangeSet(5)
m.x = Var(m.s, initialize=5)
m.c = Constraint(m.s)
m.c.add(1, expr=m.x[1] == m.x[3])
m.c.add(2, expr=m.x[2] == m.x[4])
m.c.add(3, expr=m.x[2] == m.x[3])
m.c.add(4, expr=m.x[1] == 1)
m.c.add(5, expr=(2, m.x[5], 3))
m.y = Var([1, 2], initialize={1: 3, 2: 4})
m.c_too = Constraint(expr=m.y[1] == m.y[2])
m.z1 = Var()
m.z2 = Var()
m.ignore_me = Constraint(expr=m.y[1] + m.z1 + m.z2 <= 0)
m.ignore_me_too = Constraint(expr=m.y[1] * m.y[2] == 0)
m.multiple = Constraint(expr=m.y[1] == 2 * m.y[2])
return m
示例10: test_induced_linearity_case2
# 需要导入模块: from pyomo.environ import ConcreteModel [as 别名]
# 或者: from pyomo.environ.ConcreteModel import c [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))
示例11: test_None_key
# 需要导入模块: from pyomo.environ import ConcreteModel [as 别名]
# 或者: from pyomo.environ.ConcreteModel import c [as 别名]
def test_None_key(self):
"""Test keys method"""
model = ConcreteModel()
model.x = Var()
model.c = Constraint(expr=model.x == 1)
self.assertEqual(list(model.c.keys()),[None])
self.assertEqual(id(model.c),id(model.c[None]))
示例12: _trivial_constraints_ub_conflict
# 需要导入模块: from pyomo.environ import ConcreteModel [as 别名]
# 或者: from pyomo.environ.ConcreteModel import c [as 别名]
def _trivial_constraints_ub_conflict(self):
m = ConcreteModel()
m.v1 = Var(initialize=1)
m.c = Constraint(expr=m.v1 <= 0)
m.v1.fix()
TransformationFactory(
'contrib.deactivate_trivial_constraints').apply_to(m)
示例13: test_binary_expressions
# 需要导入模块: from pyomo.environ import ConcreteModel [as 别名]
# 或者: from pyomo.environ.ConcreteModel import c [as 别名]
def test_binary_expressions(self):
m = ConcreteModel()
m.x = Var()
m.y = Var()
m.z = Var()
m.c = Constraint(expr=0 <= m.x + m.y - m.z * m.y / m.x + 7)
m.o = Objective(expr=m.x)
self.assertTrue(satisfiable(m))
示例14: test_solver_arg
# 需要导入模块: from pyomo.environ import ConcreteModel [as 别名]
# 或者: from pyomo.environ.ConcreteModel import c [as 别名]
def test_solver_arg(self):
m = ConcreteModel()
m.x = Var()
m.c = Constraint(expr=m.x == 2)
m.o = Objective(expr=m.x)
os = StringIO()
m.write(os, format="gams", io_options=dict(solver="gurobi"))
self.assertIn("option lp=gurobi", os.getvalue())
示例15: test_fixed_var_out_of_bounds_ub
# 需要导入模块: from pyomo.environ import ConcreteModel [as 别名]
# 或者: from pyomo.environ.ConcreteModel import c [as 别名]
def test_fixed_var_out_of_bounds_ub(self):
m = ConcreteModel()
m.s = RangeSet(2)
m.v = Var(m.s, bounds=(0, 5))
m.c = ConstraintList()
m.c.add(expr=m.v[1] == m.v[2])
m.c.add(expr=m.v[1] == 6)
with self.assertRaises(ValueError):
TransformationFactory('contrib.aggregate_vars').apply_to(m)