Getting the value of the objective from AMPL console

15 views
Skip to first unread message

Fulya Trösser

unread,
Jul 9, 2022, 3:50:27 PM7/9/22
to AMPL Modeling Language
Hi,

I'm working with the AMPL console in the terminal window. I have a MIP for which I defined all the variables and constraints, and finally an objective function as follows:

minimize objective1_UnsatDemand: sum{d in Demands} Unsat[d];
objective objective1_UnsatDemand;

Then I run the "solve;" command, and get the optimal solution. What I want at this point is to fetch the value of objective1_UnsatDemand, define a new constraint:

subject to cstr_ObjUnsat:
sum{d in Demands} Unsat[d] <= objective1_UnsatDemand.val;

and then delete objective1_UnsatDemand and define a new objective function, to run the model with this new constraint above and the new objective function.

However, when I try to do so, I get the error below:

MIP.mod, line 214 (offset 8323):

   cstr_ObjUnsat must be redeclared without objective1_UnsatDemand.val because objective1_UnsatDemand is a defined variable.

context:  sum{d in Demands} Unsat[d] <=  >>> objective1_UnsatDemand.val; <<< 

Any help or workaround is much appreciated!

Thanks in advance,
Fulya


AMPL Google Group

unread,
Jul 10, 2022, 12:29:11 AM7/10/22
to AMPL Modeling Language
Your constraint "subject to cstr_ObjUnsat: sum{d in Demands} Unsat[d] <= objective1_UnsatDemand.val;" depends on objective1_UnsatDemand, so deleting objective1_UnsatDemand will cause an error.

However, a model can have more than one objective function. So in addition to defining cstr_ObjUnsat, you can define

minimize objective2_UnsatDemand: . . . ;
objective objective2_UnsatDemand;

where . . . is replaced by the expression for your second objective function. Then you can run "solve;" again, and the second objective will be optimized.


--
Robert Fourer
am...@googlegroups.com
{#HS:1944645602-110921#}
--
You received this message because you are subscribed to the Google Groups "AMPL Modeling Language" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ampl+uns...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ampl/6045ea81-081b-40ec-ad2d-942708884861n%40googlegroups.com.

Fulya Trösser

unread,
Jul 13, 2022, 2:43:42 AM7/13/22
to AMPL Modeling Language
Dear Robert,

Many thanks for your answer.

I can indeed do that, however, my problem of not being able to use the value of the first objective function as the right hand side of a new constraint persists. How can I do this?

Best regards,
Fulya

AMPL Google Group

unread,
Jul 13, 2022, 3:55:11 PM7/13/22
to AMPL Modeling Language
Try something like this, after solving the first time:

param obj1_unsatdemand;
let obj1_unsatdemand := objective1_UnsatDemand.val;

subject to cstr_ObjUnsat:
   sum {d in Demands} Unsat[d] <= obj1_unsatdemand;

minimize objective2_UnsatDemand: ... ;
objective objective2_UnsatDemand;
solve;


--
Robert Fourer
am...@googlegroups.com
{#HS:1944645602-110921#}
On Wed, Jul 13, 2022 at 6:43 AM UTC, AMPL Modeling Language <am...@googlegroups.com> wrote:
Dear Robert,

Many thanks for your answer.

I can indeed do that, however, my problem of not being able to use the value of the first objective function as the right hand side of a new constraint persists. How can I do this?

Best regards,
Fulya

On Sun, Jul 10, 2022 at 4:28 AM UTC, AMPL Google Group <am...@googlegroups.com> wrote:
Your constraint "subject to cstr_ObjUnsat: sum{d in Demands} Unsat[d] <= objective1_UnsatDemand.val;" depends on objective1_UnsatDemand, so deleting objective1_UnsatDemand will cause an error.

However, a model can have more than one objective function. So in addition to defining cstr_ObjUnsat, you can define

minimize objective2_UnsatDemand: . . . ;
objective objective2_UnsatDemand;

where . . . is replaced by the expression for your second objective function. Then you can run "solve;" again, and the second objective will be optimized.


--
Robert Fourer
am...@googlegroups.com
Reply all
Reply to author
Forward
0 new messages