Combine a piecewise linear objective function and linear objective function
AnsweredCombine a piecewise linear objective function and a linear objective function.
Currently, I have studied a model with a piecewise linear objective function.
Luckily, setPWLObj is working well.
However, I need to introduce an additional linear term in the objective function.
For example, let f(x) be the current piecewise linear objective function, and it is implemented as follows (Python):model.setPWLObj( var[t], breakpoints, y_values )
I want to add a linear function g(x) to the objective function. Let g(x) = x1+x2. How can I do this?
I already tried to use addGenConstrPWL.
I introduced a new variable, var_obj, and added the following constraints:model.addGenConstrPWL( var_obj[t], var[t], breakpoints, y_values )
and set the objective function as follows:model.setObjective( gp.quicksum( var_obj[t] for t in T ) , sense=GRB.MINIMIZE)
However, the results are weird.
Please help me.
-
Hi Jaehee,
In our PWL Python example you can see how this can be achieved.
https://docs.gurobi.com/projects/examples/en/current/examples/piecewise.html
The objective function in this example contains two PWL functions and linear function. If you write it to an LP file and open it in a text editor you will see the following objective:
__pwl(x) - y + __pwl(z)Kind Regards,
Riley0
Please sign in to leave a comment.
Comments
1 comment