LINDO lp files

The LINDO LP file format provides a facility for entering a problem in a natural, algebraic LP formulation from the keyboard. The problem can be modified and saved from within lpsolve. This procedure is one way to create a file in a format that lpsolve can read. An alternative technique is to create a similar file using a standard text editor and to read it into lpsolve.

The LINDO FILE format is provided as an input alternative to the MPS file format. An LP format file may be easier to generate than an MPS file if your problem already exists in an algebraic format or if you have an application that generates the problem file more readily in algebraic format (such as a C application).

Note that the LINDO FILE format is not the same as the lpsolve LP format. See LP file format for a description about the native lpsolve lp format. To read/write this format from lpsolve, you need an XLI (see External Language Interfaces). The XLI for the LINDO format is called xli_LINDO.

Options

The XLI accepts no options at this time.

Example

lp_solve -rxli xli_LINDO input.lpt
lp_solve -mps input.mps -wxli xli_LINDO output.lpt

Syntax Rules of the LINDO FILE Format

lpsolve will accept any problem saved in an ASCII file provided that it adheres to the following syntax rules.

The MPS file format is a column-oriented format. If a row-oriented format is more convenient, then the LINDO file format is of interest. The list of rules is rather short and easy to learn.

Flow of Control

The objective function must always be at the start of the model and is initiated with any of the following keywords:

MAX MIN
MAXIMIZE MINIMIZE
MAXIMISE MINIMISE

The end of the objective function and the beginning of the constraints are signified with any of the following keywords:

SUBJECT TO
SUCH THAT
S.T.
ST

The end of the constraints is signified with the word END.

Formatting

Variable names are limited to eight characters. Names must begin with an alphabetic character (A to Z), which may then be followed by up to seven additional characters. These additional characters may include anything with the exception of the following: ! ) + - = < >. As an example, the following names are valid:

XYZMY_VARA12SHIP.LA

whereas the following are not:

THISONEISTOOLONGA-HYPHEN1INFRONT

The first example contains more than eight characters, the second contains a forbidden hyphen, and the last example does not begin with an alphabetic character.

You may, optionally, name constraints in a model. Constraint names must follow the same conventions as variable names. To name a constraint, you must start the constraint with its name terminated with a right parenthesis. After the right parenthesis, you enter the constraint as before. As an example, the following constraint is given the name XBOUND:

    XBOUND) X < 10

Only five operators are recognized: plus (+), minus (-), greater than (>), less than (<), and equals (=). When you enter the strict inequality operators greater than (>) and less than (<), they will be interpreted as the loose inequality operators greater-than-or-equal-to () and less-than-or-equal-to (), respectively. This is because many keyboards do not have the loose inequality operators. Even for systems having the loose operators, they will not be recognized. However, if you prefer, you may enter ">=" (and "<=") in place of ">" (and "<").

Parentheses as indicators of a preferred order of precedence are not accepted. All operations are ordered from left to right.

Comments may be placed anywhere in a model. A comment is denoted by an exclamation mark. Anything following an exclamation mark on the current line will be considered a comment. For example:

    MAX 10 STD + 15 DLX   ! Max profit
    SUBJECT TO
    ! Here are our factory capacity constraints
    ! for Standard and Deluxe computers
        STD < 10
        DLX < 12
    ! Here is the constraint on labor availability
        STD + 2 DLX < 16
    END

Comments are allowed, but they will not be stored with the model. Therefore, if later an equivalent model will be written, the comments will be removed.

Constraints and the objective function may be split over multiple lines or combined on single lines. You may split a line anywhere except in the middle of a variable name or a coefficient. The following would be mathematically equivalent to our example (although not quite as easy to read):

    MAX
        10
        STD  + 15 DLX  SUBJECT TO
    STD
    <
    10
    DLX < 12  STD + 2
    DLX < 16 END

However, if the objective function appeared as follows:

    MAX 10 ST
    D + 1
    5 DLX
    SUBJECT TO

then an error would be returned because the variable STD is split between lines and the coefficient 15 is also.

Only constant values--not variables--are permitted on the right-hand side of a constraint equation. Thus, an entry such as:

    X > Y

would be rejected. Such an entry could be written as:

    X - Y > 0

Conversely, only variables and their coefficients are permitted on the left-hand side of constraints. For instance, the constraint:

    3X + 4Y - 10 = 0

is not permitted because of the constant term of -10 on the left-hand side. The constraint may be recast as:

    3X + 4Y = 10

By default, all variables have lower bounds of zero and upper bounds of infinity.

Optional Modeling Statements

In addition to the three required model components of an objective function, variables, and constraints, a number of other optional modeling statements may appear in a model following the END statement. These statements and their functions appear in the table below:

Model Statement Function
FREE <Variable> Removes all bounds on <Variable>, allowing <Variable> to take on any real value, positive or negative.
GIN <Variable> Makes <Variable> a general integer (i.e., restricts it to the set of nonnegative integers).
INT <Variable> Makes <Variable> binary (i.e., restricts it to be either 0 or 1).
SLB <Variable> <Value> Places a simple lower bound on <Variable> of <Value>.Use in place of constraints of form X = r.
SUB <Variable> <Value> Places a simple upper bound on <Variable> of <Value>.Use in place of constraints of form X = r.
TITLE <Title> Makes <Title> the title of the model.

