How to iterate/loop until GAMS solution is infeasible

Problems with modeling
Post Reply
jonkaneshiro
User
User
Posts: 2
Joined: 7 years ago

How to iterate/loop until GAMS solution is infeasible

Post by jonkaneshiro »

Hello,
I am currently creating an optimization model that maximizes entropy with respect to a varying population. I'll be doing a lot of scenarios and was wondering if there is a way to make GAMS stop at an infeasible solution while in the loop.

I noticed there are some answers about this with modelstat, but I don't fully understand the syntax of that. Can someone please help? Thank you!

$offorder
Model selfsufficiency /all/ ;
file results /results_entropy.res/ ;
put results ;
loop(Pop,
varying_population = (ord(Pop))*130000 ;
Solve selfsufficiency using NLP maximize TotalEntropy ;
put @5, varying_population, @15, TotalEntropy.l/;
);
putclose results;
User avatar
bussieck
Moderator
Moderator
Posts: 1033
Joined: 7 years ago

Re: How to iterate/loop until GAMS solution is infeasible

Post by bussieck »

Code: Select all

scalar stopped /0/;
loop(Pop$(not stopped),
  varying_population = (ord(Pop))*130000 ;
  Solve selfsufficiency using NLP maximize TotalEntropy ;
  if (selfsufficiency.modelstat=1 or selfsufficiency.modelstat=2,
    put @5, varying_population, @15, TotalEntropy.l/;
  else
    put @5, varying_population, @15, "Not optimal anymore. Model status: ", selfsufficiency.modelstat:0:0 /;
    stopped = 1;
  );
);
putclose results;
Instead of checking for infeasible, I checked for "not (locally) optimal". The list of all model status values can be found here https://www.gams.com/latest/docs/usergu ... odelStatus

-Michael
CurtisL
User
User
Posts: 3
Joined: 7 years ago

Re: How to iterate/loop until GAMS solution is infeasible

Post by CurtisL »

Maybe you can try "abort" command. Good luck
Post Reply