Page 1 of 1

Optimal solution in a loop (NLP)

Posted: Fri Mar 05, 2021 2:09 pm
by doti2109
We are trying to solve a non-linear optimization system for H units in a loop (H=4000). We obtain optimal solutions for some units (f) and Infeasable (nf=H-f) for the others. How can we get the subset of units of H ie f for which we have obtained an optimal solution. We will continue to work only with those units for which we have an optimal solution.
Thank you for your answer.
Dorothée

Re: Optimal solution in a loop (NLP)

Posted: Fri Mar 05, 2021 2:51 pm
by abhosekar
Hi,

You can create a subset f(H).

Inside the loop, you can assign it elements to it. The broad idea is as follows. Following code fragment is syntactically incomplete.

loop(H,
solve...
if (feasible,
f(H) = yes;
);
);

f(H) = yes is the place where you assign elements to set f. After the completion of this loop, you can use set f. Hope this helps.

- Atharv

Re: Optimal solution in a loop (NLP)

Posted: Fri Mar 05, 2021 5:00 pm
by doti2109
Thank you for your response. However, we have an error message of the type unknown symbol for "feasible". Does this need to be declared previously? Thank you. Dorothée

Re: Optimal solution in a loop (NLP)

Posted: Fri Mar 05, 2021 9:35 pm
by doti2109
Thank you very much Atharv, for your answer.
However, we have an error message of the type unknown symbol for "feasible". Does this need to be declared previously? I suppose so but how?

Thank you again. Dorothée

Re: Optimal solution in a loop (NLP)

Posted: Fri Mar 05, 2021 10:08 pm
by abhosekar
As I mentioned in my message, the code fragment is not syntactically complete.
Instead of if (feasible, ..)

You should check modelname.numinfes https://www.gams.com/latest/docs/UG_Gam ... AOnuminfes
(of course, modelname here is your model name)

you would write

if (modelname.numinfes eq 0,
..
);

Again the code fragment is not tested for syntax and can have minor errors. Your question was about populating the set f and this is the way to do it.

- Atharv

Re: Optimal solution in a loop (NLP)

Posted: Sat Mar 06, 2021 11:08 am
by doti2109
Merci beaucoup. Notre problème est effectivement résolu. :D