Developing a LINGO Model

For our sample model, we will create a small, product mix example.  Let's imagine that the CompuQuick Corporation produces two models of computers - Standard and Turbo.  CompuQuick can sell every Standard unit it produces for a profit contribution of $100, and each Turbo unit for a contribution of $150.  At the CompuQuick factory, the Standard computer production line can produce, at most, 100 computers per day.  At the same time, the Turbo computer production line can turn out 120 computers per day.  Furthermore, CompuQuick has a limited supply of daily labor.  In particular, there is a total of 160 hours of labor available each day.  Standard computers require 1 hour of labor, while Turbo computers are relatively more labor intense requiring 2 hours of labor.  The problem for CompuQuick is to determine the mix of Standard and Turbo computers to produce each day to maximize total profit without exceeding line and labor capacity limits.

In general, an optimization model will consist of the following three items:

Objective Function -- The objective function is a formula that expresses exactly what it is you want to optimize.  In business oriented models, this will usually be a profit function you wish to maximize, or a cost function you want to minimize.  Models may have, at most, one objective function.  In the case of our CompuQuick example, the objective function will compute the company's profit as a function of the output of Standards and Turbos.
Variables -- Variables are the quantities you have under your control.  You must decide what the best values of the variables are.  For this reason, variables are sometimes also called decision variables.  The goal of optimization is to find the values of a model's variables that generate the best value for the objective function, subject to any limiting conditions placed on the variables.  We will have two variables in our example--one corresponding to the number of Standards to produce and the other corresponding to the number of Turbos to produce.
Constraints -- Almost without exception there will be some limit on the values the variables in a model can assume--at least one resource will be limited (e.g., time, raw materials, your department's budget, etc.).  These limits are expressed in terms of formulas that are a function of the model's variables.  These formulas are referred to as constraints because they constrain the values the variables can take.  In our CompuQuick example, we will have one constraint for each of our production lines and one constraint on the total labor used.

We will now construct the objective function for our example.  We will let the variables STANDARD and TURBO denote the number of Standard and Turbo computers to produce, respectively.  CompuQuick's objective is to maximize total profit.  Total profit is calculated as the sum of the profit contribution of the Standard computer ($100) multiplied by the total Standard computers produced (STANDARD) and the profit contribution of the Turbo computer ($150) multiplied by the total Turbo computers produced (TURBO).  Finally, we tell LINGO we want to maximize an objective function by preceding it with "MAX =".  Therefore, our objective function is written on the first line of our model window as:

MAX = 100 * STANDARD + 150 * TURBO;

Note: Each mathematical expression in LINGO is terminated with a semicolon.  These semicolons are required.  Your model will not solve without them.  For more information on the syntax of LINGO, see below.

Next, we must input our constraints on line capacity and labor supply.  The number of Standard and Turbo computers produced must be constrained to the production line limits of 100 and 120, respectively.  Do this by entering the following two constraints just below the objective function:

STANDARD <= 100;

TURBO <= 120;

In words, the first constraint says the number of Standard computers produced daily (STANDARD) must be less-than-or-equal-to (<=) the production line capacity of 100.  Likewise, the second constraint says the number of Turbo computers produced daily (TURBO) must be less-than-or-equal-to (<=) its line capacity of 120.

Note: Since most computers do not have less-than-or-equal-to keys (), LINGO has adopted the convention of using the two character symbol <= to denote .  As an alternative, you may simply enter < to signify less-than-or-equal-to.  In a similar manner, >= or > are used to signify greater-than-or-equal-to ().

The final constraint on the amount of labor used can be expressed as:

STANDARD + 2 * TURBO <= 160;

Specifically, the total number of labor hours used (STANDARD + 2 * TURBO) must be less-than-or-equal-to (<=) the amount of labor hours available of 160.

After entering the above and entering comments to improve the readability of the model, your model window should look like the following:

entermodelxp

An expression may be broken up into as many lines as you want, but the expression must be terminated with a semicolon.  As an example, we could have used two lines rather than just one to contain the objective function:

MAX = 100 * STANDARD

+ 150 * TURBO;

We have also entered some comments to improve the readability of our model.  Comments begin with an exclamation point (!) and end with a semicolon (;).  All text between an exclamation point and terminating semicolon is ignored by LINGO.  Comments can occupy more than one line and can share lines with other LINGO expressions.  For example:

X = 1.5 * Y + Z / 2 * Y; !This is a comment;

X = 1.5 * !This is a comment in the middle

of a constraint; Y + Z / 2 * Y;

You may have noticed we used all uppercase letters for our variable names.  This is not a requirement.  LINGO does not distinguish between uppercase and lowercase in variable names.  Thus, the following variable names would all be considered equivalent:

TURBO

Turbo

turbo

When constructing variable names in LINGO, all names must begin with an alphabetic character (A-Z).  Subsequent characters may be either alphabetic, numeric (0-9), or the underscore (_).  Names may be up to 64 characters in length.

A final feature you will notice is that LINGO’s editor is "syntax aware." In other words, when it encounters LINGO keywords it displays them in blue, comments are displayed in green, and all remaining text is displayed in black.  Matching parentheses are also highlighted in red when you place the cursor immediately following a parenthesis.  You should find this feature useful in tracking down syntax errors in your models.