Hello.
I have a discrete time problem for which I have some hourly variables and some daily variables that depend on dynamic sets which change in every iteration, depending on two sets: k and r. I made a code that has the following structure:
sets
i days /1*100/
t hours /1*1000/
ii(i) dynamic set of i
tt(t) dynamic set of t
k independent iterations /1*5/
r dependent iterations within k /1*10/;
scalars
d initial day;
variables;
*My variables depend on the dynamic sets
equations
*I have equations blocks that depend on my dynamic sets
eq1(tt)..;
eq2(ii)..;
etc..;
model cycle_days /all/;
options mip = cplex;
*Merge solutions:
cycle_days.solveopt = 1;
*Use file with starting solution:
cycle_days.optfile = 1;
loop(k,
d = ord(k)-1;
loop(r,
loop(t,
tt(t) = no;
tt(t) = yes$(ord(t) ge (ord(r)+d)*24-23 and ord(t) le 24*(ord(r)+d));
*for d=0, r=1, tt will be yes between 1 and 24
*for d=0, r=2, tt will be yes between 25 and 48
*for d=1, r=1, tt will be yes between 25 and 48
);
loop(i,
ii(i) = no;
ii(i) = yes$(ord(d) gt ord(r)+d and ord(d) le card(r)+d);
*for d=0, r=1, ii will be yes between 2 and 10
*for d=0, r=2, ii will be yes between 3 and 10
*for d=1, r=1, ii will be yes between 3 and 11
);
solve cycle_days using mip minimizing objective
*All variables that have tt=no or ii=no are set to zero by GAMS
*Now I create a feasible solution for the next r
);
*Put merged solution to excel file
*I would like here, to somehow erase the previous solution values (not set them to 0)
*so, cplex can find an initial feasible solution automatically, but I cannot use .optfile=0 in a loop
);
While I want the solver to read initial solutions while iterating over r, I want to erase everything when I iterate over k (or not read initial solution from the previous iteration). I was thinking of using option clear for every variable, but I have too many of them (plus I think it does not do what I want).
For example, before I created the loop of k, I manually changed my scalar d and pressed the run GAMS button on top, and it ran just fine. How can I make this process automated?
Thanks in advance for your help, and sorry for the long post.
Best,
Petros