Reputation: 3
I want to run several mathematical models in GAMS and count the number of infeasible solutions. How should I write the condition of IF statement?
Upvotes: 0
Views: 253
Reputation: 2292
You can check the modelstat attribute of your models after solving them. Here is a little example:
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;
If you have an integer problem you should also check for %ModelStat.Integer Infeasible% and not only %ModelStat.Infeasible%, so the check after a solve could become
solve m3 min z use mip;
if(m3.modelstat = %ModelStat.Infeasible% or m3.modelstat = %ModelStat.Integer Infeasible%,
infCount = infCount+1;
)
I hope, that helps! Lutz
Upvotes: 2