Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
在 AMPL 中,我有一组变量 x[e],对于某些计算,我需要一个二进制变量 w[e],当 x[e] > 0 时等于 1,如果 x[e] = 0,则等于 0。我尝试了很多做这个约束的东西,但我没有想出一些东西。这可能吗?
我已经通过以下方式解决了您的问题:
var u binary;
这是我们的二进制变量,它将是 0 或 1。然后我们提出以下约束:
subject to U_constraint : x <= 999999 * u;
现在,当 x = 0 时,AMPL 将使 u = 0,而当 x != 0 时,显然 u = 1。