Page 1 of 1

Dynamic set problem

Posted: Tue May 19, 2020 11:01 am
by sph_93
Hello,

i have problems with the creation of a dynamic set. I have two macroperiods, each of which should contain three microperiods. But I can't get them linked.Here are my sets:
grafik.png
grafik.png (8.57 KiB) Viewed 3867 times
And here I have tried to link them together:
grafik.png
grafik.png (19.85 KiB) Viewed 3867 times
I get the error "unknown symbol". I hope you can help me

Re: Dynamic set problem

Posted: Wed May 20, 2020 7:29 am
by bussieck
That's a very basic data organization question. I suggest you read more about using sets effectively in GAMS. There are a couple of chapters in the User's Guide that deal with that:

Code: Select all

set t /t1,t2/, s /s1*s6/, ts(t,s) /t1.(s1*s3), t2.(s4*s6)/;

-Michael

Re: Dynamic set problem

Posted: Thu May 21, 2020 3:04 am
by sph_93
Hello, Michael, thank you very much for your help. Your tip helped. I still have two last problems.
I have 3 microperiods s in 2 macroperiods t.The first microperiod in each macroperiod should get a fixed start time in the set phi. How can I program this problem?
grafik.png
grafik.png (2.19 KiB) Viewed 3804 times
I've tried:
Set
phi(s,t) Set of all microperiods with fixed starting times ;
phi(s,t)$((ord(s)=1 and ord(t)=1)) = yes;
phi(s,t)$((ord(s)=4 and ord(t)=2)) = yes;

I also need a dummy period s=S+1.
grafik.png
grafik.png (5.83 KiB) Viewed 3804 times
grafik.png
grafik.png (3.73 KiB) Viewed 3804 times
How can I define this in my set and link it to my function. I hope you can help me again.

Re: Dynamic set problem

Posted: Thu May 21, 2020 7:48 am
by bussieck
Your idea about phi isn't wrong. You can generalize this easily if your division of macro- and microperiods is regular (3 micro for each macro). Otherwise, the logic needs a little more:

Code: Select all

set t /t1,t2/, s /s1*s6/, ts(t,s) /t1.(s1*s3), t2.(s4*s6)/
set phi(s,t); phi(s,t) = (ord(t)-1)*3+1 = ord(s); display phi;
option clear=phi;
alias (s,ss); phi(s,t) = ts(t,s) and smin(ts(t,ss), ord(ss)) = ord(s); display phi;
If you have a special entity like a dummy period, it might make sense to have a dummy variable/constraint whereever you need rather than sticking this into your well defined set structure. One would need to see where this dummy period is used. The algebra "forall j,l,s" makes little sense, since there is just a single "s", the dummy period. So this looks more like "forall j,l". If y and x are variables that are also indexed with regular microperiods than my suggestion was to use a special xDummy(l,j) and yDummy(l,j) for the dummy period rather than making s part of your set structure and dealing with "exceptions" anywhere else in the code. There are also other solutions. Again, they will be clearer if you know better how to work with dynamic sets.

-Michael

Re: Dynamic set problem

Posted: Fri May 22, 2020 4:09 pm
by sph_93
If I try to link the equation with phi, I get an error. This is what I've been doing:
grafik.png
grafik.png (7.45 KiB) Viewed 3755 times
I'm sorry, I don't understand what you mean by dummy period.
I don't know how to define dummy period and then put it into the equation. I would be so grateful if you could help me with that.

Re: Dynamic set problem

Posted: Sat May 23, 2020 7:02 am
by bussieck
I guess your Zeitstr(s) should hold for all first micro-periods in all macro-periods. Since your macro-period is part of this information you need to do something about this. There are lots of different ways to do this (see below). You really need to learn more of the basic stuff. GAMS is unlike other (address oriented) programming languages. As soon as you have your sets and the relation among them under control things just fall into place. You need to invest to learn this and then a whole new world of efficient model building opens up for you. A forum like this helps to get you over the hump in very special situations, it is not a replacement for learning a sophisticated tool like GAMS properly. Besides documentation, there are lots of other materials and even courses. I hope you have a mentor that recommended GAMS to you. Go there for advice! I can't really help with the dummy period. Try your best, post a small concrete issue someone can look at, and hope for the best.

Here are some examples how to deal with your Zeitstr(s) issue:
  • Change domain of Zeitstr(s)

    Code: Select all

     Zeitstr(phi(s,t)).. w(s) =e= wquer(s);
  • Make sure the s has a t

    Code: Select all

     Zeitstr(s)$sum(phi(s,t),1).. w(s) =e= wquer(s);
  • Make a subset with first micro -periods

    Code: Select all

     set fs(s); fs(s) = sum(phi(s,t),1); Zeitstr(fs).. w(fs) =e= wquer(fs);
Good luck!
-Michael