+ All Categories
Home > Documents > SOFTHUB SYSTEMS TRAINING MANUAL FOR LINGO 11...tab of the LINGO|Options. Each button on the toolbar...

SOFTHUB SYSTEMS TRAINING MANUAL FOR LINGO 11...tab of the LINGO|Options. Each button on the toolbar...

Date post: 24-Sep-2020
Category:
Upload: others
View: 3 times
Download: 0 times
Share this document with a friend
30
SOFTHUB SYSTEMS TRAINING MANUAL FOR LINGO 11 By: UWADONE Emmanuel
Transcript
Page 1: SOFTHUB SYSTEMS TRAINING MANUAL FOR LINGO 11...tab of the LINGO|Options. Each button on the toolbar corresponds to a menu command. Not all menu commands have a toolbar button, but,

i | P a g e

SOFTHUB SYSTEMS TRAINING MANUAL FOR LINGO 11 By: UWADONE Emmanuel

Page 2: SOFTHUB SYSTEMS TRAINING MANUAL FOR LINGO 11...tab of the LINGO|Options. Each button on the toolbar corresponds to a menu command. Not all menu commands have a toolbar button, but,

ii | P a g e

Table of Contents About Softhub Systems Introduction to LINGO 11.0……………………………………..……………………………..4

How To Create a LINGO Model …………………….………………………………………..12

Solving a LINGO Model…………………………………………………………………….…13

Using Sets in LINGO……………………………………………………………………….….15

The LINGO Data Section………………………………………………………………………17

Variable Types in LINGO……………………………………………………………….…..…19

LINGO Operators and Functions……………………………………………………….……...20

Solving Linear Programming, Integer Programming, Binary Integer Programming Problems

Using Lingo ……………………………………………………………..………………….….23

LINGO Programming Examples……..………………………………………………………...28

Page 3: SOFTHUB SYSTEMS TRAINING MANUAL FOR LINGO 11...tab of the LINGO|Options. Each button on the toolbar corresponds to a menu command. Not all menu commands have a toolbar button, but,

iii | P a g e

About Softhub Systems

SoftHub is a cutting edge IT Company that specialises in the following services

Webhosting

Web development

Application Development

IT training

Business Development

Consultancy Services

Networking Services

Financial and Human Capital Management Software solutions

08067847553

Page 4: SOFTHUB SYSTEMS TRAINING MANUAL FOR LINGO 11...tab of the LINGO|Options. Each button on the toolbar corresponds to a menu command. Not all menu commands have a toolbar button, but,

iv | P a g e

1.0 Introduction to LINGO 11 LINGO is a software tool designed to efficiently build and solve linear, nonlinear, and integer

optimization models. It is licensed to Lindo Systems Inc.

1.1 LINGO 11.0 includes several new features, including:

Simplex Solver Improvements: The simplex solvers include a number of new features:

Large linear models solve an average of 80% faster using the newly enhanced dual and primal

simplex solvers.

The new release includes several enhancements to the sparse LU decomposition routines and the

addition of advanced basis repairing techniques.

Relative to earlier releases, the Simplex solvers offer improved handling of numerically difficult

problems.

Improvements in the dual simplex method that is used to reoptimize at each branch in the branch-

and-bound tree on integer models, allowing more branches to be processed per second in the search

tree.

Better handling of numerically difficult linear and integer models.

MIP Solver Improvements: LINGO's MIP solver improvements include:

The MIP solver is now an average of 40% faster on a wide range of integer models.

An advanced implementation of Feasibility Pump heuristic speeds the finding of feasible solutions on

many difficult problems.

An advanced implementation of the Relaxation Induced Neighborhood Search (RINS) technique finds

improved integer solutions faster.

General and local branching strategies have been improved to exploit model structure.

Rounding techniques have been expanded to exploit a wider range of constraint structures.

Performance has been improved on probing through out the branch-and-bound tree.

Cut management has been improved.

Global Solver Improvements:

Page 5: SOFTHUB SYSTEMS TRAINING MANUAL FOR LINGO 11...tab of the LINGO|Options. Each button on the toolbar corresponds to a menu command. Not all menu commands have a toolbar button, but,

v | P a g e

The global solver includes a number of enhancements for solving non-convex,

nonlinear models to global optimality:

New discrete space constraint propagation and convex-cut generation improve performance on

nonlinear models with integer variables and/or non-smooth functions.

A multi-formulation capability improves bounding performance and enhances tractability through

efficient cut generation.

Barrier Solver Improvements: The barrier solver improvements include:

The barrier method solves large-scale linear and quadratic models an average of 20% faster.

Improved handling of numerically difficult models.

Nonlinear Solver Improvements: The general nonlinear solver improvements include:

On average, the nonlinear solver is now 25% faster oo highly nonlinear and complex models.

An efficient implementation of Algebraic Second Order Derivatives has resulted in improved speed

and solution precision.

Solve Linear Programs in Multiple Cores:

When solving linear programs on a multi-core machine, users can specify that

two, or more, of LINGO's four different LP solvers are to be run in parallel on

different cores. LINGO then returns the solution from the first solver to finish

optimization.

K-Best MIP Solver: LINGO's new K-Best MIP solver will return the K best solutions (based on

objective value) to integer models, where K is a user controlled parameter. You

may then scroll through the K solutions, examine them, and select the one of

