## Optimal solution in a loop (NLP) Topic is solved

Solver related questions
doti2109
User
Posts: 4
Joined: 4 months ago

### Optimal solution in a loop (NLP)

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.
Dorothée

abhosekar
Moderator
Posts: 190
Joined: 10 months ago

### Re: Optimal solution in a loop (NLP)

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

doti2109
User
Posts: 4
Joined: 4 months ago

### Re: Optimal solution in a loop (NLP)

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

doti2109
User
Posts: 4
Joined: 4 months ago

### Re: Optimal solution in a loop (NLP)

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

abhosekar
Moderator
Posts: 190
Joined: 10 months ago

### Re: Optimal solution in a loop (NLP)

As I mentioned in my message, the code fragment is not syntactically complete.

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

doti2109
User
Posts: 4
Joined: 4 months ago

### Re: Optimal solution in a loop (NLP)

Merci beaucoup. Notre problème est effectivement résolu.