Download presentation

Presentation is loading. Please wait.

1
IENG442 LINGO LAB3

2
Example -1 A company produces product A and B. Product B sells for $5 per unit, and product A sells for $3 per unit. Producing a unit of product B requires 5 unit of row material 1 and 2 unit of row material 2. Producing a unit of product A requires 2 unit of row material 1 and 1 unit of row material units of row material 1 and 25 unit of row material 2 are available. Formulate an LP that can be used to maximize revenue.

3
**Modeling Variables: x1: units of product A that should be produced**

x2: units of product B that should be produced Objective Function: Max Z= 5x2 + 3x1 Subject to (constraints): 5x2 + 2x1 ≤ 60 (Row material 1 constraint) 2x2 + 1x1 ≤ 25 (Row material 2 constraint) x1 ≥ 0 x2 ≥ 0

4
**Changing model for LINGO:**

5
**Solving a LINGO Model Each model can be solved by:**

Clicking the solve button Selecting Solve from the LINGO menu Using Ctrl+S keyboard shortcut. Error (if any) will be reported.

6
**LINGO Solver Status Window**

7
**LINGO Solution Report Window**

8
Example -02 Maximize -5/36Q /9Q – 125/9 Subject to 10 ≤Q ≤ 100

9
LINGO Model

10
Example -03 Minimize 50S+100F Subject to ≥ 40 20+ 7 ≥ 60 S,F ≥ 0

11
LINGO Model

12
Example-04 Consider that each student may eat at most 16 units of food stuff per day and the amount of protein taken from animal sources should not be more than the 60% of the total protein intake. Formulate as an LP model.

13
Example-4(Solution): Objective: To obtain minimum cost daily diet which satisfying the Nutritional requirements and eating capacity Decision Variables: Xj number of units of food type j into the daily diet of the student (where j=1 (milk), 2(meat), 3(bread), 4(vegetables)). MODEL: Objective Function: Min Z= 0.42X1+0.68X2+0.32X3+0.17X4

14
**Example-4(Solution): Subject to:**

Calories: 160X1+210X2+120X3+150X4 ≤ 2700 Carbohydrate: 110X1+130X2+110X3+120X4 ≥ 300 Protein: 90X1+190X2+90X3+130X4 ≥ 250 Vitamins: 50X1+50X2+75X3+70X ≥ 60 Protein balance: 90X1+190X2 ≤ 0.6(90X1+190X2+90X3+130X4) Or: 36X1+76X2-54X3-78X4 ≤ 0 Eating Capacity: X1+X2+X3+X ≤ 16 Non-negativity: Xj ≥ 0 ; j=1,2,3,4

15
Lingo Model:

16
Example-05 A farmer must determine how many acres of corn and wheat to plant this year. You can find relevant data in the table below: Government regulations require that at least 30 bushels of corn be produced during the current year. Formulate an LP to maximize the total revenue from wheat and corn.

17
**Example-05 continuing a) b) X1 = number of acres of corn planted &**

X2 = number of acres of wheat planted. b) Y1 = number of bushels of corn produced & Y2 = number of bushels of wheat

18
**Example-05 (Solution) a) MAX Z = (10*3) X1 + (25*4) X2 Subject to:**

19
**Example-05 (LINGO MODEL)**

20
**Example-05 (LINGO Solution)**

21
**Example-05 (Solution) b) MAX Z = 3Y1 + 4Y2 Subject to: Y1>= 30**

22
**Example-05 (LINGO MODEL)**

23
**Example-05 (LINGO Solution)**

24
Overview Using Variable Domain Functions to formulate linear programming problems @BIN(X): Limits the variable X to a binary integer Value (0 or 1) @GIN(X): Limits the variable X to only integer values. @BND(L,X,U): Limits the variable X to greater or equal to L and less than or equal to U. @FREE(X): Remove the default lower bound of zero on a variable, allowing it to take any positive or negative value.

25
**Integer Programming (IP)**

If one or more decision variables must be integer, then we say that an optimization model is an integer model. An IP in which all variables are required to be integers is called a pure integer programming problem. An IP in which only some of the variables are required to be integers is called a mixed integer programming problem. An IPP in which all the variables must equal 0 or 1 is called a 0-1 (or binary) IP.