most interest based on the value of a tradeoff variable.

Generate and Display Dual Formulations: You may now generate the dual formulation of a linear programming model

with the LINGO|Generate|Dual command.

Support of Semicontinuous Variables:

Many models require certain variables to either be 0, or lie within some non-

negative range, e.g., 10 to 20. Modeling this condition in LINGO in the past

meant having to add an additional 0/1 variable and two additional

constraints. LINGO now allows you to set semi-continuous variables directly

with the @SEMIC statement.

Support of SOS (Special Ordered Sets) Variables of Type 1, 2 and 3 and

Cardinality: You may now specify sets of binary variables that are of type SOS1 (at most.one

nonzero), SOS2 (at most two nonzero and adjacent) and SOS3 (variables must

Page 6: SOFTHUB SYSTEMS TRAINING MANUAL FOR LINGO 11...tab of the LINGO|Options. Each button on the toolbar corresponds to a menu command. Not all menu commands have a toolbar button, but,

vi | P a g e

sum to 1). The cardinality feature allows you to specify sets of variables where,

at most, k variables can be nonzero. These functions allow the MIP solver to

handle models more efficiently and cuts down on the number of constraints

required in your models.

Access Excel, Databases and Text Files in Calc Sections: In prior releases, LINGO was only able to access external data sources using

static links in the Data sections of models. The @OLE, @ODBC, @TEXT and

@POINTER functions are now available in Calc sections, allowing you to

dynamically build links for importing and exporting data. These import/export

functions may also be placed in a loop, which is useful for solving multiple

instances of a model in a loop.

@RANK Sorting Function:

The @RANK sorting function may be used in calc sections to efficiently sorts

vectors and return the ranks of their members in a separate vector.

Support of Additional Trigonometric Functions: Support of the following trigonometric functions has been added: ACOS, ASIN,

ATAN, ATAN2, COSH, SINH, TANH, ASINH, ACOSH, and ATANH. These

functions are fully supported by the global solver, allowing for global solutions

to highly non-convex, trigonometric models.

Help System Updated to HTML for Windows Vista Compatibility:

LINGO's online help files have been ported to compiled HTML for native

support under Windows Vista.

@POINTER Allows Imports and Exports of Set Members from Calling

Applications:

In addition to numerical data, @POINTER can now import and export set

members via a memory location passed by a calling application.

ASP.NET Programming Example: An example illustrating how to call LINGO from ASP.NET is now included in

the \LINGO11\Programming Samples folder.

@SOLU, @OBJBND, @DEBUG and @TIME Functions in Calc

Sections: The @SOLU function in calc sections generates standard LINGO-style solution

reports, @OBJBND returns the bound on the current objective, @DEBUG

debugs infeasible or unbounded models, and @TIME returns the elapsed solver

time.

Page 7: SOFTHUB SYSTEMS TRAINING MANUAL FOR LINGO 11...tab of the LINGO|Options. Each button on the toolbar corresponds to a menu command. Not all menu commands have a toolbar button, but,

vii | P a g e

1.2 The LINGO Interface

1.3 The Lingo Menu Bar

LINGO groups commands under the following five menus:

File

Edit

LINGO

Window

Help

The File menu contains commands that primarily deal with handling input and output. The

Edit menu contains commands for editing the document in the current window. The LINGO

menu contains commands to solve a model and generate solution reports. The Window menu

has commands that deal with the mechanics of handling multiple windows. The Help menu

provides access to LINGO's help facility.

1) File Menu

Page 8: SOFTHUB SYSTEMS TRAINING MANUAL FOR LINGO 11...tab of the LINGO|Options. Each button on the toolbar corresponds to a menu command. Not all menu commands have a toolbar button, but,

viii | P a g e

New Opens a new model window.

Open Opens an existing model previously saved

to disk.

Save Saves the contents of the current window to

disk.

Save As Saves the contents of the current window to

a new name.

Close Closes the current window.

Print Prints the contents of the current window.

Print Setup Configures your printer.

Print Preview Displays the contents of the current window

as it would appear if printed.

Log Output Opens a log file for logging output to the

command window.

Take Commands Runs a command script contained in a file.

Export File Exports a model in MPS or MPI file format.

License Prompts you for a new license password to

upgrade your system.

Database User

Info

Prompts you for a user id and password for

database access via the @ODBC() function.

Exit Exits LINGO.

2) Edit Menu

Undo Undoes the last change.

Redo Redoes the last undo command.

Cut Cuts the current selection from the

document.

Copy Copies the current selection to the clipboard.

Paste Pastes the contents of the clipboard into the

document.

Page 9: SOFTHUB SYSTEMS TRAINING MANUAL FOR LINGO 11...tab of the LINGO|Options. Each button on the toolbar corresponds to a menu command. Not all menu commands have a toolbar button, but,

ix | P a g e

Paste Special Pastes the contents of the clipboard into the

document, allowing choice as to how the

object is pasted.

Select All Selects the entire contents of the current

window.

Find Searches the document for the occurrence of

a specified text string.

Find Next Repeats the find operation for the last string

specified.

Replace Replaces a specified text string with a new

string.

Go To Line Moves the cursor to a specified line number.

Match

Parenthesis

Finds the parenthesis that closes a selected

parenthesis.

Paste Function Pastes a template of a selected LINGO

@function.

Select Font Specifies a font for a selected block of text.

