3

我正在尝试使用差异进化来根据成本优化可用性。但是,我在这里有三个未知参数(a、b、c),我可以使用边界来定义范围。但是,我想将附加约束定义为 a+b+c <= 10000。我正在使用 python 来执行此操作,并且我尝试在差分进化中使用选项“args”,但它不起作用。任何信息将不胜感激。

4

2 回答 2

3

这是一个黑客。我使用了文档中的最后一个示例并约束了 sum(x) > 4.1(没有这个约束,优化的解决方案是 (0,0)):

from scipy.optimize import differential_evolution
import numpy as np
def ackley(x):
    arg1 = -0.2 * np.sqrt(0.5 * (x[0] ** 2 + x[1] ** 2))
    arg2 = 0.5 * (np.cos(2. * np.pi * x[0]) + np.cos(2. * np.pi * x[1]))

    if x[0]+x[1] > 4.1: #this is the constraint, where you would say a+b+c <=1000
        return -20. * np.exp(arg1) - np.exp(arg2) + 20. + np.e
    else:
        return 1000 #some high value

bounds = [(-5, 5), (-5, 5)]
result = differential_evolution(ackley, bounds)
result.x, result.fun
于 2017-04-13T17:51:26.780 回答
-3

使用差分进化定义约束不是我上面描述的问题的合适解决方案。为此,我们可以使用具有专用选项的 Nminimize 命令来定义约束。

scipy.optimize.minimize(fun, x0, args=(), method=None, jac=None, hess=None, hessp=None, bounds=None, constraints=(), tol=None, callback=None, options=None)
于 2017-04-22T20:35:01.120 回答