26
Example 06 A young couple, Evren and Steven, want to divide their main household chores between them so that each has two tasks but the total time they spend on household duties is kept to a minimum. Their efficiencies on these tasks differ, where the time each would need to perform the task is given by the following table. Formulate a BIP model for this problem.

27
Example 06-Solution We have 4 types of tasks; marketing, cooking, dishwashing and laundry Our decision variables are: Si and Ei (i=1…4). Si=1 ;if Steven does the ith task Si=0 ;otherwise Ei=1 ;if Evren does the ith task Ei=0 ;Otherwise

28
Example 06-LINGO Model

29
**Example 06-LINGO Solution**

30
**Example 06-LINGO Solution**

31
Example 07 A paper company has machines that produce large rolls of paper of a given diameter and width, say 100 inches. To fill customer order (200 rolls with 45 inches width and 110 rolls with 30 inches width), these large rolls must be cut in to narrow width (using some patterns). Formulate this problem to minimize the number of standard rolls cut in filling the order.

32
**Example 07- Solution We have some patterns to cut the standard rolls:**

So our decision variables are: Xj= number of standard rolls cut by pattern j (It must be integer)

33
Example 7-LINGO Model

34
**Example 07-LINGO Solution**

35
**Example 07-LINGO Solution**

36
Example 08 A factory has two machines and produces two types of products. Selling prices, working hours, current orders amounts and maximum amounts of production are shown in the table. Formulate this problem to maximize the profits.

37
**Example 08- Solution Decision variables are:**

Xi =number of product i that should be produced to maximized the profits (i=1,2)

38
Example 08-LINGO Model

39
**Example 08-LINGO Solution**

40
**Example 08-LINGO Solution**

41
Example 09 (FREE(X)) A baker has 30 ounces of flour and 5 packages of yeast (additive material). Baking a loaf of bread requires 5 ounces of flour and 1 package of yeast. Each loaf of bread can be sold for $30. The baker may purchase additional flour at $4 or sell leftover flour at the same price. Formulate this problem to maximize the baker’s profits.

42
**Example 09- Solution Decision variables:**

X1= number of loaves of bread baked X2=number of ounces by which flour supply is increased by cash transactions (so, X2 can be positive (purchasing), negative (selling) or zero) Note: The baker can not purchase any additional yeast!

43
Example 09-LINGO Model

44
**Example 09-LINGO Solution**

45
**Example 09-LINGO Solution**

46
**Brute Production Process (@GIN):**

Rylon Corporation manufactures Brute and Chanelle perfumes. The raw material needed to manufacture each type of perfume can be purchased for 3$ per pound. Processing 1 lb of raw material requires 1 hour of laboratory time. Each pound of processed raw material yiels 3 oz of Regular Brute Perfume and 4 oz of Regular Chanelle Perfume. Regular Brute can be sold for 7$/oz and Regular Chanelle for $6/oz. Rylon also has the option of further processing Regular Brute and Regular Chanelle to produce Luxury Brute, sold at 18$/oz, and Luxury Chanelle,sold at $14/oz. Each ounce of Regular Brute processed further requires an additional 3 hours of laboratory time and 4$ processing cost and yields 1 oz of Luxury Brute. Each ounce of Regular Chanelle processed further requires an additional 2 hours of laboratory time and $4 processing cost and yields 1 oz of Luxury Chanelle. Each year, Rylon has 6,000 hours of laboratory time available and can purchase upto 4,000 lb of raw material. Formulate an LP that can be used to determine how Rylon can maximize profits. Assume that the cost of laboratory hours is a fixed cost.

47
Solution to Example 1: Determine how much raw material to purchase and mow much of each type of perfume to produce X1=number of ounces of Regular Brute sold annually X2=number of ounces of Luxury Brute sold annuallly X3=number of ounces of Regular Chanelle sold annually X4=number of ounces of Luxury Chanelle sold annually X5=number of pounds of raw material purchased annually Profit=revenues from perfume sales-processing costs-costs of purchasing raw material =7X1+18X2+6X3+14X4-(4X2+4X4)-3X5

48
**Max z =7X1+14X2+6X3+10X4-3X5 Subject to X5<=4,000**

