本文整理汇总了Python中pyomo.environ.ConcreteModel.a方法的典型用法代码示例。如果您正苦于以下问题:Python ConcreteModel.a方法的具体用法?Python ConcreteModel.a怎么用?Python ConcreteModel.a使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pyomo.environ.ConcreteModel
的用法示例。
在下文中一共展示了ConcreteModel.a方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_contains
# 需要导入模块: from pyomo.environ import ConcreteModel [as 别名]
# 或者: from pyomo.environ.ConcreteModel import a [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)
示例2: test_no_column_ordering_linear
# 需要导入模块: from pyomo.environ import ConcreteModel [as 别名]
# 或者: from pyomo.environ.ConcreteModel import a [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)
示例3: test_no_row_ordering
# 需要导入模块: from pyomo.environ import ConcreteModel [as 别名]
# 或者: from pyomo.environ.ConcreteModel import a [as 别名]
def test_no_row_ordering(self):
model = ConcreteModel()
model.a = Var()
components = {}
components["obj"] = Objective(expr=model.a)
components["con1"] = Constraint(expr=model.a >= 0)
components["con2"] = Constraint(expr=model.a <= 1)
components["con3"] = Constraint(expr=(0, model.a, 1))
components["con4"] = Constraint([1, 2], rule=lambda m, i: model.a == i)
for key in components:
model.add_component(key, components[key])
self._check_baseline(model, file_determinism=2)
示例4: test_var_on_other_model
# 需要导入模块: from pyomo.environ import ConcreteModel [as 别名]
# 或者: from pyomo.environ.ConcreteModel import a [as 别名]
def test_var_on_other_model(self):
other = ConcreteModel()
other.a = Var()
model = ConcreteModel()
model.x = Var()
model.c = Constraint(expr=other.a + 2 * model.x <= 0)
model.obj = Objective(expr=model.x)
baseline_fname, test_fname = self._get_fnames()
self._cleanup(test_fname)
self.assertRaises(
RuntimeError,
model.write, test_fname, format='gams')
self._cleanup(test_fname)
示例5: test_unary_expressions
# 需要导入模块: from pyomo.environ import ConcreteModel [as 别名]
# 或者: from pyomo.environ.ConcreteModel import a [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)
示例6: test_detect_effectively_discrete_vars
# 需要导入模块: from pyomo.environ import ConcreteModel [as 别名]
# 或者: from pyomo.environ.ConcreteModel import a [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])
示例7: test_rule
# 需要导入模块: from pyomo.environ import ConcreteModel [as 别名]
# 或者: from pyomo.environ.ConcreteModel import a [as 别名]
def test_rule(self):
def rule1(model):
return Constraint.Skip
model = ConcreteModel()
try:
model.o = Constraint(rule=rule1)
except Exception:
e = sys.exc_info()[1]
self.fail("Failure to create empty constraint: %s" % str(e))
#
def rule1(model):
return (0.0,model.x,2.0)
model = ConcreteModel()
model.x = Var(initialize=1.1)
model.o = Constraint(rule=rule1)
self.assertEqual(model.o(),1.1)
#
def rule1(model, i):
return Constraint.Skip
model = ConcreteModel()
model.a = Set(initialize=[1,2,3])
try:
model.o = Constraint(model.a,rule=rule1)
except Exception:
self.fail("Error generating empty constraint")
#
def rule1(model):
return (0.0,1.1,2.0,None)
model = ConcreteModel()
try:
model.o = Constraint(rule=rule1)
self.fail("Can only return tuples of length 2 or 3")
except ValueError:
pass