Question on conditional sets

Hi all



I am writing some code for which I need to process time series data defined on three dimensions namely years (y), months(m) and weeks(w).



Calendar-wise I have a regular monthly 4-4-5 weeks pattern meaning that:


\

  • for Jan I have 4 weeks (ie weeks 1-4)

  • for Feb I have 4 weeks (5-8)

  • for Mar I have 5 weeks (ie 9-13).

-…………



This 4-4-5 pattern repeats every three month so I have always 52 weeks every year.



Now I need to create a tuple such that the byproduct (m,w) is filled with “yes” such that it reflect the pattern labeling described above.



I have created the following code which works fine for me.



My question to the most experienced GAMS users in this forum : is there any more elegant / efficient way to get to the same result?



Thanks

Massimiliano









sets

y year /2007*2013/

m month /1*12/

w week /1*52/

mw(m,w) /#m.#w/;


\

  • we now set the mw set to zero

mw(m,w)=no;





parameter ffw(w) 445 month corresponding to each week/

1 1

2 1

3 1

4 1

5 2

6 2

7 2

8 2

9 3

10 3

11 3

12 3

13 3

14 4

15 4

16 4

17 4

18 5

19 5

20 5

21 5

22 6

23 6

24 6

25 6

26 6

27 7

28 7

29 7

30 7

31 8

32 8

33 8

34 8

35 9

36 9

37 9

38 9

39 9

40 10

41 10

42 10

43 10

44 11

45 11

46 11

47 11

48 12

49 12

50 12

51 12

52 12

/;


\

  • we now fill the mw set with yes only in those weeks with corresponding

  • month based on the ffw table

mw(m,w)$(m.val=ffw(w))=yes;

display mw;






CONFIDENTIALITY NOTICE
NOTICE: This message is intended for the use of the individual or entity to which it is addressed and may contain information that is confidential, privileged and exempt from disclosure under applicable law. If the reader of this message is not the intended recipient, you are hereby notified that any printing, copying, dissemination, distribution, disclosure or forwarding of this communication is strictly prohibited. If you have received this communication in error, please contact the sender immediately and delete it from your system. Thank You.




Attachments-228/Test03.gms

Massimiliano,

First, thanks for observing the posting guidelines so well. A well-defined question with some working source posted too. Renger’s efforts in educating the group users are bearing fruit. and your post deserves a good answer. I hope the code below qualifies.

-Steve

sets
y year /20072013/
m month /1
12/
w week /1*52/
mw(m,w) /#m.#w/;

parameter ffw(w) 445 month corresponding to each week;
ffw(w) = 1 + floor(0.2 + (ord(w)-1) * 3 / 13);

  • fill all values with one assignment
    mw(m,w) = (m.val=ffw(w));
    display mw;


    On Wed, May 28, 2014 at 7:18 AM, Massimiliano Marinucci wrote:

Hi all



I am writing some code for which I need to process time series data defined on three dimensions namely years (y), months(m) and weeks(w).



Calendar-wise I have a regular monthly 4-4-5 weeks pattern meaning that:


\

  • for Jan I have 4 weeks (ie weeks 1-4)

  • for Feb I have 4 weeks (5-8)

  • for Mar I have 5 weeks (ie 9-13).

-…………



This 4-4-5 pattern repeats every three month so I have always 52 weeks every year.



Now I need to create a tuple such that the byproduct (m,w) is filled with “yes” such that it reflect the pattern labeling described above.



I have created the following code which works fine for me.



My question to the most experienced GAMS users in this forum : is there any more elegant / efficient way to get to the same result?



Thanks

Massimiliano









sets

y year /2007*2013/

m month /1*12/

w week /1*52/

mw(m,w) /#m.#w/;


\

  • we now set the mw set to zero

mw(m,w)=no;





parameter ffw(w) 445 month corresponding to each week/

1 1

2 1

3 1

4 1

5 2

6 2

7 2

8 2

9 3

10 3

11 3

12 3

13 3

14 4

15 4

16 4

17 4

18 5

19 5

20 5

21 5

22 6

23 6

24 6

25 6

26 6

27 7

28 7

29 7

30 7

31 8

32 8

33 8

34 8

35 9

36 9

37 9

38 9

39 9

40 10

41 10

42 10

43 10

44 11

45 11

46 11

47 11

48 12

49 12

50 12

51 12

52 12

/;


\

  • we now fill the mw set with yes only in those weeks with corresponding

  • month based on the ffw table

mw(m,w)$(m.val=ffw(w))=yes;

display mw;






CONFIDENTIALITY NOTICE
NOTICE: This message is intended for the use of the individual or entity to which it is addressed and may contain information that is confidential, privileged and exempt from disclosure under applicable law. If the reader of this message is not the intended recipient, you are hereby notified that any printing, copying, dissemination, distribution, disclosure or forwarding of this communication is strictly prohibited. If you have received this communication in error, please contact the sender immediately and delete it from your system. Thank You.

\