Solution to Example 1: Max z =7X1+14X2+6X3+10X4-3X5 Subject to X5<=4,000 3X2+2X4+X5<=6,000 X1+X2-3X5=0 X3+X4-4X5=0 Xi>=0 (i=1,2,3,4,5)

52
**Using Sets in LINGO When and Why?**

Whenever you are modeling situations in real life there will be one or more groups of related objects. Such as customers, products, trucks, machines or workers. LINGO allows you to group these related objects together in to sets. So, sets are groups of related objects. Using sets, you can write a series of similar constraints in a single statement. Each member in the set may have one or more characteristics associated with it, which are called attributes (They can be known in advance or unknown that LINGO solves for).

53
**Types of Sets in LINGO Some simple examples: Types of Sets:**

Product: Price Truck: Hauling capacity Warehouse: Storage Capacity Types of Sets: 1) Primitive Set 2) Derived Set Primitive Set: Compose only of objects, which can not be further reduced (e.g.: A set composed of 8 trucks). Derived set: It made from one or more other sets, or it is a subset of other sets or it is a combination of elements from the other sets.

54
**How to use Sets? Defining Primitive Sets:**

Sets are defied in sets section. A sets section may appear anywhere in a model. It’s necessary to define sets before using them in a model. The sets section begins with “SETS:” and ends with “ENDSETS”. Defining Primitive Sets: Set name / member list / :attribute list ; Example: machines / m1, m2, m3, m4 / :working hours; Note: member list may be either explicitly or implicitly.

55
**Defining Primitive Sets**

Explicitly: When the list of members is explicit (cleared and separated) by entering a unique name for each member. Example: Trucks / Truck1 Truck2/ Hauling capacity ; Implicitly: When there is no list of each member’s name. In fact it is not necessary to list a name for each set member. Set Name / Member1 .. Member N / :attribute list ; Where member1 is the name of the fist member in the set and member N is the name if the last member. LINGO automatically generates all the intermediate member names between member1 and member N.

56
**Defining Primitive Sets**

Implicit member list format: 1- 1..n e.g members: 1, 2, 3, 4, 5 2- day M .. day N e.g. MON..FRI members: MON, TUE, WED, THU, FRI 3- String M.. String N e.g. Mach1 .. Mach4 members: Mach1, Mach2, Mach3, Mach4 4- Month M .. Month N e.g. OCT .. JAN members: OCT, NOV, DEC, JAN 5- MonthYearM ... MonthYearN e.g. OCT JAN2002 members:Oct2001, Nov2001, Dec2001, Jan2002

57
**Defining Primitive Sets**

Set members may have one or more attributes. Each attribute displays one property of each member. Example: students / / name, surname, ID ; Example: Suppose that The XYZ company has 5 warehouses supplying 8 vendors with their products. There is limitation for capacity and demand for warehouses and vendors, respectively. Define the appropriate sets for warehouses and vendors. SETS: Warehouse /1..5/ :capacity; Vendor / 1..8 / demand; ENDSETS

58
Defining Derived Sets A derived set definition had the following syntax: Set name (parent-set-list) / member list / :attribute list; The parent-set-list is a list of previously defined sets, separated by commas. Without specifying a member list element, LINGO constructs (builds) all combinations of members from each parent set to create the members of the new derived set. Note: For variable having more than one indices (e.g.: Xij) they should be represented in a derived set.

59
**Defining Derived Sets Example1: SETS: Product / A B / ;**

Machine / M N / ; Week / 1..2 / ; Allowed (Product, Machine, Week) ; ENDSETS Member Member (A, M, 1) (A, M, 2) (A, N, 1) (A, N, 2) (B, M, 1) (B, M, 2) (B, N, 1) (B, N, 2) Allowed set members:

60
**Defining Derived Sets Example2 (Explicit member): SETS:**

Product / A B / ; Machine / M N / ; Week / 1..2 / ; Allowed (Product, Machine, Week) / A M 1, B N 2 / ; ENDSETS Member Member (A, M, 1) (B, N, 2) Allowed set members:

61
**Example (defining primitive set)**

