offset on my data

29 views
Skip to first unread message

Mifthahul Janna Rosyid

unread,
Nov 5, 2023, 8:52:11 AM11/5/23
to AMPL Modeling Language
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} :
the model.png

I have input the data base on that param:Screenshot 2023-11-05 171032.png

and it keep making errors like thisScreenshot 2023-11-05 171117.png

AMPL Google Group

unread,
Nov 6, 2023, 11:34:21 AM11/6/23
to AMPL Modeling Language
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.


--
Robert Fourer

We're switching to a new, enhanced user forum.
Join it now at discuss.ampl.com.
{#HS:2411384442-120412#}

Mifthahul Janna Rosyid

unread,
Nov 7, 2023, 9:08:55 AM11/7/23
to AMPL Modeling Language
okey, thank you very much robert 

Mifthahul Janna Rosyid

unread,
Nov 7, 2023, 9:08:56 AM11/7/23
to AMPL Modeling Language
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:

#PARAMETER

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/INDEKS

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)

#PARAMETER (1)

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;

#VARIABLE

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;

#OBJECTIVE FUNCTION

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;

#CONSTRAINT

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

Screenshot 2023-11-07 111651.png
On Tuesday, November 7, 2023 at 12:34:21 AM UTC+8 AMPL Google Group wrote:

AMPL Google Group

unread,
Nov 7, 2023, 5:34:06 PM11/7/23
to AMPL Modeling Language
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.


--
Robert Fourer

We're switching to a new, enhanced user forum.
Join it now at discuss.ampl.com.
{#HS:2411384442-120412#}
On Tue, Nov 7, 2023 at 2:09 PM UTC, AMPL Modeling Language <am...@googlegroups.com> wrote:
okey, thank you very much robert

On Mon, Nov 6, 2023 at 4:33 PM UTC, AMPL Google Group <am...@googlegroups.com> wrote:
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.


--
Robert Fourer

We're switching to a new, enhanced user forum.
Join it now at discuss.ampl.com.
Reply all
Reply to author
Forward
0 new messages