The primitive sets in this model are the nut types and the brands of mixed nuts. We can declare them in the sets section as follows:

SETS:

  NUTS: SUPPLY;

  BRANDS: PRICE, PRODUCE;

ENDSETS

The NUTS set has the single attribute SUPPLY, which we will use to store the daily supply of nuts in pounds. The BRANDS set has PRICE and PRODUCE attributes, where PRICE stores the selling price of the brands, and PRODUCE represents the decision variables of how many pounds of each brand to produce each day.

We need one more set, however, which is the dense derived set we have been promising. In order to input the brand formulas, we will need a two dimensional table defined on the nut types and the brands. To do this, we will generate a derived set named FORMULA from the cross of the NUTS and BRANDS sets. Adding this derived set, we get the completed sets section:

SETS:

  NUTS: SUPPLY;

  BRANDS: PRICE, PRODUCE;

  FORMULA( NUTS, BRANDS): OUNCES;

ENDSETS

We have titled the derived set FORMULA. It has the single attribute OUNCES, which will be used to store the ounces of nuts used per pound of each brand. Since we have not specified the members of this derived set, LINGO assumes we want the complete, dense set that includes all pairs of nuts and brands, for a total of eight (nut,brand) pairs.

Now that our sets are declared, we can move on to building the data section. We initialize our three sets, NUTS, BRANDS and FORMULA, as well as the two data attributes SUPPLY and PRICE as follows:

DATA:

  NUTS,     SUPPLY =

   PEANUTS   750

   CASHEWS   250;

 

  BRANDS,   PRICE =

   PAWN      2

   KNIGHT    3

   BISHOPP   4

   KING      5;

 

  FORMULA = 15 10  6  2

             1  6 10 14;

ENDDATA

With the sets and data established, we can begin to enter our objective function and constraints. The objective function of maximizing total revenue is straightforward. We can express this as:

MAX = @SUM( BRANDS( I): PRICE( I) * PRODUCE( I));

Our model has only one class of constraints: We can't use more nuts than we are supplied with on a daily basis. In words, we would like to ensure:

For each nut i, the number of pounds of nut i used must be

  less-than-or-equal-to the supply of nut i.

We can express this in LINGO as:

@FOR( NUTS( I):

@SUM( BRANDS( J):

 OUNCES( I, J) * PRODUCE( J) / 16) <= SUPPLY( I)

);

We divide the sum on the left-hand side by 16 to convert from ounces to pounds.