简体   繁体   English

如何在AMPL中写“不等于”或设置变量参数的条件?

[英]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<>nm!=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.

相关问题 Q:AMPL 语法错误:如何在定义变量时写公式 - Q:AMPL syntax error:How to write a formula in the definition of a variable 如何根据另一个数组的条件自动设置数组值? - How to set array values automatically from another array's condition? 为什么我们必须定义变量 dp = [0] * (n+1) 只是为了将其变量设置为等于 0(在动态规划中) - Why we have to define variable dp = [0] * (n+1) just to set its variable equal to 0( In Dynamic Programming) 设置n个数字的S - 具有一个子集,其中S中每个元素的概率相等 - Set S of n numbers - have a subset with the probability of each element of S occuring in it equal 如何检查 C++ 中的双变量是否几乎等于零? - how to check if double variable is almost equal to zero in C++? 如何根据项目的权重将项目列表拆分为相等的分区? - How to split a list of items into equal partitions according to the item's weight? 如何为依赖于 x 的非线性薛定谔方程中的初始条件编写子程序 - How to write a subroutine for initial condition in Nonlinear Schrodinger Equation that depends on x 如何编写代码,以便只有在条件为true时才能单击Button? - How to write code so that Button is only clickable when condition is true? 条件参数调整 - condition parameter adjustment 最大的子矩阵,等于1和0 - Largest submatrix with equal no of 1's and 0's
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM