Once you remove all the syntax errors from your LINGO model, there is still one very important step required: model verification.  LINGO’s set-based modeling capabilities are very powerful, and they allow you to generate large, complex models quickly and easily.  However, when you first develop a model you will need to verify that the model being generated matches up to the model you actually intended to generate. Many set-based models can be quite complex, and it is highly likely that logic errors may creep into one or more expressions, thereby causing your generated model to be flawed. The GEN (short for generate) command is very useful for debugging such errors. It expands all of the model's compact set-based expressions and then writes out the full scalarbased equivalent of the LINGO model. The expanded model report explicitly lists all the generated constraints and variables in your model.  You will find that the Generate report can be an invaluable tool in tracking down errors.

As an example of the output from the generate command, consider the transportation model developed in Chapter 1:

MODEL:

! A 6 Warehouse 8 Vendor Transportation Problem;

SETS:

  WAREHOUSES: CAPACITY;

  VENDORS: DEMAND;

  LINKS( WAREHOUSES, VENDORS): COST, VOLUME;

ENDSETS

DATA:

  !set members;

  WAREHOUSES = WH1 WH2 WH3 WH4 WH5 WH6;

  VENDORS = V1 V2 V3 V4 V5 V6 V7 V8;

 

  !attribute values;

  CAPACITY = 60 55 51 43 41 52;

  DEMAND = 35 37 22 32 41 32 43 38;

  COST = 6 2 6 7 4 2 5 9

         4 9 5 3 8 5 8 2

         5 2 1 9 7 4 3 3

         7 6 7 3 9 2 7 1

         2 3 9 5 7 2 6 5

         5 5 2 2 8 1 4 3;

ENDDATA

! The objective;

  [OBJECTIVE] MIN = @SUM( LINKS( I, J):

   COST( I, J) * VOLUME( I, J));

! The demand constraints;

  @FOR( VENDORS( J): [DEMAND_ROW]

   @SUM( WAREHOUSES( I): VOLUME( I, J)) =

    DEMAND( J));

! The capacity constraints;

  @FOR( WAREHOUSES( I): [CAPACITY_ROW]

   @SUM( VENDORS( J): VOLUME( I, J)) <=

    CAPACITY( I));

END

Model: WIDGETS

The objective will generate one expression; there should be one demand constraint generated for each of the eight vendors and one supply constraint generated for each of the six warehouses, for a grand total of 15 rows in the expanded model.  Running the generate command to verify this reveals the following report:

