I want to check if a set A is empty or not. If it is empty, then no equation Q(A).
how can I modify the following code?
set A;
equation Q(A);
variable d;
Q(A)$A..
d =E= 0;
how to check if a set is empty

 User
 Posts: 108
 Joined: 1 year ago
Re: how to check if a set is empty
Q(A)$A.. is very redundant.
Just with Q(A).. Equation Q will be written one time for each member of A.
If A is empty, it will never be written. Remember that you can only have empty sets if you choose option $Onempty, indicate dimension and have empty bars. Take this example:
$Onempty
set A(*) / /;
variable d;
equation Q,dummy;
Q(A).. d =E= 0;
dummy.. d=l=2;
model p /all/;
solve p using lp maximizing d
Just with Q(A).. Equation Q will be written one time for each member of A.
If A is empty, it will never be written. Remember that you can only have empty sets if you choose option $Onempty, indicate dimension and have empty bars. Take this example:
$Onempty
set A(*) / /;
variable d;
equation Q,dummy;
Q(A).. d =E= 0;
dummy.. d=l=2;
model p /all/;
solve p using lp maximizing d