我想在GAMS中运行几个数学模型并计算不可行解决方案的数量。我该如何写IF语句的条件?
答案 0 :(得分:3)
解决后,您可以检查模型的modelstat属性。这是一个小例子:
equation obj;
variable z;
positive variable x;
obj.. z =e= 1;
equation feasible;
feasible.. x =g= 1;
equation infeasible1;
infeasible1.. x =l= -1;
equation infeasible2;
infeasible2.. x =l= -2;
model m1 /obj, feasible /;
model m2 /obj, infeasible1/;
model m3 /obj, infeasible2/;
scalar infCount Number of infeasible models /0/;
solve m1 min z use lp;
if(m1.modelstat = %ModelStat.Infeasible%, infCount = infCount+1;)
solve m2 min z use lp;
if(m2.modelstat = %ModelStat.Infeasible%, infCount = infCount+1;)
solve m3 min z use lp;
if(m3.modelstat = %ModelStat.Infeasible%, infCount = infCount+1;)
display infCount;
如果您有整数问题,您还应该检查%ModelStat.Integer不可行%,而不仅仅是%ModelStat.Infeasible%,因此解决后的检查可能会变为
solve m3 min z use mip;
if(m3.modelstat = %ModelStat.Infeasible% or m3.modelstat = %ModelStat.Integer Infeasible%,
infCount = infCount+1;
)
我希望,这有帮助! 鲁兹