I am trying to implement a piecewise-linear objective in a gurobi optimization problem in python. When trying to get familiar with this method using the example from the gurobi web-site (http://examples.gurobi.com/production-scheduling/)
I got stuck and could not really solve the issue myself for several days. Now I hope that someone here can show me, where my interpretation is wrong.
The mentioned example optimizes the profit from the production of several goods with limited production capacity, especially a limited amount of working hours of the staff. However, the latter constraint is not hard, but, for some bonus payment, the possible work-hours can be expanded (this is the piecewise-linear function). In the general problem formulation, the problem looks like this:
profit = revenue−cost = ∑r(i)x(i)−cost(t)
, where r depicts the specific revenues for good “i" and x the share of this good, while the cost term provides potential extra cost for overtime. However, in the actual code, the objective misses the cost term, at least according to my understanding:
# Set objective
m.setObjective( quicksum(revenue[i]*x[i] for i in range(n)), GRB.MAXIMIZE)
I suspect that this is somehow introduced/ accounted for by the Piecewise-linear objective, but unfortunately, I just don’t get how.
# Set piecewise linear objective
nPts = 101
ti = []
costi = []
lb = 0
ub = maxhours;
for i in range(nPts):
ti.append(lb + (ub - lb) * i / (nPts - 1))
costi.append(-cost(ti[i], limithours, penalty))
m.setPWLObj(t, ti, costi)
m.optimize()
Are PWLObj always substracted from the main objective? Is there a way to e.g. multiply the PWLObj to the main objective function? I hope that I not just missed some trivial point (I am still pretty new to programming and optimizing alike). Thanks a lot for your time and support!