任何人都可以解释参数界限是如何工作的。我正在阅读文档而我无法理解它。 https://docs.scipy.org/doc/scipy/reference/optimize.linprog-simplex.html
答案 0 :(得分:1)
我不确定你要求什么,因为文档完全描述了它。但这里有一些例子:
from scipy.optimize import linprog
c = [-1, 4]
A = [[-3, 1], [1, 2]]
b = [6, 4]
没有明确的界限: 默认的行为;每个变量都相同
res = linprog(c, A, b)
# Default: lower-bound of each variable is 0, upper-bound is +inf
一对显式界限: 所有变量的一个边界定义
x0_bnds = (-3, 5)
res = linprog(c, A, b, bounds=x0_bnds)
# lower-bound of each -3, upper-bound 5
x1_bnds = (-3, None)
res = linprog(c, A, b, bounds=x1_bnds)
# lower-bound of each -3, upper-bound +inf
x2_bnds = (-np.inf, None)
res = linprog(c, A, b, bounds=x2_bnds)
# lower-bound of each -inf, upper-bound +inf
对的序列作为明确的界限: 每个变量的一个边界定义
x0_bnds = (None, None)
x1_bnds = (-3, None)
res = linprog(c, A, b, bounds=(x0_bnds, x1_bnds))
# x0 between 0 and +inf
# x1 between -3, +inf
# len(bounds) = len((x0_bnds, x1_bnds)) needs to be equal to number of vars