Insert New

Object

Embeds an OLE object into the document.

Links Controls the links to external objects in your

document.

Object Properties Specifies the properties of a selected,

embedded object.

3) LINGO Menu

Solve Solves the model in the current window.

Solution Generates a solution report window for

the current model.

Range Generates a range analysis report for the

current window.

Options Sets system options.

Generate Generates the algebraic representation for

Page 10: SOFTHUB SYSTEMS TRAINING MANUAL FOR LINGO 11...tab of the LINGO|Options. Each button on the toolbar corresponds to a menu command. Not all menu commands have a toolbar button, but,

x | P a g e

the current model.

Picture Displays a graphical picture of the models

matrix.

Debug Tracks down formulation errors in

infeasible and unbounded linear

programs.

Model Statistics Displays a brief report regarding the

technical details of a model.

Look Generates a formulation report for the

current window.

4) Window Menu

Command

Window

Opens a command window for command-

line operation of LINGO.

Status Window Opens the solver's status window.

Send to Back Sends the current window behind all other

open windows.

Close All Closes all open windows.

Tile Arranges all open windows into a tiled

pattern.

Cascade Arranges all open windows into a cascading

pattern.

Arrange Icons Aligns all iconized windows at the bottom

of the main frame window.

5) Help Menu

Help Topics Accesses LINGO's Help facility.

Register Registers your version of LINGO online.

AutoUpdate Checks to see if an updated copy of LINGO is

available for download on the LINDO Systems

Web site.

About

LINGO

Displays the version and size of your copy of

LINGO, along with information on how to

contact LINDO Systems.

Page 11: SOFTHUB SYSTEMS TRAINING MANUAL FOR LINGO 11...tab of the LINGO|Options. Each button on the toolbar corresponds to a menu command. Not all menu commands have a toolbar button, but,

xi | P a g e

1.4 The Toolbar By default, the toolbar runs along the top of the screen and is illustrated in the following

picture:

LINGO's toolbar "floats." Thus, you can reposition it by dragging it to any part of the screen.

You can also choose to suppress the toolbar by clearing the Toolbar button on the Interface

tab of the LINGO|Options.

Each button on the toolbar corresponds to a menu command. Not all menu commands have a

toolbar button, but, in general, the most frequently used commands have an equivalent

button.

LINGO displays "tool tips" for each button. When you position the mouse over a button, a

short description of what the button does appears in a pop up window and in the status bar at

the bottom of the screen.

Page 12: SOFTHUB SYSTEMS TRAINING MANUAL FOR LINGO 11...tab of the LINGO|Options. Each button on the toolbar corresponds to a menu command. Not all menu commands have a toolbar button, but,

xii | P a g e

2.0 How To Create a LINGO Model An optimization model consists of three parts:

• Objective function – This is single formula that describes exactly what the model should

optimize. A general manufacturing example of an objective function would be to

maximize profit for a given product.

• Variables – These are the quantities that can be changed to produce the optimal value of

the objective function.

• Constraints – These are formulas that define the limits on the values of the variables.

A sample model for production of two sequential products at a paint manufacturing company is

given by:

!Two products are manufactured passing sequentially through three machines.

Time per machines allocated to the two products is limited to 10 hours per day.

The production time and the per unit cost of each products are given in the table.

Minutes per unit

Product Machine1 Machine2 Machine 3 Profit

1 10 6 8 ₦200

2 5 20 15 ₦300

Find the optimal mix for the two products.

MODEL

!Objective function;

MAX = 200 * X + 300 * Y;

! Constraints;

10 * X + 5 * Y <= 600;

6 * X + 20 *Y <= 600;

8 * X + 15 *Y <= 600;

!Hidden Constraints;

Some things must be noted about this model:

• Comments in the model are initiated with an exclamation point (!) and appear in green

text.

• LINGO specified operators and functions appear in blue text.

• All other text is shown in black.

• Each LINGO statement must end in a semi-colon (;).

• Variable names are not case-sensitive and must begin with a letter (A-Z). Other

characters in the variable name may be letters, numbers (0-9), or the underscore character

(_). Variable names can be up to 32 characters in length.

Page 13: SOFTHUB SYSTEMS TRAINING MANUAL FOR LINGO 11...tab of the LINGO|Options. Each button on the toolbar corresponds to a menu command. Not all menu commands have a toolbar button, but,

xiii | P a g e

3.0 Solving a LINGO Model

Once the LINGO model has been entered into the LINGO Model window, the model can be

solved by clicking the Solve button on the toolbar, by selecting LINGO | Solve from the menus,

or by using the ctrl + u keyboard shortcut.

LINGO will notify you of any errors it has encountered. The best way to get information about

these errors is to consult the Error Messages section in the software’s proprietary tutorial. If no errors are found, then the LINGO Solver Status window appears.

This window provides information on the number of nonlinear, integer, and total variables in

the

model; the nonlinear and total number of constraints used in the model; and the number of

nonlinear and total nonzero variable coefficients used. The Solver Status box in this window

details the model classification (LP, QP, ILP, IQP, NLP, etc.), state of the current solution

(local

or global optimum, feasible or infeasible, etc.), the value of the objective function, the

infeasibility of the model (amount constraints are violated by), and the number of iterations

required to solve the model. The Extended Solver Status box details similar information for the

