本文整理汇总了Python中pyomo.environ.ConcreteModel类的典型用法代码示例。如果您正苦于以下问题:Python ConcreteModel类的具体用法?Python ConcreteModel怎么用?Python ConcreteModel使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了ConcreteModel类的17个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: test_not_transform_improperly
def test_not_transform_improperly(self):
"""Tests that invalid constraints are not transformed."""
m = ConcreteModel()
m.v1 = Var(initialize=0, domain=Binary)
m.c1 = Constraint(expr=-1 * m.v1 <= 0)
TransformationFactory('contrib.propagate_zero_sum').apply_to(m)
self.assertFalse(m.v1.fixed)
开发者ID:Pyomo,项目名称:pyomo,代码行数:7,代码来源:test_zero_sum_propagate.py
示例2: test_multiple_objectives
def test_multiple_objectives(self):
m = ConcreteModel()
m.x = Var()
m.o = Objective(expr=m.x)
m.o2 = Objective(expr=m.x + 1)
with self.assertRaisesRegexp(ValueError, "Model has multiple active objectives"):
SolverFactory('gdpopt').solve(m)
开发者ID:Pyomo,项目名称:pyomo,代码行数:7,代码来源:test_gdpopt.py
示例3: test_multiple_obj
def test_multiple_obj(self):
m = ConcreteModel()
m.x = Var()
m.o = Objective(expr=m.x)
m.o2 = Objective(expr=m.x)
with self.assertRaisesRegexp(RuntimeError, "multiple active objectives"):
SolverFactory('multistart').solve(m)
开发者ID:Pyomo,项目名称:pyomo,代码行数:7,代码来源:test_multi.py
示例4: test_None_key
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]))
开发者ID:Pyomo,项目名称:pyomo,代码行数:7,代码来源:test_con.py
示例5: _trivial_constraints_ub_conflict
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)
开发者ID:Pyomo,项目名称:pyomo,代码行数:7,代码来源:test_deactivate_trivial_constraints.py
示例6: test_unique_component_name
def test_unique_component_name(self):
m = ConcreteModel()
m.x = 5
m.y = Var()
name = unique_component_name(m, 'z')
self.assertEqual(name, 'z')
name = unique_component_name(m, 'x')
self.assertEqual(len(name), 3)
self.assertEqual(name[:2], 'x_')
self.assertIn(name[2], '0123456789')
name = unique_component_name(m, 'y')
self.assertEqual(len(name), 3)
self.assertEqual(name[:2], 'y_')
self.assertIn(name[2], '0123456789')
name = unique_component_name(m, 'component')
self.assertEqual(len(name), 11)
self.assertEqual(name[:10], 'component_')
self.assertIn(name[10], '0123456789')
for i in range(10):
setattr(m, 'y_%s' % i, 0)
name = unique_component_name(m, 'y')
self.assertEqual(len(name), 4)
self.assertEqual(name[:2], 'y_')
self.assertIn(name[2], '0123456789')
self.assertIn(name[3], '0123456789')
开发者ID:Pyomo,项目名称:pyomo,代码行数:30,代码来源:test_modeling.py
示例7: test_reclassification
def test_reclassification(self):
m = ConcreteModel()
m.t = ContinuousSet(bounds=(0, 1))
m.x = ContinuousSet(bounds=(5, 10))
m.s = Set(initialize=[1, 2, 3])
m.v = Var(m.t)
m.v2 = Var(m.s, m.t)
m.v3 = Var(m.x, m.t)
m.dv = DerivativeVar(m.v)
m.dv2 = DerivativeVar(m.v2, wrt=(m.t, m.t))
m.dv3 = DerivativeVar(m.v3, wrt=m.x)
TransformationFactory('dae.finite_difference').apply_to(m, wrt=m.t)
self.assertTrue(m.dv.type() is Var)
self.assertTrue(m.dv2.type() is Var)
self.assertTrue(m.dv.is_fully_discretized())
self.assertTrue(m.dv2.is_fully_discretized())
self.assertTrue(m.dv3.type() is DerivativeVar)
self.assertFalse(m.dv3.is_fully_discretized())
TransformationFactory('dae.collocation').apply_to(m, wrt=m.x)
self.assertTrue(m.dv3.type() is Var)
self.assertTrue(m.dv3.is_fully_discretized())
开发者ID:Pyomo,项目名称:pyomo,代码行数:25,代码来源:test_diffvar.py
示例8: test_linear
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)
开发者ID:Pyomo,项目名称:pyomo,代码行数:7,代码来源:test_calc_var_value.py
示例9: test_GDP_nonlinear_objective
def test_GDP_nonlinear_objective(self):
m = ConcreteModel()
m.x = Var(bounds=(-1, 10))
m.y = Var(bounds=(2, 3))
m.d = Disjunction(expr=[
[m.x + m.y >= 5], [m.x - m.y <= 3]
])
m.o = Objective(expr=m.x ** 2)
SolverFactory('gdpopt').solve(
m, strategy='LOA',
mip_solver=mip_solver,
nlp_solver=nlp_solver
)
self.assertAlmostEqual(value(m.o), 0)
m = ConcreteModel()
m.x = Var(bounds=(-1, 10))
m.y = Var(bounds=(2, 3))
m.d = Disjunction(expr=[
[m.x + m.y >= 5], [m.x - m.y <= 3]
])
m.o = Objective(expr=-m.x ** 2, sense=maximize)
SolverFactory('gdpopt').solve(
m, strategy='LOA',
mip_solver=mip_solver,
nlp_solver=nlp_solver
)
self.assertAlmostEqual(value(m.o), 0)
开发者ID:Pyomo,项目名称:pyomo,代码行数:28,代码来源:test_gdpopt.py
示例10: test_simple_unsat_model
def test_simple_unsat_model(self):
m = ConcreteModel()
m.x = Var()
m.c1 = Constraint(expr=1 == m.x)
m.c2 = Constraint(expr=2 == m.x)
m.o = Objective(expr=m.x)
self.assertFalse(satisfiable(m))
开发者ID:Pyomo,项目名称:pyomo,代码行数:7,代码来源:test_satsolver.py
示例11: build_model
def build_model():
"""Simple non-convex model with many local minima"""
model = ConcreteModel()
model.x1 = Var(initialize=1, bounds=(0, 100))
model.x2 = Var(initialize=5, bounds=(5, 6))
model.x2.fix(5)
model.objtv = Objective(expr=model.x1 * sin(model.x1), sense=maximize)
return model
开发者ID:Pyomo,项目名称:pyomo,代码行数:8,代码来源:test_multi.py
示例12: test_invalid_derivative
def test_invalid_derivative(self):
m = ConcreteModel()
m.t = ContinuousSet(bounds=(0, 10))
m.v = Var(m.t)
m.dv = DerivativeVar(m.v, wrt=(m.t, m.t, m.t))
with self.assertRaises(DAE_Error):
TransformationFactory('dae.finite_difference').apply_to(m)
开发者ID:Pyomo,项目名称:pyomo,代码行数:8,代码来源:test_finite_diff.py
示例13: test_var_bound_propagate_crossover
def test_var_bound_propagate_crossover(self):
"""Test for error message when variable bound crosses over."""
m = ConcreteModel()
m.v1 = Var(initialize=1, bounds=(1, 3))
m.v2 = Var(initialize=5, bounds=(4, 8))
m.c1 = Constraint(expr=m.v1 == m.v2)
xfrm = TransformationFactory('contrib.propagate_eq_var_bounds')
with self.assertRaises(ValueError):
xfrm.apply_to(m)
开发者ID:Pyomo,项目名称:pyomo,代码行数:9,代码来源:test_equality_propagate.py
示例14: test_fixed_var_out_of_bounds_ub
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)
开发者ID:Pyomo,项目名称:pyomo,代码行数:9,代码来源:test_var_aggregator.py
示例15: test_no_integer
def test_no_integer(self):
m = ConcreteModel()
m.x = Var()
output = StringIO()
with LoggingIntercept(output, 'pyomo.contrib.preprocessing', logging.INFO):
xfrm('contrib.integer_to_binary').apply_to(m)
expected_message = "Model has no free integer variables."
self.assertIn(expected_message, output.getvalue())
开发者ID:Pyomo,项目名称:pyomo,代码行数:9,代码来源:test_int_to_binary.py
示例16: test_no_objective
def test_no_objective(self):
m = ConcreteModel()
m.x = Var(bounds=(-5, 5))
m.c = Constraint(expr=m.x ** 2 >= 1)
output = StringIO()
with LoggingIntercept(output, 'pyomo.contrib.gdpopt', logging.WARNING):
SolverFactory('gdpopt').solve(m, nlp_solver=nlp_solver)
self.assertIn("Model has no active objectives. Adding dummy objective.",
output.getvalue().strip())
开发者ID:Pyomo,项目名称:pyomo,代码行数:9,代码来源:test_gdpopt.py
示例17: test_set_expr_inline
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)
开发者ID:Pyomo,项目名称:pyomo,代码行数:9,代码来源:test_con.py
注:本文中的pyomo.environ.ConcreteModel类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论