python - 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.])
解决方案
推荐阅读
- mysql - 设置时间后如何更改mysql中的值
- reactjs - 需要在我的 reactJs 页面中有元刮板或链接预览
- javascript - 解析另一个对象角度中的字符串值
- python - 开放大学 (Open Learn) 学习编码以进行数据分析
- html - 如何使用 html 和 css 编写幻灯片?
- python - gr-phosphor 中的信号映射如何工作
- python - 使用 pandas 的 dataframe.plot 显示不同的数据
- apache-spark - 使用 spark StreamingKMeans 实时获取集群的中心
- highcharts - 将 Highcharts.js 与 odoo 一起使用
- vba - VBA 中的工厂模式和单例对象