[AMPL 24864] offset on my data

Good day everyone.
I dont know what’s wrong on my data. It keep telling me there are some errors on my data. Most of them are caused by the 3x3 matrix Im trying to write. Can you fix it please?

This is my model. Im trying to make the data base on param Cost_Transportation {M, D, T} :

I have input the data base on that param:

and it keep making errors like this

Line 108 of T2.dat needs to have a ; character at the end. (The ; tells AMPL that the previous data table has ended, and that a new table starts with line 110. When the ; is missing, AMPL sees line 110 as part of the previous table, which results in the unexpected error that you see.)

Also, check you other tables in T2.dat to be sure that each one ends with a ; character.

okey, thank you very much robert

good day, i want to ask about the error. Can you help me with this?

Error executing “solve” command:

error processing objective Nutrient_Value_Score:

invalid subscript shortfall[18,1]

this is my code:


param num_commodity integer; # number of commodity (K)

param num_nutrition integer; # number of nutrition (N)

param num_local_market integer; # number of local market (M)

param num_distribution_center integer; # number of distibution center (D)

param num_cost_commodity integer; # number of cost commodity (C)

param num_month integer; # number of month (T)


set K := 1 … num_commodity; # set of commodity (k)

set N := 1 … num_nutrition; # set of nutrition (n)

set M := 1 … num_local_market; # set of local market (m)

set D := 1 … num_distribution_center; # set of distribution center (d)

set C := 1 … num_cost_commodity; # set of cost commodity (c)

set T := 1 … num_month; # set of time period (t)


param nutrient_value {K, N};

param cost_transportation {M, D, T};

param transportation_capacity {M, D, T};

param minimal_nutrient {N, T};

param cost_commodity {C};

param total_month;

param total_nutrition;


var ratio_commodity {K, T};

var flow_of_commodity {m in M, d in D, t in T} >= 0;

var nutrient_requirement {n in N} >= 0;

var shortfall {n in N, t in T} >= 0;

var overshoot {n in N, t in T} >= 0;

var shortfall_indicator {n in N, t in T} binary;


minimize total_operation_cost: sum {m in M, d in D, t in T} cost_transportation [m,d,t] * flow_of_commodity [m,d,t];

maximize kilocalories: sum {k in K, n in N, t in T} nutrient_value [k, n] * ratio_commodity [k, t] / total_month;

maximize nutrient_value_ccore: sum {k in K, n in K, t in T} (1 - shortfall [n,t]) / (total_nutrition * total_month) * 100;


subject to food_basket_optimize {n in N, t in T}:

sum {k in K} nutrient_value [k,n] * ratio_commodity [k,t] >= nutrient_requirement [n];

subject to capacity {m in M, d in D, k in K, t in T}:

sum {j in K} flow_of_commodity [m, d, t] <= transportation_capacity [m, d, t];

subject to supplied_nutrient {n in N, t in T}:

sum{k in K} nutrient_value [k,n] * ratio_commodity [k,t] = nutrient_requirement [n] * (1 - shortfall [n,t] + overshoot [n,t]);

subject to Shortfall {n in N, t in T}:

shortfall [n,t] <= shortfall_indicator [n,t];

subject to Overshoot {n in N, t in T}:

overshoot [n,t] <= (1 - shortfall [n,t]) * 10;

This is the data related to the shortfall

The “invalid subscript shortfall[18,1]” message appears because your model refers to shortfall[18,1], but that variable is not defined in your model. The reason this happens is that you write

var shortfall {n in N, t in T} >= 0;

but in the objective function nutrient_value_ccore you have

sum {k in K, n in K, t in T}
   (1 - shortfall[n,t]) / (total_nutrition * total_month) * 100

Since the variable is defined for n in N, you should be summing it over n in N instead:

sum {n in N, t in T}
   (1 - shortfall[n,t]) / (total_nutrition * total_month) * 100

Note that you should not have “k in K” in the summation, as there is no k in the expression that you are summing.