本文整理汇总了Python中cobra.Model.change_objective方法的典型用法代码示例。如果您正苦于以下问题:Python Model.change_objective方法的具体用法?Python Model.change_objective怎么用?Python Model.change_objective使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类cobra.Model
的用法示例。
在下文中一共展示了Model.change_objective方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_inequality
# 需要导入模块: from cobra import Model [as 别名]
# 或者: from cobra.Model import change_objective [as 别名]
def test_inequality(self):
# The space enclosed by the constraints is a 2D triangle with
# vertexes as (3, 0), (1, 2), and (0, 1)
solver = self.solver
# c1 encodes y - x > 1 ==> y > x - 1
# c2 encodes y + x < 3 ==> y < 3 - x
c1 = Metabolite("c1")
c2 = Metabolite("c2")
x = Reaction("x")
x.lower_bound = 0
y = Reaction("y")
y.lower_bound = 0
x.add_metabolites({c1: -1, c2: 1})
y.add_metabolites({c1: 1, c2: 1})
c1._bound = 1
c1._constraint_sense = "G"
c2._bound = 3
c2._constraint_sense = "L"
m = Model()
m.add_reactions([x, y])
# test that optimal values are at the vertices
m.change_objective("x")
self.assertAlmostEqual(solver.solve(m).f, 1.0)
self.assertAlmostEqual(solver.solve(m).x_dict["y"], 2.0)
m.change_objective("y")
self.assertAlmostEqual(solver.solve(m).f, 3.0)
self.assertAlmostEqual(solver.solve(m, objective_sense="minimize").f,
1.0)