How to write this in ampl

42 views
Skip to first unread message

Mifthahul Janna Rosyid

unread,
Sep 23, 2023, 11:05:10 AM9/23/23
to AMPL Modeling Language
Hi, i got confused about how to write this objective function in Ampl, while CAL is for kilocalories. Would you mind help me?
Screenshot 2023-09-23 110418.jpgScreenshot 2023-09-23 110457.jpgScreenshot 2023-09-23 110518.jpgScreenshot 2023-09-23 111036.jpg

AMPL Google Group

unread,
Sep 25, 2023, 3:58:41 PM9/25/23
to AMPL Modeling Language
The description says, "We define variables Rk . . ." but the expression for CAL refers to Rkt. The index "t" is not defined in the CAL expression, so maybe Rk should be used in that expression instead. Then the AMPL expression for minimizing calories could be written

minimize CAL: (sum {k in COMMOD} nutval[k,"energy"] * R[k]) / card(T);

(The function "card" computes the cardinality of the set T, which is just the number of members in the set.) Alternatively, if Rkt is correct, then you need to define t by, for example by summing over all t in T:

minimize CAL: (sum {k in COMMOD, t in T} nutval[k,"energy"] * R[k,t]) / card(T);

You will need to use your knowledge of the problem to determine which expression is correct.


--
Robert Fourer

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

Mifthahul Janna Rosyid

unread,
Nov 5, 2023, 8:52:11 AM11/5/23
to AMPL Modeling Language
Hi, i got trouble again. Could you fix this error? 
T2.dat, line 110 (offset 5610):
irregular : ... : header
context: param Cost_Transportation >>> := <<< #cost transportation (m,d,t)

im trying to write this kind of parameter 
param Cost_Transportation {M, D, T};

then i input the data on my ampl like this: 
Screenshot (1439).png

AMPL Google Group

unread,
Nov 6, 2023, 11:36:15 AM11/6/23
to AMPL Modeling Language
See the comment in your other question about this.


--
Robert Fourer

We're switching to a new, enhanced user forum.
Join it now at discuss.ampl.com.
{#HS:2369867371-119574#}
On Sun, Nov 5, 2023 at 1:52 PM UTC, AMPL Modeling Language <am...@googlegroups.com> wrote:
Hi, i got trouble again. Could you fix this error?
T2.dat, line 110 (offset 5610):
irregular : ... : header
context: param Cost_Transportation >>> := <<< #cost transportation (m,d,t)
im trying to write this kind of parameter
param Cost_Transportation {M, D, T};

then i input the data on my ampl like this:
Screenshot (1439).png

On Mon, Sep 25, 2023 at 7:58 PM UTC, AMPL Google Group <am...@googlegroups.com> wrote:
The description says, "We define variables Rk . . ." but the expression for CAL refers to Rkt. The index "t" is not defined in the CAL expression, so maybe Rk should be used in that expression instead. Then the AMPL expression for minimizing calories could be written

minimize CAL: (sum {k in COMMOD} nutval[k,"energy"] * R[k]) / card(T);

(The function "card" computes the cardinality of the set T, which is just the number of members in the set.) Alternatively, if Rkt is correct, then you need to define t by, for example by summing over all t in T:

minimize CAL: (sum {k in COMMOD, t in T} nutval[k,"energy"] * R[k,t]) / card(T);

You will need to use your knowledge of the problem to determine which expression is correct.


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