本文整理汇总了Python中pyomo.environ.ConcreteModel.write方法的典型用法代码示例。如果您正苦于以下问题:Python ConcreteModel.write方法的具体用法?Python ConcreteModel.write怎么用?Python ConcreteModel.write使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pyomo.environ.ConcreteModel
的用法示例。
在下文中一共展示了ConcreteModel.write方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_solver_arg
# 需要导入模块: from pyomo.environ import ConcreteModel [as 别名]
# 或者: from pyomo.environ.ConcreteModel import write [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())
示例2: test_gams_connector_in_active_constraint
# 需要导入模块: from pyomo.environ import ConcreteModel [as 别名]
# 或者: from pyomo.environ.ConcreteModel import write [as 别名]
def test_gams_connector_in_active_constraint(self):
m = ConcreteModel()
m.b1 = Block()
m.b2 = Block()
m.b1.x = Var()
m.b2.x = Var()
m.b1.c = Connector()
m.b1.c.add(m.b1.x)
m.b2.c = Connector()
m.b2.c.add(m.b2.x)
m.c = Constraint(expr=m.b1.c == m.b2.c)
m.o = Objective(expr=m.b1.x)
os = StringIO()
with self.assertRaises(RuntimeError):
m.write(os, format="gams")
示例3: test_gams_expanded_connectors
# 需要导入模块: from pyomo.environ import ConcreteModel [as 别名]
# 或者: from pyomo.environ.ConcreteModel import write [as 别名]
def test_gams_expanded_connectors(self):
m = ConcreteModel()
m.x = Var()
m.y = Var()
m.CON1 = Connector()
m.CON1.add(m.x, 'v')
m.CON2 = Connector()
m.CON2.add(m.y, 'v')
m.c = Constraint(expr=m.CON1 + m.CON2 >= 10)
TransformationFactory("core.expand_connectors").apply_to(m)
m.o = Objective(expr=m.x)
os = StringIO()
io_options = dict(symbolic_solver_labels=True)
m.write(os, format="gams", io_options=io_options)
# no error if we're here, but check for some identifying string
self.assertIn("x + y", os.getvalue())