Define the sets and attributes by using decision variables: - REGt: Number of cars produced by regular time labor, during month t (t= 1 … 12) - OVt: Number of cars produced by over time labor, during month t (t=1 … 12) Solution: SETS: Month / / :REG, OV ; ENDSETS

62
**Example (defining derived set)**

Define the sets and attributes by using decision variables: - ADVj: dollars spends daily on advertising gas j (j=1,2,3) - PROD ij: Barrels of crude oil i used daily to produced gas j (i=1…3) SETS: Gas / 1..3 / :ADV ; Oil / 1..3 / Capacity ; Production (Oil, Gas) :prod ; ENDSETS

63
**Beginning of the membership filter Related to the first parent**

Suppose, you have already defined a set called TRUCK and each truck (There are 100 truck in this set) has an attribute called Capacity. So, the truck set is as following: Truck / / :Capacity ; You would like to derived a subset from Truck that contain only those trucks capable of hauling big load (greater than 5000 kg). So, you can use a Membership Filter as follows: Heavy-Duty (Truck) | Capacity (&1) #GT# 5000 ; Greater than Set Name Derived from Beginning of the membership filter Set index placeholder Related to the first parent

64
**List of Contents LINGO operators: General Mathematical Functions**

Arithmetic Operators Relational Operators Logical Operators General Mathematical Functions DATA section Set-Looping Function @SUM @MIN @MAX @FOR Problem

65
**Arithmetic Operators LINGO has five binary arithmetic operators:**

^ : Power * : Multiplication / : Division + : Addition - : Subtracting

66
Relational Operators Relational operators have numeric operand and return logical results (True or False). All relational operators are binary. LINGO has six relational operators: # EQ # : Returns True if the operands are equal, False if not. # NE # : Returns True if the operands are not equal, False if the operands are equal. # GT # : Returns True if the left operand is strictly greater than the right operand, False if not. # GE # : Returns True if the left operand is greater than or equal to the right operand, False otherwise. # LT # :Returns True if the left operand is strictly less than the right operand, False if not. # LE # : Returns True if the left operand is less than or equal to the right operand, False otherwise.

67
Logical Operators Logical operators have logical operands and returns logical results. Logical operators are used to connect relational and logical expressions. Note: In an expression involving both relational and logical operators, relational operators have higher precedence (It means that, relational operators are evaluated before logical operators). LINGO has three logical operators, listed here in descending order of precedence.

68
**Logical Operators # NOT # # AND # # OR #**

Negates the logical value of its operand. # NOT # is a unary operator, with its sole argument to the right. # AND # Returns the logical AND of its two operands. # AND # returns True only if both its arguments are True, otherwise it returns False. # OR # Returns the logical OR of its two operands. # OR # returns False only if both its arguments are False, otherwise it returns True.

69
**General Mathematical Functions**

@ABS(X): Returns the absolute value of X. @COS(X): Returns the cosine of X, where X is the angle in radian. @EXP(X): Returns the e ( …) to the power X. @LGM(X): Returns the natural (base e) logarithm of the gamma function of X. For integral value of X the following is true: @LOG(X): Returns the natural logarithm of X. @SIGN(X): Returns -1 if X<0, returns +1 if X>0. @SIN(X): Returns the sine of X, where X is the angle in radian. @SIZE (set name): Returns the number of elements in the set. @SMAX (List): Returns largest value in list of scalars. @SMIN (List): Returns smallest value in list of scalars. @TAN(X): Returns the tangent of X, where X is the angle in radian.

70
**Assigning values to SETS**

If you want to assign value to set attributes, you have to use another optional section which called DATA section. The DATA section begins with “DATA:” and ends with “ENDDATA”. attribute list = value list Example2: SETS: Trucks / T1 T2/ :Hauling capacity ; ENDSET DATA: Hauling capacity = ; ENDDATA

71
**Applying DATA section Example2: SETS: OR (for DATA section):**

Set1 / s1, s2, s3 / :X, Y; ENDSETS DATA: X = 1 3 5; Y = 2 4 6; ENDDATA OR (for DATA section): X Y = 1 2 3 4 5 6;

72
Set-Looping Function SET looping functions allow you to iterate through all the members of a set to perform some operation. The set looping functions are as follows: @FOR: It is used to generate constraints over members of a set. @SUM: It computes the sum of an expression over all member of a set. @MIN: Computes the minimum of an expression over all member of a set. @MAX: Computes the maximum of an expression over all member of a set. The syntax is as follows: @function (set name | condition : expression)

73
**@SUM set looping function**

Example3: Consider the following model: SETS: Trucks /T1 .. T6 / :capacity; ENDSETS DATA: capacity = ; ENDDATA Now, we sum up the values of capacity: Total (Trucks (j) : capacity (j)); OR (in our case): Total (Trucks : capacity);

74
@SUM / using condition Example4: In the previous model, how can we sum the first four elements of the attribute “capacity”? In this case we have to use conditional qualifier: Desired capacity (Trucks (j) | j # LE # 4 : capacity (j));

75
@MIN set L. Fn. Example5: In the previous model, how can we compute the minimum and maximum capacity? min-capacity (Trucks (j) : capacity (j)) ; max-capacity (Trucks (j) : capacity (j)) ; Example6: And how can we compute the minimum and maximum capacity among the first four elements? Again, we have to use conditional qualifier: Desired min-capacity (Trucks (j) | j # LE # 4 : capacity (j)); Desired max-capacity (Trucks (j) | j # LT # 5 : capacity (j));

76
**@FOR set looping function**

function is used to generate constraints across members of a set. Now, consider the following example: SETS: Trucks / T1 .. T5 / :capacity ; ENDSETS If we want to limit the capacity of each truck by 10 tons, what should we do? We function: @FOR (Trucks (j) : capacity (j) <= 10) ;

77
**Applying @FOR function**

Example7: consider the following model: SETS: NUM / / :value, reciprocal; ENDSETS DATA: value = ; ENDDATA How can we compute the reciprocal of these five numbers? @FOR (NUM (j) : reciprocal (j) = 1/value (j)) ; Example8: If value = , what should we do? @FOR (NUM (j) | value (j) # NE # 0 : reciprocal (j) =1/value (j)) ;

78
**Appling set looping Functions**

Problem: Suppose we have seven songs, each with a different length, that must be placed on a cassette tape. The goal is to maximize the number of songs on one side of the tape without exceeding half of the total time of the music on the side.

79
**Problem solution Lj: Length of the song j**

Yj: equal to “1” if song j is selected, “0” otherwise So, we have: Max Z= Y1 +Y2 + … +Y7 Subject to: 14Y1+6Y2+… +8Y7 ≤ (1/2)(14+6+ … +8) Yj: Binary (J=1 … 7)

80
**Converting to LINGO MODEL: SETS: Songs / 1 .. 7 / :Length, Y; ENDSETS**

DATA: Length = ; ENDDATA MAX (Songs (j) : Y (j)) ; @SUM (Songs (j) :Length (j)*Y (Songs (j) : Length (j)) / 2; @FOR (Songs (j) (Y)) ; END

81
LINGO answer

82
**Transportation Models**

Problem: A transportation company wants to ship products from 6 warehouses to 5 customers with minimal shipping cost. Capacity of warehouses and demand of customers are given. In addition shipping costs from one city to another are given.

84
**Solution Ci: Capacity of warehouse i Dj: Dmand of customer j**

Costij: Cost of shipping from warehouse i to customer j Vij: Amount of shipping from warehouse i to customer j Max Z= Subject to: for j=1 … 5 for i=1 ...6

85
Converting to LINGO

86
LINGO answer

87
LINGO answer

88
LINGO answer

89
LINGO answer

90
LINGO answer

Similar presentations

OK

WOOD 492 MODELLING FOR DECISION SUPPORT Lecture 9 Intro to Sensitivity Analysis.

WOOD 492 MODELLING FOR DECISION SUPPORT Lecture 9 Intro to Sensitivity Analysis.

© 2018 SlidePlayer.com Inc.

All rights reserved.

Ads by Google

Ppt on the periodic table of elements Ppt on teachers day celebration Keynote read ppt on iphone Ppt on nitrogen cycle and nitrogen fixation is carried Ppt on resources and development class 10 cbse result Ppt on column chromatography videos Ppt on acute myeloid leukemia Ppt on tsunami the killer sea waves Ppt on mahatma gandhi as a leader Ppt on social contract theory rousseau