more advanced branch-and-bound, global, and multistart solvers. By closing this window, you can then view the Solution Report window.

Page 14: SOFTHUB SYSTEMS TRAINING MANUAL FOR LINGO 11...tab of the LINGO|Options. Each button on the toolbar corresponds to a menu command. Not all menu commands have a toolbar button, but,

xiv | P a g e

This window shows the values of each variable that will produce the optimal value of

the objective function. The reduced cost for any variable that is included in the optimal solution

is always zero. For variables not included in the optimal solution, the reduced cost shows how

much the value of the objective function would decrease (for a MAX problem) or increase (for

a MIN problem) if one unit of that variable were to be included in the solution. For example, if

the reduced cost of a certain variable was 5, then the optimal value of the MAX problem would

decrease by 5 units if 1 unit of the variable were to be added.

The Slack or Surplus column in the Solution Report shows how tight the constraint is. If

a constraint is completely satisfied as an equality, then slack/surplus is zero. If slack/surplus is

positive, then this tells you how many more units of the variable could be added to the optimal

solution before the constraint becomes an equality. If slack/surplus is negative, then the

constraint has been violated. The Dual Price column describes the amount to which the value of

the objective function would improve if the constraining value is increased by one unit.

Page 15: SOFTHUB SYSTEMS TRAINING MANUAL FOR LINGO 11...tab of the LINGO|Options. Each button on the toolbar corresponds to a menu command. Not all menu commands have a toolbar button, but,

xv | P a g e

4.0 Using Sets in LINGO

What Are Sets?

Sets are simply groups of related objects. A set might be a list of products, trucks, or

employees. Each member in the set may have one or more characteristics associated with it.

We call these characteristics attributes. Attribute values can be known in advance or

unknowns that LINGO solves for. For example, each product in a set of products might have a

price attribute; each truck in a set of trucks might have a hauling capacity attribute; and each

employee in a set of employees might have a salary attribute, as well as a birth date attribute.

LINGO recognizes two kinds of sets: primitive and derived.

A primitive set is a set composed only of objects that can’t be further reduced. A set

composed of eight vendors is a primitive set.

A derived set is defined using one or more other sets. In other words, a derived set derives its

members from other pre-existing sets. It is also possible to build derived sets from other

derived sets.

The Sets Section

Sets are defined in an optional section of a LINGO model called the sets section. Before you

use sets in a LINGO model, you have to define them in the sets section of the model. The sets

section begins with the keyword SETS: (including the colon), and ends with the keyword

ENDSETS. A model may have no sets section, a single sets section, or multiple sets sections.

A sets section may appear anywhere in a model. The only restriction is you must define a set

and its attributes before they are referenced in the model's constraints.

A primitive set could be defined as follows: SETS:

Employees /EMP1..EMP27/:Pay;

ENDSETS

This set is given the setname “Employees” and contains 27 members, identified by EMP1 –

EMP27.

The attributes for each member are called “Pay.”

The derived set is defined similarly, but must also include the parent set list. An example of a derived set could be:

SETS:

Product/X Y/;

Machine/L M/;

Make(Product Machine)/X L, X M,

Y M/;

ENDSETS

Page 16: SOFTHUB SYSTEMS TRAINING MANUAL FOR LINGO 11...tab of the LINGO|Options. Each button on the toolbar corresponds to a menu command. Not all menu commands have a toolbar button, but,

xvi | P a g e

This set declaration defines two primitive sets, Product and Machine, and one derived set called

Make. The Make set is derived from the parent sets Product and Machine. Members are

specified as shown. If all combinations of the parent sets are possible, then no member set need

be defined. An attribute list for the derived set can also be included in the same way as for a

primitive set.

Set Looping Functions

Several set looping functions are also available for use in LINGO. Set looping functions operate

over an entire set and, with the exception of the @FOR function, produce a single result. The

syntax for a set looping function is:

@function( setname [ ( set_index_list)

[ | conditional_qualifier]] : expression_list);

@function corresponds to one of the set looping functions listed below. setname is the name

of the set you want to loop over. The set_index_list is optional and is used to create a list of

indices, which correspond to the parent primitive sets that form the setname set. As LINGO

loops through the members of the setname set, it will set the values of the indices in the

set_index_list to correspond to the current member of the setname set.

The conditional_qualifier is optional and may be used to limit the scope of the set looping

function. When LINGO is looping over each member of the setname set, it evaluates the

conditional_qualifier. If the conditional_qualifier evaluates to true, then @function is

performed for the set member. Otherwise, it is skipped.

The expression_list is a list of expressions to be applied to each member of the setname set.

When using the @FOR function, the expression_list may contain multiple expressions,

separated by semicolons. These expressions will be added as constraints to the model. When

using the remaining three set looping functions (@SUM, @MAX, and @MIN), the

expression_list must contain one expression only. If the set_index_list is omitted, all

attributes referenced in the expression_list must be defined on the setname set.

The available set looping functions are listed below:

@FOR( setname [ ( set_index_list) [ | cond_qualifier]]: exp_list) This generates the expressions contained in exp_list for all members of the setname

set. @FOR is used to generate constraints over all the members of a set, and is one of

the most powerful features of LINGO.

@MAX( setname [ ( set_index_list) [ | cond_qualifier]]: expression) This returns the maximum value of expression taken over the setname set.

