gpt4 book ai didi

SciPy - Warning when there are Contradictory constraints?(科学-当存在相互矛盾的约束时发出警告?)

转载 作者:bug小助手 更新时间:2023-10-25 16:28:09 24 4
gpt4 key购买 nike



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中的消息?

Does this answer your question? Scipy.optimize.minimize method='SLSQP' ignores constraint Looks like SLSQP can use mode=4 to signal this issue.

这回答了你的问题吗?Scipy.Optimize.Minimize方法=‘SLSQP’忽略约束看起来SLSQP可以使用MODE=4来通知此问题。

优秀答案推荐
更多回答

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com