USING SETS IN LINGO What Are Sets?

Slides:



Advertisements
Similar presentations
Chapter 7 Introduction to Procedures. So far, all programs written in such way that all subtasks are integrated in one single large program. There is.
Advertisements

IENG 431_LAB2 27/03/09 Friday.
CS1061 C Programming Lecture 7: Floating Point A. O’Riordan, 2004.
1.2 – Open Sentences and Graphs
CS0007: Introduction to Computer Programming Introduction to Arrays.
Optimization Models Mathematical optimization models usually contain an objective (what to do) constraints (the rules that must be followed). Also referred.
Notes 6IE3121 Knapsack Model Intuitive idea: what is the most valuable collection of items that can be fit into a backpack?
Lists Computers and Programming. Agenda What is a list? How to access elements in the list? The for statement Operations on lists Looping with.
Notes 5IE 3121 Knapsack Model Intuitive idea: what is the most valuable collection of items that can be fit into a backpack?
Week 12 - Wednesday.  What did we talk about last time?  Asymptotic notation.
RESEARCH ASSISTANTS Mazyar Ghadirinejad & Farhood Rismanchian.
Transportation and Distribution Planning Matthew J. Liberatore John F. Connelly Chair in Management Professor, Decision and Information Techologies.
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.
LINGO Part III (IE 311 – Lab) Spring ‘07. Variables Domain Function  Variables in a LINGO model default to being nonnegative and continuous.  LINGO.
Example 15: A manufacturer has 4 warehouses and 5 vendors all in different cities. In the first warehouse there are 50 products, in the second warehouse.
Chapter # 2 Part 2 Programs And data
Section 2-4: Adding Integers using Rules
Using Variable Domain Functions
Control Flow Testing Handouts
Example 15: A manufacturer has 4 warehouses and 5 vendors all in different cities. In the first warehouse there are 50 products, in the second warehouse.
Analysis of Algorithms
Ch 2.2: Separable Equations
© 2016 Pearson Education, Ltd. All rights reserved.
Using Derivatives to Find Absolute Maximum and Minimum Values
Chapter 5: Control Structure
Quick Test What do you mean by pre-test and post-test loops in C?
Outline of the Chapter Basic Idea Outline of Control Flow Testing
Repetition-Counter control Loop
Prepared By: G.UshaRani B.Pranalini A.S.Lalitha
لینگو به نام خدا.
Variables ,Data Types and Constants


Prof: Dr. Shu-Ching Chen TA: Yimin Yang
IDENTIFIERS CSC 111.
Unit 2 Programming.
Prof: Dr. Shu-Ching Chen TA: Hsin-Yu Ha
Entity Relationship Diagrams
Section 1-6: Multiplying Integers
2017 Jan Sun Mon Tue Wed Thu Fri Sat

Prof: Dr. Shu-Ching Chen TA: Haiman Tian
LINGO TUTORIAL 2.
1.6) Storing Integer:.
3.1 Iteration Loops For … To … Next 18/01/2019.
Jan Sun Mon Tue Wed Thu Fri Sat
Chapter # 2 Part 2 Programs And data
LINGO LAB 4.
LINGO LAB 3/4.
Sun Mon Tue Wed Thu Fri Sat
IMPLICIT DIFFERENTIATION
CprE 185: Intro to Problem Solving (using C)
Loop Construct.
CS 240 – Lecture 7 Boolean Operations, Increment and Decrement Operators, Constant Types, enum Types, Precedence.
Chapter 6 Network Flow Models.
Chapter 7 Functions of Several Variables
Date Functions Part Two and Arithmetic Combinations of Functions
Sun Mon Tue Wed Thu Fri Sat
Instructions.
CprE 185: Intro to Problem Solving (using C)

CMSC-461 Database Management Systems
LINGO LAB 3/4.
2016 | 10 OCT SUN MON TUE WED THU FRI SAT
Sun Mon Tue Wed Thu Fri Sat
IMPLICIT DIFFERENTIATION
TIMELINE NAME OF PROJECT Today 2016 Jan Feb Mar Apr May Jun
CprE 185: Intro to Problem Solving (using C)
1.6) Storing Integer: 1.7) storing fraction:
Integer Linear Programming
Presentation transcript:

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.

Why Use Sets? Primitive 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.

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: WAREHOUSES / WH1 WH2 WH3 WH4 WH5 WH6/: CAPACITY;

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:

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:

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.

The names of the functions and their uses are: 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.

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

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

@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 VENDORS: DEMAND; VENDORS, DEMAND = V1,5 V2,1 V3,3 V4,4 V5,6;

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

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.

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