Manual
Manual
Tony Hürlimann
Version 6.93
Copyright © 2022
MatMod GmbH
Email: [email protected]
WWW: https://matmod.ch
i
Para mi amada mujer Lilí
y mis niñas adoradas Malika y Selma
ii
Acknowledgements
I wish to thank the following institutions for their nancial support and the
iii
Availability of the LPL-Modelling-System
The mathematical modeling and all case studies in this book are based on
1
the software LPL . It is my own contribution to the eld of computer-based
mathematical modeling.
You do not need to install any software to run most of the examples in this
manual all you need is an electronic version of this manual, Internet con-
MatMod Homepage
1 The secret meaning of LPL is L'art Pour L'art because modeling should
be considered as a science but also as an art. Initially, it was an abbreviation
of Linear Programming Language, since it was designed exclusively for mathemat-
ical Linear Programs. During the intervening years, LPL's capability in logical
modeling has become so important that one could also call it Logical Programming
Language. My intention, however, is to oer a tool for full model documentation
too. Therefore, in the future it might also be called Literate Programming Language
(see [1]).
iv
Contents
Acknowledgements . . . . . . . . . . . . . . . . . . . . . . . . . . . iii
1 Introduction 1
1.1 What is LPL? . . . . . . . . . . . . . . . . . . . . . . . . . . . 2
2.2 Programs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9
2.2.1 lplc.exe . . . . . . . . . . . . . . . . . . . . . . . . . . 10
2.2.2 lpls.exe . . . . . . . . . . . . . . . . . . . . . . . . . . 10
2.2.3 lplw.exe . . . . . . . . . . . . . . . . . . . . . . . . . . 11
v
3.2 LPL Tokens . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14
3.4 Identiers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15
3.5 Numbers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15
3.6 Dates . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16
3.7 Strings . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16
3.8 Delimiters . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17
3.9 Comments . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18
3.10 Elements . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18
3.13 Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23
vi
4.1.6 The subject_to Attribute . . . . . . . . . . . . . . . . 110
5 Index-Sets 121
5.1 Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . 121
vii
5.3 Relations (Compound Sets) . . . . . . . . . . . . . . . . . . . 124
viii
9 Miscellaneous 159
9.1 File Inclusion . . . . . . . . . . . . . . . . . . . . . . . . . . . 159
ix
11 Appendix A: LPL Syntax 201
x
Chapter 1
Introduction
importante.
A. de Saint-Exupéry
Et moi, ..., si j'avais su comment en revenir, je n'y serais point
allé.
Jules Verne
Wenn Gedanken die Sprache korrumpieren, dann kann die Sprache
George Orwell
This document is the Reference Manual for the mathematical modeling lan-
free version of LPL and various shorter papers as well as many modeling
1
2 CHAPTER 1. INTRODUCTION
language which allows one to build, maintain, modify and document large
communicates with
Large optimization problems encoded as models in the LPL language are
solver packages
interpreted by the LPL executable. This Program
and non-linear problems. Among the supported solvers are Gurobi, Cplex,
Xpress, MOPS, GLPK, lp_solve, XA, Mosek, Conopt, Knitro and Loqo. In
addition to those LPL comes with its own LP-solver that is suitable for small
declarative
as such perfectly suitable to express the problems encountered in practice
algorithmic
similar to the mathematical models on paper. However, LPL also oers the
trol ow. This is often useful for pre- and post-processing data but also to
language. The language further permits to break down a complex model into
municate their results. None the less, LPL is clearly focused on the model
of LPL.
Solver(s)
LPL
LPL Interpreter
SVG
Text Files, Tables
Visulaizations
Tables, Excel
Data Bases Sheets & PDF
Reports
Writing to
Databases
LPL has strong support for large multidimensional arrays. Those are
where we normally work with graphs and networks that are large and
Fast production of MPSX standard les and other output les is a key
environments.
setting.
LPL can easily read and write from and to a variety of sources. Text
les, tables (such as the Excel format), can be read and written to.
The software comes also with a Draw library with which solutions can
Not only is it easy to read from databases, LPL can also create
The report generator that can read/write complete tables form and
LPL also comes as dynamic link libraries that can be integrated into
other applications. Examples for Java, C++, Pascal and Visual Basic
are fond in chapter 10. The diagram 1.2 shows how LPL is used in
this scenario.
LPL is split into a client and server, that can be deployed separately.
This allows setting up a dedicated server for the solver, with which
comes with LPL. Tools for debugging and viewing the model such as
Chapter 4 contains all the information about the structure and overall
Chapter 6: internal data and table formats of data in a model are ex-
plained.
explained.
Chapter 10 explains the use of the dynamic link library, normal and Java-
If you are a new LPL user, read the Tutor Paper tutor.pdf and run
basic syntax. Here, one also can nd the references of all functions.
If you are not familiar with the very basics of mathematical indexed
Java, or another language using the LPL capabilities and its powerful
contains some limitations. All les at the site are stored as a compressed
le install-lpl.exe. Go to the install guide at: install.pdf witch gives more
LPL-le
LPL-compiler rst parses the LPL code and (optionally) runs it. The source
interface, the solver writes the results into les or passes the data directly
NOM-le
back to LPL in memory. Finally, LPL writes all output specied by the
an error pointer is placed at the position where the error occurred together
with an error message read from the le lplmsg.txt (where all compiling and
running error messages are listed). At the beginning of the parsing, the le
lplcfg.lpl if present and found is read and parsed also. If this le is in
7
8 CHAPTER 2. INSTALL AND RUN LPL
the same directory as the launched compiler it will be found. This le must
be in LPL syntax and contains general options such as solver interface pa-
rameters, directory paths, and others. The LPL compiler can generate other
information (besides the NOM-le) about the model as les, called the ???-
les (where ??? are three letters). These le names can be derived from the
extension of the le name: For example, if mymodel.lpl is the LPL-le then
MPS-le : a MPSX le for linear and quadratic models. The MPS-
of the MPS le may be found in the literature. One should note
that LPL does not generate a RANGE section. BOUNDS are limited
to FX, UP, and LO. The COLUMN section may, however, contain
a complete and explicit constraint listing of the model with all indexes
link to some solvers. It represents the model with all indices expanded
much like a full equation listing. The LPO-le is just a convenient way
to store the fully instantiated model, like the standard MPS-le. But
contrary to the MPS-le it takes less space on disk and is not limited
evaluate the constraints and the derivatives which are mandatory for
the INT-le).
9
ated.
le.
These les are generated using dierent compiler switches (see 9.7). The
LPL-le itself is not generated, it is the source code written in LPL syntax
of the model. The lename extension of this le must be '.lpl'. Several
les (EQU, BUG, MPS, INT-le) are generated multiple times after each
2.2. Programs
LPL consists of ve executables of the compiler: two console versions (lplc.exe,
lpls.exe), a wysiwyg version (lplw.exe), and two dynamic link libraries (lpl.dll,
lplj.dll). All executables and the libraries are based on the same code.
10 CHAPTER 2. INSTALL AND RUN LPL
2.2.1 lplc.exe
The executable lplc.exe is the console LPL compiler. It parses and runs the
solver, writes the NOM-le and exits. This execution path, however, can
be modied using the compiler switches (see 9.7). Note that lplc.exe can be
is called as follows:
<modelle> is the LPL-le. The LPL-le must have a lename extension lpl.
CompilerSwitches can be empty. The APL parameter species the assigned
2.2.2 lpls.exe
The executable <it lpls.exe is another console LPL compiler/solver. It sup-
poses that an LPO-le has already been generated by a LPL compiler and
reads it. Then it calls a solver, which solves the model, nally an LPX-le
<modelle> is the LPO-le. The LPO-le must have a le extension lpo.
This program is used as an LPL-server for the LPL Internet Service. The
Service can be used automatically by any LPL client just by conguring the
in the Internet compiles the model with LPL and writes an LPO-le that is
transferred to the LPL server through the Internet. The generated LPX-le
at the LPL Server then is retransferred to the client. The executable lpls.exe
is typically installed in a Tomcat environment, where it can be called as a
process.
11
2.2.3 lplw.exe
The executable lplw.exe is more than just an LPL-compiler and interpreter.
It contains an entire model environment to browse and edit the model. The
The User manual at user.pdf explains the modeling user interface in more
details.
tegrates the complete LPL functionality and can be called and used from
any other applications. This library and its use is explained in details in
Chapter 10.
12 CHAPTER 2. INSTALL AND RUN LPL
Chapter 3
Since all these characters are printable, an LPL code can be edited and ma-
and other elements (the words or tokens of the language) are formed us-
ing one or more of these characters. These words are written in sequences
Between the words, any number of spaces (blanks), tabs or linefeed charac-
ters or other control character can be placed to separate the words. A good
13
14 CHAPTER 3. BASIC LPL LANGUAGE ELEMENTS
on a new line, and emphasize the structure of the model using indentation.
distribute it into several les helps also to make the model readable and
maintainable.
An LPL model consists of dierent basic elements: the tokens (or the words
1. Reserved Words, words that have certain xed meaning, they form an
user.
or run a code.
All these elements are called tokens (words) and are the basic building
block for the language. The dierent kinds of tokens are explained in the
subsequent sections.
Reserved words (also keywords) are an integral part of the language LPL.
They cannot be used as user-dened identiers and they have a xed mean-
letters, digits or underscores. Identiers are case-sensitive, that is, LPL dis-
tinguishes lower and upper case letters. Hence, AllProducts and ALLPRODUCTS
are two dierent identiers. Examples are:
Var_1
TEXT
_None
ImportedProducts
This_is_A_long_Identifier
3xY (not correct, starts with a digit)
Two words (not correct, cannot contain spaces)
LPL can handle qualied identiers. These are identiers containing one or
3.5. Numbers
Numbers are constants of real type. They constitute the numerical data of
the model. They may also be used to denote elements of a set. If nothing
as TRUE. Examples:
16 CHAPTER 3. BASIC LPL LANGUAGE ELEMENTS
123
+234.980
-87467632.098
- 56
3.6E-3 (or 3.6e-3) (same as: 0.0036)
0.5
.5 (a number can begin with a dot)
5. (a number can end with a dot)
In data tables within an LPL model, a dot (.) may be used to replace a
3.6. Dates
Dates are values to dene a time point. Internally they are stored and
handled as numbers, so LPL does not make any dierence between dates
and numbers (except in output and input). One can calculate with them
in the same way as numbers, although not many operators make sense for
them. In the LPL code, however, they have a specic syntax. They always
begin with a character '@' followed by four digits for the year. Optional
then it follows a dash and two digits for the month, another dash and two
digits for the day, followed by an optional time, initiated by a 'T' and two
digits for the hour, a colon and two digits for the minutes, another colon
1
For a small model example see learn07 .
3.7. Strings
Strings are sequences of arbitrary Unicode characters. They can be used in
expressions. They must be written within single quotes. Strings can also be
1 https://lpl.matmod.ch/lpl/Solver.jsp?name=/learn07
17
'MyString'
'another string'
'45\'==? and character in string'
\a bell
\b backspace
\f form feed
\n new line
\r carriage return
\t tab
\\ \ (backslash char)
\' ' (single quote)
\" " (double quote)
follows:
'ABC\tDEF\tGHI\n'
To break a string over several lines, a backslash must be added to the end
of a line. This removes the end-of-line and all blanks at the beginning of the
following line:
used in the context of le names. The non-printable characters above can
3.8. Delimiters
A blank (the space), all character with Unicode number lower then 32 (such
as new-line or tab), all characters with Unicode number greater than 127 are
2 https://lpl.matmod.ch/lpl/Solver.jsp?name=/learn26
18 CHAPTER 3. BASIC LPL LANGUAGE ELEMENTS
3.9. Comments
Three kinds of comments are dened in LPL. The rst two kinds are skipped
/* This is a comment */
/* comment /* nested comment */ ends first comment */
that these comments can span over several lines. Like strings, they can
3.10. Elements
Elements of a set can be identiers, strings or numbers. Examples:
Note also that the element syntax is case-sensitive. Hence, 'June' and 'JUNE'
are considered dierent elements.
19
( ) expression nesting
/ * division, multiplication
:= assignment operator
3
These operators form expressions such as (see learn01 :
The operators have the following meaning (where x and y are arbitrary ex-
pressions):
( x ) return x , (nesting x)
3 https://lpl.matmod.ch/lpl/Solver.jsp?name=/learn01
20 CHAPTER 3. BASIC LPL LANGUAGE ELEMENTS
x % y return x modulo y
x || y return x bitwise or y
x * y return multiplication
x - y return subtraction
x + y return addition
Examples:
C
Note, there is no explicit true or false Boolean value. Like in the language
, the numerical values 1 (or any value dierent from zero) means true
and 0 means false. This means that an expression such as 'a<>0' can be
21
written just as 'a'. Since the value of 'a' can be a real, this rises a problem of
precision and must be used with care. Note also that numerical and Boolean
set. The rst argument must be a local index or a bounded index (see
Chapter 5), the second argument must be an unbounded set name. See
4 5 6
model learn03 , learn05 , or learn15 .
The relational operators = <> <= >= < > compare numerical or alphanumer-
ical values.
2 <= 3 result is 1
'abc' = 'bcd' result is 0
where x is a variable and the {k}(a,b) are the k piece-wise parts. An example
7
is given in model Bill227 .
The assign -operator =: need an identier on the left-hand side and an ex-
as a shortcut for
1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 10
4 https://lpl.matmod.ch/lpl/Solver.jsp?name=/learn03
5 https://lpl.matmod.ch/lpl/Solver.jsp?name=/learn05
6 https://lpl.matmod.ch/lpl/Solver.jsp?name=/learn15
7 https://lpl.matmod.ch/lpl/Solver.jsp?name=/Bill227
22 CHAPTER 3. BASIC LPL LANGUAGE ELEMENTS
P
The symbol is an indexed operator for the summation. There are other
indexed operators, such as Π, for multiplication, max and min for the max-
V
imum or minimum, or even Boolean indexed operator, such as for the
8
indexed and, and others .
In LPL, The indexed operators are keywords. The following words are de-
ned:
P
sum{i} a[i] return the sum of a over index i (
i ai )
count{i} a[i] return the count of a over index i ( counti ai )
prod{i} a[i] return the product of a over index i (Πi ai )
The operator for is the loop operator in LPL. A shortcut for the loop is the
missing indexed operator: just write '{i}A' to run the expression 'A' as many
times as 'i' has elements (cardinality of 'i'). The indexed operators are
Examples:
8 If
the reader is unfamiliar with these operations, there is a paper that explains
the details of the notation and mechanism of these operators: See Indexing Paper
[2]
23
3.13. Functions
LPL denes a certain number of functions that can be includes into expres-
specic libraries.
Alldi(c)
Add an element e to set s
Arctan(x)
Dene Alldi constraint c
Ceil(x)
Return Arctan of x
ClearData(c,...)
Return the smallest integer greater than x
Complements(s)
Clear the data tables c,...
Contains(x,i)
Constraint: complements
Cos(x)
Alldi function only
DateToStr(d)
Return the Cosinus of x
El(r,s)
Return date d as string
En(r,x)
Return element position in r of name s
Exp(x)
Return element name in r at position x
Find(x,i)
Return ex
Floor(x)
Alldi function only
Format(s,e,...)
Return the greatest integer smaller than x
Freeze(c,...)
Return a formatted string s, lled with e,...
GetAttr([r,] a)
Inactivate constraints or x variables c,...
GetName([r,] a)
Return attribute a of ref entity r as string
GetParam(a)
Return the name of reference r as string
GetParamS(a)
Return a global parameter value as double
GetProblemType()
GetSolverStatus()
Return problem type
GetValue([r,] a)
Return the solver status
GetValueS([r,] a)
Return a numerical value of reference r
Index(x,i)
Return a string value of reference r
Log(x)
Alldi function only
Max(x,...)
Return the e log of x
Min(x,...)
Return the largest in the list
NextFocus(a)
Return the smallest in the list
NextPosition[(i)]
Sets the focus the the next entity of genus a
Now()
Jumps to the next data entry
OSCall(s)
Return actual date and time
Ord(c)
Call an OS program s
Read(s,e,...,[E])
Return Unicode code of a char c
Rgb(r,g,b)
Read data from le
Rnd(x,y)
Returns a Rgb color code
Rnde(m)
Returns an uniform random number in range [x...y]
Rndn(m,s)
Returns an exponentially distributed random number
Round(x[,y])
Returns an normally distributed random number
SetFocus[(r)]
Returns a rounded integer of x
SetPaths(c)
sets the focus to reference r
SetRandomSeed(x)
Add a le paths to the directory list
SetServer(s)
Sets the random seed to x
SetSolver(s[,t])
Sets the Internet address of the LPL server
SetSolverList(s)
Sets the solver and its parameters
SetWorkingDir(s)
Sets a list of solvers to s
Sin(x)
Sets the working directory to s
Sl(a[,b][,c])
Return the Sinus of x
Sort(a,b[,n])
add a slack variable
Sos1(c)
Sort data
Sos2(c)
Denes SOS1 constraint c
Split(s,c,t,...)
Denes SOS2 constraint c
Sqrt(x)
Split a string s into parts separated by a char c
Strbin(s
Return the square root of x
Strbin0(n)
Return a integer from a binary string
Strdate(s[,c,n])
Return a binary string from a integer
Stroat(s[,c,n])
Return and convert string s to a date
StringToSet(s,p)
Return and convert string s to oat
Strlen(s)
Links a set s to a (string) parameter p
Strpos(s1,s)
Return the length of a string s
Strreplace(s,s1,s2)
Return the position of a substring s1 within a string s
Strreverse(s
Strsub(s,b,l)
Returns the reverse string of s
Trunc(x)
Returns a substring of s of length l beginning at b
Unfreeze(c,...)
Return the truncated integer of x
Write(s,...)
Activate constraints or unx variables c,...
Writep(r,...)
Write data to le
Draw.Animate([id,t,id1,]dur,beg,fr,to[,fr1,to1,fr1,to1])
Draw.Arc([id,t,]x,y,r,a1,a2[,c2,w,o2,a])
Animate a Draw
Draw.DefFill(id,c1,c2,w,o1,o2)
Draw a circle
Draw.DefFilter(id,f[,in1,re,x ])
Dene the ll properties
Draw.DefFont([id,] t,h,c1,c2,fw,fs,fv)
i Dene a lter
Draw.DefGrad(id,sm,x,y,x1,y1,fy,o ,c } )
Dene font properties
Draw.DefLine(id,sd1,sd2,sd3,slc,slj,sljl)
i i Dene a gradient
Draw.DefTrans(id,t, [x1,y1,z1])
Dene line properties
Draw.Path([id,]t[,x ,y ])
Draw a straight line
Draw.Picture(t [,x,y,w,h])
i i Draw a path
Draw.Rect([id,t,] x,y,w,h[,c1,c2,w,o1,o2,rx,ry,rot])
Load/draw a picture
Draw.Save(t)
Draw a rectangle
Draw.Scale(zx,zy [,x,y,w,h])
Save drawings to le s
Draw.XY(x,y[,z,w][,t,s,c])
Draw a triangle
Draw a XY plot
Statistical Library
Stats.Binomial(n,k,p,cum)
Stats.NegBinomial(n,k,p,cum)
Return Binomial distribution
Stats.Poisson(k,mu,cum)
Return negative Binomial distribution
Stats.Logseries(k,p,cum)
Return Poisson distribution
Stats.Geometric(k,p,cum)
Return Log Series distribution
Stats.Hypergeometric(n,k,n1,k1,cum)
Return Geometric distribution
Stats.Gumbeldis(x,m,b)
Return Hypergeometric distribution
Stats.Normdis(x,m,s)
Stats.Norminv(x,m,s)
Return Normal cumulative
Graph Library
Graph.Bfs(r,c,n,m)
Graph.Components(r,c)
Return bfs tree c, of a graph r
Graph.Dfs(r,c,n,m)
Return components c, of a graph r
Graph.Mincut(r,c [,s,th])
Return dfs tree c, of a graph r
Graph.Mstree(r,c)
Return minimal cut
Graph.SPath(r,c,s[,t])
Return minimal spanning tree
Graph.Topo(r,c)
Return length of shortest paths
Geometry Library
Geom.Inside(x,y,X,Y)
Geom.Intersect(X,Y,i,j,m,n)
Return true if (x,y) is inside polygon (X,Y)
Struct Library
Struct.AddMap(x,y)
Struct.DeQueue()
Return void
Struct.EnQueue(x)
Return a Queue entry
Struct.GetMap(x)
add a Queue entry
Struct.InMap(x)
Return a Map entry
Struct.Map(n[,c])
Check if in Map
Struct.Queue(n[,c])
Create a Map
Create a Queue
Example :
e : is a string or a number
Example :
Note : In LPL all sets are ordered. That means that each element has
a position within a set. The element e is added to the set in the last
position. The added element is the last element. All tables indexed
over the set s are internally reorganized. Hence, this operation can
(set s:=1..10, for example), then the set is extended with a additional
9
integer independent what e is. For an example see learn01b .
Example :
9 https://lpl.matmod.ch/lpl/Solver.jsp?name=/learn01b
28 CHAPTER 3. BASIC LPL LANGUAGE ELEMENTS
constraint B: Alldiff({x,y,z,v,w)
Result : All 5 variables must have dierent values from each other
Return Value : double. It is the angle for the tangent in radiant unit.
Example :
Example :
10 https://lpl.matmod.ch/lpl/Solver.jsp?name=/sudokuInt
29
(sub)-model names.
Example :
ClearData(model) Result :
Note : Tables that are dened with the attribute frozen are not
cleared.
s : a constraint expression
Example :
Example :
Example :
Example :
Note 0
: In LPL dates are stored as doubles. the date zero ( ) is dened
r : a set identier.
x : a string
Example :
r : a set identier.
x : an integer
Example :
Example :
Example :
Example :
a:=Floor(-5.1) Result : a = −6
a:=Floor(5.9) Result : a=5
Note : See also the function .
holders.
Example :
a:=Format('a=%5.2f',23.36543)
Result : a= 'a=23.37'
a:=Format('Result is: %d',12^2)
Result : 'Result is: 144'
Note : The function has the same parameters as the function Write
with the exception of the (rst) le parameter. And also as the Write it
14 15
can be indexed. For examples see the model tutor08e and learn26a .
Example :
Freeze(a,b)
Result : sets the frozen attribute for a and b
Freeze(mymodel)
Result : sets the frozen attr. of the model mymodel
Freeze({i|i<=2} C[i])
Result : This will remove the rst two
Note : The function Unfreeze clears the frozen attribute. If the frozen
attribute of a variable is set then the value of a variable is xed and
set for a constraint then the constraint is not passed to a solver, the
14 https://lpl.matmod.ch/lpl/Solver.jsp?name=/tutor08e
15 https://lpl.matmod.ch/lpl/Solver.jsp?name=/learn26a
16 https://lpl.matmod.ch/lpl/Solver.jsp?name=/learn34
34 CHAPTER 3. BASIC LPL LANGUAGE ELEMENTS
model)
Example :
Any other value of the parameter a returns an empty string. See the
17
model learn22 for an example.
model)
a : an integer )in the range: 0 . . . 6), any other integer return the ID
name only
Example :
17 https://lpl.matmod.ch/lpl/Solver.jsp?name=/learn22
18 https://lpl.matmod.ch/lpl/Solver.jsp?name=/learn23
19 https://lpl.matmod.ch/lpl/Solver.jsp?name=/learn27
36 CHAPTER 3. BASIC LPL LANGUAGE ELEMENTS
a : an integer 1 . . . 16
Example :
11 Number of variables
14 Number of constraints
a : an integer 0 . . . 15
Example :
example) :
5 APL parameter
7 working directory
8 Version of LPL
9 execution folder
11 (not documented)
14 Get SolverList
15 (not documented)
16 (not documented)
Example :
1 LP linear program
The function returns the number of the problem type (rst column).
If one needs the name (second column), a call to the function Get-
ParamS(3) has to be used (see GetParamS). Se also the function Set-
commas. The entries dene the solver that should solve that type of
problem.
Example :
Example :
ing then the attribute of the focused entity is returned (see function
21 22
SetFocus (See model learn20 and learn27 for an example). The
21 https://lpl.matmod.ch/lpl/Solver.jsp?name=/learn20
22 https://lpl.matmod.ch/lpl/Solver.jsp?name=/learn27
40 CHAPTER 3. BASIC LPL LANGUAGE ELEMENTS
a : an integer 0
Example :
23 https://lpl.matmod.ch/lpl/Solver.jsp?name=/learn20
24 https://lpl.matmod.ch/lpl/Solver.jsp?name=/learn39
25 https://lpl.matmod.ch/lpl/Solver.jsp?name=/learn20
26 https://lpl.matmod.ch/lpl/Solver.jsp?name=/learn27
41
table.
Example :
Example :
Example :
a:=Max(10,5,4,12,5) Result : a = 12
Example :
a : an integer expression.
Example :
genus list genus). The function jumps within the model to the next
(there was one entity) or false if the end of the model has been reached.
27
For an example see model learn27 .
27 https://lpl.matmod.ch/lpl/Solver.jsp?name=/learn27
43
Example :
Note : This function sets an internal pointer to the next data entry
within a entity table. This data can now be retrieved with the function
28
GetV alue. For an example see model learn27 .
Example :
string.
s : a string
28 https://lpl.matmod.ch/lpl/Solver.jsp?name=/learn27
44 CHAPTER 3. BASIC LPL LANGUAGE ELEMENTS
Example :
Example :
a:=Ord('a') Result : a = 97
a:=Ord(' ') Result : a = 32
s : a string, the source from where to read an what part to read. This
below):
Examples :
45
Read('text.txt',a=2)
Result : read from le 'text.txt' the 2nd token on the rst line into a
Read{i}('text.txt',b=3)
Result : read the third column from le into b
Read{i}('text.txt',a,b,c)
Result : read the rst 3 columns from le into a, b, c
Read{i}('-:txt:text.xls',a,b,c)
Result : read the rst 3 columns from le as a text le into a, b, c,
if le exists
Note : The function Read is a powerful mean to read from text les,
There are no open or close le instruction. Here only the syntax is
s [*]
[prex] [type] s le type
The rst string parameter is now explained. The rst part (
type
from what type of le to read (text les, databases, Excel sheets or
.mdb
snapshots). Normally, if the is missing, the LPL parser derives
.db .xls
the le type from the lename extension (default). If it is or
.sps
, then the le type is a database, if the extension is the le
type ’txt:’
= read from a text le
The [prex] is empty or '-:'. If it is '-:' it means that if the le does
present than LPL records from a a previous read of the same read
instruction where the le pointer is, and can than continue to read
from that location. This is only relevant for text les, see model
29
tutor07d .
29 https://lpl.matmod.ch/lpl/Solver.jsp?name=/tutor07d
46 CHAPTER 3. BASIC LPL LANGUAGE ELEMENTS
will read a block token by token into a single datacube, see model
30
tutor07e .
s lename
table table
The next part of parameter is the . It is followed by a
text-les table %
block number
For , the begins with the percent sign fol-
optional , an list of
'text.txt,%2;1:Table:End,\t\n ,]-'
with 'End', 'Table' or and end of le. It skips the rst line
after 'Table'. Tabs, new line and spaces are token separators,
and ] and - are ignored chars (that is, they are translated
lename
into spaces). (see Chapter 8 for more detailed information). It
databases lename
table
For , the consists of the connection string
extended by the database le name and the consists of a
data.
30 https://lpl.matmod.ch/lpl/Solver.jsp?name=/tutor07e
31 https://lpl.matmod.ch/lpl/Solver.jsp?name=/tutor07
32 https://lpl.matmod.ch/lpl/Solver.jsp?name=/tutor07b
33 https://lpl.matmod.ch/lpl/Solver.jsp?name=/tutor07a1
47
source
source
a , an indication from where the data are read. Basically,
source
The source can be dropped together with the equal sign, if the
fault, tabs, spaces and the comma are considered as delimiters, whereat
Return Value :
Example :
34 https://lpl.matmod.ch/lpl/Solver.jsp?name=/learn12
48 CHAPTER 3. BASIC LPL LANGUAGE ELEMENTS
Example :
in the range [l . . . u[. The upper limit is excluded from the range. The
Example :
mean m. The random seed can be set with the function SetRandom-
Seed.
Example :
49
a:=Rndn(0,1)
Result : a is normal random number with µ=0 and σ=1
a:=Rndn(-5.5)
Result : a = 5.5
Note : The function returns a normally distributed number with
mean m and standard deviation s. The random seed can be set with
Example :
a:=Round(23.4) Result : a = 23
a:=Round(5.5) Result : a=6
a:=Round(5.5549,-2) Result : a = 5.55
Note : The function rounds a fractional number to the closest integer,
Example :
50 CHAPTER 3. BASIC LPL LANGUAGE ELEMENTS
function without parameter sets the focus to the very beginning of the
LPL model before the rst model declaration. The focus is then used
Example :
SetPaths('c:/mypath;d:/myotherpath)
Result: the two paths are added to the directory list (see 9.3)
Note : The global directory list of LPL contains always two paths:
the path to the model called, (the working directory and the path to
SetPaths the directory list can be extended, and all les are searched
automatically in this list, with the exception of the license le lpl.lic,
the message le lplmsg.txt, the lpl.ini le, and the lpl.le.policy which
Example :
51
random numbers. With the same random seed, the same sequence
random seed is chosen at random each time. Note that by default the
Example :
SetServer('https://lpl.unifr.ch/lpl/');
SetSolver('l,,Internet');
Result : The LPL Internet server is set to this address
cally send to the LPL Internet server where it is solved and the result
is then sent back to the LPL client. In this case, SetSolver must be
propriate solver that will solve the problem. The solution is sent back
Example :
SetSolver(gurobiLSol,'timelimit=100;VarBarnch=1')
Result : Sets the gurobi solver and passes a time limit of 100secs as well as the V
SetSolver('l,,Internet')
Result : Sets the Internet solver
Example :
(SetSolverList(',gurobi,gurobi,gurobi,gurobi,
gurobi,gurobi,lindoLSol,lindoLSol,gurobi,gurobi,conopt,knitroLSol,tabuSol');
Result : Assign the appropriated solver to each problem type.
Note : There are 14 problem types that LPL can automatically detect
above, if LPL detects that the problem is of type iNLP then the solver
knitroLSol will be called to solve it. If the problem type is MIP then
the solver gurobi will be called because it is the 4-th entry in the list
(problem type for MIP is 4). Note that the list begins with a comma.
That is, the rst entry is empty (no solver solves a problem of type
Example :
SetWorkingDir('c:/lpl')
Result :set the model directory path to 'c:/lpl'
x : a double
Example :
slack variable is frozen to the the actual value, otherwise (if zero) it is
unfrozen again.
Example :
becoming a xed variable, that is, the frozen attribute of the variable
is set.
Note also that the compiler switch 'p' adds an Sl function to all con-
straints with the goal to soften all constraints. This can be used to
nd infeasibilities.
straint, zero means all. So, the use in an objective function adds the
Example :
35 https://lpl.matmod.ch/lpl/Solver.jsp?name=/learn39
36 https://lpl.matmod.ch/lpl/Solver.jsp?name=/goalpr2
37 https://lpl.matmod.ch/lpl/Solver.jsp?name=/library
55
Example :
Note : At most one of the variables in the list is 1 all others are
zero.
Example :
Note : At most two consecutive variables in the list are dierent from
zero.
(see below)
Example :
x : a double
Example :
39 https://lpl.matmod.ch/lpl/Solver.jsp?name=/learn25
57
Example :
a:=Strbin('1101') Result : a = 13
n : an integer
Example :
s : a string
c : an char
n : an integer
Example :
integer. Note that the string must be in the format yyyy-mm-dd where
yyyy is the year, mm is the month and dd ist the day. The returned
integer counts the days since 1899-12-31 which day 1. If the string
function also can extract the n-th occurrence from the substring and
40
converts this extracted substring into a date (see model learn26 ).
40 https://lpl.matmod.ch/lpl/Solver.jsp?name=/learn26
58 CHAPTER 3. BASIC LPL LANGUAGE ELEMENTS
s : a string
c : an char
n : an integer
Example :
Note : The function converts a string to a oat and returns the oat.
c then the function also can extract the n-th occurrence from the
substring and converts this extracted substring into a oat (see model
41
learn26 ).
s : a set identier
eter)
Example :
41 https://lpl.matmod.ch/lpl/Solver.jsp?name=/learn26
59
W ritep the string ai replaces the set name i. For an example see the
in
42
model learn23 . Note also the parameter a can also be a numerical
s : a string
Example :
s1 : a string, (substring)
s : a string
Example :
42 https://lpl.matmod.ch/lpl/Solver.jsp?name=/learn23
43 https://lpl.matmod.ch/lpl/Solver.jsp?name=/learn26
44 https://lpl.matmod.ch/lpl/Solver.jsp?name=/learn26
60 CHAPTER 3. BASIC LPL LANGUAGE ELEMENTS
s : a string, (substring)
s1 : a string
s2 : a string
Example :
s : a string
Example :
s : a string
b : an integer
45 https://lpl.matmod.ch/lpl/Solver.jsp?name=/learn26
61
l : an integer
Example :
x : a double
Example :
a:=Trunc(-5.7) Result : a = −5
a:=Trunc(5.8) Result : a=5
Note : The function cuts the fractional part of the number
names.
Example :
Unfreeze(a,b)
Result : remove the frozen attribute for a and b
Unfreeze(mymodel)
Result : remove the frozen attribute of model mymodel
46 https://lpl.matmod.ch/lpl/Solver.jsp?name=/learn26
62 CHAPTER 3. BASIC LPL LANGUAGE ELEMENTS
Note : See also Freeze. Unfreeze function removes the frozen attribute
written.
Example :
Write('written text\n')
Result : Writes a line to the default write le
Each Write instruction opens a le, writes data to it, and closes it au-
see Chapter 7.
s
s prex
The string parameter is now explained. The rst part of the param-
prex
the following:
= ’+:’ add records to the table, append mode for text le
text le)
63
One can also use the specication '-:' for text les, which means that
the le, if it exists, is rst deleted before the writing takes place and
'+:' for text les means append mode. The two other specications
.xls .sps
from the extension. If it is or a the le type is a
type type
the le type is a snapshot, in all other cases the le is considered as a
Read
type
be one of the following (same as in the call):
s lename
table
The next part in parameter is the , followed (for database
text-les table
lename
For , there is no indication. It is not necessary
databases lename
table
For , the consists of the connection string
extended by the database le name and the consists of a
48
database table name. For an example see model tutor08b .
case, the data are appended to the le, dened in a previous Write
instruction. If no previous lename was given or if the parameter is
'nom', the le is the NOM-le, that is, the le with the same name
reports and can only be used when writing to databases. It is the name
47 https://lpl.matmod.ch/lpl/Solver.jsp?name=/tutor08
48 https://lpl.matmod.ch/lpl/Solver.jsp?name=/tutor08b
49 https://lpl.matmod.ch/lpl/Solver.jsp?name=/tutor08a1
64 CHAPTER 3. BASIC LPL LANGUAGE ELEMENTS
.fr3
table
and extension of . If templ is a star (*), then the name is the same
The parameter f is only used for text les, and species the format
source
destinations
a , an expression that is evaluated and the result is the
destination
left to right beginning with 1. They can be dropped together
eld name.
constraint names.
Example :
50 https://lpl.matmod.ch/lpl/Solver.jsp?name=/tutor08e
65
not dened then the tables are written to the NOM-le. The last
argument can be 'sum', then the tables are printed with all subtotals
in each dimension.
Draw.Animate([id,t,id1,] dur,beg,fr,to,fr1,to1,fr2,to2])
Index
Draw an arc
t : string, attribute
Example :
66 CHAPTER 3. BASIC LPL LANGUAGE ELEMENTS
Draw.Rect(’obj’,’label’,52,53,60,60)
Draw.Animate(’obj’,’translate’,’anim-id’,2,3,0,50,0,60);
Draw.Animate(’obj’,’translate’,’anim-id’,3,6,50,100,60,60);
with an inline text 'label') moves from its origin location (that is
3secs and lasts 2secs. In a second animation the same object then
'skewY'
Draw.Arc([id,t,]x,y,r,a1,a2[,c2,w,o2,a]) Index
Draw an arc
id : string
x : double, x-center
y : double, y-center
51 https://lpl.matmod.ch/lpl/Solver.jsp?name=/learn50
67
Example :
Draw.Arc(’A’,0,0,100,-10,-80,3,5)
80, 3
color red ( ), stroke width is 5. a2
Note that angle are measured in clock-
wise direction.
Draw.Arrow([id,t,]x,y,x1,y1[,z,c2,w,o2,a]) Index
Draw an arrow
id : string
Example :
68 CHAPTER 3. BASIC LPL LANGUAGE ELEMENTS
Draw.Arrow(’efg’,0, 0,100,20,20);
Draw.Arrow(’abc’,0,40,100,60, 0,3,1,-2,-.9);
a = .99 means: close to the ending (x1, y1). Same for negative values:
if a = 0.001 then the text is placed close to (x, y). If a < 0 then the
text is not place on the line, but the text follows the line from left to
52 53
right. For a model example see xDrawLine and xDrawAll .
id : string
52 https://lpl.matmod.ch/lpl/Solver.jsp?name=/xDrawLine
53 https://lpl.matmod.ch/lpl/Solver.jsp?name=/xDrawAll
69
Example :
Draw.CArrow(’efg’,0,0,100,40,25);
Draw.CArrow(’abc’,0,40,100,60,-50,0,3,1,-2,-.5)
efg
Note : Parameter a, see Arrow. The bend factor d is the larger the
54
more the line is curved. For a model example see xDrawLine and
55
xDrawAll .
id : string
Example :
id : string
ra : double, radius
0
c1 : integer, ll color, default black ( )
Example :
56 https://lpl.matmod.ch/lpl/Solver.jsp?name=/xDrawLine
57 https://lpl.matmod.ch/lpl/Solver.jsp?name=/xDrawAll
71
Draw.Circle(’hh’,50,50,40,3,4,5)
Draw.Circle(100,100,30,6,5,5,.1,.2)
id : string
Example :
58 https://lpl.matmod.ch/lpl/Solver.jsp?name=/xDrawCircle
72 CHAPTER 3. BASIC LPL LANGUAGE ELEMENTS
Draw.DefFill(’id1’,3,4,5);
Draw.DefFill(’id2’,0,5,1,0.2,0.9);
Draw.Rect(’#id1’,’id1’, 0, 0,50,50);
Result
Draw.Rect(’#id2’,’id2’,20,55,50,50);
: Two rectangles are drawn. The rst with
in1 :
res :
Example :
the resulting lter (an integer number from 0 to 9), that can be used
59 https://lpl.matmod.ch/lpl/Solver.jsp?name=/xDrawAll
73
10 "SourceGraphic"
11 "SourceAlpha"
12 "BackgroundImage"
13 "BackgroundAlpha"
14 "FillPaint"
15 "StrokePaint"
All other parameters depend on the lter primitive. For a model ex-
60
ample see xDrawFilters . The dierent lter primitives are displayed
60 https://lpl.matmod.ch/lpl/Solver.jsp?name=/xDrawFilters
74 CHAPTER 3. BASIC LPL LANGUAGE ELEMENTS
fe x1 x2 x3 x4 x5 x6
1 in2 mode*
2 type* values=
3
4 in2 op* k1 k2 k3 k4
5 order kernelMatrix divisor bias targetX targetY
6 sS* DiuseConstant
kUL*
7 in2 scale xCS* yCS*
8 ood-color ood-
opacity
9 stdDeviation
10 eRR* PAR* xlink:href
11
12 op** radius
13 dx dy
14 surfaceScale SC* SE* kUL* lC*
15
16 baseFrequencynumOctaves seed sT* typ***
17
18 z
19 z pAtX pAtY pAtZ SE* LCA*
20 slope int. amp. exp. oset
21 slope int. amp. exp. oset
22 slope int. amp. exp. oset
23 slope int. amp. exp. oset
24
Example :
5 basic fonts that always work: serif ', 'sans-serif ', 'cursive', 'fantasy',
61
and 'monospace'. For a model example see xDrawText .
Draw.DefGrad(id,sm,x,y,x1,y1,fy,oi,ci} ) Index
Dene a gradient
gradient (cx)
61 https://lpl.matmod.ch/lpl/Solver.jsp?name=/xDrawText
76 CHAPTER 3. BASIC LPL LANGUAGE ELEMENTS
gradient (cy)
gradient
(fy)
Example :
Draw.DefLine(id,sd1,sd2,sd3,slc,slj,sljl) Index
Dene line (path) properties
id : string
sd2 : double, the length of the gap between the dashes (stroke-dasharray)
62 https://lpl.matmod.ch/lpl/Solver.jsp?name=/xDrawGrad0
63 https://lpl.matmod.ch/lpl/Solver.jsp?name=/xDrawGrad1
64 https://lpl.matmod.ch/lpl/Solver.jsp?name=/xDrawGrad2
77
Example :
Draw.DefLine('line.dash',8,3);
Draw.Line('#dash',690,460,590,265,2,3);
Result : Dashed line of length 8,3
Dene a transformation
id : string
(skewX),^'sY' (skewY).
Example :
65 https://lpl.matmod.ch/lpl/Solver.jsp?name=/xDrawAll
78 CHAPTER 3. BASIC LPL LANGUAGE ELEMENTS
Draw.DefTrans(’tr’,’t’,100,20);
Result
Draw.DefTrans(’tr’,’r’,60);
: An rectangle (red) is
Draw.Rect(’#tr’,0,0,100,100,1,3,10);
drawn with left/top (0, 0), and size
Note : The three parameters x1, y1, z1 are the corresponding nu-
center (y1,z1)
id : string
x : double, x-center
y : double, y-center
rx : double, x-radius
ry : double, y-radius
66 https://lpl.matmod.ch/lpl/Solver.jsp?name=/xDrawTrans1
79
0
c1 : integer, ll color, default black ( )
Example :
id : string
Example :
67 https://lpl.matmod.ch/lpl/Solver.jsp?name=/xDrawCircle
80 CHAPTER 3. BASIC LPL LANGUAGE ELEMENTS
id : string
Example :
Draw.Path('M',10,10)
Result : Move the cursor to (10, 10)
Draw.Path('V',20); Draw.Path('H',20);
Result : Draw a vertical then a horizontal line
path. Each path must begin with a moveto ('M') instruction, if not,
LPL will automatically add the path instruction "M 0 0", that is, the
path type 'Z' or 'Y' or by a call to any other drawing function. The
letters are for absolute, lower-case letters are for relative positions.
68 https://lpl.matmod.ch/lpl/Solver.jsp?name=/xDrawLine
69 https://lpl.matmod.ch/lpl/Solver.jsp?name=/xDrawAll
70 https://lpl.matmod.ch/lpl/Solver.jsp?name=/DrawClock
81
this case, x1 and y1 dene the ll and stroke color, x2 is the stroke
width, and y2, x3 are the ll- and stroke-opacity of the path. An
example is:
Bézier curves and a straight line in the middle. For a model example
71 72
see xDrawPath , see also xDrawArcPath .
The path instruction can also be used to dene only a path without
drawing it. This is interesting for drawing text paths, for an example
73
see xDrawTextPath .
Example :
Draw.Rect([id,t,]x,y,w,h[,c1,c2,w,o1,o2,rx,ry,rot]) In-
dex
Draw a rectangle
id : string
71 https://lpl.matmod.ch/lpl/Solver.jsp?name=/xDrawPath
72 https://lpl.matmod.ch/lpl/Solver.jsp?name=/xDrawArcPath
73 https://lpl.matmod.ch/lpl/Solver.jsp?name=/xDrawTextPath
83
0
c1 : integer, ll color, default black ( )
Example :
Example :
74 https://lpl.matmod.ch/lpl/Solver.jsp?name=/xDrawRect
84 CHAPTER 3. BASIC LPL LANGUAGE ELEMENTS
Note : This function terminates a Draw function call list and writes
at the end of a run to write a SVG-le with name of the model and
extension svg.
Example :
Draw.Scale(2,1)
Result : Zoom graphic only in x direction by a factor 2
Draw.Scale(1,1,10,10,200,215)
Result : viewport of graphic is (0,0) to (210,225)
drawing function and can be called only once per graphic. It can be
can use the other four parameters to dene the global viewport and
size: (x · zx, y · zy) is the left/top coordinate and (w · zx, h · zy) is the
Draw.Text([id,]t,x,y[,h,c1,c2,w,o1,o2,a,r]) Index
Draw a text
id : string
x : double, x-position
y : double, y-position
right [0.67-1])
Example :
Draw.Text('Text',20,20)
Result :'Text' is placed at (20, 20), left/bottom
75 https://lpl.matmod.ch/lpl/Solver.jsp?name=/xDrawText
86 CHAPTER 3. BASIC LPL LANGUAGE ELEMENTS
id : string
Example :
Draw.Triangle('hh',50,50,40,3,4,5)
Draw.Triangle(100,100,30,6,5,5,.1,.2,180)
The rst contains a text inside, the ll color is 3 (red) the stroke color
is 4 (green), the stroke width is 5.
For the second circle the ll color is 6 (yellow) with an opacity of 0.1,
the stroke color is 5 (blue) with an opacity of 0.2.
Draw.XY(x,y[,z,w][,t,s,c]) Index
Draw a XY plot
Example :
Draw.XY(x,y)
Draw.XY(x,y,z)
in the y-axe.
are discrete distribution functions. The last parameter cum may missing
Example :
76 https://lpl.matmod.ch/lpl/Solver.jsp?name=/xDrawXY1
88 CHAPTER 3. BASIC LPL LANGUAGE ELEMENTS
Example :
Example :
77 https://lpl.matmod.ch/lpl/Solver.jsp?name=/binomial
89
Example :
Note : The function generates the value of the Log Series distribution
L(k, p).
Example :
G(k, p).
n : population size
n1 : size of a samples
Example :
Example :
Example :
Note :
Example :
Note :
92 CHAPTER 3. BASIC LPL LANGUAGE ELEMENTS
traversal
Example :
79 https://lpl.matmod.ch/lpl/Solver.jsp?name=/learn36
80 https://lpl.matmod.ch/lpl/Solver.jsp?name=/maze
93
Example :
traversal
Example :
81 https://lpl.matmod.ch/lpl/Solver.jsp?name=/learn30
82 https://lpl.matmod.ch/lpl/Solver.jsp?name=/maze
94 CHAPTER 3. BASIC LPL LANGUAGE ELEMENTS
th : a threshold of min-cut
Example :
Note : The function Mincut returns three results: (1) the min-cut
edge list in the table c, the subset of vertices that are on one side of
the cut as S, and the resulting weight of the min-cut. The threshold
can be set to any number th, if the algorithm has found a cut of at most
83
th it stops. As an model example see learn31 . (LPL implements the
graph.)
Example :
83 https://lpl.matmod.ch/lpl/Solver.jsp?name=/learn31
95
list in the table c, and the resulting weight of the minimal spanning
84
tree. For an model example see learn32 .
Example :
edge list in the table c, and (2) the resulting length. If the parameter t
(the destination) is missing then the shortest path tree (starting from
node s is returned. In this case the length is zero. If the graph contains
84 https://lpl.matmod.ch/lpl/Solver.jsp?name=/learn32
85 https://lpl.matmod.ch/lpl/Solver.jsp?name=/learn37
96 CHAPTER 3. BASIC LPL LANGUAGE ELEMENTS
Return Value : 0
Example :
Note : The function Topo returns the topological sorting of the nodes
of a DAG (Directed Acyclic Graph). Note that The function does not
86
check whether r is a DAG. For an model example see learn52 .
X : a set of x-coordinates
Y : a set of y-coordinates
86 https://lpl.matmod.ch/lpl/Solver.jsp?name=/learn52
97
Example :
Note : The number of point in the third (X) and the fourth parameter
87
(Y) must be the same. For a model example see xDrawInside.lpl .
Example :
87 https://lpl.matmod.ch/lpl/Solver.jsp?name=/xDrawInside.lpl
88 https://lpl.matmod.ch/lpl/Solver.jsp?name=/xDrawIntersect.lpl
98 CHAPTER 3. BASIC LPL LANGUAGE ELEMENTS
x : rst entry
Return Value : 0
Example :
Example :
x : Queue entry
Return Value : 0
Example :
x : rst entry
Example :
x : rst entry
Return Value : 1 or 0
Example :
Return Value : 0
Example :
argument is missing or dierent from 'i', 'l', 'd' the entries are integers.
Return Value : 0
Example :
argument is missing or dierent from 'i', 'l', 'd' the entries are integers.
* multiply operator
|| bitwise or operator
^ power operator
101
{ } to bracket an index-list
: dene operator
# cardinality operator
~ NOT operator
@ date/time data
// same as
:= assign operator
names, etc.), numbers, dates, strings, operators and functions are used to
written in the LPL language are very close to ordinary mathematical nota-
P
The indexed operators such as used in mathematics to sum terms
table. If they are not dened they return a default value. The same is
specied element within the set (set are always considered as ordered in
LPL). If indices are used in an expression, they must be bound (see Chapter
in-operator). Examples:
model code:
in parameter of functions
103
Examples:
Abs(a-b*3) in parameters
The comma operator is a list operator the left term is evaluated then the
right term is evaluated (in this order) and the value of the second is returned.
Example:
operator (using also a for loop) is the following LPL code to calculate the
greatest common divisor of the two numbers 994009 and 96709 (Euclid's
algorithm):
with the while statement, see next example). The loop operator is followed
break condition and the second is the return value. Since the second is
itself a list of expression, they are executed until the break condition is false
a
and the last ( ) is returned. This feature allows the modeler to implement
89 https://lpl.matmod.ch/lpl/Solver.jsp?name=/learn01a
104 CHAPTER 3. BASIC LPL LANGUAGE ELEMENTS
Chapter 4
In Chapter 2 all basic elements of a LPL model are explained. This Chapter
explains how to put these elements together to form a complete model. The
model <ModelHeader>
<statement list>
end
The model code begins with the reserved word model and ends with the
set declaration
parameter declaration
to declare sets
variable declaration
to declare data
constraint declaration
to declare variables
expression declaration
to dene constraint expressions
model declaration
to dene expressions
to declare sub-models
solve statement
if statement
to solve a model
while statement
to branch a statement list
for statement
to loop statements
to loop statements
105
106 CHAPTER 4. THE STRUCTURE OF A LPL MODEL
model-call statement
expression statement
to call sub-models
assignment statement
to execute an expression
to assign an expression
type attribute
genus attribute
to dene the type of a declaration
name attribute
to identify the kind of statement
index attribute
to dene a name for the declaration
range attribute
to specify vector and tables
subject_to attribute
to dene lower/upper bound range
if attribute
to specify the constraints to solve
friend attribute
to specify whether the statement is used or not
priority attribute
to access the scope of another model
quote attribute
to dene hints/start value/priority of variables
comment attribute
used to mark a statement
default attribute
to specify a qualied comment
frozen attribute
to dene a default value
expression attribute
to activate/x an entity
to assign an expression
Not all statements contain all attributes. Each statement ends with a semi-
The keyword integer is the type attribute, variable is the genus attribute,
x, X is the name attribute (the variable has two names x and X ), "Quantity
to transport" is the comment attribute, and [0..100] is the range attribute.
First, the attributes are explained, then the dierent statements are listed.
exception of the if, for, and while statements which have a special syntax.
107
integer
binary
to declare integer values
date
to declare binary (0-1) values
string
to declare date/time values
alldi
to declare alpha-numerical values
double
The attribute denes the type of a declaration. If no type attribute is used,
integer
the value domain of a declaration is (8-byte oating point). The
binary
type stands for integral numbers. If it is used for variables it declares
alldi
or one. Used in variables it declares logical variables (0-1 variables). This
type overrules the range attribute. The type is applicable for indexed
variables. It says that all variables of this declaration must be integer and
date
dierent from each other. LPL automatically generates the corresponding
string
constraints. The type is basically the same as double, however the
input and output are dates. The type declares the entity to be a
Examples:
following keywords:
set
parameter
for a set declaration
expression
for a parameter declaration
variable
for an expression declaration
constraint
for a variable declaration
model
for a constraint declaration
maximize
for a (sub)-model declaration
minimize
for a solve statement
solve
if
for a solve statement
while
for a if statement
for
for a loop statement
The model-call and the expression statement do not contain a genus at-
tribute. Examples:
If several consecutive statements declare the same genus then it is not neces-
sary to repeat the genus attribute over and over again (see above the decla-
ration of the variable y ). The model declaration is special in the sense that
it can contain itself a complete model See below). Models can be recursively
However, sometimes it is useful to have more than one name for the same
entity. These two additional identiers are called aliases. Normally the
the model. It is useful especially for sets and index names. Example:
109
Because set names can also be used as index names in LPL if the context
allows this it is very convenient to dene several names for the same set.
This avoids to introduce local index names in expressions when i and j have
use more than one identier for a set. The code fragment above could also
mathematical notation):
These previous ve attributes if used must be in this order. The next 8
entity. The lower bound and upper bound are especially for variables: they
are translated as bounds for the solver. LPL translates the expression auto-
The bounds are dened only for numerical entities otherwise they are ig-
range [0 . . . ∞]. Parameters and variables of non-linear models have the de-
fault range [−∞ . . . ∞]. Binary variable automatically have range [0 . . . 1].
This statement says that all constraints in model modA, but none in model
modB and the constraint const1, but not the constraint const2 must be taken
Alternatively, the expression can also begin with an if keyword. It then has
the syntax (where BoolExpr1 and BoolExpr2 are two arbitrary Boolean expres-
sions and subjectList1 and subjectList2 are two lists as described before):
1 https://lpl.matmod.ch/lpl/Solver.jsp?name=/semi-1
2 https://lpl.matmod.ch/lpl/Solver.jsp?name=/semi-2
3 https://lpl.matmod.ch/lpl/Solver.jsp?name=/mchoice-3
4 https://lpl.matmod.ch/lpl/Solver.jsp?name=/learn40
111
friend followed by a model name. It means that all identiers in the friend
model are also valid in the actual model without the qualied (dot) notation.
For example:
This means that a identier id within the model data can also be used in
the output model without dots: just use id instead of data.id. See model
5
learn30 .
For integer and binary variables one can add a priority. This priority is
passed over to the MIP solver whenever possible, where the way of branching
For the Gurobi solver, this attribute can be used to pass a (partial) solution
to the solver (warm start) or to pass hint values for variables. If the ex-
pression is -1 then the value of the variable is passed as a warm start, if the
expression is positive then the value of the variable is passed as a hint and
for hints). If the expression is zero then nothing is passed. If the expres-
sion is less than -1 then its positive value is passed as a branching priority
attribute. Note that for all these options to be eective the solver option
5 https://lpl.matmod.ch/lpl/Solver.jsp?name=/learn30
112 CHAPTER 4. THE STRUCTURE OF A LPL MODEL
function for dening various attributes (see Chapter 7) and in some other
comments are remembered by LPL and can be recalled later on, it is espe-
declares a default value for the entity, that is, the value used for a dot or
for the values not assigned to the entity. If no default attribute is used, the
default is zero.
model m;
parameter a := 4 frozen; -- keep that value
parameter b := 5; -- volatile
ClearData(m); -- delete all data within m (except a)
end
Applied to variables their values are frozen against solvers (a solver does not
change their value because they are dened as xed bounds). Applied to
constraints, it means to ignore the constraint for the solver the constraint
is switched o .
113
operator is : (a colon). One can use the two operators interchangeable. Good
practice is to use the colon only with constraint and expression statements.
pound set) used in the model. An index set is also called a set. A set consists
of integers or a string with a dene syntax. Sets may be indexed too, and
they are called compound sets. The set statement begins with the reserved
set
i;
-- declares an index (set) called 'i' (no data)
h := [ 1 2 ];
-- declares a set h with its elements '1' and '2'
j := [1..10];
-- declares a set j with its elements '1' to '10'
Seasons := [ spring, summer, autumn, winter ] ;
-- declares a set Seasons with four elements
IndexedSet{i,h}; -- a list of (i,h) tuples
Note that it is not necessary to repeat the keyword set after each declaration.
114 CHAPTER 4. THE STRUCTURE OF A LPL MODEL
merical) used in the model. They are normally numerical values (real or
by the sets, which have been declared before in the set statement. The
parameter
a;
-- declares a single parameter a (no data)
b := -4.678;
-- defines a single parameter and assigns a value
c{i};
-- declares a vector c where i is an set
-- the length of the array depends on the number
-- of the elements of i
d{i,j};
-- declares a 2-dimensional numerical data array d
-- (a matrix) with index i and j
-- the maximal length of the matrix is the Cartesian
-- product over i times j)
e{i} := b*c[i];
-- define e from an expression
i and j are set names, which must have been declared before in the model.
It has exactly the same structure as the parameter statement except that it
7. Example:
They are declared exactly in the same way as parameters are, which are
dened by expressions, except that they are headed by the reserved words
expression a := b;
parameter b := 2;
Write(a); -- write the value 2
b:=3;
Write(a); -- writes the value 3
Expression names can also be used within constraints. They will be ex-
variable x; y; z;
expression XY: x+y;
constraint A: XZ + 2*z <= 5;
clared within models. Sub-models are like functions: they can be executed
by calling them. Models nested within other models have their own name
space, which means that: (1) The same name can be reused in another
models without a name conict, (2) The identier is exportable using the
model m; -- line 1
parameter a; b; c; -- line 2
model mm; -- line 3
parameter a; bb; cc; -- line 4
end -- line 5
model nn; -- line 6
parameter d; -- line 7
end -- line 8
end -- line 9
Two models (model mm and nn) are nested within the model m. The
parameters a, b, and c on line 2 are visible within the model m (from line 2
to line 9) which means that they are also visible within its sub-models. They
are even visible outside model m and can be accessed by the dot notation
The parameters a and bb on line 4 are dened within model mm, i.e. they are
only visible inside the model mm which extends from line 4 to 5. They can,
mm.a, and outside model m, through the notation m.mm.a. The path
of model identiers separated by a dot from the nested models inwards
determines how the corresponding entity is accessed from outside. The two
parameters a (on line 2 and 4) have the same name which means that the
a (line 2) has a hole from line 3 to 5. Using the identier a
visibility of
within the model mm refers the parameter a (line 4) and not a (line 2).
The concept of model is important not only for structuring the informa-
tion hierarchically but also for hiding and encapsulate a piece of knowledge
be declared after their call instruction within other models. This is called
forward referencing.
Models can have formal parameters like a function in other languages note
are declared like declarations. All parameters are passed by reference, except
singleton @parameter@ declarations they are passed by value. See the tutor
6 7
examples learn41 and learn42 .
6 https://lpl.matmod.ch/lpl/Solver.jsp?name=/learn41
7 https://lpl.matmod.ch/lpl/Solver.jsp?name=/learn42
117
model. They are declared exactly in the same way as constraints, which
are dened by expressions, except that they are headed by the reserved
Example:
4.2.8 if Statement
This statement is for branching. It begins with the keyword if followed by
if a>b then
<statement list> --(to be executed if a>b is true)
else
<statement list> --(to be executed if a>b is false)
end
while a>b do
<statement list> -- (to be executed as long as a>b is true)
end
for{i} do
<statement list> -- (to be executed for all elements in set i)
end
No declaration can be placed in the statement lists within the for statement.
was declared before or after the call. Note that recursive model calls are not
MyModel;
also contain these parameters. The type and the genus must match. Only
singleton @parameter@ parameters are passed by value, all others are passed
by reference. Note that in the calling list, singletons can be arbitrary ex-
8 9
pressions. See the tutor examples learn41 and learn42 .
8 https://lpl.matmod.ch/lpl/Solver.jsp?name=/learn41
9 https://lpl.matmod.ch/lpl/Solver.jsp?name=/learn42
119
declarations can be written without repeating every time the keyword set,
as seen above. So, we may write
Example:
set i;
j;;
MyModel;
The set declaration list must be ended with an empty statement (that is,
The LPL code is a hierarchical structure and a model within a model can be
dened hierarchically as seen above. The main model is the model declared
Parsing the code means to create an internal structure of the model. The
LPL parser is a three-pass parser: on the rst pass all entities are collected,
on the second pass all index-set identier are attached to the indexed entities,
and on the third pass the model and all expressions are considered. The
three pass parser guarantees that the order of declarations in the code is not
important.
(and all submodels). The procedure is explain in details in the paper [3].
which they are written in the code. Submodels are executed by calling them
not important.
If the top model contains two submodels with the name data and /or
output then these models are executed without calling them explicitly. If
called explicitly, they behave like any other model call (without an extra
implicit call). If not called explicitly, then data is called before the rst
executable statement and the output model is called at the very end of
a run. One can redirect the implicit calls to other submodels with the
APL parameter @IN and @OUT. In this way, the data can be separated
Index-Sets
This chapter explains how sets and indices are declared and used in LPL.
1
They are the most important construct in the LPL language .
5.1. Introduction
A set is a nite collection of dierent elements. In mathematical modeling,
xi,j with ∀ i ∈ I, j ∈ J
The matrix xi,j consists of m×n single entries, which explicitly written
121
122 CHAPTER 5. INDEX-SETS
Sets and indexes are used in the mathematical modeling to build expressions
that sums all items xi,j in the matrix can be written as:
XX
xi,j
i∈I j∈J
On the base of these declarations, one can dene matrices in LPL as:
In contrast to mathematical notation, LPL can also use the same identier
as index name and as set name if the context allow it. The previous example
This is much shorter and more readable and does not give cause for con-
fusion: the identiers i and j are used as set names and index names in
The number of elements that a set contains is called its cardinality. The
are always considered as strings even if they are written as numbers. Hence
the two following sets containing 4 elements are exactly the same in LPL:
The elements can be separated by optional comma. The order of the el-
ements are important in LPL. Each element has a position within the set
beginning with 1. The last element has a position that is equal to the car-
dinality of the set. In the previous example the element '1930' has position
begin with 1. The three following set declarations are basically the same:
set i := [ 1 2 3 4 5 ];
set i := [ 1..5 ];
set i := 1..5;
Note, however, that the last of the three statement is an expression and 5
can be an expression, whereas in the second form this is a xed set already
Note that a[1930] is not the same. It is correct from the syntactical point
of view, and would reference the 1930-th entry of a{i} that does not exist.
LPL would not complain and just returns the default value of a{i} (which
set location,i := [ NY BO LA ];
set links{i,i} := [ NY BO , NY LA , LA NY ];
the set location is a simple set containing 3 elements. The set links is a
compound set also containing 3 elements tuples of length two, and mod-
els the list of connections between the locations, which is a subset of the
5.4. Index-Lists
Sets and indices are used in LPL to dene multidimensional objects such as
The number of subscripts following an object is called the dimension (or the
arity) of that object. In LPL, the subscripts are written within curly braces,
for example: x{i,j}. The {i,j}-part is called index-list. Index-lists are used
X
...
i∈I,j∈J,k∈K|i=k∧ai 6=12
The condition after the character | can be any legal (Boolean) expression. If
the condition evaluates to zero (false), it means that the specic tuple is not
selected and must be discarded. This limits the tuple-list and the resulting
a{i,j} is a sparse table, x{i,j} also will be a sparse table. Subsequent use
X
x t = yt + ak zk with k, t ∈ {1, . . . , 5}
k<t
They can be formulated in LPL as (note the use of two set names:
example. Suppose, there is a network with three nodes (cities NY, BO, and
general, we have a graph G = (I, E) with a nodes set I and a n edges set
E. Let take a trivial example with 3 nodes and 3 edges: the declarations in
set i,j := [ NY BO LA ];
set e{i,j} := [ (NY,BO) , (NY,LA) , (LA,NY) ];
parameter a{i,j} := ...(some data) ;
variable x{e};
parameter a{i,j};
Note that the variable x is indexed over e which is a subset of the Cartesian
product {i,j}. LPL remembers this, so the following three expressions are
sum{i,j} x[i,j]
sum{i,j|e[i,j]} x[i,j]
sum{e} x[e] ...
The rst expression runs through the whole Cartesian product, generates
the sum and excludes all x[i,j] that are not in part of e. So, for example,
The second expression is an explicit way to sum over the e. The third is the
most straight forward way. It is also the most ecient way. Whereas the
rst two formulations have running complexity of Ω(|i| · |j|) that is the full
Cartesian product, the third formulation has complexity Ω(|e|). (For small
graph, it is not big deal, and one can use either formulation!)
One can also mix sparse and not sparse tables as in the following expression
sum{e[i,j]} c[i,j]*x[e]
sum{e[i,j]} c[i,j]*x[i,j] -- the same
sum{i,j} x[e] ...
Note that c was declared over the full Cartesian product {i,j} while x was
only over e. Both expressions are correct in LPL without sacricing e-
X
ci,j · xi,j
(i,j)∈Ei,j
several (active) index-lists. The simplest such case is the ow constraint:
X X
xi,j = xj,i forall i∈I
j:(i,j)∈e j:(j,i)∈e
In LPL, this can be written in two ways, the rst been a non-sparse way
2
The sparse way must be used in the big model short-swiss-5 , for example.
2 https://lpl.matmod.ch/lpl/Solver.jsp?name=/short-swiss-5
127
set i:=1..7;
parameter s{i}:=i;
parameter r{i,j in 2..s[i]} := 10*i+j;
size that its role is active it guides the running through all elements, its
indexes are like loop variables that are assigned sequentially to an element
active role of receiving an element after the other. The i in the expression
ai plays a passive role of being assigned the same element as its active
dierence between active and passive index-lists. The expression above must
sum{i} a[i]
While active index-lists contain curly braces, passive index-list always must
sibling index (its counterpart) with the same name in a previously dened
that an index in the active index-list does not necessarily need an sibling in
a passive index-list.) The LPL parser tries hard to bind every index. If it
The rst expression is perfectly correct. LPL binds the i in b[i,j] to the i
in a{i,j}. However, the i in c[i,j] is bound to closer sum{i}. The second
x. The third expression does not generate an error, but it is not clear to
which i the index will be bound. The last expression is a clear error, because
k cannot be bound.
128 CHAPTER 5. INDEX-SETS
with increasing positions of elements from right to left within the index-list.
a[i,j] --or
a[(#i-1)*i+j]
The rst notation is a convenient way to access the entry (i, j). What LPL
really does is calculating (m − 1)i + j to access this entry. Note that this
The notation is very common the access the next entry of i, etc. This is
useful in ordered sets such as time period and others. In this way we can
integer parameter n;
parameter a{i} := b[i%#i+1]
parameter a{i} := b[(i-1+n)%#i+1]
Note that % and # are the modulo and the cardinality operators. The rst
n is negative.
Chapter 6
All numerical values, strings or dates used in an LPL model are called data.
Data in LPL are normally read from external devices, such as text-les or
databases. However, they can also be stored inside models in tables or gener-
parameter declaration
ated by expressions. While sets are dened in the set declaration, numerical
ample:
The rst declaration assigns the value 10 to the identier a. The second
Data can also be alpha-numerical. Strings are declared within the parameter
string parameter
c := 'Hello';
d := c & ' world';
text := 'A whole phrase might be \
assigned to a string variable\n';
e{i} := 'X_' & i;
The rst declaration dened such a string, the second is a concatenation, the
third is a longer string broken into two lines containing a linefeed character.
129
130 CHAPTER 6. DATA IN THE MODEL
Data can also be added directly to a LPL model in two special table formats:
the format A and the format B. The rst is for full table data, the second
6.1. Format A
In the format A, the table data are included in brackets after the assignment
set i := [1..6];
parameter a{i} := [10 20 30 . 7 9];
Note that the set i has 6 elements. The parameter vector a{i}, therefore
the single data. A data can also be replace by a dot (.) which is replaced
the example above, this means that a[4]:=0 and a[1]:=10, for example.
Note that the format A always denes full tables. All entries must be written
The format A is also used for dening lists of elements of sets or tuples sets.
The last is a compound (tuple-list set (see below). And it can also be written
as:
Stars are used like place-holders, see below in format B section template
option.
This format A can also be used to assign sparse numeric tables as in:
A somewhat shorter way is to use format B to assign the same sparse table
(see below):
6.2. Format B
The table format B is a powerful format specication to dene sparse multi-
tions: (1) the list-option, (2) the colon-option, (3) the transpose-option, and
(4) the template-option. The table specication begins with a slash (/) and
consists of the tuples list of the set elements followed by a value. Example:
set k := [A B C D E] ;
parameter v{k} := /A 1, C 3, E 5/;
The set k contains 5 elements. The sparse table v{k} contains three entries:
We have v[1]:=1 (v['A']:=1), v[3]:=3, and v[5]:=5. Note that v[2] and v[4]
are not dened. (An entry that is not dened can be accessed by an expres-
sion it returns the default value.) Note that the sparse entries consists
of the set element name followed by the value. An optional comma may
If the table is two-dimensional, then the two set elements are written followed
set i := [A B C] ;
set j := [X Y Z] ;
parameter w{i,j} := /A X 1, C Y 3, A Z 5/;
If the table is a relation (tuple-lists), then the value is missing, only the
set i := [A B C];
set j := [X Y Z];
set t{i,j} := [A X, C Y, A Z];
set s{i} := [B C];
The declaration of t{i,j} can also written by enclosing the tuples within
The most simple way to specify this matrix using LPL data table formats
would be to explicitly list all entries dierent from zeroes (or the default)
: c1 c2 c3 c4 c5 :
r3 1 1 1 1 1
: c6 c7 :
r14 12 12
r13 13 14
The blocks begin with a colon (:) followed by a list of elements of the last set
(cols) in any order. A second colon terminates the set element list. Right
after this, an element of the rst set (rows) and as many data as there are
elements between the two colons follow. This can be repeated. New-line
characters are not important within the format. So, the next to the last
: c6 c7 : r14 12 12 r13 13 14
An interesting option inside the colon-option right after the rst colon is
called the transpose-option written as (tr). It just reverses the last and the
134 CHAPTER 6. DATA IN THE MODEL
next to the last index in such a way that elements from the next to the
last index are listed within the colons, whereas elements of the last index
must be written after the second colon. This is interesting especially for
two-dimensional tables, but is also valid for higher dimensional tables. The
eect is obvious, if one looks at the last block in the matrix dened above.
The whole matrix could be considered as one block and one may also write
The colon-option can also be used for one or higher than two-dimensional
tables. Consider the following table e{i,j,k} which was declared as:
set e{i,j,k} := / : k1 k2 k3 k4 :
i1 j1 1 . . .
i2 j1 . 2 . .
i3 j1 . . 3 .
i3 j2 . . . 4 /;
table into non-sparse blocks of the same dimension as the original table.
To do this, the modeler can use the template-option. Consider again our 14×
14 matrix. The matrix can be viewed as a list of slices of (one-dimensional)
A slice begins with a template, that is, by a left bracket a list of elements
of indices used in the index-list {...}. The number of the stars indicates
is supposed that the dimension of the slice is the same as the original table.
the default template is [*,*]. It is not needed to write the default template,
one dimension (since one star is used in the template). The rst index (rows)
is bound to the element r1 for the whole slice and the second (cols) is free.
Hence, we need only to list elements of the free index-sets together with the
corresponding value for numerical tables. For relations, only the element
Several templates and slices can be repeated in arbitrary order. Let a four-
set i; j; k; m;
parameter d{i,j,k,m} := / i1 j1 k1 m1 1
i1 j1 k1 m2 2
i1 j1 k2 m1 3
i1 j2 k2 m3 4
i2 j1 k3 m4 5
i2 j3 k3 m5 6
i2 j3 k4 m1 7 /;
parameter d{i,j,k,m} := /
[i1,j1,*,*] k1 m1 1 k1 m2 2 k2 m1 3
[*,*,*,*] i1 j2 k2 m3 4 i2 j1 k3 m4 5
[i2,j3,*,*] k3 m5 6 k4 m1 7 /;
Or as:
parameter d{i,j,k,m} := /
[i1,j1,k1,*] m1 1 m2 2
[i1,*,k2,*] j1 m1 3 j2 m3 4
[i2,*,*,*] j1 k3 m4 5 j3 k3 m5 6 j3 k4 m1 7 /;
The template-option and the colon-option can also be mixed in the same
parameter d{i,j,k,m} := /
[i1,j1,*,*] : m1 m2 :
k1 1 2
k2 3 .
[i2,*,*,*] : m1 m4 m5 :
j1 k3 . 5 .
j3 k3 . . 6
j3 k4 7 . .
[*,*,*,*] i1 j2 k2 m3 4 /;
If the sparse table contains just some unrelated tuples, the list-option
is an appropriate mean.
1 https://lpl.matmod.ch/lpl/Solver.jsp?name=/multmip1
2 https://matmod.ch/lpl/doc1/multmip1.txt
137
If the table can be broken down into blocks of lower dimensional tables,
7.1. Variables
variable state-
All unknowns used in an model are called model variables or just variables.
ment
Each variable used in an LPL model must be declared in the
variable
. Variables are declared in exactly the same way as parameters, except
can also be assigned exactly like parameters. The dierence is that their
values are under the control of a solver, that is, if a solver is called they
variable
x; -- a single variable declaration named 'x'
Name; -- another single variable 'Name'
y{i,j}; -- an indexed variable 'y' (i and j are sets)
z{i,j,k,m}; -- a four dimensional variable 'z'
w{i|i<>5}; -- with a condition
Like parameters, variables may also have default values, lower and upper
bounds, integer or binary type. Lower and upper bounds on variables di-
integer model. Note that the default lower bound of variables for linear and
139
140 CHAPTER 7. VARIABLES AND CONSTRAINTS
(convex) quadratic models is zero, and for non-linear model it is minus in-
nity. The default upper bound is always plus innity. Variables and pa-
rameters are almost the same: they have both numerical values, which can
integer variable
x; -- integer variable x
w [1..10]; -- bounds and integer type
However, there are subtle dierences (1) the variables are assigned under the
control of an external solver, (2) one can assign a value to a variable, this
value is considered as start value for a solution process; (3) One can even
variable x;
parameter a := x;
variable y := 3;
variable z := x + y;
gets a start value of 3 that will be modied by the solver, eventually. In the
A special kind of integer variables are the alldiff variable. They dene a
the Quote attribute (full fetched model examples can be found in [4]):
7.2. Constraints
The constraint statement contains the constraints and the objective function
constraint t : x-y;
constraint t : x-y >= 0;
constraint r : x+y^2 = 2;
constraint re{i}: lo(i) <= xe[i] - sum{j} ye[i,j] <= up[i];
maximize ma : x-y+z;
(as in the rst expression x-y, then it is interpreted as being greater or equal
The same variable may be used several times in the constraint. LPL takes
care of this automatically and will reduce the expression (supposing the
constraint R : 13*y - x = 0;
attribute. An inactive constraint does not produce any output to the LPO-
le and to the solver, only the active once does. An inactive constraint can
constraint
r1 : x+y+z <= a;
r2 : x-y-z > b;
r3 frozen: 2*x-y-1 < d; --inactive constraint
....
Unfreeze(r3); -- reactivates the constraint r3
A constraint expression can contain also the comma operator. This allows
the run immediately before the constraint is generated the run some code
1
for data manipulation. An example is given in model learn48 .
1 https://lpl.matmod.ch/lpl/Solver.jsp?name=/learn48
142 CHAPTER 7. VARIABLES AND CONSTRAINTS
maximize profit: x + y + z;
The solve statement within model X generates a model instance that is, it
collects all constraints within X calls a solver and reads the solution back
into LPL in the meantime the execution of the model run is stopped.
By default, all constraints (whether dened before or after the solve state-
ment) within the model, where the solve statement occurs, are sent to the
solver. Note that no constraints in other models even within submodels are
sent to the solver, even if the submodel would have be called. There is an-
used together with the solve statement and lists all constraints that must be
This solve statement collects all constraints within model mod1 and model
mod1 together with the constraint mod3.const1, but excludes the single con-
straint mod2.const2.
The solve statement may be used several times within the same model. Be-
tween two optimizing stage, several variables may be xed or unxed using
the Freeze and Unfreeze function. This is useful for multi-stage modeling.
tween two optimizing stages. Another way to activate and inactivate con-
The constraint C is active if the condition a>=b is true, otherwise the con-
straint is not considered (same as frozen), that is, it is not sent to the solver.
LPL checks whether all constraints are linear. If they are, it returns LP,
or MIP. If the objective function is quadratic and all constraints are linear,
143
LPL returns QP, with integer variables it returns iQP. If some constraints
have quadratic expressions, then it returns QCP, and with integer variables it
returns iQCP, if the constraints are non-convex then the type is NQCP or iNQCP.
In all other cases it returns NLP or iNLP with integer variables. The type
PERM is a special problem type (see Chapter 9.2.3) and can be solved using
(1) Only one variable is declared as: alldiff, (2) Only an optimization
This means that all integer and binary variables are transformed to real
If the quote attribute is ' ∼cbcSol' then this means that the model cannot
be solved by the free CBC solver (this is basically for serial model testing
MIP (mixed integer) formulation. Suppose one wants to impose the following
double:
variable x [0..100];
constraint R : x>=20 or x<=10;
All variables that are used in logical constraints must be bounded explicitly.
would not be able to solve the model. Therefore, LPL translates it auto-
One can see that the two mathematical constraints (R1 and R2) are the same
d is, x can only be in the two intervals [0 . . . 10] or [20 . . . 100]. (Note that
the upper bound (100) on x is important and necessary).
user also can explicitly introduce indicator (or binary) variables as follows
Two powerful functions ( Read and Write) give the user a tool to read
Write
data from and write data to (1) plain text les, (2) databases, (3) Excel
generate complex reports using the FastReport library. Together, they cover
ferent from other languages. Each reading/writing call opens and closes the
le each time, there is no open or close function. However, the le name of
the previous reading and writing instruction is retained, so they must not
145
146 CHAPTER 8. INPUT AND REPORT GENERATOR
lines, records, or spreadsheet rows can be read in a single call. In text les,
this concept is called a table (such a part of the text le), in database it is
prex lename
The rst parameter is a string, consisting of at most 4 parts: (1) The rst
table
is , it has already been explained here. (2) The second
lines begins with a ; followed by a integer, and the block delimiters begins
table
with a : followed by the block begin delimiter and an optional block end
%2;5:Table:Endtable -- an example
'%2' (block number is 2)
';5' (number of skipping lines is 5)
':Table' (block begin delimiter , reading begins on next line)
':Endtable' (block end delimiter , line to end reading)
A block is a part of a text le that begins with the block delimiter at the
beginning of a line and ends with the same block begin delimiter (or the
block end delimiter) at the beginning of a line or end with the end of le. If
the le does not contain any block delimiter then the whole le is considered
The block number tells which block within the le has to be read. A block
number of %3 means to jump to the 3-rd block, that is, the le part that
begins with the 3-rd occurrence of the block delimiter within the le and ends
with the 4-th occurrence of the block delimiter or the end of le. The number
of skipping lines instructs to skip lines within the block at the beginning of
the block. A number of skipping lines of ';4' means to skip 4 lines within the
block and to begin reading at the 5-th line within the block. The number of
skipping lines can be -1 (but not less) meaning that the line with the block
2
begin delimiter is part of the next reading instruction (see model tutor07e ).
2 https://lpl.matmod.ch/lpl/Solver.jsp?name=/tutor07e
147
The lename and the block delimiter string are remembered from previous
read calls and do not need to be repeated over and over again. A missing
Now, an Read function-call opens a le, reads a text line from a text le,
3
and closes the le. Text lines beginning with /*, --, //, or empty lines are
skipped automatically we call them unreadable lines (all others are readable
lines. Hence, unreadable lines cannot be read by LPL's Read function.
delimiter
After the line was read it is manipulated depending on the third parame-
into parts called tokens delimited by one of the delimiter characters. The
tokens are numbered beginning with one from left to right the token num-
ber. By default, the three characters comma, tab, and space are considered
ignore
as token-separators. Note that several consecutive spaces (Unicode 32) are
it is a list of single characters that are ignored by the reader they are
destination =
source
The next parameters in the Read function have the syntax:
dening the receiver of the data. This is followed by an option equal sign
and a integer the token number (the source), indicating the token to be
3 a line that contains only white space characters such as spaces, tabs, and others,
is considered as an empty line by LPL
148 CHAPTER 8. INPUT AND REPORT GENERATOR
The rst Read opens the le with the name 'file.txt', reads the rst
pace char, assigns the rst token to a and the second token to b (while
The second Read opens the le with the name 'file.txt' (remembered
from the previous Read), reads the second readable line skipping
The third Read opens the le with the name 'file.txt', jumps to the
3-rd block, reads the third readable line skipping two readable lines
is, the whole line is takes as is), assigns the rst (and unique) token
to a.
The fourth Read opens the le with the name 'text.txt', jumps to the
1-st block, reads the second readable line skipping one readable line
(;1), tokenizes it into the tokens delimited by an tab char, assigns the
The last Read opens the le with the name 'file.txt', reads the rst
runs through the tokens and assigns them to the elements of set i.
Note that we use {i} to force the repeated assignment on the read
line.
Note that the reader is quite error tolerant. If, for example, the correspond-
ing line does not exist, because it reached already the end of the le, then
A Read call can be indexed, meaning that all readable lines within a block
will be read sequentially. In the following Read call, the second block lines
are read, where the rst token is assigned to i and the third to the parameter
4
a (for a complete example see the model tutor07 :
set i;
parameter a{i};
Read{i}('file.txt,%2' , i, a=3);
4 https://lpl.matmod.ch/lpl/Solver.jsp?name=/tutor07
149
Write (see below). The whole internal data structure is stored in a le a
only has one parameter: the snapshot le name. LPL automatically does a
Read('file.sps');
Read('sps:file');
Read('+:file.sps'); --read cumulatively
Snapshots can be read cumulatively, that is, several snapshots can be read
and the store is extended by each snapshot read. All tables are augmented by
5
an additional index-set _SNAP_. For a complete model example see learn33 .
The prex has already been explained here. The filename consists of a
database connection string and a database le name. It is supposed that the
corresponding database driver has been installed. For example for accessing
The part table contains a database table name or a SQL SELECT statement.
destination = source.
dening the receiver of the data. This is followed by an equal sign and a
quoted eld name within the database table (the source). The eldname can
If this is not possible, zero is assigned (no error occurs). Some Examples:
5 https://lpl.matmod.ch/lpl/Solver.jsp?name=/learn33
150 CHAPTER 8. INPUT AND REPORT GENERATOR
The examples declares a set i and a parameter b{i}. Next follows a string
parameter DB dening the connection string for the MS Jet Engine and the
database le. The Read call says to read from the database table iTable
the two elds with name ID and Price. The two data are assigned to the
set i and the parameter b. Note that all records within the table are read
The prex has already been explained here. The filename consists of a Excel
The next parameters in the Read function have the syntax: destination. The
set i;
Read('tutor.xls,[Sheet1$C3:L3]', {i} i)
The examples declares a set i. The Read call says to read from the range
6 https://lpl.matmod.ch/lpl/Solver.jsp?name=/tutor07b
7 https://lpl.matmod.ch/lpl/Solver.jsp?name=/tutor07a
8 https://lpl.matmod.ch/lpl/Solver.jsp?name=/tutor07a
9 https://lpl.matmod.ch/lpl/Solver.jsp?name=/tutor07a1
10 LPL
uses the 32bit jet engine of Microsoft to work with Excel. Since Microsoft
announced that no 64bit version of the OLE Jet Engine will be provided, these
models only work with LPL 32bit version.
151
writes data to it, and closes it automatically. There are no open or close le
instructions.
The rst parameter is a string, consisting of the prex and the lename have
already been explained here. The rst parameter can be missing. In this
case the data are written to a default le, called the NOM-le, or to the
le specied in the previous Write call. Since the second parameter is also a
string, LPL will recognize that the rst parameter is missing by investigating
it: If it contains a newline character, or the char % or the Write has only one
The second parameter formatting is also a string and this string is writ-
ten to the text le. If it contains place-holders they are replaced by the
The rst Write opens the default le NOM-le, jumps to the end of
the le and appends the string 'A small text' and adds a newline char
The second Write also opens the default le NOM-le, jumps to the
end of the le and appends the string 'The message is: Hello World'
and adds a newline char (\n), it then closes the le again.
The third Write opens the le with the name 'file.txt', jumps to the
end of the le and adds the string The result is: 1234' and a newline
The fourth Write opens the default le NOM-le, jumps to the end of
i = 1 , i^3 = 1
i = 2 , i^3 = 8
i = 3 , i^3 = 27
i = 4 , i^3 = 64
i = 5 , i^3 = 125
i = 6 , i^3 = 216
i = 7 , i^3 = 343
i = 8 , i^3 = 512
i = 9 , i^3 = 729
i = 10 , i^3 = 1000
The formatting string can contain place-holder having the syntax as follows:
this order:
0 an optional zero to ll leading chars with zero (otherwise they are spaces)
For all oating-point formats, the actual characters used as decimal and
operating system.
For the date/time type t, a second character follows this is the standard
that has been adopted also by Java 5. These date/time types are similar
to but not completely identical to those dened by GNU date and POSIX
time:
H Hour of the day for the 24-hour clock, formatted as two digits with a leading zero as
necessary i.e. 00-23. 00 corresponds to midnight.
k Hour of the day for the 24-hour clock, i.e. 0-23. 0 corresponds to midnight.
I Hour for the 12-hour clock, formatted as two digits with a leading zero as necessary, i.e.
01-12. 01 corresponds to one o'clock (either morning or afternoon).
l Hour for the 12-hour clock, i.e. 1-12. 1 corresponds to one o'clock (morning or afternoon).
M Minute within the hour formatted as two digits with a leading zero as necessary, i.e. 00-59.
S Seconds within the minute, formatted as two digits with a leading zero as necessary, i.e.
00-60 ('60' is a special value required to support leap seconds).
L Millisecond within the second formatted as three digits with leading zeros as necessary,
i.e. 000-999.
p Locale-specic morning or afternoon marker in lower case, e.g.'am' or 'pm'.
11
For a model example see tutor08e .
11 https://lpl.matmod.ch/lpl/Solver.jsp?name=/tutor08e
155
Write as follows:
Write('file.sps');
Write('sps:file.abc');
The unique parameter is the le name. Note that the le name must have
extension sps or the prex must contain sps:. For a model example see
12
learn33 .
The rst parameter is a string, consisting of the prex and the lename have
already been explained here. Note that the lename must contain a database
connection string.
string parameter
DB:='Provider=Microsoft.Jet.OLEDB.4.0;Data Source=tutor08out.mdb';
Write(DB&',iTable', 'Robots'='Robot1', 'Price'=234567);
Write('-:'&DB&',iTable', 'Robots'='Robot1', 'Price'=234567);
Write('+:'&DB&',iTable', 'Robots'='Robot1', 'Price'=234567);
The parameter DB denes the database connection string and the database
le name.
The rst Write opens the database tutor08out.mdb tries to write data
into the table iTable. If the database or the table does not exist, the
looks for the primary key eld Robots, jumps to the corresponding
record and lls the data (here eld Price). The database is nally
closed.
12 https://lpl.matmod.ch/lpl/Solver.jsp?name=/learn33
156 CHAPTER 8. INPUT AND REPORT GENERATOR
The second Write opens the database tutor08out.mdb clears all records
of the table iTable before writing a new record. The database then is
closed.
The third Write opens the database tutor08out.mdb tries to write data
into the table iTable. A new record is added to the table. The database
then is closed.
Creating a Database
Using the Write, one also can create a database and its tables on the y.
string parameter
DB:='Provider=Microsoft.Jet.OLEDB.4.0;Data Source=tutor08out.mdb';
Write{i}('&:'&DB&',iTable', 'Robots'=i, 'Price'=Price,'Ordered'= Ordered);
Write{i}('*:'&DB&',rTable', 'Robots'=i, 'Quan'=Robots);
The rst Write has a prex of &:, which means to create a new MS Access
database DB. Note that an existing database le will be deleted. At the same
time a new table named iTable is added to the database with the elds
Robots, Price, and Ordered. The type of the elds correspond to the type of
the LPL specication: sets and string parameter generate string types in
the database. There are some convention about the eld names:
If the eld name begins with a capital 'I' then this eld is considered
as a primary key eld, and in addition to the eld a primary key will
be generated.
If the eld name begins with a character '_' (underscore) then the
13
For a complete model example see tutor08b .
Creating Reports
Fas-
tReport
LPL includes the functionality of a professional report generator, called
There is only a small dierence in the rst string parameter: The lename
must be concatenated with a comma and a second le name which is the
13 https://lpl.matmod.ch/lpl/Solver.jsp?name=/tutor08b
157
string parameter
DB:='Provider=Microsoft.Jet.OLEDB.4.0;Data Source=tutor08out.mdb';
Write('&:'&DB&',tbl,tmpl' , 'a'='A Report', 'b'='Title');
Write('&:'&DB&',tabl,*' , 'a'='A Report', 'b'='Title');
Write('&:'&DB&',tble,*,*.pdf' , 'a'='A Report', 'b'='Title');
In the rst Write a new database tutor08out.mdb is created with the table
tbl and the elds a and b as explained in the previous section. In addition,
the rst parameter contains the part ',tmpl'. With this additional comma
separated part, LPL will generated a new report template le with the name
already exists then it will not be created once again. The name can also be
replaced by the character star (*), meaning that the template le name is
the same as the table name with extension fr3. The template name of the
Note that LPL works hard to generate a rst useful template using the elds
and the eldnames if the database table to place the data on the template
page. Nevertheless, the user can open the template le using the template
designer of FastReport and modify every single item within the page. LPL
the report le name. If this part is used then the so far generated template
pages are collected and a complete report le is written. In the example the
le name extension various le type can be generated. If the extension are
as follows:
14
A complete model example is given in tutor08c .
14 https://lpl.matmod.ch/lpl/Solver.jsp?name=/tutor08c
158 CHAPTER 8. INPUT AND REPORT GENERATOR
Chapter 9
Miscellaneous
Files can be included into the source le using the directive /*$. There are
two directives.
/*$I 'filename' */
/*$E 'filename:int:delimiter' */
by a string parameter that was marked with the 'incl' quote attribute. Of
point and at the end of that le reading continues from the calling le.
Hence, the model source may be split in dierent LPL les. For an example
159
160 CHAPTER 9. MISCELLANEOUS
1
see the model tutor06 . Nested include les are also possible up to a level
The include le name can contain a wildchar * (star), which will be replaced
by a real lename if just extists. If the le does not exist then a warning ist
at this point and at the end of that le part reading continues from
the calling le. In contrast to /*$I, this directive reads only a part of a le
between two delimiter in a similar way then does the text reading instruction.
Example:
/*$E 'MA.pla:8:Table' */
This instruction opens the le MA.pla and reads from the 8-th occurrence of
the delimiter Table. From there on, it copies the part to a new le M08.pla-8
(lename composed from lename and the int separated by a dash), a le
created on-the-y. The scanner then opens this le M08.pla-8 and continues
LPL can communicate with various solvers commercial and free once.
An LPL model can also contain function calls. They dene various directives
to control behavior of the LPL compiler, solver or other part of LPL. They
are as follows:
1 https://lpl.matmod.ch/lpl/Solver.jsp?name=/tutor06
161
parameters (SIP) placed in the single string and separated by commas within
the string. For later reference, we call these parameters SIP1, SIP2, ..., and
SIP22).
For several solvers the SIP is already predened in the le lplcfg.lpl as
SIP1 and SIP2 are empty (the SIP begins with two commas, and the third
the default LPL Internet solver. That is, the problem is sent to a LPL Server
(dened in the function SetServer), and the server chooses the appropriate
solver if it exists. The last denition (mySolver), sends the model to the server
le), the call to the function SetSolver (within the model) becomes:
It is also possible to predene the solvers for all problem types (see Get-
Example: If the SIP1 consists of the string 'lm', then LPL generates
the LPO-le and the MPS-le just before it calls the solver.
Example: If the SIP2 consists of the string 's', then LPL reads the
3. SIP3 : The program or the library that is called as solver. Note that
strings beginning with 'lib:' will call a dynamic link library. First, this
also that '*' is a wild-char. For example: if the string is: 'lib:gurobi90',
4. SIP4 : The name of the Solver Options Mapping File (SOMF) (ex-
5. SIP5 : The name of the Solver Parameter File (SPF) (explained be-
low),
6. SIP6 : The default Solver Options (SO). The dierent options are
Name=Value
cplex the option to dene the time limit for the solver is TILIM. The
option to this value. For example to set the solver time limit in cplex
TIMLIM=60
Name is dened either in the SOMF le (see below) or they are passed
7. SIP7 : The string replacing %3 within the SIP6, if the model has
8. SIP8 : The string replacing %3 within the SIP6, if the model has to
be minimized,
9. SIP9 : The lename from which LPL has to read the solution (SOL-
le),
the SOL-le the rst character of the variable name is found. If this
parameter is missing or zero then the SOL-le has the format "X>nr>
<space> >value>" beginning with the second line (for gurobi and
12. SIP12 : An integer indicating the length of the numerical value of the
13. SIP13 : The lename from which LPL has to read the dual values
(DUA-le),
model is optimal,
model is infeasible,
model is unbounded,
19. SIP19 : The string replacing %4 within the SIP6, if the model is a
20. SIP20 : The string 'd' or 'dh' or empty. An empty string means that
LPL will not generate derivatives or the Hessian, 'd' means to generate
between two calls of the solver callback) (only for library solvers).
(default 3000ms).
between two model call, called from the solver callback if an (integer)
adding lazy constraints or when the solution process takes a long time
(using Writes). Of course, the submodel is only called after the rst
(integer) solution has been found by the solver. (default 0ms). The
2 3
model example learn10 and also model tsp-6 using lazy constraints
to ask the solver for a free licence. LPL checks the solver licence. If
SIP23 is larger then 0 and if a free solver licence is not found, LPL
rests for a certain time specied in SIP24 and tries again to obtain
(default is 0).
All SIP parameters (except parameter 8 and 9) may contain also the follow-
ing strings:
2 https://lpl.matmod.ch/lpl/Solver.jsp?name=/learn10
3 https://lpl.matmod.ch/lpl/Solver.jsp?name=/tsp-6
166 CHAPTER 9. MISCELLANEOUS
Any other characters or strings are taken literally. (Note that a backslash
used to read the solution back to the LPL system. They suppose that the
solver writes the solution to a SOL-le and DUA-le. They must contain
one variable name per line with its value. All lines not containing a variable
and communicated to the solver. The default solver options are dened in
the solver interface parameter SIP6, these options are always pass to the
in the SetSolver call. These options override the options dened in SIP6
eventually.
All solver options for a particular solver are specied in the Solver Option
Mapping File (SOMF). An example is the le cplex.prm used for the Cplex's
dynamic link library. As an example: the le contains the following line
The solver option instruction to limit the time to 60secs would be TILIM=60.
LPL now makes a lookup in the SOMF le to translate this instruction into
Each line in the SOMF le is separated into four parts from left to right:
(1) the name as used in LPL's SIP6 (option solver string) (TILIM), (2) the
substitute (here: 1039), (3) an attribute (here: d) (this is used in the LPL-
CPLEX interface to call the right routine: possible values are i (for integer
values), d for double, and s for string values) (4) the rest of the line, which
167
is a comment. The four parts must be separated by at least one blank. The
The SOMF le for the Gurobi solver is gurobi.prm. For Gurobi all parame-
ters (see Gurobi documentation) are dened in this le. For example, to set
the time limit to 100secs, the MIPFocus to 1, and the Seed to 2, one would
add the following statement to the LPL code (gurobiLSol is dened in the
le lplcfg.lpl) :
SetSolver(gurobiLSol,'TimeLimit=100;MIPFocus=1;Seed=2');
X
1. Callback within solver: Adding 'CALLBACK=X' means that an LPL
solution to the solver. That is, all variable values are passed to the
solver as a starting value (note that this value is the default value
4.1.8), this can also be used to pass only a partial solution or to pass
2. If the problem type is NONE then the procedure exits and no solver
is called.
4. The SOL- and DUA-les are erased if they exist and the values of all
5. The solver options SIP6 are processed, that is, the parameters that
are passed to the solver or written to a le that the solver then calls.
(b) SIP6 is merged with the solver option string dene as the second
(c) SIP4 (if not empty) is interpreted as a lename (the solver op-
tions mapping le (SOMF)) and all solver options in the SIP6
le (SPF)) and the modied SIP6 string is written to this le.
SetSolver(cplex,'timelimit 60');
The solver cplex must be dened before (typically in the le lplcfg.lpl) as
following:
Note that all SIP parameters are empty except the third and the fourth
for this solver. The model is handed over to the solver directly within the
directly within the memory also. SIP3 says to call (in Windows) the DLL
work with the library. Note also that the function SetSolver() can be called
with two parameters, where the second parameter is a string containing the
solver options.
The solver MOPS (www.mops.fu-berlin.de) must have been dened before (typ-
SIP1 is 'm', hence, at step 3 the MPS-le is created. In step 5 the solver
imized, and the objective name is obj then the SIP6 will be translated into
XFNMPS='xyz.mps';XMINMX=max;XFNLPS='xyz.sol'; XFNIPS='xyz.sol';XOUTLV=3;
XMXLPT=1;XMXMIN=1
SIP4 is empty, hence this string is left unchanged. SIP5 is ' XMOPS.PRO '.
Hence the default conguration le XMOPS.PRO (the solver parameter le (SPF))
XFNMPS='xyz.mps'
XMINMX='max'
XFNLPS='xyz.sol'
XFNIPS='xyz.sol'
XOUTLV=3
XMXLPT=1
XMXMIN=1
These are the solver parameters that will be read from the MOPS solver.
Next in step 6, the solver specied in SIP3 is called, that is, the program
mops.exe is executed. Next in step 7, SIP2 is 's'. Therefore, the le specied
DUA-le.
models. It cannot solve integer problems and should not be used for large
SetSolver(lpl-lp);
min f (πi )
i∈π
This problem has many applications. Four solvers are directly integrated:
(1) a heuristic based on a simple tabu search method, (2) a heuristic based
on local search; (3) a random search solver; and (4) a full enumeration solver.
The purpose of this solver was to show the feasibility to integrate an arbitrary
solver into the LPL system. The solver is not particularly powerful. The
tabu search solver is useful in nding good solution to many small problems.
The local search solver looks in the neighborhood repeatedly until it nds
a local minimum and then stops. The random search solver is not a solver
function for each permutation. It gathers the minimum, the maximum found
and returns the means as well as the standard deviation (in the LOG-le).
The full enumeration solver enumerates all permutations and returns the
SetSolver(tabuSol);
SetSolver(randSol;
SetSolver(locaSol);
SetSolver(enumSol);
These solvers should only be used for permutation problems. LPL recognizes
communicate this within the LPL model by one of the four solvers. The
user can congure, in a limited way, these four solvers through the SIP6.
0;60;30000;17;100;20;8;1;1
4=enum),
171
proved solution has been found (0=to be mute, 1=yes write it).
les are searched in this directory list. The paths in the directory list are
see 9.7.
172 CHAPTER 9. MISCELLANEOUS
The working directory is normally the directory specied in the rst program
is the directory of the executable or the current directory from where the
executable was launched. The working directory can be changed within LPL
SetWorkingDir('<workingDirectoryName>');
(In the Windows version the working directory is also changed through a
open le dialog box; however the SaveAs dialog does not change it.) All in-
termediary les generated by LPL are saved in the working directory (except
The directory of the executable (EXEDir) is the directory where the exe-
cutable (lplw.exe or lplc.exe or the application that calls the lpl.dll) is lo-
cated. If LPL is called as as library, then the executable that calls the
The APL-path is the path-list dened by the APL parameter @PATH (see
below APL)
SetPaths('c:/lpl;c:/lpl/models;c:/solver/cplex');
If a le to be read is not found in any path before then LPL looks for the
le if present in the EXEDir is read at the very beginning even before
Example:
copt=wwvv
maxa=2000000
173
Note that, there is no need for memory allocation in LPL. LPL reallocate
memory on the y. However, for very large models it might be advantageous
to do so.
If the le lplcfg.lpl exists in the LPL directory list, then this le is
rst model declaration at the very top of each model le. The user can
dene dierent options (for example solver interface parameters) which are
If this le is present in the EXEDir directory then one can restrict reading
and writing les from all directories except the working dir, its subdirecto-
ries, the EXEDir, and the once that are explicitly mentioned in its list. This
The LPL compiler can be called with three parameters. The rst is a le-
name (a model in LPL syntax). The extension of the lename must be lpl.
The second parameter the compiler switches is an optional string to in-
struct LPL how to compile, and the third (APL) is explained in the next
section).
The second parameter (compiler switches) can be empty or can contain any
of the compiler:
174 CHAPTER 9. MISCELLANEOUS
The order of the characters does not matter. Note, however, that there are
explained further: Using the switch ss, parses the model, strips all comments
out and stores the model source in the LPL-le then exits. The switch sss,
in addition of stripping all comments, replaces all identiers in a way that
the model cannot be read anymore by a user, but LPL still can run it. It is
made to hide the knowledge modeled in the model to others. At the same
time a CRP-le is generated (a le with the same name as the model but
with extension .crp), which maps the real names with the encrypted names.
ID=value
it can be one of the following strings: @IN, @INF, @OUT, @OUTF, @RAN, @DOC, @PATH,
@ID, @IP, @IP1, @SOL. The second part value must by a value assigned to the
PATH gets the value c:\modeling, and the model parameter seed gets the value
3) :
@RAN=2#@PATH='c:\modeling'#seed=3
The APL can be used as a third parameter when calling lplw , bf lplc,
LPLset-
etc. In this case, the '#' character can also be replaced by a space. When
ParamS(5,APL)
using the lpl library, the APL must be assigned using the function
exactly in the same way, as if it where dened within the model. For
and one calls the LPL compiler with the following command:
then the parameter within the model gets the value 10 after a parse
of the model xx.lpl. Note that if the parameter is assigned within the
176 CHAPTER 9. MISCELLANEOUS
data
case, a model call is automatically added before the rst executable
statement, otherwise if the model with name exists then a model
4
call to this model is added (see model learn53 ).
output
case, a model call is automatically added as a last statement in the
main model, otherwise if the model with name exists then a
model call to this model is added.
data
must be in LPL syntax and the main model name in that le must be
. In this case, The (data) model is included into the main model.
5
(see model wl2 ).
output
le must be in LPL syntax and the main model name in that le must
be . In this case, The (output) model is included into the main
6
model. (see model wl2 ).
4 https://lpl.matmod.ch/lpl/Solver.jsp?name=/learn53
5 https://lpl.matmod.ch/lpl/Solver.jsp?name=/wl2
6 https://lpl.matmod.ch/lpl/Solver.jsp?name=/wl2
177
subsection for the model, and the option t1 generates a section for the model.
translated into HTML using the free pdf2htmlEX software). The model
documentation in the LPL source code is part of the model source code. It
Comment attributes are strings within quotes ("...") and have already
star sign) on all lines within the documentation comment are ignored.
For example:
mally placed in the source code before the formal declaration of the
the main model after the formal model. Each documentation comment
AT X specication and commands (that make sense
can contain any L E
in a particular context) because the model documentation is automat-
AT X typesetting system. The documentation
ically processed by the L E
comment in LPL may also contain one the following @-specications
(note the char @ can be escaped by \@):
on a new line): adds the model with the name modelname in mixed
Math-Mode and text mode. This is very new and powerful for
larger models.
All @ AT X
specications could also be realized by using the appropriate L E
commands.
AT X distribution (p.e.
1. Software needed: You'll need LPL and a free L E
from www.miktex.org, download the minimal package from the Miktex
7
2. Write the documentation in the LPL-code (Example see learn08 .
lplc mymodel t3
The batch job modeldoc.bat batch job can automatically be called from the
The whole documentation can also written to or read from a separate le.
The le can be read automatically after a parse by the @DOC APL-parameter,
as explained. (The compiler switch f writes the le.) The structure of the
the entity name to which it belongs. Then follows a blank and the
Each formatting string in a Write statement begins with the two char-
Each comment in the le can contain multiple line the comment ends when
7 https://lpl.matmod.ch/lpl/Solver.jsp?name=/learn08
180 CHAPTER 9. MISCELLANEOUS
ically recognizes if a le is encrypted and takes the necessary steps. The
user does not intervene in any case. The user can encrypt a le or decrypt a
le using the local popup menu in the lplw.exe browser's editor. To encrypt
and to decrypt, the user must enter a password. Each le in a model pro ject
can be encrypted separately and with a dierent password and can only be
decrypted with the same password again. There is also a procedure in the
Any of the functions initializes a new drawing space. The size, the viewport
and scaling of the drawing space can be controlled by the function Scale.
If the function is not used, the size of the drawing space is automatically
derived. If it is used it must be the rst function call of the library. Further-
more, it can be called only once (additional calls have no eect). (Well, it can
be used again after the graphic has been written to a le using Draw.Save).
The function Scale has two forms:
the dierence that all coordinates are scaled by the factor (zx,zy)
and h dene the whole size and the viewport of the graphic. The size
of the graphic is (w,h), and (x,y) are the top/left coordinate of the
and zy.
matically set to svg. If no Save instruction is used in the LPL code, then
LPL automatically calls it at the end of a run to write a svg-le with name
of the model. After the call to Draw.Save a fresh draw instruction list can
not-used, that is, a missing optional parameter value is the same as -2. All
functions dene various drawing attributes, such as the font size, opacity,
Draw.DefFont('myid','Verdana,sans-serif',50);
In the function that draws a text, this denition can be referenced by the
One can also cumulate the references in a drawing function. For example,
if a text with the previous font myid must be drawn rotated as dened in
ro denition then it is possible to use both names as follows (the two names
All the other functions in the Draw library are drawing functions and they
are placed in the svg-le in the order of their appearances in the LPL code.
182 CHAPTER 9. MISCELLANEOUS
In many functions the two parameters c1 and c2 are used. They are color
color. They can also be assigned by the function Rgb(r,g,b), which generates
three colors), and Rgb(255,0,0) means red (red only is saturated). Another
that result in a positive number. (The only negative number that can be
Grey gradient: 32 to 63
Red gradient: 64 to 91
The numbers 0 to 31 are reserved in LPL for a list of saturated colors. Model
8
examples are xDrawColors .
just add the two le names as parameters in the console. The program checks
whether the two les are equal, if not, it generates two additional les with
the same names and extension '.di ' that contains the dierences. The
and variables), if the EQU-les have been generated with the compiler switch
'e6'. The EQZU-les can be very large and the program is very ecient.
Call
8 https://lpl.matmod.ch/lpl/Solver.jsp?name=/xDrawColors
183
to the space from 1 to 50. The four elements (1,2), (2,3), (3,4) and
(4,5) are mapped to the four numbers 2, 8, 14, and 20. It corresponds
four elements, but still they are mapped to the space from 1 to 50. By
introducing a new set newij with the same cardinality than ij one
To make the correspondence between the two sets (ij and newij), $
can be used as an unary function in an expression, which makes the
2. Compiler switch k has the eect that sets are read at once and can-
keys of a database without modifying all the read statements, for ex-
for example), then all derived tables containing the foreign key ID
SELECT is necessary.
184 CHAPTER 9. MISCELLANEOUS
parameter M := 10;
set i := 1..M;
the parameter is sparse then the index is running through the sparsity
of the parameter.
Chapter 10
The LPL package comes with a 32-bit DLL and 64-bit (Dynamic Link Li-
brary) called lpl.dll (lplj.dll for Java). These DLLs allows the user to
other language, for example C++, Java, etc. This chapter is an overview
basic knowledge. The library exports procedures to access and modify LPL
stdcall
The dynamic link library of LPL exports the following functions (note that
procedure LPLsetLicense(s:pChar);
procedure LPLsetCallbacks(c:TProc; w:TProcC);
procedure LPLinitParam();
procedure LPLinit(Fn:pChar; maxt,maxa,maxr:integer);
function LPLcompile():integer;
function LPLcompileWithCallbacks(c:TProc; w:TProcC):integer;
procedure LPLfree;
function LPLwhere:integer;
procedure LPLgetErrMessage(n:integer; var msg:pChar);
function LPLgetError:integer;
procedure LPLsetError(n:integer);
function LPLgetParam(attr:integer):double;
procedure LPLgetParamS(which:integer; var sP:pChar);
185
186 CHAPTER 10. RUNTIME LIBRARY OF LPL
procedure LPLsetFocus(name:pChar);
function LPLgetGenus:integer;
procedure LPLgetAttr(attr:integer; var sP: pChar);
function LPLnextFocus(genus:integer):integer;
function LPLnextPosition(i:integer):integer;
procedure LPLgetName(opt:integer; var sP:pChar);
function LPLgetValue(attr:integer):double;
procedure LPLgetValueS(attr:integer; var sP:pChar);
procedure LPLPivotSetParam(s:pChar);
function LPLPivotGetParam(which:integer):integer;
procedure LPLPivotInit(var w,h:integer);
function LPLPivotX:integer;
function LPLPivotY:integer;
function LPLPivotData:pChar;
procedure LPLsetSelect(n,what:integer);
procedure LPLEncryptFile(FileName,Key:pChar; encr:integer);
integer 4 bytes
double 8 bytes oat point
pChar pointer to a null-terminated string
TProc pointer to a parameterless procedure (4 bytes)
TProcW pointer to procedure(s:pChar); stdcall; (4
bytes)
char 2 bytes char (Unicode)
var pChar means also a null terminated string, the caller must reserve
enough space to receive the string.
Certain procedures must be called in a specic order. Call the LPLsetLicense
function rst to set the license and the LPLsetCallbacks to specify the call-
back functions. Then LPLinit must be called to allocate the memory and
to initialize all variables. Next one may call LPLcompile or LPLsolve. After
these calls all model and solution information can be queried used various
functions. If the error value at the return time of one of them is dier-
ent from zero which means that an error occurred then one can call
LPLgetErrorMessage and LPLgetError to nd out more about the specic error.
Finally, before leaving the library, one must call LPLfree to free the memory
as var x: pChar. In this case, the user only needs to pass a pointer to a
memory location where he must allocate space before the call. The proce-
the client's responsibility to allocate enough space. The procedures are now
LPLsetLicense allows one to include a license key to the library. The pa-
rameter s is the license key (the string that is in the lpl.lic le). Alterna-
tively, the license le lpl.lic must be present and found by the application.
LPLsetCallbacks c
allows the user to set the callback ( ) and to redirect
the output of the LPL messages during the compilation ( w). The procedure
empty callback procedure is executed (nothing is done). The user can hook
his own procedure here to allow him to get the control periodically while
empty, w or ww. All messages are handled by the callback procedure w:TprocC
(second argument of LPLsetCallbacks). The user can write his own write
procedure and redirect these messages. Example: Suppose the user writes
...
LPLsetCallbacks(MyCallback,MyWriteToLog);
...
All LPL messages will be printed wherever writeln writes. The MyWrite-
could be written into a LOG-window (like in lplw.exe) which uses this same
WithCallbacks instead.
that includes lpl.dll (model name, compiler switches) and passes them to
called as:
MyProg test.lpl ww
then LPL's (1) the model name ('test.lpl') and (2) LPL's compiler switches
LPLinit allocates memory and initializes the internal store of LPL. The
LPL has an automatic allocation mechanism for memory and the user does
not need to do something special. Assigning the three parameter maxt, maxa
the best choice. LPL then will allocate a default amount of memory. If
later in the run this turns out to be too small then LPL's memory manager
minimal values of the three parameters are reported at the end of a run in the
lpllog.txt le (option wwvv). The user of lpl.dll could then copy these thee
the procedure LPLinit as model name. Before calling, one can call LPLset-
pile and/or run the model, an error is generated and the return value is the
sage. This number reects an error message in the text le lplmsg.txt. The
comes with two further parameters (the two callback parameters in LPLset-
LPLfree frees the memory and clears the LPL store completely. It should
be called once at the end. LPLinit and LPLfree should be used in pair.
After a call to LPLfree, one can again call LPLinit to reallocate the memory
compiler:
189
2 After parsing
6 while parsing
7 while running
9 while solving
within the le lplmsg.txt. The second parameter is the returned message.
LPLsetError can be used to set an error (in particular the error 599 (user
abort). But this works only if no error has been occurred prior to this call.
Hence, it can be called only once, any other call has no eect. The procedure
program lplw.exe):
procedure MyCallBack;
begin
case LPLwhere of
0: Form.Label2.Caption:='No model';
1: Form.Label2.Caption:='LPL kernel initialized';
2: Form.Label2.Caption:='Model parsed';
3: Form.Label2.Caption:='Model ran';
4: Form.Label2.Caption:='Model ran/instance created';
6: Form.Label2.Caption:='parsing...';
7: Form.Label2.Caption:='running...';
8: Form.Label2.Caption:='constraint generating...';
9: Form.Label2.Caption:='solving...';
10..19: Form.Label2.Caption:='Multi-Snapshot Analysis';
end;
SouForm.Update;
periodically in which state the LPL compiler is and returns a message to the
data from LPL as double. The function returns the following value for the
parameter attr :
5 optimal value
11 number of variables
14 number of constraints
dierent information pieces from the LPL kernel depending on the rst pa-
sP.
it. If the parameter which is the number as follows then the following infor-
1 the modelname
only.)
otherwise do nothing
191
the appropriate solver and writes the solution to an LPX-le then exits.
parameter add is an integer. If add is zero then LPL's data store is cleared
and replaced by the data in the snapshot. If add is dierent from zero, then
LPL store of a model. Make sure that the empty database access.mdb is
The following procedures work with a focus , that is, an internal pointer
to a given entity of the model. This pointer can be set by the procedure
can set the focus to the beginning calling LPLsetFocus(); that is calling
LPLsetFocus with an empty string parameter. Note that the function works
While running a model, the focus is set automatically to the actual execut-
ing statement. This allows the user to access the attributes of the actual
ers). Note that (since LPL is case-sensitive) the name must exactly match
As an example let us run through the whole model an collect all set names.
sP. Note that the attribute is returned exactly as it is stored in the source
LPLgetGenus returns the genus of the focused entity. The genus return
193
the next position within the datacube exists or not. (see example below).
It returns a string from the focused entity that is the instance name as a
It returns a value from the focused entity. The parameter attr are dened
at GetValue(r,a).
It returns a string for the focused entity. The parameter attr is dened at
GetValueS(r,a).
The following example runs through all variables and returns the names the
is set, then default parameters are used. The parameter s species which of
the pivot-table parameters has to be set. One can call the function several
times to set various pivot-table parameters or one can call it once where the
LPLPivotGetParam
BCa=x a= 1..6, x>0 Backcolor, default: ’BCa=..’
must be called before the next three functions. It returns the size of the
LPLPivotX LPLPivotY
and return the (x,y)-position of the current pivot
LPLPivotData returns the content of the (x,y) cell. After the data has
been returned, this function advances to the next (non-empty) (x,y) cell.
LPLPivotX returns -1, if the end of the table has been reached. Example
LPLPivotInit(w,h);
while LPLPivotX<>-1 do begin
x:= LPLPivotX; y:= LPLPivotY;
Grid.Cell[x,y] := LPLPivotData;
end;
The set must be in the focus. The parameter n is the n-th element of the
set. If n is zero then the selection is applied to all elements. The parameter
a le is encrypted the same key must be used to decrypt it again. The last
to load true 32-dll (or a 64-bit dll library. Several examples are given.
easily using the LPL library lpl.dll. The complete source code of lplc.exe
(using the library) in Delphi would be:
begin
LPLsetCallbacks(MyCallBack,MyWrite);
LPLinitParam();
LPLinit('alloy.lpl',0,0,0);
LPLcompile();
LPLfree;
end.
nel (LPLinit), then it compiles and runs the model (LPLcompile) and nally
cleanup the LPL kernel (LPLfree) and exits. Hence, this implements a com-
lplc MyModel ww
MyModel is a LPL-le and ww are the compiler switches. The two param-
eters MyModel and ww are automatically handled and read by the LPLin-
itParam procedure.
Option Explicit
Private Declare Sub LPLsetCallbacks Lib "lpl" (ByVal cl As Long, ByVal wl As Long)
Private Declare Sub LPLinit Lib "lpl" (ByVal Fn As String, _
ByVal maxa As Long, ByVal maxt As Long, ByVal maxr As Long)
Private Declare Function LPLcompile Lib "lpl" () As Long
Private Declare Sub LPLfree Lib "lpl" ()
Private Declare Function LPLwhere Lib "lpl" () As Long
Private Declare Sub LPLsetError Lib "lpl" (err As Long)
Private Declare Sub LPLgetParamS Lib "lpl" (ByVal n As Long, s As String)
197
Sub main()
AbortBottonClick = False
Compile
End Sub
A call to the routine Main() will call the LPL-compiler, generate a MPS-
le or a LPO-le (depending on the compiler switches), call the solver, and
nally write the result into the NOM-le exactly as from the executable
lplc.exe. Furthermore, all LPL callback messages are written into the Im-
alloy.lpl using C++. It does it just like the lplc.exe program from the LPL
198 CHAPTER 10. RUNTIME LIBRARY OF LPL
or somewhere that it could be found from this code. The complete code of
//-----------------------------------------------------------------------
// Language: C++, Win32API
// Date: 06.03.06
//-----------------------------------------------------------------------
// Language: C++, Win32API
int CallLplDll(void)
{
// Define types of function pointers to imported DLL functions:
typedef void (CALLBACK* LPFNDLL_LPLinit)(LPCSTR, INT, INT, INT);
typedef INT (CALLBACK* LPFNDLL_LPLcompile)(void);
typedef void (CALLBACK* LPFNDLL_LPLfree)(void);
FreeLibrary(hDll);
return 0;
}
//-----------------------------------------------------------------------
braries are identical from the functional point of view. Java needs a special
signatures. See le NativeLPL.java for the correct signature. On the base of
the class NativeLPL and the two interfaces LogCallback and LPLCallback
(as displayed above), one can implement, for example, the complete LPL
2. Copy lplj.dll and alloy.lpl into that folder also (if they are not there
book has been prepared, the user can download it at LPLS.ipynb. A addi-
tional Jupyter Notebook for the Julia kernel is available at: LPLSJ.ipynb
Chapter 11
The following symbols are meta-symbols (are not part of the LPL syntax),
| means or
... (in "A" | ... | "Z") means all letters from "A" to "Z"
" encloses a literal (except """, which means the character ")
All other symbols are part of LPL. Reserved words are boldface. The starting
symbol is Model.
201
202 CHAPTER 11. APPENDIX A: LPL SYNTAX
111, 1984.
205