Understanding Sets in LINGO: Types, Syntax, and Usage

Slide Note
Embed
Share

Sets in LINGO are groups of related objects used to define characteristics such as products, trucks, or employees. They can be primitive or derived sets, each having specific syntax for defining members and attributes. LINGO allows for quick modeling of complex systems using sets efficiently in the DATA section. Explore how to create sets, define values, and optimize models using LINGO for a streamlined approach to problem-solving.


Uploaded on Sep 25, 2024 | 0 Views


Download Presentation

Please find below an Image/Link to download the presentation.

The content on the website is provided AS IS for your information and personal use only. It may not be sold, licensed, or shared on other websites without obtaining consent from the author. Download presentation by click this link. If you encounter any issues during the download, it is possible that the publisher has removed the file from their server.

E N D

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 Example List Format Set Members 1..n 1..5 1, 2, 3, 4, 5 dayM..dayN MON..FRI MON, TUE, WED, THU, FRI monthM..monthN OCT..JAN OCT, NOV, DEC, JAN Month Year M.. Month Year N OCT2001..JAN2002 OCT2001, 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. 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. @MIN Computes the minimum of an expression over all members of a set. @MAX Computes the maximum of an expression over all members of a set.

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

  10. @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) );

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

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

  13. Example : Solve the following knapsack problem by using lingo software : Max 5X1+3X2+8X3+9X4+4X5 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.

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

Related


More Related Content