I am trying to solve several problems in a loop and for each, I am generating the corresponding .gdx and .xlsx file

Code: Select all

```
Scalar product ;
Scalar supplier ;
Scalar time ;
Sets i products / i0*i50 /
j suppliers / j0*j50 /
t time periods / t0*t50 /
sub_j(j) dynamic subset for j
sub_t(t) dynamic subset for t
sub_i(i) dynamic subset for i ;
Alias ( k , t ) ;
Parameter D( i , t ) ;
Parameter P( i , j ) ;
Parameter H( i ) ;
Parameter O( j ) ;
Variables x ( i , j , t )
y ( j , t )
R( i , t )
Z( i , j , t )
cost ;
Positive Variables x ,R, Z;
Binary Variable y ;
Equations obj objective function
con1 ( i , t ) ;
obj ..
cost =E= sum ( ( sub_i(i) , sub_j(j) , sub_t(t) ) ,P( i , j )* x ( i , j , t ))
+sum ( ( sub_j(j) , sub_t(t) ) ,O( j )* y ( j , t ) )
+sum ( ( sub_i(i) , sub_t(t) ) ,H( i ) * ( sum ( k$ ( ord ( t ) GE ord ( k ) ) , sum ( sub_j(j) , x ( i , j , k))-D( i , k ) ) ) ) ;
con1 ( sub_i(i) , sub_t(t) ) ..
R( i , t ) =E= sum ( k$ ( ord ( t ) GE ord ( k ) ) , sum ( sub_j(j) , x ( i , j , k))-D( i , k ) ) ;
display "---------------------formulation ----------------------";
option optcr =0;
option limrow =0;
option limcol =0;
Model test /all/;
Scalar num /0/;
for ( product = 5 to 15 by 5,
for( supplier = 5 to 10 by 5,
for ( time = 5 to 10 by 5,
sub_i(i) = ord(i) <= product;
sub_j(j) = ord(j) <= supplier;
sub_t(t) = ord(t) <= time;
num = num+1 ;
D(sub_i,sub_t) = uniformint(10,20);
P(sub_i,sub_j) = uniformint(10,20);
H(sub_i) = uniformint(1,4);
O(sub_j) = uniformint(10,20);
display num;
Solve test minimizing cost using mip ;
Put_utility 'log' / 'Create GDX File F:\Sameh\test_'product:0:0'_'supplier:0:0'_'time:0:0'_p'num:0:0'.gdx';
Put_utility 'gdxout' / 'F:\Sameh\test_'product:0:0'_'supplier:0:0'_'time:0:0'_p'num:0:0'.gdx' ;
Execute_unload;
Put_utility 'exec' / 'gdx2xls F:\Sameh\test_'product:0:0'_'supplier:0:0'_'time:0:0'_p'num:0:0'.gdx';
);
);
);
```

The problem size is i= 5, j= 10 and t = 5

However, in the gdx file the x and y variables are messed up with previous x and y from the previous problem which is problem 2 having i= 5, j= 5 and t = 10

It looks like when the size of the variable becomes smaller for example t here from 10 becomes 5 in the loop it uses the old variable values

Do you have any suggestions, please?

any help would be appreciated