Professional Documents
Culture Documents
Using Sets in Lingo
Using Sets in Lingo
Using Sets in Lingo
products, trucks, or employees. Each member in the set may have one
or more characteristics.
easily.
Types of Sets
Primitive Sets:
A primitive set is a set composed only of objects that can’t be reduced.
1..n 1..5 1, 2, 3, 4, 5
Derived set :
The derived set is defined similarly primitive set, but must also include
the parent set list. An example of a derived set could be:
SETS:
PRODUCT / A B/;
MACHINE / M N/;
WEEK / 1 2/;
ENDSETS
Sets PRODUCT, MACHINE, and WEEK are primitive sets, while ALLOWED is
derived from parent sets, PRODUCT, MACHINE, and WEEK. Taking all
ALLOWED set:
USING DATA IN LINGO:
LINGO provides a separate section called the DATA section in which
values can be defined for different variables.
The DATA section begins with the tag DATA: and ends with the tag ENDDATA.
Statements within the DATA section follow the syntax: object_list = value_list;
Example 1:
SETS:
WAREHOUSES / 1..NUMBER_OF_WH/: CAPACITY;
ENDSETS
DATA:
NUMBER_OF_WH = 6;
ENDDATA
EXAMPLE 2: consider the following model:
SETS:
SET1: X, Y;
ENDSETS
DATA:
SET1 = A B C;
X = 1 2 3;
Y=4 5 6;
DATA END
We have two attributes X and Y defined on the set SET1. The three values
of X are set to 1, 2, and 3, while Y is set to 4, 5, and 6.
Set Looping Functions
There are currently four set looping functions in LINGO.
The syntax for a set looping function is:
@function(setname [ (set_index_list) [|conditional_qualifier]] :
expression_list);
@FOR
Used to generate constraints over members of a set.
@SUM
Computes the sum of an expression over all members of a set.
Example 4:
Here is a model that uses an @FOR statement to compute the reverse value for five numbers placed into the VALUE
attribute:
MODEL:
SETS:
NUMBERS /1..5/: VALUE, Reverse;
ENDSETS
DATA:
VALUE = 3 4 2 7 10;
ENDDATA
@FOR( NUMBERS(I): REVERSE( I ) = 1 / VALUE(I) );
@MIN and @MAX Set Looping Functions
Again, consider the Example 3:
SETS:
VENDORS/ V1..V5 /:DEMAND;
ENDSETS
DATA:
DEMAND = 5 1 3 4 6;
ENDDATA
MIN_DEMAND = @MIN( VENDORS( J): DEMAND( J));
MAX_DEMAND = @MAX( VENDORS( J): DEMAND( J));
END
3X1+X2+5X3+4X4+X5=25
0≤X1 ≤2 , 0 ≤X2 ≤1 , 0 ≤X3 ≤4 , 0 ≤X4 ≤2, 0 ≤X5 ≤1
X1,X2,X3,X4,and X5 are integer.
Example :
Solve the following LP problem
MAX 4X1+2X2+3X3+6X4-4X5-11X6
3X1+X2+5X3+2X4-2X5-X6 ≤ 9
-X1+X2+X3+2X4-3X6 ≤ 3
2X1-X2-4X3+X4+X5-X6 ≤ -2
X1,X2,X3,X4,X5and X6 are binary variables