import numpy
from numpy import asarray
Initial = numpy.asarray [2.0, 4.0, 5.0, 3.0, 5.0, 6.0] # Initial values to start with
bounds = [(1, 5000), (1, 6000), (2, 100000), (1, 50000), (1.0, 5000), (2, 1000000)]
# actual passed bounds
b1 = lambda x: numpy.asarray([1.4*x[0] - x[0]])
b2 = lambda x: numpy.asarray([1.4*x[1] - x[1]])
b3 = lambda x: numpy.asarray([x[2] - x[3]])
constraints = numpy.asarray([b1, b2, b3])
opt= optimize.fmin_slsqp(func,Initial,ieqcons=constraints,bounds=bounds, full_output=True,iter=200,iprint=2, acc=0.01)
问题: 我想传入不等式约束。考虑到我有 6 个参数
[ a, b, c, d, e, f]
在Initial
值中,我的约束是:
a<=e<=1.4*a ('e' varies from a to 1.4*a)
b<=f<=1.4*b ('f' varies from b to 1.4*b)
c>d ('c' must always be greater than d)
但这不能正常工作。我不知道错误是什么。有没有更好的方法将我的约束作为函数传递?请帮我。