本文整理汇总了Python中pulp.LpProblem.sortedVariables方法的典型用法代码示例。如果您正苦于以下问题:Python LpProblem.sortedVariables方法的具体用法?Python LpProblem.sortedVariables怎么用?Python LpProblem.sortedVariables使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pulp.LpProblem
的用法示例。
在下文中一共展示了LpProblem.sortedVariables方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: pulp_solve
# 需要导入模块: from pulp import LpProblem [as 别名]
# 或者: from pulp.LpProblem import sortedVariables [as 别名]
def pulp_solve(A, b, c):
problem = LpProblem(sense = pulp.constants.LpMaximize)
x = [LpVariable('x' + str(i + 1),
0,
None,
LpInteger)
for i in xrange(len(c))]
problem += lpSum(ci * xi for ci, xi in zip(c, x))
for ai, bi in zip(A, b):
problem += lpSum(aij * xj for aij, xj in zip(ai, x)) == bi
status = problem.solve()
return (pulp.constants.LpStatus[status],
[variable.varValue for variable in problem.sortedVariables()],
problem.objective.value())
示例2: pulp_solve
# 需要导入模块: from pulp import LpProblem [as 别名]
# 或者: from pulp.LpProblem import sortedVariables [as 别名]
def pulp_solve(A, b, c, bounds):
problem = LpProblem(sense = pulp.constants.LpMaximize)
x = [LpVariable('x' + str(i + 1),
bound['low_bound'],
bound['up_bound'],
LpInteger)
for i, bound in enumerate(bounds)]
problem += lpSum(ci * xi for ci, xi in zip(c, x))
for ai, bi in zip(A, b):
problem += lpSum(aij * xj for aij, xj in zip(ai, x)) == bi
status = problem.solve()
return (pulp.constants.LpStatus[status],
[variable.varValue for variable in problem.sortedVariables()],
problem.objective.value())