I am using the SciPy package from Python in order to solve a minimization problem with many constraints.
我使用的是来自Python的SciPy包,目的是解决一个有很多约束的最小化问题。
Let's say I have contradictory constraints on my solution. For purposes of this questions, let's just say I had these constraints:
比方说我的解决方案有相互矛盾的限制。出于这个问题的目的,让我们假设我有这些限制:
def con1(x):
return 0.9 * x[0] - x[1]
def con2(x):
return 0.9 * x[1] - x[0]
With these bounds [(0.001, None), (0.001, None)]
so that they are both positive.
有了这些界限[(0.001,无),(0.001,无)],使得它们都是正的。
When I run scipy.optimize.minimize
with these constraints: minimize(objective, initial_guess, method='SLSQP', bounds=bounds, constraints=cons)
当我运行带有以下约束的scipy.Optimize.Minimize时:Minimize(客观,初始_猜测,方法=‘SLSQP’,Bound=Bound,Constraints=cons)
Is there any way for scipy to tell me that these are contradictory constraints? As it stands, I either just get a solution which ignores my conditions or a bounds error.
Scipy有没有办法告诉我,这些是相互矛盾的限制?目前的情况是,我要么得到一个忽略我的条件的解,要么得到一个边界错误。
Is there any way for scipy to directly tell me that the conditions cannot be satisfied?
有没有办法让Scipy直接告诉我条件不能满足?
更多回答
Which method do you use to minimize the objective function?
你使用哪种方法来最小化目标函数?
@Corralien Have updated my Question, but it is SLSQP
@科拉伦已经更新了我的问题,但它是SLSQP
Not reproducible until you show code that actually attempts the optimization. Are you checking the success boolean?
不可重现,直到您显示实际尝试进行优化的代码。您是否在检查Success Boolean?
Or the message
in the OptimizeResult
?
或者是OptimizeResult中的消息?
我是一名优秀的程序员,十分优秀!