To unsubscribe from this group and stop receiving emails from it, send an email to gamsworld+unsubscribe@googlegroups.com.
To post to this group, send email to gamsworld@googlegroups.com.
Visit this group at http://groups.google.com/group/gamsworld.
For more options, visit https://groups.google.com/d/optout.



\

Steven Dirkse, Ph.D.
GAMS Development Corp., Washington DC
Voice: (202)342-0180 Fax: (202)342-0181
sdirkse@gams.com
http://www.gams.com

Thanks Steven

Your suggestion works and was exactly what I was looking for.



Best regards

M



From: gamsworld@googlegroups.com [mailto:gamsworld@googlegroups.com] On Behalf Of Steven Dirkse
Sent: Wednesday, May 28, 2014 16:47
To: gamsworld@googlegroups.com
Subject: Re: Question on conditional sets



Massimiliano,



First, thanks for observing the posting guidelines so well. A well-defined question with some working source posted too. Renger’s efforts in educating the group users are bearing fruit. and your post deserves a good answer. I hope the code below qualifies.



-Steve



sets

y year /2007*2013/

m month /1*12/

w week /1*52/

mw(m,w) /#m.#w/;



parameter ffw(w) 445 month corresponding to each week;

ffw(w) = 1 + floor(0.2 + (ord(w)-1) * 3 / 13);


\

  • fill all values with one assignment

mw(m,w) = (m.val=ffw(w));

display mw;



On Wed, May 28, 2014 at 7:18 AM, Massimiliano Marinucci wrote:

Hi all



I am writing some code for which I need to process time series data defined on three dimensions namely years (y), months(m) and weeks(w).



Calendar-wise I have a regular monthly 4-4-5 weeks pattern meaning that:


\

  • for Jan I have 4 weeks (ie weeks 1-4)

  • for Feb I have 4 weeks (5-8)

  • for Mar I have 5 weeks (ie 9-13).

-…………



This 4-4-5 pattern repeats every three month so I have always 52 weeks every year.



Now I need to create a tuple such that the byproduct (m,w) is filled with “yes” such that it reflect the pattern labeling described above.



I have created the following code which works fine for me.



My question to the most experienced GAMS users in this forum : is there any more elegant / efficient way to get to the same result?



Thanks

Massimiliano









sets

y year /2007*2013/

m month /1*12/

w week /1*52/

mw(m,w) /#m.#w/;


\

  • we now set the mw set to zero

mw(m,w)=no;





parameter ffw(w) 445 month corresponding to each week/

1 1

2 1

3 1

4 1

5 2

6 2

7 2

8 2

9 3

10 3

11 3

12 3

13 3

14 4

15 4

16 4

17 4

18 5

19 5

20 5

21 5

22 6

23 6

24 6

25 6

26 6

27 7

28 7

29 7

30 7

31 8

32 8

33 8

34 8

35 9

36 9

37 9

38 9

39 9

40 10

41 10

42 10

43 10

44 11

45 11

46 11

47 11

48 12

49 12

50 12

51 12

52 12

/;


\

  • we now fill the mw set with yes only in those weeks with corresponding

  • month based on the ffw table

mw(m,w)$(m.val=ffw(w))=yes;

display mw;








CONFIDENTIALITY NOTICE
NOTICE: This message is intended for the use of the individual or entity to which it is addressed and may contain information that is confidential, privileged and exempt from disclosure under applicable law. If the reader of this message is not the intended recipient, you are hereby notified that any printing, copying, dissemination, distribution, disclosure or forwarding of this communication is strictly prohibited. If you have received this communication in error, please contact the sender immediately and delete it from your system. Thank You.


\

To unsubscribe from this group and stop receiving emails from it, send an email to gamsworld+unsubscribe@googlegroups.com.
To post to this group, send email to gamsworld@googlegroups.com.
Visit this group at http://groups.google.com/group/gamsworld.
For more options, visit https://groups.google.com/d/optout.




\

Steven Dirkse, Ph.D.
GAMS Development Corp., Washington DC
Voice: (202)342-0180 Fax: (202)342-0181
sdirkse@gams.com
http://www.gams.com


To unsubscribe from this group and stop receiving emails from it, send an email to gamsworld+unsubscribe@googlegroups.com.
To post to this group, send email to gamsworld@googlegroups.com.
Visit this group at http://groups.google.com/group/gamsworld.
For more options, visit https://groups.google.com/d/optout.


CONFIDENTIALITY NOTICE
NOTICE: This message is intended for the use of the individual or entity to which it is addressed and may contain information that is confidential, privileged and exempt from disclosure under applicable law. If the reader of this message is not the intended recipient, you are hereby notified that any printing, copying, dissemination, distribution, disclosure or forwarding of this communication is strictly prohibited. If you have received this communication in error, please contact the sender immediately and delete it from your system. Thank You.

\

To unsubscribe from this group and stop receiving emails from it, send an email to gamsworld+unsubscribe@googlegroups.com.
To post to this group, send email to gamsworld@googlegroups.com.
Visit this group at http://groups.google.com/group/gamsworld.
For more options, visit https://groups.google.com/d/optout.