@MIN( setname [ ( set_index_list) [ | cond_qualifier]]: expression) This returns the minimum value of expression taken over the setname set.

@PROD( setname [ ( set_index_list) [ | cond_qualifier]]: expression) This returns the product of an expression over the setname set.

@SUM( setname [ ( set_index_list) [ | cond_qualifier]]: expression) This returns the sum of an expression over the setname set.

Page 17: SOFTHUB SYSTEMS TRAINING MANUAL FOR LINGO 11...tab of the LINGO|Options. Each button on the toolbar corresponds to a menu command. Not all menu commands have a toolbar button, but,

xvii | P a g e

Examples of expressions using set looping function are as follows:

• This @FOR statement sets the hauling capacity for all 27 delivery trucks in the Trucks

set to at most 3000 pounds: @FOR(Trucks(T): Capacity(T)<=3000);

• This @SUM statement calculates the total hauling capacity from the individual trucks: TOTAL_HAUL=@SUM(Trucks(J): Capacity(J));

• These @MIN and @MAX statements find the extreme hauling capacity levels from the

individual delivery trucks: MIN_HAUL = @MIN(Trucks(J): Capacity(J));

MAX_HAUL = @MAX(Trucks(J): Capacity(J));

5.0 The LINGO Data Section

A separate section called the DATA section in which values can be defined for different

variables provided by LINGO. Set members can be initialized in this section, attributes of the

sets can be defined, or scalar variable parameters can be assigned values as well. The data

section allows you to isolate data from the rest of your model. This is a useful practice in that it

facilitates model maintenance and scaling of a model’s dimensions.

The data section begins with the keyword DATA: (including the colon) and ends with the

keyword ENDDATA. In the data section, you can have statements to initialize set members

and/or the attributes of the sets you instantiated in a previous sets section. These expressions

have the syntax:

object_list = value_list;

The object_list contains the names of the attributes and/or a set whose members you want to

initialize, optionally separated by commas. There can be no more than one set name in

object_list, while there may be any number of attributes. If there is more than one attribute

name in object_list, then the attributes must be defined on the same set. If there is a set name

in object_list, then all attributes in object_list must be defined on this set.

The value_list contains the values you want to assign to the members of object_list,

optionally separated by commas. As an example, consider the following model:

SETS: SET1 /A, B, C/: X, Y; ENDSETS DATA: X = 1, 2, 3; Y = 4, 5, 6; ENDDATA

We have two attributes, X and Y, defined on the SET1 set. The three values of X are set to 1,

2, and 3, while Y is set to 4, 5, and 6. We could have also used the following compound data

statement to the same end:

SETS: SET1 /A, B, C/: X, Y; ENDSETS DATA: X, Y = 1, 4, 2, 5,

Page 18: SOFTHUB SYSTEMS TRAINING MANUAL FOR LINGO 11...tab of the LINGO|Options. Each button on the toolbar corresponds to a menu command. Not all menu commands have a toolbar button, but,

xviii | P a g e

3, 6; ENDDATA

When LINGO reads a data statement's value list, it assigns the first n values to the first

position of each of the n attributes in the attribute list, the second n values to the second

position of each of the n attributes, and so on. In other words, LINGO is expecting the input

data in column form rather than row form.

As mentioned, we can also initialize the set members in the data section. Modifying our

sample model to use this approach by moving the set members from the sets section to the

data section we get:

SETS: SET1: X, Y; ENDSETS DATA: SET1, X, Y = A 1 4 B 2 5 C 3 6; ENDDATA

This final method is, perhaps, the most sophisticated in that all model data--attribute values

and set members--are isolated within the data section.

When parameters or attributes are defined in the DATA section of a model, a feature called

Whatif

Analysis can be used to examine the effects of varying the value of the parameter or attribute.

For example, if the inflation rate is most likely going to fall between 2% and 6%, the parameter

can be defined as follows in the DATA section:

____________________________________________________________________________ DATA:

INFLATION_RATE = ?;

ENDDATA_________________________________________________________

When LINGO encounters the ? in the DATA section, it will prompt the user to enter a value for

the parameter. The user can then enter values between 2% and 6%, and LINGO will solve the

model using that “what-if” value.

All the elements of an attribute can be initialized to a single value using the DATA section as

well. The following example shows how to assign the value of 20 to all seven members of the

NEEDS attribute and 100 to all seven members of the COST attribute:

____________________________________________________________________________ SETS:

DAYS / MO, TU, WE, TH, FR, SA,

SU/: NEEDS, COST;

ENDSETS

DATA:

NEEDS, COST = 20, 100;

ENDDATA_________________________________________________________

Data values can also be omitted from the DATA section of a LINGO model to indicate that

Page 19: SOFTHUB SYSTEMS TRAINING MANUAL FOR LINGO 11...tab of the LINGO|Options. Each button on the toolbar corresponds to a menu command. Not all menu commands have a toolbar button, but,

xix | P a g e

LINGO is free to determine the values of those attribute itself. The following example shows

that the first two values of the attribute CAPACITY have been initialized to 34, but the last

three variables have not been defined:

____________________________________________________________________________ SETS:

YEARS /1..5/: CAPACITY;

ENDSETS

DATA:

CAPACITY = 34, 34, , , ;

ENDDATA_________________________________________________________

The Init Section

The init section is another optional section offered by LINGO. In the init section, you enter

