Why do I get an “invalid subscript discarded” message when I display an AMPL parameter?

Either a data table gave values for the parameter with incorrect subscripts, or the parameter’s indexing set changed, causing some previously valid subscripts to become invalid. For example, in the diet.mod + diet.dat example (Figures 2-1 and 2-2) of the AMPL book, values of parameter cost are supplied for all eight members of set FOOD :

ampl: display cost; 
cost [*] := 
BEEF 3.19 FISH 2.29 MCH 1.89 SPG 1.99 CHK 2.59 HAM 2.89 MTL 1.99 TUR 2.49 
;

If you remove the member CHK from FOOD , using for example a let command, then you get a message that cost["CHK"] has also been dropped from the data:

ampl: let FOOD := FOOD diff {"CHK"}; 
ampl: display cost; 
Error executing "display" command: 
error processing param cost: invalid subscript cost['CHK'] discarded. 
cost [*] := 
BEEF 3.19 HAM 2.89 MTL 1.99 TUR 2.49 FISH 2.29 MCH 1.89 SPG 1.99

Since cost["CHK"] has now been dropped, no further error message will appear if you type display cost again.

To avoid error messages of this sort, you can define a more flexible set structure for your model as shown in dietflex.mod and dietflex.dat. The auxiliary set FOOD_DROP defaults to empty, so that the problem is solved for all foods; but you can change FOOD_DROP to {"CHK"} to solve without member CHK :

ampl: model dietflex.mod; 
ampl: data dietflex.dat; 
ampl: option show_stats 1; 

ampl: solve; 
8 variables, all linear 
6 constraints, all linear; 47 nonzeros 
        5 inequality constraints
        1 range constraint
1 linear objective; 8 nonzeros. 

MINOS 5.51: optimal solution found. 
13 iterations, objective 118.0594032 

ampl: let FOOD_DROP := {"CHK"}; 

ampl: solve; 
7 variables, all linear 
6 constraints, all linear; 42 nonzeros 
	5 inequality constraints
	1 range constraint
1 linear objective; 7 nonzeros. 

MINOS 5.51: optimal solution found. 
3 iterations, objective 117.3218891

Changing FOOD_DROP does not affect the set FOOD_ALL , and consequently all of the subscripts in the data remain valid.