首页 > 解决方案 > Scipy - 不等式约束不兼容

问题描述

知道这意味着什么吗?我是 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.])

标签: pythonpython-3.x

解决方案


推荐阅读