我正在使用 scipy 差分进化。我必须设置以下线性约束。0<x1+x2+x3+x4<=1。x2+x3=1。我设置了以下矩阵 A=[0 1 1 0] B=[1]。线性约束 = 线性约束(A,B,B,真)。我还将下限和上限设置为 0 和 1。然而,在每次迭代过程中,目标函数的输出是 InF,而差分进化没有调用目标函数
谁能提出什么问题?我的 Scipy 版本是 1.5.4 和 python 3.7。
感谢提前..
我正在使用 scipy 差分进化。我必须设置以下线性约束。0<x1+x2+x3+x4<=1。x2+x3=1。我设置了以下矩阵 A=[0 1 1 0] B=[1]。线性约束 = 线性约束(A,B,B,真)。我还将下限和上限设置为 0 和 1。然而,在每次迭代过程中,目标函数的输出是 InF,而差分进化没有调用目标函数
谁能提出什么问题?我的 Scipy 版本是 1.5.4 和 python 3.7。
感谢提前..
您需要将约束设置为:
from scipy.optimize import LinearConstraint
A = np.array([[1.0, 1.0, 1.0, 1.0],
[0.0, 1.0, 1.0, 0.0]])
lc = LinearConstraint(A, [0, 1], [1, 1])
关键字将keep_feasible
被忽略。为了使约束可行,每个参数的边界必须包含一个可行区域。例如,如果x2
andx3
是正数,则x1
or之一x4
必须能够访问负值。
在受约束的最小化中,仅当试验解决方案不可行时才评估目标函数。
如果满足以下条件,则接受试用解决方案:
Trial is accepted if:
* it satisfies all constraints and provides a lower or equal objective
function value, while both the compared solutions are feasible
- or -
* it is feasible while the original solution is infeasible,
- or -
* it is infeasible, but provides a lower or equal constraint violation
for all constraint functions.