initialization statements that look much like the data statements found in the data section.

The values you input in the init section are used as starting points by LINGO's solver. Unlike

the variables that are initialized in the data section, the solver is free to alter the values of

variables initialized in the init section.

As an example of how a good starting point may help to reduce the number of iterations and

hence the solution times, consider the init section to the small model below:

______________________________________________________________________

INIT: A = 0; B = 1;

ENDINIT

_____________________________________________________________________________

A <= @LOG10(B);

A + B^3 <=1;

6.0 Variable Types in LINGO

The default assumption for a variable is that it is continuous with a lower bound of 0 and

non-negative. Variable domain functions place additional restrictions on the values that

variables can assume. The functions and their effects are as follows:

@BIN( variable) Restricts variable to being a binary (0/1) integer value.

@BND( lower_bound, variable, upper_bound) Limits variable to being greater-than-or-equal-to lower_bound and less-than-or-equal-to

upper_bound.

@CARD( 'card_set_name', variable|N)

Page 20: SOFTHUB SYSTEMS TRAINING MANUAL FOR LINGO 11...tab of the LINGO|Options. Each button on the toolbar corresponds to a menu command. Not all menu commands have a toolbar button, but,

xx | P a g e

Use @CARD to restrict a a set of variables to have a cardinality of N. See section

Cardinality for more information.

@FREE( variable) Removes the default lower bound of zero on variable, allowing it to take any positive or

negative value.

@GIN( variable)

Restricts variable to integer values (e.g., 0,1,2, ...).

@SEMIC( lower_bound, variable, upper_bound,)

Restricts variable to being either 0 o in the range of [lower_bound, upperbound].

@SOS{1|2|3}( 'sos_set_name', variable)

Use the @SOS1, @SOS2 and @SOS3 functions to set up special ordered sets of

variables.

7.0 LINGO Operators and Functions LINGO provides the mathematical modeler with a number of functions and operators. These

operator and functions are broken down into the following categories:

Standard Operators - Arithmetic, logical, and relational operators such as +, -, =, and <=.

Mathematical - Trigonometric and general mathematical functions.

Financial - Common financial functions used to determine present values.

Probability - Functions used to determine a wide range of probability and statistical answers. Poisson

and Erlang queuing functions are among those provided.

Variable Domain - Functions used to define the range of values (domain) a variable can take on (e.g.,

lower and upper bounds or integer restrictions).

Set Handling - Functions useful for manipulating sets.

Set Looping - Looping functions used to perform an operation over a set (e.g., to compute the sum,

maximum, or minimum of a set of numbers).

Import/Export - Functions used to create links to external data sources.

Page 21: SOFTHUB SYSTEMS TRAINING MANUAL FOR LINGO 11...tab of the LINGO|Options. Each button on the toolbar corresponds to a menu command. Not all menu commands have a toolbar button, but,

xxi | P a g e

Miscellaneous - Miscellaneous functions are listed under this heading.

The arithmetic operators are as follows:

Operator Interpretation

^ Exponentiation

* Multiplication

/ Division

+ Addition

- Subtraction

Priority

Level

Operator(s)

Highest - (negation)

^

* /

Lowest + -

Logical

Operator Return Value

#NOT# TRUE if the operand immediately

to the right is FALSE, else

FALSE.

#EQ# TRUE if both operands are equal,

else FALSE.

#NE# TRUE if both operands are not

Page 22: SOFTHUB SYSTEMS TRAINING MANUAL FOR LINGO 11...tab of the LINGO|Options. Each button on the toolbar corresponds to a menu command. Not all menu commands have a toolbar button, but,

xxii | P a g e

equal, else FALSE.

#GT# TRUE if the left operand is

strictly greater than the right

operand, else FALSE.

#GE# TRUE if the left operand is

greater-than-or-equal-to the right

operand, else FALSE.

#LT# TRUE if the left operand is

strictly less than the right

operand, else FALSE.

#LE# TRUE if the left operand is less-

than-or-equal-to the right

operand, else FALSE.

#AND# TRUE only if both arguments are

TRUE, else FALSE.

#OR# FALSE only if both its arguments

are FALSE, else TRUE.

Priority

Level Operator(s)

Highest #NOT#

#EQ# #NE# #GT# #GE# #LT# #LE#

Lowest #AND# #OR#

Relational

Operator Interpretation

= The expression to the left must

equal the one on the right.

<= The expression to the left must be

less-than-or-equal-to the expression

on the right.

Page 23: SOFTHUB SYSTEMS TRAINING MANUAL FOR LINGO 11...tab of the LINGO|Options. Each button on the toolbar corresponds to a menu command. Not all menu commands have a toolbar button, but,

xxiii | P a g e

>= The expression to the left must be

greater-than-or-equal-to the

expression on the right.

The following list contains a selection of mathematical functions that can be used in LINGO:

• @ABS(X) – returns the absolute value of X

• @SIGN(X) – returns -1 if X is negative and +1 if X is positive

• @EXP(X) –Returns e (2.718281...) raised to the power X.

• @LOG(X) – calculates the natural log of X

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

@SINH( X) _Returns the hyperbolic sine of X, where X is an angle in radians.

@SMAX( X1, X2,..., XN) Returns the maximum value of X1, X2, ..., and XN.

@SMIN( X1, X2,..., XN) Returns the minimum value of X1, X2, ..., and XN.

