indicator function in the objective?

1,318 views
Skip to first unread message

sverkunoff

unread,
Sep 23, 2011, 2:53:12 PM9/23/11
to am...@googlegroups.com
Suppose the objective function is 
sum {i in I} F[i] 
where F[i] should be f(x_i)+a if x_i>0 and f(x_i) otherwise, where x_i are the choice variables. What's a good way to implement this? (using KNITRO for a solver)

Thanks!

Robert Fourer

unread,
Sep 23, 2011, 6:30:49 PM9/23/11
to am...@googlegroups.com

Assuming a is positive and you are minimizing, you can write something like

 

   minimize obj: sum {i in I} f(x[i]) + a*y[i];

 

   subj to ydef {i in I}: x[i] <= U[i] * y[i];

 

where y is a binary variable (integer taking only the values 0 and 1), "f(x[i])" is replaced by some AMPL expression involving x[i], and U[i] is a good upper limit on the value of x[i] in an optimal solution.  (Setting U[i] much larger than necessary is likely to give unreliable results.)  When x[i] is positive the constraint will force y[i] to be one, and when x[i] is zero the objective will force y[i] to be zero.

 

For maximization with continuous x[i] the problem is not in general well defined, but for integer x[i] you can add a constraint like y[i] <= x[i] to force y[i] to zero when x[i] is zero.

 

This is a hard problem when f is nonlinear, but KNITRO has a good chance of being able to handle it if the problem is not too large and the function f is continuous.  If f is linear then it's another matter, and you're better off using a linear solver like CPLEX or Gurobi.

 

Bob Fourer

4...@ampl.com

 

 

From: am...@googlegroups.com [mailto:am...@googlegroups.com]

On Behalf Of sverkunoff
Sent: Friday, September 23, 2011 1:53 PM
To: am...@googlegroups.com
Subject: [AMPL 5064] indicator function in the objective?

sverkunoff

unread,
Sep 23, 2011, 8:59:05 PM9/23/11
to am...@googlegroups.com, 4...@ampl.com
Thank you for a quick response Bob! I should have said that f is nonlinear but continuous. x[i] are also continuous. Just a quick clarification: what you say about the maximization not being well defined - what if for maximization a<0? Seems like the same approach as you described for minimization should work?



Robert Fourer

unread,
Sep 26, 2011, 11:56:58 AM9/26/11
to am...@googlegroups.com

Certainly, the same approach should work to maximize when a < 0, since then minimizing the negative has the same form as the example I gave, and can be transformed with a binary variable in the same way.

 

The case to avoid would be something like

 

   Maximize  -x^2 + (if x <> 0 then 1 else 0)

 

since given any solution x = e there is a better solution x = e/2, yet x = 0 is definitely not the maximum.

 

Bob Fourer

4...@ampl.com

 

 

From: am...@googlegroups.com [mailto:am...@googlegroups.com]

On Behalf Of sverkunoff
Sent: Friday, September 23, 2011 7:59 PM
To: am...@googlegroups.com
Cc: 4...@ampl.com
Subject: Re: [AMPL 5067] indicator function in the objective?

Reply all
Reply to author
Forward
0 new messages