New to "GAMS. Have a quick question

Hi all,

I’ve read through much of the documentation but having a difficult time understanding how to manipulate multi-dimensional tables.

Below is a program that I’ve created. This is typical how my premium is going to come in. What I need to do is:

  1. create another parameter prems(i) = premium field from the table attrib
  2. create another parameter prembycred which has the levels “levels_credit” and sums up the premium by credit from the table attrib.

Please help! Been stuck on this all day.


********************************** PROGRAM ************************************
Sets

i /1*10/

levels_credit /c600_690, c700_790, c800_890, c900_997, nht, nsr/

levels_lmtgrp /1*5/

levels_ms /1*5/

vars /credit, premium/
;

acronyms c600_690, c700_790, c800_890, c900_997, nht, nsr;

parameters
prembycred(levels_credit)
prems(i)
;

Table attrib(i,vars)
credit premium
1 c700_790 1670.63
2 c700_790 1288.92
3 c800_890 891.55
4 c900_997 698.54
5 c800_890 1120.09
6 c900_997 1080.2
7 c700_790 1729.22
8 c700_790 396.82
9 c800_890 966.55
10 c700_790 296.93
;

display
attrib
;


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.

Hi

I probably would make two distinct tables, one for i with the premiums and one for the credit levels and the premiums.

But, if you want, you could define a mapping (see the manual) and change the table as follows (note that it is now defined over two sets instead of over one set). There surely is a more elegant way:



Table attrib(i,levels_credit,*)

premium

  1.    c700_790        1670.63
    
  2.    c700_790        1288.92
    
  3.    c800_890        891.55
    
  4.    c900_997        698.54
    
  5.    c800_890        1120.09
    
  6.    c900_997        1080.2
    
  7.    c700_790        1729.22
    
  8.    c700_790        396.82
    
  9.    c800_890        966.55
    
  10.   c700_790        296.93
    

;



Now define the mapping, that maps i to levels_credit:



set mapi_credit(i,levels_credit)

/1. c700_790,

  1.    c700_790,
    
  2.    c800_890,
    
  3.    c900_997,
    
  4.    c800_890,
    
  5.    c900_997,
    
  6.    c700_790,
    
  7.    c700_790,
    
  8.    c800_890,
    
  9.   c700_790/;
    




And do the summing



prembycred(levels_credit) =sum(i, attrib(i,levels_credit, “premium”));

loop(mapi_credit(i,levels_credit),

prems(i) = attrib(i,levels_credit,“premium”););

display prems, prembycred;





Cheers



Renger




\


Modelworks

Gewerbestrasse 15

3600 Thun – Switzerland

+41 79 818 53 73

Info@modelworks.ch

blog.modelworks.ch







prembycred(levels_credit) = attrib(, “premium”)
prems(i) = attrib(i,”premium”)



From: gamsworld@googlegroups.com [mailto:gamsworld@googlegroups.com] On Behalf Of gamsnewb
Sent: Samstag, 15. März 2014 01:20
To: gamsworld@googlegroups.com
Subject: New to "GAMS. Have a quick question



Hi all,



I’ve read through much of the documentation but having a difficult time understanding how to manipulate multi-dimensional tables.



Below is a program that I’ve created. This is typical how my premium is going to come in. What I need to do is:


\

  1. create another parameter prems(i) = premium field from the table attrib

  2. create another parameter prembycred which has the levels “levels_credit” and sums up the premium by credit from the table attrib.



    Please help! Been stuck on this all day.





    ********************************** PROGRAM ************************************

Sets


i /110/


levels_credit /c600_690, c700_790, c800_890, c900_997, nht, nsr/


levels_lmtgrp /1
5/


levels_ms /1*5/


vars /credit, premium/
;



acronyms c600_690, c700_790, c800_890, c900_997, nht, nsr;



parameters
prembycred(levels_credit)
prems(i)
;


Table attrib(i,vars)
credit premium
1 c700_790 1670.63
2 c700_790 1288.92
3 c800_890 891.55
4 c900_997 698.54
5 c800_890 1120.09
6 c900_997 1080.2
7 c700_790 1729.22
8 c700_790 396.82
9 c800_890 966.55
10 c700_790 296.93

;



display
attrib
;


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.


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.