Reputation: 371
I am trying to define some sets dynamically with set operations (in my case the "-" operation). However, the "-" operation seems to apply only during the execution phase, and when using this set when defining other sets, gams fails with the following error: 644 set.ident or #.ident has undefined data. I believe the issue is that the set defined with the minus operation does not get created until the execution phase.
I could not find a solution to create the set during the compilation phase. Any help appreciated, with a minimal reproducible example below.
set alphabet /
"a"
"b"
"c"
/;
set a(alphabet) /
"a"
/;
sets bc(alphabet);
bc(alphabet) = alphabet(alphabet) - a(alphabet);
set test1(alphabet)
/
#a
/;
set test2(alphabet)
/
#a
#bc
/;
set test3(alphabet)
/
set.a
/;
set test4(alphabet)
/
set.a
set.bc
/;
Upvotes: 1
Views: 153
Reputation: 2292
You are right, "bc(alphabet) = alphabet(alphabet) - a(alphabet);" is an execution time statement. Doing a set subtraction at compile time in GAMS directly, is not so easy (in contrast to a set addition, which works). But if you use a recent GAMS system (24.9), you could use the new embedded code facility to do this:
set alphabet /
"a"
"b"
"c"
/;
set a(alphabet) /
"a"
/;
sets bc(alphabet);
$onEmbeddedCode Python:
gams.set("bc", list(set(gams.get("alphabet")) - set(gams.get("a"))))
$offEmbeddedCode bc
I hope that helps! Lutz
Upvotes: 1