MODEL:

  [OBJECTIVE] MIN= 6 * VOLUME_WH1_V1 + 2 * VOLUME_WH1_V2 + 6 *

  VOLUME_WH1_V3 + 7 * VOLUME_WH1_V4 + 4 * VOLUME_WH1_V5 + 2 *

  VOLUME_WH1_V6 + 5 * VOLUME_WH1_V7 + 9 * VOLUME_WH1_V8 + 4 *

  VOLUME_WH2_V1 + 9 * VOLUME_WH2_V2 + 5 * VOLUME_WH2_V3 + 3 *

  VOLUME_WH2_V4 + 8 * VOLUME_WH2_V5 + 5 * VOLUME_WH2_V6 + 8 *

  VOLUME_WH2_V7 + 2 * VOLUME_WH2_V8 + 5 * VOLUME_WH3_V1 + 2 *

  VOLUME_WH3_V2 + VOLUME_WH3_V3 + 9 * VOLUME_WH3_V4 + 7 *

  VOLUME_WH3_V5 + 4 * VOLUME_WH3_V6 + 3 * VOLUME_WH3_V7 + 3 *

  VOLUME_WH3_V8 + 7 * VOLUME_WH4_V1 + 6 * VOLUME_WH4_V2 + 7 *

  VOLUME_WH4_V3 + 3 * VOLUME_WH4_V4 + 9 * VOLUME_WH4_V5 + 2 *

  VOLUME_WH4_V6 + 7 * VOLUME_WH4_V7 + VOLUME_WH4_V8 + 2 *

  VOLUME_WH5_V1 + 3 * VOLUME_WH5_V2 + 9 * VOLUME_WH5_V3 + 5 *

  VOLUME_WH5_V4 + 7 * VOLUME_WH5_V5 + 2 * VOLUME_WH5_V6 + 6 *

  VOLUME_WH5_V7 + 5 * VOLUME_WH5_V8 + 5 * VOLUME_WH6_V1 + 5 *

  VOLUME_WH6_V2 + 2 * VOLUME_WH6_V3 + 2 * VOLUME_WH6_V4 + 8 *

  VOLUME_WH6_V5 + VOLUME_WH6_V6 + 4 * VOLUME_WH6_V7 + 3 *

  VOLUME_WH6_V8 ;

  [DEMAND_ROW_V1] VOLUME_WH1_V1 + VOLUME_WH2_V1 +

  VOLUME_WH3_V1 + VOLUME_WH4_V1 + VOLUME_WH5_V1 +

  VOLUME_WH6_V1 = 35 ;

  [DEMAND_ROW_V2] VOLUME_WH1_V2 + VOLUME_WH2_V2 +

  VOLUME_WH3_V2 + VOLUME_WH4_V2 + VOLUME_WH5_V2 +

  VOLUME_WH6_V2 = 37 ;

  [DEMAND_ROW_V3] VOLUME_WH1_V3 + VOLUME_WH2_V3 +

  VOLUME_WH3_V3 + VOLUME_WH4_V3 + VOLUME_WH5_V3 +

  VOLUME_WH6_V3 = 22 ;

  [DEMAND_ROW_V4] VOLUME_WH1_V4 + VOLUME_WH2_V4 +

  VOLUME_WH3_V4 + VOLUME_WH4_V4 + VOLUME_WH5_V4 +

  VOLUME_WH6_V4 = 32 ;

  [DEMAND_ROW_V5] VOLUME_WH1_V5 + VOLUME_WH2_V5 +

  VOLUME_WH3_V5 + VOLUME_WH4_V5 + VOLUME_WH5_V5 +

  VOLUME_WH6_V5 = 41 ;

  [DEMAND_ROW_V6] VOLUME_WH1_V6 + VOLUME_WH2_V6 +

  VOLUME_WH3_V6 + VOLUME_WH4_V6 + VOLUME_WH5_V6 +

  VOLUME_WH6_V6 = 32 ;

  [DEMAND_ROW_V7] VOLUME_WH1_V7 + VOLUME_WH2_V7 +

  VOLUME_WH3_V7 + VOLUME_WH4_V7 + VOLUME_WH5_V7 +

  VOLUME_WH6_V7 = 43 ;

  [DEMAND_ROW_V8] VOLUME_WH1_V8 + VOLUME_WH2_V8 +

  VOLUME_WH3_V8 + VOLUME_WH4_V8 + VOLUME_WH5_V8 +

  VOLUME_WH6_V8 = 38 ;

  [CAPACITY_ROW_WH1] VOLUME_WH1_V1 + VOLUME_WH1_V2 +

  VOLUME_WH1_V3 + VOLUME_WH1_V4 + VOLUME_WH1_V5 +

  VOLUME_WH1_V6 + VOLUME_WH1_V7 + VOLUME_WH1_V8 <= 60 ;

  [CAPACITY_ROW_WH2] VOLUME_WH2_V1 + VOLUME_WH2_V2 +

  VOLUME_WH2_V3 + VOLUME_WH2_V4 + VOLUME_WH2_V5 +

  VOLUME_WH2_V6 + VOLUME_WH2_V7 + VOLUME_WH2_V8 <= 55 ;

  [CAPACITY_ROW_WH3] VOLUME_WH3_V1 + VOLUME_WH3_V2 +

  VOLUME_WH3_V3 + VOLUME_WH3_V4 + VOLUME_WH3_V5 +

  VOLUME_WH3_V6 + VOLUME_WH3_V7 + VOLUME_WH3_V8 <= 51 ;

  [CAPACITY_ROW_WH4] VOLUME_WH4_V1 + VOLUME_WH4_V2 +

  VOLUME_WH4_V3 + VOLUME_WH4_V4 + VOLUME_WH4_V5 +

  VOLUME_WH4_V6 + VOLUME_WH4_V7 + VOLUME_WH4_V8 <= 43 ;

  [CAPACITY_ROW_WH5] VOLUME_WH5_V1 + VOLUME_WH5_V2 +

  VOLUME_WH5_V3 + VOLUME_WH5_V4 + VOLUME_WH5_V5 +

  VOLUME_WH5_V6 + VOLUME_WH5_V7 + VOLUME_WH5_V8 <= 41 ;

  [CAPACITY_ROW_WH6] VOLUME_WH6_V1 + VOLUME_WH6_V2 +

  VOLUME_WH6_V3 + VOLUME_WH6_V4 + VOLUME_WH6_V5 +

  VOLUME_WH6_V6 + VOLUME_WH6_V7 + VOLUME_WH6_V8 <= 52 ;

END

Model: WIDGETS

As expected, there are 15 rows in the generated model: [OBJECTIVE], [DEMAND_ROW_V1] through [DEMAND_ROW_V8], and [CAPACITY_ROW_WH1] through [CAPACITY_ROW_WH6].

As a side note, it’s interesting to compare the generated model to the original, set-based model.  We think most would agree that the set-based model is much easier to comprehend, thereby illustrating one of the primary benefits of modern algebraic languages over more traditional, scalar-based languages.

In addition to verifying that the correct

number of rows is being generated, you should also examine each of the rows to determine that the correct variables are appearing in each row along with their correct coefficients.

Note:The reports generated by the GEN command are valid LINGO models.  You may load Generate reports into LINGO and solve them as you would any other model.

One thing to keep in mind when examining generated model reports is that the LINGO model generator performs fixed variable reduction.  This means that any variables that are fixed in value are substituted out of the generated model.  For example, consider the simple model:

MODEL:

 MAX = 200 * WS + 300 * NC;

 WS = 60;

 NC <= 40;

 WS + 2 * NC <= 120;

END

If we generate this model we get the following, reduced model:

MODEL:

  MAX= 300 * NC + 12000 ;

  NC <= 40 ;

  2 * NC <= 60 ;

END

At first glance, it seems as if both the first constraint and the variable WS are missing from the generated model.  Note that by the first constraint in the original model (WS = 60), WS is fixed at a value of 60. The LINGO model generator exploits this fact to reduce the size of the generated model by substituting WS out of the formulation.  The final solution report will still contain the values for all the fixed variables, however, the fixed variables will not appear in the generated model report.  If you would like to suppress fixed variable reduction so that all variables appear in your generated model, you may do so via the Fixed Var Reduction option.

Note:To capture the results of the GEN command in a file, use the DIVERTcommand to open an output file before issuing the GEN command.