Set elements are strings, not numbers

Frequently asked questions about GAMS

Moderator: aileen

Forum rules
Please ask questions in the other sub-forums
Locked
aileen
User
User
Posts: 136
Joined: 3 years ago

Set elements are strings, not numbers

Post by aileen »

If I have defined set t "time slots" /1*10/;

Now I want to to change this to something like

Code: Select all

Set t "time slots" /1* "some multiplier of 10"/;


How can I do this?
aileen
User
User
Posts: 136
Joined: 3 years ago

Re: Set elements are strings, not numbers

Post by aileen »

You may try something like this

Code: Select all

$if not set maxt $set maxt 10
Set t "time slots" /1* %maxt%/;
display t
To change the value of maxt from 10 to another number (i.e. 50), please add –maxt=50 to the command line (see double dash parameters).

Please also keep in mind that set elements are not numbers - even if you choose labels that look like numbers. In fact, my recommendation is to avoid using set elements that look like numbers since it can cause confusion in different circumstances. If you write

Code: Select all

 Set t /t1 * t5/;
 Set i /i1 * i5/;
you won't get the two confused. If you write

Code: Select all

Set i /5 * 9/;
Set j /3 * 8/;
you'll be surprised to find that the order of elements in set j is 5, 6, 7, 8, 3, 4. That's because the ordering comes from the collection of all unique set elements in a GAMS program - and the order is defined by when they appear.
Locked