0
我希望尽量减少与多个参数和约束功能与Scipy.optimize.minimize:Scipy最小化:如何将x限制为0和1?
def f(x):
return -1*(0.9*x[0] + 0.8*x[1] + 0.85*x[2])*(0.95*x[3] + 0.8*x[4] + 0.7*x[5])*(0.98*x[6] + 0.94*x[7])
x0 = [0, 0, 1, 0, 0, 1, 0, 1]
cons=({'type': 'eq',
'fun': lambda x: x[0] + x[1] + x[2] - 1},
{'type': 'eq',
'fun': lambda x: x[3] + x[4] + x[5] - 1},
{'type': 'eq',
'fun': lambda x: x[6] + x[7] - 1},
{'type': 'ineq',
'fun': lambda x: -1*(3*x[0] + x[1] + 2*x[2] + 3*x[3] + 2*x[4] + x[5] + 3*x[6] + 2*x[7] - 6)})
我怎么告诉蟒蛇是X [I]只能是0和1?
另请参阅:http://stackoverflow.com/questions/17864474/how-to-minimize-a-function-with-discrete-variable-values-in-scipy – cel