ieng442 l.
Skip this Video
Loading SlideShow in 5 Seconds..
IENG442 PowerPoint Presentation
Download Presentation

Loading in 2 Seconds...

play fullscreen
1 / 90

IENG442 - PowerPoint PPT Presentation

  • Uploaded on

IENG442. LINGO LAB3. Example -1.

I am the owner, or an agent authorized to act on behalf of the owner, of the copyrighted work described.
Download Presentation

PowerPoint Slideshow about 'IENG442' - lars

An Image/Link below is provided (as is) to download presentation

Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author.While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server.

- - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - -
Presentation Transcript




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



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

solving a lingo model
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.

example 02
Example -02
  • Maximize -5/36Q2 + 160/9Q – 125/9
  • Subject to 10 ≤Q ≤ 100
example 03
Example -03
  • Minimize 50S+100F
  • Subject to

5 + 17≥ 40

20+ 7 ≥ 60

S,F ≥ 0

e xample 0 4

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 4 solution14
  • Subject to:
  • Calories: 160X1+210X2+120X3+150X4 ≤ 2700
  • Carbohydrate: 110X1+130X2+110X3+120X4 ≥ 300
  • Protein: 90X1+190X2+90X3+130X4 ≥ 250
  • Vitamins: 50X1+50X2+75X3+70X4 ≥ 60
  • Protein balance:

90X1+190X2 ≤ 0.6(90X1+190X2+90X3+130X4)

  • Or: 36X1+76X2-54X3-78X4 ≤ 0
  • Eating Capacity: X1+X2+X3+X4 ≤ 16
  • Non-negativity: Xj ≥ 0 ; j=1,2,3,4
example 0 5
  • 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 0 5 continuing
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 0 5 solution
Example-05 (Solution)
  • a)

MAX Z = (10*3) X1 + (25*4) X2

Subject to:

X1 + X2 <= 7

4X1 + 10X2 <= 40

10X1 >= 30

X2 >= 0

example 0 5 solution21
Example-05 (Solution)
  • b)

MAX Z = 3Y1 + 4Y2

Subject to:

Y1>= 30

Y1/10 + Y2/25 <= 7

Y1/4 + Y2/10 <= 40

Y2 >= 0

  • 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
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 0 6 @bin x
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 0 6 solution
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
example 0 7 @gin x
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 0 7 solution
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 0 8 @bnd l x u
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 0 8 solution
Example 08- Solution
  • Decision variables are:

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

example 0 9 free x
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 0 9 solution
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!

brute production process @gin
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
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


solution to example 148
Solution to Example 1:

Max z =7X1+14X2+6X3+10X4-3X5

Subject to





Xi>=0 (i=1,2,3,4,5)

using sets in lingo when and why
Using Sets in LINGOWhen 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
Types of Sets in LINGO
  • Some simple examples:
    • 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.
how to use 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.
defining primitive sets
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 sets56
Defining Primitive Sets
  • Implicit member list format:

1- 1..n e.g. 1..5 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. OCT2001 ..JAN2002

members:Oct2001, Nov2001, Dec2001, Jan2002

defining primitive sets57
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.


Warehouse /1..5/ :capacity;

Vendor / 1..8 / demand;


defining derived sets
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.
defining derived sets59
Defining Derived 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:

defining derived sets60
Defining Derived Sets

Example2 (Explicit member):


Product / A B / ;

Machine / M N / ;

Week / 1..2 / ;

Allowed (Product, Machine, Week) / A M 1, B N 2 / ;


Member Member

(A, M, 1) (B, N, 2)

Allowed set members:

example defining primitive set
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)



Month / 1..12 / :REG, OV ;


example defining derived set
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)


Gas / 1..3 / :ADV ;

Oil / 1..3 / Capacity ;

Production (Oil, Gas) :prod ;


membership filter
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:

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

list of contents
List of Contents
  • LINGO operators:
    • Arithmetic Operators
    • Relational Operators
    • Logical Operators
  • General Mathematical Functions
  • DATA section
  • Set-Looping Function
    • @SUM
    • @MIN
    • @MAX
    • @FOR
  • Problem
arithmetic operators
Arithmetic Operators
  • LINGO has five binary arithmetic operators:
    • ^ : Power
    • * : Multiplication
    • / : Division
    • + : Addition
    • - : Subtracting
relational operators
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
  • 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 operators68
Logical Operators
  • # NOT #
    • 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.
general mathematical functions
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, 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
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 ;



Hauling capacity = 5000 10000 ;


applying data section
Applying DATA section

Example2: SETS:

Set1 / s1, s2, s3 / :X, Y;



X = 1 3 5;

Y = 2 4 6;


OR (for DATA section):


X Y = 1 2

3 4

5 6;


set looping function
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
@SUM set looping function
  • Example3: Consider the following model:


Trucks /T1 .. T6 / :capacity;



capacity = 5 7 10 10 16 24 ;


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


  • 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
Applying @FOR function
  • Example7: consider the following model:


NUM / 1 .. 5 / :value, reciprocal;



value = 3 4 2 8 5;


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?

@FOR (NUM (j) | value (j) # NE # 0 : reciprocal (j) =1/value (j)) ;

appling set looping functions
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
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)

converting to lingo
Converting to LINGO



Songs / 1 .. 7 / :Length, Y;



Length = 14 6 4 5 6 4 8 ;


MAX = @SUM (Songs (j) : Y (j)) ;

@SUM (Songs (j) :Length (j)*Y (j))<= @SUM (Songs (j) : Length (j)) / 2;

@FOR (Songs (j) : @BIN (Y)) ;


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

  • 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