Linearizing max function in a constraint

390 views
Skip to first unread message

bt_sb

unread,
Apr 6, 2021, 10:39:14 AM4/6/21
to am...@googlegroups.com
I have a variable R, which is not part of the objective function. I want to
write a constraint so that R is set to be the maximum pmax value in the
below constraint. My problem is minimization and I am linearizing the R =
max{pmax[i]} as follows:

subject to {i in UNIT, t in TIME}:
R >= pmax[i,t]*U[i,t];

subject to {i in UNIT, t in TIME}:
some_variable >= R;

where, U[i,t] are binary variables. However, when I run the program R is set
to a value that is larger than the largest pmax value. I want R to be
exactly equal to the maximum pmax value. How do I achieve that in AMPL?
Thank you in advance.



--
Sent from: http://ampl.996311.n3.nabble.com/

AMPL Google Group

unread,
Apr 7, 2021, 1:31:21 PM4/7/21
to AMPL Modeling Language
The constraint "R >= pmax[i,t]*U[i,t]" for all i in UNIT, t in TIME is equivalent to R >= max {i in UNIT, t in TIME} >= pmax[i,t]*U[i,t]". Since your model, with this constraint, gives an optimum where R is greater than the max, you will need a separate constraint that implies R <= the max. That will require some additional binary variables:

var Z {i in UNIT, t in TIME} binary;
subject to Rge {i in UNIT, t in TIME}: R >= pmax[i,t]*U[i,t];
subject to Rle {i in UNIT, t in TIME}: R <= pmax[i,t]*U[i,t] + M*(1-Z[i,t]);
subject to Z1: sum {i in UNIT, t in TIME} Z[i,t] = 1;


Constraint Z1 requires exactly one variable Z[i,t] to equal 1, and the other constraints can be satisfied only if the corresponding pmax[i,t] * U[i,t] is maximal. M should be taken as some large value, such as the difference between the largest and smallest possible value of pmax[i,t] * U[i,t] for any i and t.


--
Robert Fourer
am...@googlegroups.com
{#HS:1475722320-103349#}

bt_sb

unread,
Apr 8, 2021, 5:21:05 PM4/8/21
to am...@googlegroups.com
Thank you Dr. Fourer!
Reply all
Reply to author
Forward
0 new messages