Next, we will briefly illustrate the use of each of these statements.

FREE Statement

The default lower bound for a variable is 0. In other words, unless you specify otherwise, variables are not allowed to be negative. The FREE statement allows you to remove all bounds on a variable, so it may take on any real value, positive or negative.

The following small example illustrates the use of the FREE statement:

    MIN 5X + Y
    ST
        X+Y>5
        X-Y>7
    END
    FREE Y

Had we not set Y to be a free variable in this example, the optimal solution of X = 6 and Y = -1 would not have been found. Instead, given the default lower bound of 0 on Y, the solution X = 7 and Y = 0 would be returned.

GIN Statement

By default, all variables are assumed to be continuous. In other words, unless told otherwise, variables are assumed to be any nonnegative fractional number. In many applications, fractional values may be of little use (e.g., 2.5 employees). In these instances, you will want to make use of the general integer statement, GIN. The GIN statement followed by a variable name restricts the value of the variable to the nonnegative integers (0,1,2,...).

The following small example illustrates the use of the GIN statement:

    MAX 11X + 10Y
    ST
        2X + Y < 12
        X - 3Y > 1
    END
    GIN X
    GIN Y

Had we not specified X and Y to be general integers in this model, the optimal solution of X = 6 and Y = 0 would not have been found. Instead, X and Y would have been treated as continuous and returned the solution of X = 5.29 and Y = 1.43.

Note also that simply rounding the continuous solution to the nearest integer values does not yield the optimal solution in this example. In general, rounded continuous solutions may be nonoptimal and, at worst, infeasible. Based on this, one can imagine that it can be very time consuming to obtain the optimal solution to a model with many integer variables. In general, this is true, and you are best off utilizing the GIN feature only when absolutely necessary.

INT Statement

Using the INT statement restricts a variable to being either 0 or 1. These variables are often referred to as binary variables. In many applications, binary variables can be very useful in modeling all-or-nothing situations. Examples might include such things as taking on a fixed cost, building a new plant, or buying a minimum level of some resource to receive a quantity discount.

The following small example illustrates the use of the INT statement:

    MAX -100X + 20A + 12B
    ST
        A - 10X < 0
        A + B < 11
        B < 7
    END
    INT X     !Make X 0/1

Had we not specified X to be binary in this example, a solution of X = .4, A = 4, and B = 7 for an objective value of 124 would not have been returned. Forcing X to be binary, you might guess that the optimal solution would be for X to be 0 because .4 is closer to 0 than it is to 1. If we round X to 0 and optimize for A and B, we get an objective of 84. In reality, a considerably better solution is obtained at X = 1, A = 10, and B = 1 for an objective of 112.

In general, rounded continuous solutions may be nonoptimal and, at worst, infeasible. Based on this, one can imagine that it can be very time consuming to obtain the optimal solution to a model with many binary variables. In general, this is true and you are best off utilizing the INT feature only when absolutely necessary.

SUB and SLB Statements

If you do not specify otherwise, LINDO API assumes variables are continuous (bounded below by zero and unbounded from above). That is, variables can be any positive fractional number increasing indefinitely. In many applications, this assumption may not be realistic. Suppose your facilities limit the quantity produced of an item. In this case, the variable that represents the quantity produced is bounded from above. Or, suppose you want to allow for backordering in a system. An easy way to model this is to allow an inventory variable to go negative. In which case, you would like to circumvent the default lower bound of zero. The SUB and SLB statements are used to alter the bounds on a variable. SLB stands for Simple Lower Bound and is used to set lower bounds. Similarly, SUB stands for Simple Upper Bound and is used to set upper bounds.

The following small example illustrates the use of the SUB and SLB:

    MAX 20X + 30Y
    ST
        X + 2Y < 120
    END
    SLB X 20
    SUB X 50
    SLB Y 40
    SUB Y 70

In this example, we could have just as easily used constraints to represent the bounds. Specifically, we could have entered our small model as follows:

    MAX 20X + 30X
    ST
        X + 2Y < 120
        X > 20
        X < 50
        Y > 40
        Y < 70
    END

This formulation would yield the same results, but there are two points to keep in mind. First, SUBs and SLBs are handled implicitly by the solver, and, therefore, are more efficient from a performance point of view than constraints. Secondly, SUBs and SLBs do not count against the constraint limit, allowing you to solve larger models within that limit.

TITLE Statement

This statement is used to associate a title with a model. The title may be any alphanumeric string of up to 74 characters in length. Unlike all the other statements that must appear after the END statement, the TITLE statement may appear before the objective or after the END statement of a model.

Here is an example of a small model with a title:

    TITLE Your Title Here
    MAX 20X + 30Y
    ST
        X < 50
        Y < 60
        X + 2Y < 120
    END