Compare the difference in objective with different data

7 views
Skip to first unread message

林暐竣(Lin)

unread,
Oct 28, 2022, 10:43:47 AM10/28/22
to AMPL Modeling Language
Dear all,
  I want to compare the difference in objective with two data files in the same .mod and .run files. I have solve objective in same .mod file with two data files Individually. How can I count the difference in objective between them. Please let me know how to store the objective value in .run files in order to compare them. 

Thank you.

螢幕擷取畫面 2022-10-28 215302.png

AMPL Google Group

unread,
Oct 28, 2022, 12:56:46 PM10/28/22
to AMPL Modeling Language
Before the first solve, define a parameter where you will store the objective values. For example,

param ObjVal {1..2};

Suppose that your objective function is named TotalCost, Then after the first solve, save the objective value with this command:

let ObjVal[1] := TotalCost;

After the second solve, save the value with this command:

let ObjVal[2] := TotalCost;

At any later point in your .run file, the difference between the two objective values is given by this AMPL expression:

abs(ObjVal[1] - ObjVal[2])

Of course, you should substitute the actual name of your objective function for "TotalCost" in this example. Also, you can use ObjVal[1] and ObjVal[2] in other expressions besides the one shown in the example above.


--
Robert Fourer
am...@googlegroups.com
{#HS:2051444835-112552#}

林暐竣

unread,
Oct 29, 2022, 8:58:31 AM10/29/22
to am...@googlegroups.com
Thank you for your help. I have handled this problem according to you.

螢幕擷取畫面 2022-10-29 075051.png



AMPL Google Group <am...@googlegroups.com> 於 2022年10月29日 週六 凌晨12:56寫道:
--
You received this message because you are subscribed to a topic in the Google Groups "AMPL Modeling Language" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/ampl/-AOM3Tu1pCk/unsubscribe.
To unsubscribe from this group and all its topics, send an email to ampl+uns...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ampl/reply-77152-2051444835-6098940726-1666976204-1262826070%40helpscout.net.
Reply all
Reply to author
Forward
0 new messages