为什么在 Python 中使用 Mystic 优化非线性约束优化时会收到 'cannot simply inequalities' 错误?

Why when using Mystic in Python to optimise a non linear constrained optimisation do I receive a 'cannot simply inequalities' error?

我正在尝试使用 Mystic 优化以下问题。我目前收到一个我不明白的错误,希望更熟悉该库的人可以提供帮助。

def objective(x):
    x0,x1,x2,x3,x4,x5,x6,x7,x8 = x
    return x0**2 + x4**2 + x8**2
equations = '''
x0 + x1 + x2 - x3 - x6 - 20 == 0.0
x4 + x3 + x5 - x1 - x7 - 150 == 0.0
x8 + x6 + x7 - x2 - x5 + 100 == 0.0
x6 == 0
x7 == 0
x0 >= 10
x4 >= 60
'''
from mystic.symbolic import generate_conditions, generate_penalty
pf = generate_penalty(generate_conditions(equations), k=1e4)
from mystic.symbolic import generate_constraint, generate_solvers, solve
cf = generate_constraint(generate_solvers(solve(equations))

计算 cf 时我收到一个 'NotImplementedError:cannot simplify inequalities' 并且想知道为什么会这样? 如果有人知道我将如何扩展它以便我可以通过函数或以不同的方式创建约束,我也很想知道。 干杯

我是神秘作者。你应该总是先尝试使用 solve(equations) 看看会发生什么。由于不等式,它可能无法象征性地求解方程。如果是这样,则尝试改为 simplify(equalities) 。这象征性地简化了方程式,因此每条线的 LHS 上只有一个变量。不等式求解器通常可以在这种情况下工作。如果失败,您可以重写方程式,使 LHS 上只有一个变量。

>>> def objective(x):
...     x0,x1,x2,x3,x4,x5,x6,x7,x8 = x
...     return x0**2 + x4**2 + x8**2
... 
>>> import mystic
>>> equations = '''
... x0 + x1 + x2 - x3 - x6 - 20 == 0.0
... x4 + x3 + x5 - x1 - x7 - 150 == 0.0
... x8 + x6 + x7 - x2 - x5 + 100 == 0.0
... x6 == 0
... x7 == 0
... x0 >= 10
... x4 >= 60
... '''
>>> eqns = mystic.symbolic.simplify(equations)
>>> print(eqns)
x0 == -x1 - x2 + x3 + x6 + 20
x8 == x2 + x5 - x6 - x7 - 100
x4 >= 60
x7 == 0
x6 == 0
x0 >= 10
x4 == x1 - x3 - x5 + x7 + 150
>>> from mystic.symbolic import generate_constraint, generate_solvers 
>>> cf = generate_constraint(generate_solvers(eqns))
>>> cf([0,1,2,3,4,5,6,7,8])
[26, 1, 2, 3, 143, 5, 0, 0, -106]
>>>