Model Control

In this category we have two types of statements.  First are the SUBMODEL and ENDSUBMODEL statements used to identify submodels, which are separate models contained within larger models.  We also have the @SOLVE statement for use in solving submodels.

SUBMODEL and ENDSUBMODEL:

These two statements are used to bracket a submodel within a larger, composite model.  The SUBMODEL statement must be followed immediately by a unique name of up to 32 characters that follows the normal LINGO naming conventions.  The name must then be followed by a colon.  You must also place a ENDSUBMODEL statement immediately after the last statement of your submodel.   Submodels may only exist in the model section and are not allowed in data, init and calc sections. As an example, the following illustrates a submodel for solving a knapsack type model:

SUBMODEL Pattern_Gen:

  [R_OBJ] MAX = @SUM( FG(i): PRICE(i)* Y(i));

  [R_WIDTH] @SUM( FG(i): WIDTH(i)*Y(i)) <= RMWIDTH;

  @FOR( FG(i): @GIN(Y(i)));

ENDSUBMODEL

In this example, the submodel is titled Pattern_Gen and contains one objective, R_OBJ, one constraint, R_WIDTH, and one @FOR loop to force the Y variables to be general integers via the @GIN function.

@DEBUG( [SUBMODEL_NAME[, …, SUBMODEL_NAME_N]])

Infeasible or unbounded submodels may be debugged in a calc section with the use of the @DEBUG statement.  Refer to the Solver|Debug command for more information of model debugging.

If your model contains submodels, you can choose to debug a particular submodel by specifying its name as an argument to @DEBUG.  If desired, you may also specify more than one submodel name, in which case, LINGO will simultaneously debug all the specified models as one combined model.  If a submodel name is omitted, LINGO will solve all model statements occurring before the @DEBUG statement and not lying within a submodel section.  It is the user’s responsibility to make sure the submodels together make sense, e.g., at most one submodel in an @DEBUG invocation can have an objective function.

In the following example, we solve a small submodel and then invoke the debugger if the solution is found to be non-optimal:

MODEL:

 

SUBMODEL M:

  MIN = X + Y;

  X>4;

  Y<3;

  Y>X;

ENDSUBMODEL

 

CALC:

  @SOLVE( M);

  @IFC( @STATUS() #NE# 0: @DEBUG( M));

ENDCALC

 

END

Note: Submodels must be defined in the model prior to any references to them via the @DEBUG statement.

@SOLVE( [SUBMODEL_NAME[, …, SUBMODEL_NAME_N]])

Submodels may be solved in a calc section with the use of the @SOLVE statement.  If your model contains submodels, you can choose to solve a particular submodel by specifying its name as an argument to @SOLVE.  If desired, you may also specify more than one submodel name, in which case, LINGO will simultaneously solve all the specified models as one combined model.  If a submodel name is omitted, LINGO will solve all model statements occurring before the @SOLVE statement and not lying within a submodel section.  It is the user’s responsibility to make sure the submodels together make sense, e.g., at most one submodel in an @SOLVE invocation can have an objective function.

As an example, to solve the submodel Pattern_Gen listed immediately above, you would add the following statement to a calc section:

@SOLVE( Pattern_Gen);

Note: Submodels must be defined in the model prior to any references to them via the @SOLVE statement.