@SQR( X) Returns the value of X squared.

@SQRT( X) Returns the square root of X.

8.0 SOLVING LINEAR PROGRAMMING, INTEGER PROGRAMMING, BINARY

INTEGER PROGRAMMING PROBLEMS USING LINGO

BINARY INTEGER PROGRAMMING

! Maximize Z=9x1+5x2+6x3+4x4 subject to the constraints 6x1+3 x2+5 x3+2x4≤10, x3+ x4≤1,

-x1+ x3 ≤ 0,- x2+ x4≤0 where xi ≤ 1 for 1 ≤ i ≤ 4 and xi ≥ 0.

MODEL

MAX = 9 * X1 + 5 * X2 + 6 * X3 + 4 * X4;

6 * X1 + 3 * X2 + 5 * X3 + 2 * X4 <= 10;

X3 + X4 <= 1;

-1 * X1 + X3 <=0;

-1 * X2 + X4 <=0;

@BND(0,X1,1);

@BND(0,X2,1);

@BND(0,X3,1);

@BND(0,X4,1);

Page 24: SOFTHUB SYSTEMS TRAINING MANUAL FOR LINGO 11...tab of the LINGO|Options. Each button on the toolbar corresponds to a menu command. Not all menu commands have a toolbar button, but,

xxiv | P a g e

After entering the model above the output L0 is given as

We choose variable x1 as the first encountered non binary value and we branch into two sub-

division as x1 = 0 and x1 = 1. Then we repeat the above iteration for each of the branches while

remembering to add the new conditions. For x1 = 0 we have branch L1 with model MAX = 9 * X1 + 5 * X2 + 6 * X3 + 4 * X4;

6 * X1 + 3 * X2 + 5 * X3 + 2 * X4 <= 10;

X3 + X4 <= 1;

-1 * X1 + X3 <=0;

-1 * X2 + X4 <=0;

X1=0 ;

@BND(0,X1,1);

@BND(0,X2,1);

@BND(0,X3,1);

@BND(0,X4,1);

The output for L1 is

Page 25: SOFTHUB SYSTEMS TRAINING MANUAL FOR LINGO 11...tab of the LINGO|Options. Each button on the toolbar corresponds to a menu command. Not all menu commands have a toolbar button, but,

xxv | P a g e

Branch L1 is fathomed* so we move to branch L2.

For x1 = 1 we have branch L2 with model MAX = 9 * X1 + 5 * X2 + 6 * X3 + 4 * X4;

6 * X1 + 3 * X2 + 5 * X3 + 2 * X4 <= 10;

X3 + X4 <= 1;

-1 * X1 + X3 <=0;

-1 * X2 + X4 <=0;

X1=1 ;

@BND(0,X1,1);

@BND(0,X2,1);

@BND(0,X3,1);

@BND(0,X4,1);

The output for L2 is

*Rule of Fathoming A subproblem or subdivision is fathomed if 1. The relaxation of the subproblem has an optimal solution with z < z∗ where z∗ is the current best

solution; 2. The relaxation of the subproblem has no feasible solution; 3. The relaxation of the subproblem has an optimal solution that has all integer values (or all binary if it is an BIP).

Page 26: SOFTHUB SYSTEMS TRAINING MANUAL FOR LINGO 11...tab of the LINGO|Options. Each button on the toolbar corresponds to a menu command. Not all menu commands have a toolbar button, but,

xxvi | P a g e

Next we choose variable x2 with the bounds x2 ≤ 0 and x2 ≥ 1. Then we repeat the above

iteration for each sub-problem until all is fathomed. The summary of all the iterations is given

below :

L0

X1 = 0.8333

X2 =1

X3 =0

X4 =1

Z = 16.5

X1 = 0 X1 = 1

L1

X1 = 0

X2 = 1

X3 = 0

X4 = 1

Z = 9 *fathomed

L2

X1 = 1

X2 = 0.8

X3 = 0

X4 = 0.8

Z = 16.2

Page 27: SOFTHUB SYSTEMS TRAINING MANUAL FOR LINGO 11...tab of the LINGO|Options. Each button on the toolbar corresponds to a menu command. Not all menu commands have a toolbar button, but,

xxvii | P a g e

X2 = 0 X2 = 1

X3 = 0 X3 = 1

L5

X1 = 1

X2 = 0

X3 =0

X4 = 0

Z = 9

*fathomed

L2

X1 = 1

X2 = 0.8

X3 = 0

X4 = 0.8

Z = 16.2

L3

X1 = 1

X2 = 0

X3 = 0.8

X4 = 0

Z = 13.8

L4

X1 = 1

X2 = 1

X3 = 0

X4 = 0.5

Z = 16

L7

X1 = 1

X2 = 1

X3 =0.2

X4 = 0

Z = 15.2

L8

No feasible

Solution

*fathomed

L6

No feasible

Solution

*fathomed

L9

X1 = 1

X2 = 1

X3 =0

X4 = 0 Z = 14

Final Answer

L10

No feasible

Solution

*fathomed

X3 = 0 X3 = 1

X4 = 0 X4 = 1

Page 28: SOFTHUB SYSTEMS TRAINING MANUAL FOR LINGO 11...tab of the LINGO|Options. Each button on the toolbar corresponds to a menu command. Not all menu commands have a toolbar button, but,

