我正在尝试使用 python 中的 cvxopt 库对线性目标函数和凸约束进行约束优化(最大化)问题。目前,约束是二次的,但我想最终用一个通用的凸多项式来做。问题基本上是:最大化 c_1*x_1 + c_2*x_2 + c_3*x_3 受约束 k_1*x_1^(alpha+1) + k_2*x_2^(alpha+1) + k_3*x_3^(alpha+1) <= 预算,并且 x_i 非负数。我的代码:
import numpy as np
from cvxopt import solvers, matrix, spdiag, mul
c = -matrix([1.,2.,3.]) #minimize negative for maximization
alpha = 1.
rate_vec = matrix([.1,.2,.3])
budget = 1000
def F(x = None, z = None):
if x is None: return 1, matrix([1.,1.,1.])
if min(x) <= 0: return None
f = matrix(rate_vec.trans() * x**(alpha + 1.) - budget)
Df = matrix((alpha + 1.)*mul(rate_vec, x**alpha)).trans()
if z is None: return f, Df
H = spdiag(z[0,0]*(alpha + 1.)*alpha*mul(rate_vec, x**(alpha -1.)))
return f, Df, H
t = solvers.cpl(c,F)
我的输出是:
pcost dcost gap pres dres
0: -6.0000e+00 -1.0054e+03 1e+00 1e+00 1e+00
1: -7.3931e+00 -1.7384e+01 2e-02 1e+00 1e+00
2: -1.1174e+01 -1.1274e+01 4e-04 1e+00 1e+00
3: -2.1707e+01 -2.1904e+01 8e-06 1e+00 1e+00
4: -2.2126e+01 -2.2519e+01 2e-07 1e+00 1e+00
5: -2.2667e+01 -2.3448e+01 3e-09 1e+00 1e+00
6: -2.3665e+01 -2.5217e+01 6e-11 1e+00 1e+00
7: -2.5861e+01 -2.8941e+01 1e-12 1e+00 1e+00
8: -3.1961e+01 -3.8037e+01 2e-14 1e+00 1e+00
9: -5.9255e+01 -7.0625e+01 5e-16 9e-01 1e+00
10: -1.0993e+02 -1.2780e+02 9e-18 8e-01 1e+00
Terminated (singular KKT matrix).
关于出了什么问题的任何提示?