# Using the LP format

The Interactive Optimizer supports LP file format to enter a problem.

Entering a new problem is basically like typing it on
a page, but there are a few rules to remember. These rules conform
to the CPLEX LP file format and are documented in the *CPLEX File Formats Reference Manual*.
LP format appears throughout this tutorial.

The problem should be entered in the following order:

## Objective function

Before entering the objective function, you must state whether the problem is a minimization or maximization. For this example, you type:

```
maximize
x1 + 2x2 + 3x3
```

You may type `minimize` or `maximize` on
the same line as the objective function, but you must separate them
by at least one space.

## Variable names

In the example, the variables are named simply `x1` , `x2` , `x3` ,
but you can give your variables more meaningful names such as `cars` or `gallons` .
The only limitations on variable names in LP format are that the names
must be no more than 255 characters long and use only the alphanumeric
characters (a-z, A-Z, 0-9) and certain symbols: ! " # $ % & (
) , . ; ? @ _ ‘ ’ { } ~. Any line with more than 510
characters is truncated.

A variable name cannot begin with a number or a period,
and there is one character combination that cannot be used: the letter `e` or `E` alone
or followed by a number or another `e` ,
since this notation is reserved for exponents. Thus, a variable cannot
be named `e24` nor `e9cats` nor `eels` nor
any other name with this pattern. This restriction applies only to
problems entered in LP format.

## Constraints

After you have entered the objective function, you can move on to the constraints. However, before you start entering the constraints, you must indicate that the subsequent lines are constraints by typing:

`subject to`

or

`st`

These terms can be placed alone on a line or on the same line as the first constraint if separated by at least one space. Now you can type in the constraints in the following way:

```
st
-x1 + x2 + x3 <= 20
x1 - 3x2 + x3 <= 30
```

## Constraint names

In this simple example, it is easy to keep track of the
small number of constraints, but for many problems, it may be advantageous
to name constraints so that they are easier to identify. You can do
so in CPLEX by typing a constraint name and a colon before the actual
constraint. If you do not give the constraints explicit names, CPLEX
will give them the default names `c1, c2, . . . ,
cn` . In the example, if you want to call the constraints `time` and `labor` ,
for example, enter the constraints like this:

```
st
time: -x1 + x2 + x3 <= 20
labor: x1 - 3x2 + x3 <= 30
```

Constraint names are subject to the same guidelines as
variable names. They must have no more than 255 characters, consist
of only allowed characters, and not begin with a number, a period,
or the letter `e` followed by a positive
or negative number or another `e` .

## Objective function names

The objective function can be named in the same manner
as constraints. The default name for the objective function is `obj`.
CPLEX assigns this name if no other is entered.

## Bounds

Finally, you must enter the lower and upper bounds on
the variables. If no bounds are specified, CPLEX will automatically
set the lower bound to 0 and the upper bound to +∞. You must
explicitly enter bounds only when the bounds differ from the default
values. In our example, the lower bound on `x1` is
0, which is the same as the default. The upper bound 40, however,
is not the default, so you must enter it explicitly. You must type `bounds` on
a separate line before you enter the bound information:

```
bounds
x1 <= 40
```

Since the bounds on `x2` and `x3` are
the same as the default bounds, there is no need to enter them. You
have finished entering the problem, so to indicate that the problem
is complete, type:

`end`

on the last line.

The `CPLEX>` prompt returns,
indicating that you can again enter a CPLEX command.

## Summary

Entering a problem in CPLEX is straightforward, provided that you observe a few simple rules:

The terms

`maximize`or`minimize`must precede the objective function; the term`subject to`must precede the constraints section; both must be separated from the beginning of each section by at least one space.The word

`bounds`must be alone on a line preceding the bounds section.On the final line of the problem,

`end`must appear.