Using the values of variable in the objective function before optimizing
AnsweredHi!
I am facing a problem to multiply a term in objective function. My objective function is :
\[\begin{equation}
\min \sum_{t=1}^T p_{t} * (1+r) * y_{t}
\end{equation}\]
where \(p\) is the price, \(y\) is the quantity (decision variable) and \(r\) is the price surcharge. \(t\) is the index for time periods.
The problem is that the value of \(r\) depends on between which interval the value of \(y\) (decision variable) lies as shown by the following piecewise function.
\[\begin{equation}
r_t (Y_t) = \begin{cases} 0 & \mathrm{if }\; Y_t \leq b_0 \\
0.05 & \mathrm{if }\; b_0 < Y_t \leq b_1 \\
0.1 & \mathrm{if }\; b_1 < Y_t \leq b_2\\
... & \mathrm{if }\; ...
\end{cases}
\end{equation}\]
where \(b_0\), \(b_1\) etc. are set of quantity intervals = [0, 50, 100, 150,..]
Since we don't have the values of \(y\) until at the point where objective function is specified (cause value of decision variables) are only available once we give call to optimize m.optimize(). So, how we could program this in Python interface.
Any leads will be highly appreciated. Thanks in advance.
-
Official comment
This post is more than three years old. Some information may not be up to date. For current information, please check the Gurobi Documentation or Knowledge Base. If you need more help, please create a new post in the community forum. Or why not try our AI Gurobot?. -
Hi Syed,
You should be able to use the piecewise-linear constraint constructor Model.addGenConstrPWL() to model such a formulation. Here's some more information on piecewise-linear functions:
I hope that helps.
Cheers,
Matthias0 -
This is a duplicate and also handled over at OR-Exchange: optimization - Using the values of variable in the objective function before optimizing - Operations Research Stack Exchange
0 -
Hi Matthias,
Thanks for the answer. Could you please provide a clue as to how we could formulate piecewise objective function for this problem. I went through the examples mentioned but can't relate as to how I could apply for in my case.
Secondly, when developing piecewise objectives, where do we specify the objective function to be maximize or minimize as I can't seem to find it in the example of piecewise.py?
0 -
This post is continued in this post.
0
Post is closed for comments.
Comments
5 comments