You can try mystic. It fails to solve the problem for infeasible solutions to the constraints. While not "obvious" (maybe), it returns an inf for infeasible solutions... I guess the behavior could be improved upon (I'm the author) to make it more obvious that only infeasible solutions are found.>>> def objective(x):... return x[0]**2 + x[1]**2...>>> equations = """... x0 + x1 = 11... """>>> bounds = [(6,None),(6,None)]>>>>>> from mystic.solvers import fmin_powell, diffev2>>> from mystic.symbolic import generate_constraint, generate_solvers, simplify>>>>>> cf = generate_constraint(generate_solvers(simplify(equations)))>>>>>> result = fmin_powell(objective, x0=[10,10], bounds=bounds, constraints=cf, gtol=50, disp=True, full_output=True)Warning: Maximum number of iterations has been exceeded>>> result[1]array(inf)>>>>>> result = diffev2(objective, x0=bounds, bounds=bounds, constraints=cf, npop=40, gtol=50, disp=True, full_output=True)Warning: Maximum number of iterations has been exceeded>>> result[1]inf 这篇关于对于不可行的NLP,Scipy.optimize成功终止的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云! 07-11 17:16