Scipy-不平等约束不兼容

时间:2018-12-13 14:31:04

标签: python python-3.x

有什么意思吗?我是Python的新手,所以我总体上可能做的不正确,但只想将约束条件设为X [0]> = 0,但它表示不兼容。

def objective (x):
    global sumIp
    global sumIm
    if (NIt[i-1] < s[i-1]):
        NIt[i] = NIt[i-1] - d[i-1] + x[0]
    else:
        NIt[i] = NIt[i-1] - d[i-1]
    It[i] = NIt[i] - d[i] - x[0] + Qt[i-LT]
    if It[i] >= 0:
        sumIp = sumIp+It[i]
        sumIm = sumIm+0
    elif It[i] < 0:
        sumIp = sumIp+0
        sumIm = sumIm-It[i]
    return h*sumIp+b*sumIm


def constraint1 (x):
    return x[0]

(...)

x0 = 1
con1 = {'type': 'ineq', 'fun': constraint1}
cons = [con1]
sol = minimize(objective, x0, constraints=cons)

这是sol返回的内容(请记住,它包含在循环中,因此现在仅打印最后一次迭代)

fun: 26249.99991133809
jac: array([3.99297739e+10])
message: 'Inequality constraints incompatible'
nfev: 3
nit: 1
njev: 1
status: 4
success: False
x: array([1.])

0 个答案:

没有答案