Hello everybody,

In my work, I need to write a loop for my objective function.

In my objective function, I use one set which is coded with j. And I need the model results for every j values. I write an loop but I obtained "ERROR 149: Uncontrolled set entered as constant."

My code like this below;

Set j/1*52/

obj.. z=e= L(j,'1')

other constraints.. ( some of them still runs for every j)

MODEL test_data /ALL/ ;

loop(j,

SOLVE test_data USING NLP MINIMIZING z;

DISPLAY z.l, a.l, w.l, aa.l;)

How can I write a loop and display all results of model for each value of j?

Please help me...

Thanks a lot.

Best regards.

## Loop for objective function

### Re: Loop for objective function

Hi

Just remove the index from the objective and save the results in a parameter

Cheers

Renger

Just remove the index from the objective and save the results in a parameter

Code: Select all

```
Set j/1*52/
obj.. z=e= L('1')
other constraints.. ( some of them still runs for every j)
parameter results(j,*);
MODEL test_data /ALL/ ;
loop(j,
SOLVE test_data USING NLP MINIMIZING z;
results(j,"Objective") = z.L;
DISPLAY z.l, a.l, w.l, aa.l;)
```

Renger

____________________________________

Enjoy modeling even more: The lazy economist

Enjoy modeling even more: The lazy economist

### Re: Loop for objective function

Hi,

Actually L(j,'1') is distance function. And I coded like below

sum(q,(w(q)**n)*(abs(p(j,q)-c('1',q)))**n))**in

q and j are sets. n and in are scalars. I need the results for every j.

I could not understand how can I remove j from the objective function and save it to a parameter?

My objective function is below:

objective.. z =e= sum(q,(w(q)**n)*(abs(p(j,q)-c(m,q)))**n))**in

Thanks for your help.

Best regards.

Actually L(j,'1') is distance function. And I coded like below

sum(q,(w(q)**n)*(abs(p(j,q)-c('1',q)))**n))**in

q and j are sets. n and in are scalars. I need the results for every j.

I could not understand how can I remove j from the objective function and save it to a parameter?

My objective function is below:

objective.. z =e= sum(q,(w(q)**n)*(abs(p(j,q)-c(m,q)))**n))**in

Thanks for your help.

Best regards.

### Re: Loop for objective function

Hi

You should rewrite the set j from your model and treat the variables and parameters independent of j. Here an example:

In your case:

becomes

and if p(j,g) is a parameter, it is now set in the loop as

If p(j,g) is a variable, you define it as PJ(g) and save the result in a parameter results("p", j,g) = PJ.L(g);

Your distance function then becomes L("1").

Hope this helps.

Cheers

Renger

You should rewrite the set j from your model and treat the variables and parameters independent of j. Here an example:

Code: Select all

```
set j /1*2/;
parameter
p(j) Parameter defined over j,
pj Scalar to be used in the loop to replace p;
p(j) = ord(j);
variable OBJ,X;
equation objective, eq1;
objective..
OBJ =E= x;
eq1..
X=E= pj;
model test /all/;
loop(j,
pj = p(j);
solve test maximizing OBJ using nlp;
);
```

Code: Select all

`sum(q,(w(q)**n)*(abs(p(j,q)-c('1',q)))**n))**in`

Code: Select all

`sum(q,(w(q)**n)*(abs(pj(q)-c('1',q)))**n))**in`

Code: Select all

`pj(q) = p(j,g);`

Your distance function then becomes L("1").

Hope this helps.

Cheers

Renger

____________________________________

Enjoy modeling even more: The lazy economist

Enjoy modeling even more: The lazy economist

### Re: Loop for objective function

Hi,

In the example, x is defined. Is this equal to " sum(q,(w(q)**n)*(abs(pj(q)-c('1',q)))**n))**in " equation or x is something new?

And one more question,

parameter

p(j) Parameter defined over j,

pj Scalar to be used in the loop to replace p;

These are defined and we also defined pj(q).

pj(q) and pj are the same?

Thanks for your support.

Best regards.

In the example, x is defined. Is this equal to " sum(q,(w(q)**n)*(abs(pj(q)-c('1',q)))**n))**in " equation or x is something new?

And one more question,

parameter

p(j) Parameter defined over j,

pj Scalar to be used in the loop to replace p;

These are defined and we also defined pj(q).

pj(q) and pj are the same?

Thanks for your support.

Best regards.

### Re: Loop for objective function

2xyes

____________________________________

Enjoy modeling even more: The lazy economist

Enjoy modeling even more: The lazy economist