In gams: refer to set elements as values

In gams you have a set with numbers you would think that you can use them as “real” numbers, e.g. you can do calculations with them. But if you try to do so you’ll got error messages. Set elements can not be referred to directly as numbers.

But there is a special function i.val that you can use in these cases. Here comes an example to make it clear:

set i /1, 20, 300, 4000/;

parameter p_tmp(i)  'to store i as values';


$ontext
*** this would generate error
*** 148  Dimension different - The symbol is referenced with more/less
***        indices as declared

p_tmp(i) = 3*i;
display  p_tmp;
$offtext

p_tmp(i) = i.val/100;
display  p_tmp;


Advertisement
This entry was posted in Uncategorized. Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Connecting to %s