Hi,
I can't seem to wrap my head around an objective function formulation using Python, to be solved using Gurobi. My decision variables are binary and I would like to maximize the value of choosing those variables while penalizing the objective function when the amount of variables chosen (value equal to 1) is far from a certain constant. For example, letting x_i be the 0-1 decision variable,
max (sum_i v_i*x_i) - penalty * |(sum_i x_i) - constant|
where v_i is the value of choosing variable i and I am reducing the objective function by penalty times the distance between the number of chosen variables and a constant.
using model.addVar, I have no problem formulating the first sum, but after that, should I be making a new variable to encapsulate the whole penalty expression? I also have trouble thinking about formulating the absolute expression, as I'm not sure how to say "if sum_ix_i>=constant" when formulating using addVar.
Maybe I'm lacking some knowledge in using another way of formulating the constraints, as far as I know, I can't formulate objective functions using linear expressions.
Thanks for your help,
Putra