Jiajie Shen
Jiajie Shen

Reputation: 97

how to decide if a element is in a set in GAMS

The situation is: I define a set in gams, like:

set n /n1*n100/;

And later in the code, I want to find a way to decide a if a element is in a set. For example, I want to have a function f, such that

(1) if a element in a set, it returns true(or '1'). Like, f('n1',n) = true(or '1')

(2) if a element not in a set, it returns false(or '0'). Like, f('n111',n) = false(or '0')

Does anyone know if there exists this kink of function? Also, if exists, does it also works for multiple dimensional set?

Upvotes: 0

Views: 624

Answers (1)

Jon
Jon

Reputation: 371

The question is a bit unclear in what you want to do. That being said, subsets seem one to do what you want, for instance:

set m /n1*n100/;
set n(m) /n1*n50/;
parameter test(m);
test(m)=0;
test(n)=1;
display test;

This is overly explicit, for instance, you do not need test(m)=0; as gams default value is 0.

So that you could use param(m)$test(m) = 3; to only set the values where test is positive. Of course, it is much simpler to use param(n) = 3

Finally, strictly speaking, the instructions: sameas(set1,set2) or sameas(set1,"n101") do what you want.

Without a clearer question, it is hard to help beyond this point.

Upvotes: 1

Related Questions