! Illustrating set operations such as union, intersection in LINGO;
! Keywords: Sets, Union, Intersection;
SETS:
people; ! The base or ground set;
! Various sets derived from the people set;
suppliers( people); ! Some are suppliers;
customers( people); ! Some are customers;
! Some are at least a supplier or a customer ( union);
active( people) | @IN(customers, &1) #or# @IN(suppliers, &1);
! Some are both (intersection);
both( people) | @IN(customers, &1) #and# @IN(suppliers, &1);
ENDSETS DATA:
people = p1..p20; ! The current base set;
suppliers = p1 p3 p4 p7 p9;
customers = p4 p9 p11 p17 p19 p20;
ENDDATA
CALC:
@WRITE(' The people with whom we do business are: ', @NEWLINE(1));
@FOR( active( j):
@WRITE( ' ', active( j), @NEWLINE(1));
);
@WRITE(' The people who are both buyers and sellers are: ', @NEWLINE(1));
@FOR( both( j):
@WRITE( ' ', both( j), @NEWLINE(1));
);
! For more complicated set construction operations,
the @INSERT( derivedSet, setElement) operator may be of use;
ENDCALC
|