You are on page 1of 5

Introduction to LINGO 8.

„ LINGO is a software tool designed to


LINGO 8.0 Software Tutorial efficiently build and solve linear, nonlinear,
and integer optimization models
Created by:
Anne Hummel
Kris Thornburg

Creating a LINGO Model A Sample Model


„ An Optimization model consists of 3 parts ! A cookie store can produce drop cookies and decorated
cookies, which sell for $1 and $1.50 apiece,
„ Objective Function respectively. The two bakers each work 8 hours per day
and can produce up to 400 drop cookies and 200 decorated
„ A single formula that describes exactly what the cookies. It takes 1 minute to produce each drop cookie
and 3 minutes to produce each decorated cookie. What
model should optimize combination of cookies produced will maximize the
baker's profit? ;
„ Variables
„ Quantities that can be changed to produce the MAX = 1*Drop + 1.5*Deco;

optimal value of the objective function Drop <= 400;


„ Constraints Deco <= 200;

„ formulas that define the limits on the values of the 1/60*Drop + 3/60*Deco <=16;
variables

Things to notice Solving a LINGO Model


„ Comments in the model are initiated with an „ Once the model has been entered into the
exclamation point (!) and appear in green text
Model Window, it can be solved by:
„ LINGO specified operators and functions appear
in blue text „ clicking the Solve button
„ All other text is shown in black „ Selecting Solve from the LINGO menu
„ Each LINGO statement must end in a semi-semi-colon „ Using the ctrl+s keyboard shortcut
(;)
„ Variable names are not case-
case-sensitive and must
begin with a letter (A-
(A-Z) „ Errors (if any) will be reported

1
LINGO Solver Status Window LINGO Solution Report Window

„ If no errors are found, the LINGO Solver „ Close the Solver Status window to see the
Status window appears Solution Report window

LINGO Solution Report Window LINGO Solution Report Window

„ Slack or Surplus „ Reduced Cost


„ Zero if a constraint is completely satisfied as „ How much the objective function would
an equality degrade if one unit of a variable (not included
„ Positive shows how many more units of the in the current solution) were to be included
variable could be added to the optimal „ Dual Price
solution before the constraint becomes an „ How much the objective function would
equality improve if the constraining value is increased
„ Constraint has been violated if negative by one unit

Using Sets in LINGO Using Sets

„ LINGO allows you to group many „ SETS section must be defined before any
instances of the same variable into sets of the set members are used in the
„ Example: If a model involved 27 delivery model’s constraints
trucks, then these 27 trucks could be „ Primitive set example:
described more simply as a single set
SETS:
„ Sets may also include attributes for each
Trucks/TR1..TR27/:Capacity;
member, such as the hauling capacity for
each delivery truck ENDSETS

2
Using Sets (cont.) Set Looping Statement Examples

„ Derived set example: @FOR(Trucks(T): Capacity(T)<=3000);


SETS: „ This @FOR statement sets the hauling capacity for all 27
delivery trucks in the Trucks set to at most 3000 pounds
Product/X Y/;
Machine/L M/; TOTAL_HAUL=@SUM(Trucks(J): Capacity(J));
Make(Product Machine)/X L, X M, „ This @SUM statement calculates the total hauling
Y M/; capacity from the individual trucks
ENDSETS

LINGO Data Section LINGO Data Example

„ Values can be defined for different SETS:

variables SET1 /A, B, C/: X, Y;


ENDSETS
„ Set numbers
„ Attributes for sets DATA:
„ Scalar variable parameters X = 1, 2, 3;
Y = 4, 5, 6;
ENDDATA

Variable Types in LINGO Variable Types in LINGO (cont.)

„ All variables in a LINGO model are „ @GIN – any positive integer value
considered to be non-
non-negative and „ @BIN – a binary value (ie
(ie,, 0 or 1)
continuous unless otherwise specified „ @FREE – any positive or negative real
„ LINGO’s four variable domain functions value
can be used to override the default „ @BND – any value within the specified
domain for given variables bounds

3
LINGO Operators and Functions Mathematical Functions

„ There are three types of operators that „ @ABS(X) – returns the absolute value of X
LINGO uses „ @SIGN(X) – returns -1 if X is negative and +1 if
X is positive
„ Arithmetic
„ @EXP(X) – calculates eX
„ Logical
„ @LOG(X) – calculates the natural log of X
„ Relational „ @SIN(X) – returns the sine of X, where X is the
angle in radians
„ @COS(X) – returns the cosine of X
„ @TAN(X) – returns the tangent of X

Other Functions in LINGO LINGO Programming Example

„ LINGO also contains a plethora of „ Knapsack Problem


financial, probability, and import/export
SETS:
functions ITEMS / ANT_REPEL, BEER, BLANKET,
BRATWURST, BROWNIES, FRISBEE, SALAD,
WATERMELON/:
„ These are commonly used in more INCLUDE, WEIGHT, RATING;
advanced models ENDSETS

Knapsack (cont.)
DATA:
WEIGHT, RATING =
1, 2
3, 9
4, 3
3, 8
3, 10
1, 6
5, 4
10, 10;
KNAPSACK_CAPACITY = 15;
ENDDATA

MAX = @SUM( ITEMS: RATING * INCLUDE);

@SUM( ITEMS: WEIGHT * INCLUDE) <= KNAPSACK_CAPACITY;

@FOR( ITEMS: @BIN( INCLUDE));

4
Questions?

You might also like