更新时间:2023-11-29 13:24:22
我找到了一种使用约束的left
属性的不错方法,该属性确实具有value
属性:
I've found an ok way to do it, using the left
attribute of the constraint, which does have a value
attribute:
x.value = 3.
y.value = 1.
for c in [c1, c2, c3]:
constraint_text = '%s %s %s' % (c.left.value, c.type, c.right)
print '%s becomes %s which is %s' % (c, constraint_text, eval(constraint_text))
打印:
x >= 1.0 becomes 3.0 >= 1.0 which is True
y >= 1.0 becomes 1.0 >= 1.0 which is True
x + y <= -4.0 becomes 4.0 <= -4.0 which is False
如果有人知道更好的方法,请随时分享.
If anyone knows a better way, feel free to share.