Presentation is loading. Please wait.

Presentation is loading. Please wait.

USING SETS IN LINGO What Are Sets? Sets are simply groups of related objects. A set might be a list of products, trucks, or employees. Each member in the.

Similar presentations


Presentation on theme: "USING SETS IN LINGO What Are Sets? Sets are simply groups of related objects. A set might be a list of products, trucks, or employees. Each member in the."— Presentation transcript:

1 USING SETS IN LINGO What Are Sets? Sets are simply groups of related objects. A set might be a list of products, trucks, or employees. Each member in the set may have one or more characteristics. For example, each product in a set of products might have a price attribute; each truck in a set of trucks might have a capacity attribute; and each employee in a set of employees might have a salary attribute.

2 Why Use Sets? LINGO’s language allows you to express your largest models very quickly and easily. Types of Sets LINGO recognizes two kinds of sets: primitive and derived sets. Primitive Sets: A primitive set is a set composed only of objects that can’t be reduced. To define a primitive set, you specify: The name of the set. Optionally, its members (objects contained in the set). Optionally, any attributes the members of the set may have.

3 A primitive set has the following syntax: SETS: setname / member_list / : attribute_list; ENDSETS The set name :is a name you choose to designate the set. A member list : is a list of the members that represent the set. If the set members are included in the set definition, they may be listed either explicitly or implicitly. When listing members explicitly, you enter a unique name for each member for example we could have used an explicit member list to define the set WAREHOUSES in the sets section as follows: SETS: WAREHOUSES / WH1 WH2 WH3 WH4 WH5 WH6/: CAPACITY; ENDSETS

4 Implicit Member ExampleList FormatSet Members 1..n1..51, 2, 3, 4, 5 dayM..dayNMON..FRIMON, TUE, WED, THU, FRI monthM..monthNOCT..JANOCT, NOV, DEC, JAN Month Year M.. Month Year N OCT2001..JAN2002OCT2001, NOV2001, DEC2001, JAN2002 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:

5 SETS: PRODUCT / A B/; MACHINE / M N/; WEEK / 1 2/; ALLOWED (PRODUCT, MACHINE, WEEK) ; ENDSETS Sets PRODUCT, MACHINE, and WEEK are primitive sets, while ALLOWED is derived from parent sets, PRODUCT, MACHINE, and WEEK. Taking all the combinations of members from the three parent sets, we come up with the following members in the ALLOWED set:

6 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

7 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.

8

9

10 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); The names of the functions and their uses are: @FOR Used to generate constraints over members of a set. @SUM Computes the sum of an expression over all members of a set. @MINComputes the minimum of an expression over all members of a set. @MAXComputes the maximum of an expression over all members of a set.

11 @SUM Set Looping Function Example 3: Consider the model: MODEL: SETS: VENDORS/V1..V5/: DEMAND; ENDSETS DATA: DEMAND = 5 1 3 4 6; ENDDATA TOTAL_DEMAND = @SUM(VENDORS(J): DEMAND(J)); Note that: LINGO evaluates the @SUM function by first initializing an internal accumulator to zero. LINGO then begins looping over the members in the VENDORS set. The set index variable, J, is set to the first member of VENDORS (i.e., V1) and DEMAND (V1) is then added to the accumulator. This process continues until all DEMAND values have been added to the accumulator. The value of the sum is then stored in the TOTAL_DEMAND variable.

12

13

14 @FOR Set Looping Function 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) );

15

16 @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 We can write above example by this method SETS: VENDORS: DEMAND; ENDSETS DATA: VENDORS, DEMAND = V1,5 V2,1 V3,3 V4,4 V5,6; ENDDATA MIN_DEMAND = @MIN( VENDORS( J): DEMAND( J)); MAX_DEMAND = @MAX( VENDORS( J): DEMAND( J)); END

17

18 Using Variable Domain Functions These variable domain functions are: @GIN –any positive integer value @BIN –a binary value ( 0 or 1) @FREE –any positive or negative real value @BND –any value within the specified bounds

19 Example : Solve the following knapsack problem by using lingo software : Max 5X 1 +3X 2 +8X 3 +9X 4 +4X 5 3X 1 +X 2 +5X 3 +4X 4 +X 5 =25 0≤X 1 ≤2, 0 ≤X 2 ≤1, 0 ≤X 3 ≤4, 0 ≤X 4 ≤2, 0 ≤X 5 ≤1 X 1,X 2,X 3,X 4,and X 5 are integer.

20

21

22 Example : Solve the following LP problem MAX 4X 1 +2X 2 +3X 3 +6X 4 -4X 5 -11X 6 3X 1 +X 2 +5X 3 +2X 4 -2X 5 -X 6 ≤ 9 -X 1 +X 2 +X 3 +2X 4 -3X 6 ≤ 3 2X 1 -X 2 -4X 3 +X 4 +X 5 -X 6 ≤ -2 X 1,X 2,X 3,X 4,X 5 and X 6 are binary variables

23

24


Download ppt "USING SETS IN LINGO What Are Sets? Sets are simply groups of related objects. A set might be a list of products, trucks, or employees. Each member in the."

Similar presentations


Ads by Google