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