xxviii | P a g e

LINGO Programming Examples

1) Computing Sort Order

This simple model sorts cities according to their distance from the equator.

MODEL: ! Compute sort order; SETS: CITY/ LONDON, PARIS, NYC, LA, MOSCOW, TOKYO/: LAT, ! Its latitude; RANK; ! Its rank in distance from equator; ENDSETS DATA: LAT = 51.3 48.5 40.4 34.0 55.5 35.4; ENDDATA ! This is an N squared, rather than N log( N) sort; ! Count number of cities of greater distance + 1; @FOR( CITY( I): RANK( I) = @SUM( CITY( J)| LAT( J) #LT# LAT( I) #OR# ( LAT( J) #EQ# LAT( I) #AND# J #LT# I): 1) + 1 ); END

2) Probability Calculator

The @PROD function is used to find the product of an expression across members of a

set. As an example, consider the model:

MODEL: SETS: COMPONENTS: P; ENDSETS DATA: P = .95 .99 .98; ENDDATA P_FAIL = 1 - @PROD( COMPONENTS( I): P( I)); END

Here we have a system of three components arranged in a series. The probability that each

component functions successfully (.95, .99, and .98) is loaded into attribute P in the model’s

data section. We then compute the probability that the entire system will fail, P_FAIL, by

taking the product of the component probabilities and subtracting it from 1:

P_FAIL = 1 - @PROD( COMPONENTS( I): P( I));

As an aside, an interesting feature to note about this model is that we never initialized the

COMPONENTS set. When LINGO sees that an attribute of an undefined primitive set being

initialized to n values in a data section, it automatically initializes the parent primitive set to

contain the members: 1, 2, …, n. So, in this example, LINGO automatically assigned the

member 1, 2 and 3 to the COMPONENTS set.

Page 29: SOFTHUB SYSTEMS TRAINING MANUAL FOR LINGO 11...tab of the LINGO|Options. Each button on the toolbar corresponds to a menu command. Not all menu commands have a toolbar button, but,

xxix | P a g e

BIBLIOGRAPHY AND FURTHER READING

Black, F., and M. Scholes. (1973). "The Pricing of Options and Corporate Liabilities.",

Journal of Political Economy, vol. 81, pp. 637-654.

Bradley, S.P., A.C. Hax, and T.L. Magnanti, Applied Mathematical Programming. Reading,

MA : Addison-Wesley Publishing Company, Inc., 1977.

Cochran, W.G., Sampling Techniques. 2nd ed. New York, NY : Wiley, 1963.

Conway, R.W., W.L. Maxwell, and L.W. Miller, Theory of Scheduling. Reading, MA

: Addison-Wesley Publishing Company, Inc.,1967.

Cox, John C. and Mark Rubinstein, Options Markets, Englewood Cliffs, NJ: Prentice-Hall,

Inc., 1985.

Dantzig, G.B., Linear Programming and Extensions., Princeton, N.J. : Princeton University

Press, 1963.

Eppen, G.D., F.J. Gould, and Schmidt, C.P., Quantitative Concepts for Management:

Decision Making Without Algorithms, 3rd ed. Englewood Cliffs, N.J. : Prentice-Hall, Inc.,

1989.

Gass, S., Decision Making, Models & Algorithms. New York: Wiley-Interscience, 1985.

Geoffrion, A., The Theory of Structured Modeling, Western Management Science Institute,

UCLA, 1987.

Hadley, G., and T.M. Whitin, Analysis of Inventory Systems. Englewood Cliffs, N.J.

: Prentice-Hall, Inc., 1963.

Hillier, F., and G.J. Lieberman, Introduction to Operations Research, 6th ed. New York :

McGraw-Hill, Inc., 1995.

Johnson, L., and D.C. Montgomery, Operations Research in Production Planning,

Scheduling, and Inventory Control. New York: John Wiley & Sons, Inc., 1974.

Knowles, T., Management Science. Homewood, IL: Irwin Publishing, 1989.

Kris Thornburg and Anne Hummel, Lingo 8.0 Tutorial

Lin, S., and B. Kernighan. (1973). "An effective Heuristic Algorithm for the Traveling

Salesman Problem.", Operations Research, vol. 10, pp. 463-471.

Markowitz, H. M., Portfolio Selection, Efficient Diversification of Investments, John Wiley

& Sons, 1959.

Nemhauser, G., and L. Wolsey, Integer and Combinatorial Optimization, New York : John

Wiley & Sons, 1988.

Moder, Joseph J., and Salah E. Elmaghraby (editors), Handbook of Operations Research,

New York: Van Nostrand Reinhold Company, 1978.

Schrage, L., Optimization Modeling with LINDO, 5th. ed. Belmont, CA: Duxbury Press,

1997.

Page 30: SOFTHUB SYSTEMS TRAINING MANUAL FOR LINGO 11...tab of the LINGO|Options. Each button on the toolbar corresponds to a menu command. Not all menu commands have a toolbar button, but,

xxx | P a g e

Wagner, H.M., Principles of Management Science with Applications to Executive Decisions,

2nd ed. Englewood Cliffs, N.J. : Prentice-Hall, Inc., 1975.

Winston, Wayne L., Introduction to Mathematical Programming: Applications and

Algorithms, 3rd ed.,. Belmont, CA: Duxbury Press, 1995.


Recommended