Dynamic set problem

Problems with syntax of GAMS
Post Reply
sph_93
User
User
Posts: 8
Joined: 3 years ago

Dynamic set problem

Post 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 3859 times
And here I have tried to link them together:
grafik.png
grafik.png (19.85 KiB) Viewed 3859 times
I get the error "unknown symbol". I hope you can help me
User avatar
bussieck
Moderator
Moderator
Posts: 1037
Joined: 7 years ago

Re: Dynamic set problem

Post 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
sph_93
User
User
Posts: 8
Joined: 3 years ago

Re: Dynamic set problem

Post 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 3796 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 3796 times
grafik.png
grafik.png (3.73 KiB) Viewed 3796 times
How can I define this in my set and link it to my function. I hope you can help me again.
User avatar
bussieck
Moderator
Moderator
Posts: 1037
Joined: 7 years ago

Re: Dynamic set problem

Post 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
sph_93
User
User
Posts: 8
Joined: 3 years ago

Re: Dynamic set problem

Post 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 3747 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.
User avatar
bussieck
Moderator
Moderator
Posts: 1037
Joined: 7 years ago

Re: Dynamic set problem

Post 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
Post Reply