[英]How to write “not equal to” in AMPL or set such as a condition for a variable's parameter?
I am trying to set a variable W{m in M, n in N}
where M and N are the same set of values.我正在尝试设置一个变量W{m in M, n in N}
,其中 M 和 N 是同一组值。 M and N represent a location. M 和 N 代表一个位置。 Variable W represents a transfer between m and n.变量 W 表示 m 和 n 之间的转移。 Therefore, m cannot equal to n in variable W. For example, when m = 1, n can only equal to 2 and 3 (M=N=c(1,2,3)).因此,变量W中的m不能等于n。例如,当m=1时,n只能等于2和3(M=N=c(1,2,3))。
This is a cost-minimizing 2-stage stochastic model.这是一个成本最小化的 2 阶段随机 model。 I tried to write m <> n
into the sum conditions as well as writing m <> n
in the constraint.我试图将m <> n
写入求和条件,并在约束中写入m <> n
。 All returned syntax error.所有返回的语法错误。
I tried to add the condition into the objective function:我尝试将条件添加到目标 function 中:
sum{m in M, n in N |和{m中的m,n中的n | m <> n}W[m,n]; m <> n}W[m,n];
sum{m in M, n in N, m <> n}W[m,n]; sum{m in M, n in N, m <> n}W[m,n];
sum{m in M, n in N, m,=n}W[m;n]; sum{m 中的 m,n 中的 n,m,=n}W[m;n];
sum{m in M, n in N |和{m中的m,n中的n | m,= n}W[m;n]; m,= n}W[m;n];
I also tried to add it into the variable definition:我还尝试将其添加到变量定义中:
var W{m in M, n in N, m <> n}; var W{m 中的 m,N 中的 n,m <> n};
etc.. ETC..
I tried many ways but none is working.我尝试了很多方法,但没有一个有效。 AMPL returned syntax error if I added the m<>n
or m!=n
into the model.如果我将m<>n
或m!=n
添加到 model 中,AMPL 会返回语法错误。 After I delete the m!=n
conditions, the model works but returning the wrong number.在我删除m!=n
条件后,model 工作但返回错误的数字。
sum{m in M, n in N: m <> n} W[m,n]; sum{m in M, n in N: m <> n} W[m,n];
In AMPL you can use ":" to make a condition in the sum or forall method.在 AMPL 中,您可以使用“:”在 sum 或 forall 方法中创建条件。 Eg:例如:
sum{m in M, n in N : m <> n}W[m,n];
sum{m in M, n in N : m!=n}W[m,n];
sum{m in M, n in N : m != n}W[m,n];
I hope it helps:)我希望它有帮助:)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.