Sunteți pe pagina 1din 8

LINGO- LAB

Introduction
Lingo is a software that helps you to model and solve some kinds of optimization problems, such as: o Linear o Nonlinear o Integer Not only you can enter each term of each constraint explicitly (separately and clearly), but also you can express a whole series of similar constraints in a single compact statement. For those problems which involve large number of similar variables and constraints, using set-base model is a powerful approach.

What is an optimization model?


It consists of 3 parts: Variables (quantities that can be changed to find the optimum value of objective function) Objective Function (a formula to optimize the model, for example: maximize profit, maximize products, minimize cost, minimize working hours) Constraints (define the limits of the variables)

Linear Programming
f(x1, x2, ,xn) = c1x 1 c2x2 cnxn is a linear function. Note that we have no power of 2 or 3 or (for example x2 is not acceptable). f(x1, x2, ,xn) b or f(x1, x2, ,xn) b is a linear inequality. A linear programming problem (LP) is an optimization problem: - To max. or min. a linear function of decision variables (objective function) - The values of decision variables should satisfy a set of constraints.

Notes
Comments are initiated with (!) (exclamation point). Each statement (line) must be end in a (;) (semi-colon). Variable names must begin with a letter (A-Z) (They are not case sensitive). (*) (Asterisk) used to denote multiplication. Parentheses should use to define the order of mathematical operations. 1

IENG313 LAB NOTE

To start entering a new optimization problem type: MODEL: Enter the objective function by typing: MIN=. ; Or MAX= ; The last statement should be: END Type the constraints after the objective function without: o St o Such that o Subject to

You can use (^) (carat sign) as a power symbol (In nonlinear programming). In Lingo, the lower bound for variables is zero.

A simple example (exp-01)


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 raw material 1 and 2 unit of raw material 2. Producing a unit of product A requires 2 unit of raw material 1 and 1 unit of raw material 2. 60 units of raw material 1 and 25 unit of raw material 2 are available. Formulate an LP that can be used to maximize revenue. 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 2x2 + 1x1 25 x1 0 x2 0 Changing model for LINGO: MODEL: MAX = 5* x2 + 3*x1; 5* x2 + 2*x1 <= 60; 2* x2 + 1*x1 <= 25; END (Raw material 1 constraint) (Raw material 2 constraint)

Solving a LINGO Model


IENG313 LAB NOTE 2

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. LINGO Solver Status Window If no errors are found, the LINGO solver status window appears:

LINGO Solution Report Window Close the Solver Status window to see the Solution Report window.

IENG313 LAB NOTE

Reduced Cost: (for information)

If we increase one unit of a non-basic variable, how much the objective function will degrade (decrease)? For example, if we want to produce one unit of x2 then we have to produce 23 units of x1, so the objective function will be: (5*1) + (3*23) = 74. Then the reduced cost will be: 75 74 = 1
Dual Price: (for information)

If for example we increase (or decrease) one unit to the 2nd constraint (It is 25 now), then the objective function increase (or decrease) 3 units. Note: The second constraint is satisfied equally, so it is a Compulsory Constraint.
Slack or Surplus: (for information)

Zero: if a constraint is completely satisfied equality (3re row or 2nd constraint). Positive: shows that how many more units of the variable could be added to the optimal solution before the constraint becomes an equality (2nd row: 60- (2*25)= 10)

Negative: Constraint has been violated!

Example (exp-02)
Maximize Subject to -5/36Q2 + 160/9Q 125/9 10 Q 100

LINGO Model

LINGO Solver Status Window

IENG313 LAB NOTE

LINGO Solution Report Window

Example (exp-03)
Minimize Subject to 50S+100F 5 S + 17 F 40 20 S + 7 F 60 S,F 0

IENG313 LAB NOTE

LINGO Model

LINGO Solver Status Window

LINGO Solution Report Window

IENG313 LAB NOTE

Problem 1
A least cost diet has to be planned for the kitchen of the Strong Boys High School. The total daily requirements of the nutritional elements for healthy young boys, and the cost and the nutritional contents of general food types are given in the following table.
Required Nutritional Element

Units of Nutritional Elements Per Unit of Food Type Milk 160 110 90 50 $ 0.42 Meat 210 130 190 50 $ 0.68 Bread 120 110 90 75 $ 0.32 Vegetable 150 120 130 70 $ 0.17

Total Daily Requirement 2700 Calories 300 grams 250 grams 60 grams

Calories Carbohydrates Protein Vitamins Cots Per Unit

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.

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:
Subject to:

Min Z= 0.42X1+0.68X2+0.32X3+0.17X4 160X1+210X2+120X3+150X4 2700 110X1+130X2+110X3+120X4 300 90X1+190X2+90X3+130X4 50X1+50X2+75X3+70X4 36X1+76X2-54X3-78X4 X1+X2+X3+X4 Xj 0 16 ; j=1,2,3,4 250 60 0

Calories: Carbohydrate: Protein: Vitamins: Protein balance: Or: Eating Capacity: Non-negativity:
Lingo Model:

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

IENG313 LAB NOTE

Problem 2
Steelco manufactures two types of steel at three different steel mills. During a given month, each steel mill has 200 hours of blast furnace time available. Because of differences in the furnaces at each mill, the time and cost to produce a ton of steel differs for each mill. The time and cost for each mill are shown in the bellow table.

Steel
Cost ($) Mill 1 Mill 2 Mill 3 10 12 14 Time (Minutes) 20 24 28 Cost ($) 11 9 10

Steel 2
Time (Minutes) 22 18 30

Each month, Steelco must manufacture at least 500 tons of steel 1 and 600 tons of steel 2. Formulate an LP to minimize the cost of manufacturing the desired steel. xij: tons of steel j that reached from mill i, where i=1,2,3 and j=1,2.
Lingo Model:

IENG313 LAB NOTE

S-ar putea să vă placă și