User Tools

Site Tools


Set elements are strings, not numbers

Q: If I have defined Set t “time slots” /1*10/;

Now I want to to change this to something like

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

How can I do this?

You may try something like this

$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

 Set t /t1 * t5/;
 Set i /i1 * i5/;

you won't get the two confused. If you write

 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.

IMPRESSUM / LEGAL NOTICEPRIVACY POLICY gams/set_elements_are_strings_not_numbers.txt · Last modified: 2020/05/27 16:23 by Lutz Westermann