您可以指定一个常数成本函数,例如 0。
这是一个例子:
%pylab
from scipy.optimize import linprog
A = array([[1] + 9 * [0], 9 * [0] + [1]])
b = array([1, 1])
测量这种方法的性能表明它非常有效:
%time
res = linprog(c=zeros(A.shape[1]), A_eq=A, b_eq=b)
Output:
CPU times: user 5 µs, sys: 1 µs, total: 6 µs
Wall time: 11 µs
此外,根据res.nit
,我们只经过 2 次迭代就完成了。
结果res.x
是正确的:
array([ 1., 0., 0., 0., 0., 0., 0., 0., 0., 1.])
请注意,单纯形算法旨在查找由线性约束定义的多面体的顶点。据我了解,基于内部点的方法没有这样的偏好,尽管我不熟悉 scipy 背后的实现linprog
。因此,既然你的要求是,重点是“显然位于半空间定义的区域内”,我建议采用以下任一方法:
-
Either, pass
method='interior-point'
to linprog
.
-
Or, compute different vertices and exploit that the polyhedron is convex:
- 向恒定目标函数添加一些噪声(例如,通过
np.random.randn
)
- 通过改变噪声种子来求解噪声增强 LP 的多个实例 (
np.random.seed
).
- 最后,使用解的平均值作为最终的内点“显然在该区域内”.
由于尚不清楚内点的余量需要有多大,因此我希望第二种方法(噪声增强 LP)更加稳健。