COPYRIGHT
The LINGO software and its related documentation are copyrighted. You may not copy the LINGO
software or related documentation except in the manner authorized in the related documentation or
with the written permission of LINDO Systems Inc.
TRADEMARKS
LINGO is a trademark, and LINDO is a registered trademark, of LINDO Systems Inc. Other product
and company names mentioned herein are the property of their respective owners.
DISCLAIMER
LINDO Systems, Inc. warrants that on the date of receipt of your payment, the disk enclosed in the
disk envelope contains an accurate reproduction of the LINGO software and that the copy of the
related documentation is accurately reproduced. Due to the inherent complexity of computer programs
and computer models, the LINGO software may not be completely free of errors. You are advised to
verify your answers before basing decisions on them. NEITHER LINDO SYSTEMS, INC. NOR
ANYONE ELSE ASSOCIATED IN THE CREATION, PRODUCTION, OR DISTRIBUTION OF
THE LINGO SOFTWARE MAKES ANY OTHER EXPRESSED WARRANTIES REGARDING
THE DISKS OR DOCUMENTATION AND MAKES NO WARRANTIES AT ALL, EITHER
EXPRESSED OR IMPLIED, REGARDING THE LINGO SOFTWARE, INCLUDING THE
IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE,
OR OTHERWISE. Further, LINDO Systems, Inc. reserves the right to revise this software and related
documentation and make changes to the content hereof without obligation to notify any person of such
revisions or changes.
Copyright © 2010 by LINDO Systems Inc. All rights reserved.
Published by
1415 North Dayton Street
Chicago, Illinois 60642
Technical Support: (312) 988-9421
E-mail: tech@lindo.com
WWW: http://www.lindo.com
iii
Contents
Contents................................................................................................................................................ iii
Preface ................................................................................................................................................. vii
New Features........................................................................................................................................ xi
1 Getting Started with LINGO............................................................................................................ 1
What is LINGO? ............................................................................................................................... 1
Installing LINGO............................................................................................................................... 1
Modeling from the Command-Line..................................................................................................21
Examining the Solution....................................................................................................................24
Using the Modeling Language.........................................................................................................25
Additional Modeling Language Features.........................................................................................35
Maximum Problem Dimensions.......................................................................................................38
How to Contact LINDO Systems.....................................................................................................39
2 Using Sets.......................................................................................................................................41
Why Use Sets?................................................................................................................................41
What Are Sets?...............................................................................................................................41
The Sets Section of a Model ...........................................................................................................42
The DATA Section...........................................................................................................................48
Set Looping Functions.....................................................................................................................49
Set Based Modeling Examples .......................................................................................................55
Summary.........................................................................................................................................73
3 Using Variable Domain Functions ................................................................................................75
Integer Variables.............................................................................................................................75
Free Variables.................................................................................................................................94
Bounded Variables..........................................................................................................................99
SOS Variables...............................................................................................................................100
Cardinality .....................................................................................................................................103
Semicontinuous Variables.............................................................................................................104
4 Data, Init and Calc Sections ........................................................................................................107
The DATA Section of a Model.......................................................................................................107
The INIT Section of a Model..........................................................................................................111
The CALC Section of a Model.......................................................................................................112
Summary.......................................................................................................................................115
5 Windows Commands ...................................................................................................................117
Accessing Windows Commands...................................................................................................117
Windows Commands In Brief........................................................................................................118
Windows Commands In Depth......................................................................................................121
iv CONTENTS
1. File Menu...................................................................................................................................121
2. Edit Menu..................................................................................................................................139
3. LINGO Menu.............................................................................................................................152
4. Window Menu............................................................................................................................240
5. Help Menu.................................................................................................................................244
6 Command-Line Commands.........................................................................................................251
The Commands In Brief ................................................................................................................251
The Commands In Depth ..............................................................................................................253
7 LINGO’s Operators and Functions..............................................................................................337
Standard Operators.......................................................................................................................337
Mathematical Functions ................................................................................................................341
Financial Functions .......................................................................................................................343
Probability Functions.....................................................................................................................343
Variable Domain Functions ...........................................................................................................346
Set Handling Functions .................................................................................................................346
Set Looping Functions...................................................................................................................349
Interface Functions........................................................................................................................350
Report Functions...........................................................................................................................351
Miscellaneous Functions...............................................................................................................362
8 Interfacing with External Files.....................................................................................................365
Cut and Paste Transfers ...............................................................................................................365
Text File Interface Functions.........................................................................................................367
LINGO Command Scripts..............................................................................................................375
Specifying Files in the Command-line...........................................................................................378
Redirecting Input and Output ........................................................................................................380
Managing LINGO Files..................................................................................................................380
9 Interfacing With Spreadsheets....................................................................................................383
Importing Data from Spreadsheets................................................................................................383
Exporting Solutions to Spreadsheets ............................................................................................388
OLE Automation Links from Excel.................................................................................................396
Embedding LINGO Models in Excel..............................................................................................400
Embedding Excel Sheets in LINGO ..............................................................................................406
Summary.......................................................................................................................................410
10 Interfacing with Databases..........................................................................................................411
ODBC Data Sources .....................................................................................................................412
Importing Data from Databases with @ODBC ..............................................................................419
Importing Data with ODBC in a PERT Model................................................................................421
Exporting Data with @ODBC ........................................................................................................423
Exporting Data with ODBC in a PERT Model................................................................................426
11 Interfacing with Other Applications............................................................................................431
The LINGO Dynamic Link Library..................................................................................................431
CONTENTS v
User Defined Functions.................................................................................................................473
12 Developing More Advanced Models...........................................................................................479
Production Management Models...................................................................................................480
Logistics Models............................................................................................................................494
Financial Models ...........................................................................................................................501
Queuing Models............................................................................................................................516
Marketing Models..........................................................................................................................523
13 Programming LINGO....................................................................................................................531
Programming Features..................................................................................................................531
Programming Example: Binary Search .........................................................................................549
Programming Example: Markowitz Efficient Frontier.....................................................................552
Programming Example: Cutting Stock...........................................................................................559
Programming Example: Accessing Excel......................................................................................565
Summary.......................................................................................................................................571
14 Stochastic Programming.............................................................................................................573
Multistage Decision Making Under Uncertainty.............................................................................573
Recourse Models ..........................................................................................................................575
Scenario Tree................................................................................................................................577
Monte Carlo Sampling...................................................................................................................579
Setting up SP Models....................................................................................................................580
Language Features for SP Models................................................................................................581
Declaring Distributions ..................................................................................................................583
Gas Buying Example.....................................................................................................................590
Stock Option Example...................................................................................................................600
Investing Under Uncertainty Example...........................................................................................608
15 On Mathematical Modeling..........................................................................................................617
Solvers Used Internally by LINGO.................................................................................................617
Type of Constraints .......................................................................................................................618
Local Optima vs. Global Optima....................................................................................................620
Smooth vs. Nonsmooth Functions ................................................................................................625
Guidelines for Nonlinear Modeling ................................................................................................626
Appendix A: Additional Examples of LINGO Modeling................................................................629
Appendix B: Error Messages .........................................................................................................717
Appendix C: Bibliography and Suggested Reading.....................................................................761
Index....................................................................................................................................................763