Page 1 of 1

Re: remove element from a set

Posted: Tue Jul 11, 2017 2:51 pm
by cladelpino
Hi,

I don't know if it fits your workflow, but, using $include of different set definitions in different files is a possibility that comes to mind. Then you just comment/uncomment the ones you are currently using.

This has the advantage that you can make this kind of edits easily with your text editor of choice, or even build them on the fly with your favourite scripting tool (which of course includes using put from gams).

Best regards!
Claudio

Re: remove element from a set

Posted: Thu Jul 13, 2017 1:05 pm
by cladelpino
Hi, in main file:

Code: Select all

*You just comment or uncomment according to your needs

*$include SetDefWithA.gms
$include SetDefWithoutA.gms
*$include SomeOtherSetDef.gms
And you can have:

SetDefWithA.gms

Code: Select all

Set G /'A','B','C'/
G1(G) /'A','B'/
G2(G) /'A','C'/;
SetDefWithoutA.gms

Code: Select all

Set G /'B','C'/
G1(G) /'B'/
G2(G) /'C'/;
This approach does not rely in GAMS set manipulation, which as you have seen and as far as I know, is somehow hard to work around in some cases, like the one you bring up.

The gain in "expressivity" comes at the "cost" of having to rely on separate files (which I actually find more of a gain on itself, but this appreciation depends on your taste). If this definitions are static, nothing changes. If you are removing elements in a dynamic way (sometimes you remove A, sometimes B, and so on) it shouldn't be hard to script away the set definition files generation.

Of course, there MAY be a way to do this using only GAMS dynamic sets. I don't know it.

Best regards!
Claudio

Re: remove element from a set

Posted: Wed Mar 21, 2018 8:30 pm
by cladelpino
This is totally valid GAMS:

Code: Select all

Set G /'A','B','C'/
G1 /'A','B'/
G2 /'A','C'/;
display G,G1,G2;
G('A')=no;
display G,G1,G2;
The secret, as the original error message stated, is not to use G as the domain of G1/G2 and any other symbol.

This is the positive side of not having domain definitions. The negative side is that you don't have domain checking, so you have to be more careful.

(I didn't know this when I originally answered this... sorry!) :roll: