Presentation on theme: "IENG442 LINGOLAB3. 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."— Presentation transcript:
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 2. 60 units of row material 1 and 25 unit of row material 2 are available. Formulate an LP that can be used to maximize revenue.
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
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.
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
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.
Example-05 continuing a) 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
Example-05 (Solution) a) MAX Z = (10*3) X1 + (25*4) X2 Subject to: X1 + X2 <= 7 4X1 + 10X2 <= 40 10X1 >= 30 X2 >= 0
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.
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.
Example 06 (@BIN(X)) 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.
Example 06-Solution We have 4 types of tasks; marketing, cooking, dishwashing and laundry Our decision variables are: S i and E i (i=1…4). S i =1 ;if Steven does the i th task Si=0 ;otherwise E i =1 ;if Evren does the i th task E i =0 ;Otherwise
Example 07 (@GIN(X)) 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.
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)
Example 08 (@BND(L,X,U)) 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.
Example 08- Solution Decision variables are: X i =number of product i that should be produced to maximized the profits (i=1,2)
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.
Example 09- Solution Decision variables: X 1 = number of loaves of bread baked X 2 =number of ounces by which flour supply is increased by cash transactions (so, X 2 can be positive (purchasing), negative (selling) or zero) Note: The baker can not purchase any additional yeast!
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.
Solution to Example 1: Determine how much raw material to purchase and mow much of each type of perfume to produce X 1 =number of ounces of Regular Brute sold annually X 2 =number of ounces of Luxury Brute sold annuallly X 3 =number of ounces of Regular Chanelle sold annually X 4 =number of ounces of Luxury Chanelle sold annually X 5 =number of pounds of raw material purchased annually Profit=revenues from perfume sales-processing costs-costs of purchasing raw material =7X 1 +18X 2 +6X 3 +14X 4 -(4X 2 +4X 4 )-3X 5
Solution to Example 1: Max z =7X 1 +14X 2 +6X 3 +10X 4 -3X 5 Subject to X 5 <=4,000 3X 2 +2X 4 +X 5 <=6,000 X 1 +X 2 -3X 5 =0 X 3 +X 4 -4X 5 =0 X i >=0 (i=1,2,3,4,5)
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).
Types of Sets in LINGO Some simple examples: – Product:Price –Truck:Hauling capacity –Warehouse:Storage Capacity Types of Sets: 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). 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. 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.
How to use 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. Note: member list may be either explicitly or implicitly.
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.
Defining Primitive Sets Implicit member list format: 1- 1..ne.g. 1..5members: 1, 2, 3, 4, 5 2- day M.. day Ne.g. MON..FRI members: MON, TUE, WED, THU, FRI 3- String M.. String Ne.g. Mach1.. Mach4 members: Mach1, Mach2, Mach3, Mach4 4- Month M.. Month Ne.g. OCT.. JAN members: OCT, NOV, DEC, JAN 5- MonthYearM... MonthYearN e.g. OCT2001..JAN2002 members:Oct2001, Nov2001, Dec2001, Jan2002
Defining Primitive Sets Set members may have one or more attributes. Each attribute displays one property of each member. Example: students / 1..30 / 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
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. 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. 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.: X ij ) they should be represented in a derived set.
Defining Derived Sets Example1: SETS: Product / A B / ; Machine / M N / ; Week / 1..2 / ; Allowed (Product, Machine, Week) ; ENDSETSMemberMember (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:
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 / ; ENDSETSMember (A, M, 1)(B, N, 2) Allowed set members:
Example (defining primitive set) Define the sets and attributes by using decision variables: - REG t : Number of cars produced by regular time labor, during month t (t= 1 … 12) - OV t : Number of cars produced by over time labor, during month t (t=1 … 12) Solution:SETS: Month / 1..12 / :REG, OV ; ENDSETS
Example (defining derived set) Define the sets and attributes by using decision variables: - ADV j : 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
Membership Filter 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 / 1..100 / :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: 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 ; Set Name Derived from Beginning of the membership filter Set index placeholder Greater than Related to the first parent
List of Contents LINGO operators: –Arithmetic Operators –Relational Operators –Logical Operators General Mathematical Functions General Mathematical Functions DATA section DATA section Set-Looping Function –@SUM –@MIN –@MAX –@FOR Problem
Arithmetic Operators LINGO has five binary arithmetic operators: –^ : Power –* : Multiplication –/ : Division –+ : Addition –- : Subtracting
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.
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.
Logical Operators # NOT # –Negates the logical value of its operand. # NOT # is a unary operator, with its sole argument to the right. # AND # # AND # –Returns the logical AND of its two operands. # AND # returns True only if both its arguments are True, otherwise it returns False. # OR # # OR # –Returns the logical OR of its two operands. # OR # returns False only if both its arguments are False, otherwise it returns True.
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 (2.718281…) 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: @LGM(X)=@LOG(X-1). @LOG(X): Returns the natural logarithm of X. @SIGN(X): 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.
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 Example2: SETS: Trucks / T1 T2/ :Hauling capacity ; ENDSET ENDSET DATA: DATA: Hauling capacity = 5000 10000 ; ENDDATA ENDDATA
Applying DATA section Example2: SETS: Set1 / s1, s2, s3 / :X, Y; ENDSETS DATA: X = 1 3 5; Y = 2 4 6; ENDDATA OR (for DATA section): DATA: X Y = 1 2 3 4 5 6; ENDDATA
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)
@SUM set looping function Example3: Consider the following model: SETS: Trucks /T1.. T6 / :capacity; ENDSETS DATA: capacity = 5 7 10 10 16 24 ; ENDDATA Now, we sum up the values of capacity: Total capacity= @SUM (Trucks (j) : capacity (j)); OR (in our case): Total capacity= @SUM (Trucks : capacity);
@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 = @SUM (Trucks (j) | j # LE # 4 : capacity (j));
@MIN and @MAX set L. Fn. Example5: In the previous model, how can we compute the minimum and maximum capacity? min-capacity = @MIN (Trucks (j) : capacity (j)) ; max-capacity = @MAX (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 = @MIN (Trucks (j) | j # LE # 4 : capacity (j)); Desired max-capacity = @MAX (Trucks (j) | j # LT # 5 : capacity (j));
@FOR set looping function The @FOR 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? If we want to limit the capacity of each truck by 10 tons, what should we do? We use @FOR function: @FOR (Trucks (j) : capacity (j) <= 10) ;
Applying @FOR function Example7: consider the following model: SETS: NUM / 1.. 5 / :value, reciprocal; ENDSETSDATA: value = 3 4 2 8 5; ENDDATA How can we compute the reciprocal of these five numbers? @FOR (NUM (j) : reciprocal (j) = 1/value (j)) ; Example8: If value = 0 4 2 8 5, what should we do? Example8: If value = 0 4 2 8 5, what should we do? @FOR (NUM (j) | value (j) # NE # 0 : reciprocal (j) =1/value (j)) ;
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.
Problem solution L j : Length of the song j Y j : equal to “1” if song j is selected, “0” otherwise So, we have: Max Z= Y 1 +Y 2 + … +Y 7 Subject to: 14Y 1 +6Y 2 +… +8Y 7 ≤ (1/2)(14+6+ … +8) Y j : Binary (J=1 … 7)
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. Capacity of warehouses and demand of customers are given. In addition shipping costs from one city to another are given.
Solution C i : Capacity of warehouse i D j : Dmand of customer j Cost ij : Cost of shipping from warehouse i to customer j V ij : Amount of shipping from warehouse i to customer j Max Z= Subject to: for j=1 … 5 for j=1 … 5 for i=1...6