Reuse Expression of Existing Constraint to Build New Constraints
回答済みHello Team,
We have an optimization problem that requires using leftover inventory from previous day in calculation of inventory of next day. And the overall constraint logic is the net inventory any day for all combination of products need to be >=0.
Since the calculation of leftover inventory is based on our decision variable's , we have to build this as an expression for each day for all combination of products. However given the number of combinations and decision variables involved in this expression (over ~50M decision vars) we are running into issues of slow performance when building the inventory expression for each day especially when we reach to end day of a horizon -which by logic take's leftover inventory from previous day , which will do same from its previous day...(so if you end day of horizon was 100th day, 100th day will take leftover inventory expression for 99th day ,which will use expression from 98 th day....etc. till 1st day)
Thus the expression keeps getting longer.
Maximize
40 x#1 +60 x#2 +20 x#3
Subject To
C0: 5 x#1 - 2 y#1 >=-40
C1: 5 x#1 - 2 y#1 + 15 x#2 - 4 y#2 >= -60
........ then C100 becomes a huge expression given the number of combinations and decision variable we are dealing with and have heave performance issues in creating this expression
Is there a way in these expressions to re-use the expression in a named constraint in following constraint.
So in above case define say
C0: t= 5 x#1 - 2 y#1 >=-40
And then in define C1: t + 15 x#2 - 4 y#2 >= -60,
Is this above even possible, if I do so , do i ended by creating additional variable t that now I have to define and provide bounds for?
Instead C1 can be 15 x#2 - 4 y#1 >=-20
-
正式なコメント
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 Sneha,
Introducing auxiliary variables seems like a good way to do this. We can create a new \( t \) variable for each inventory day, then base each day's inventory off of the previous day's inventory . For example:
$$\begin{alignat*}{3} t_1 &= & 5x_1 - &&2 y_1 \\ t_2 &= t_1 + & 15x_2 - && 4y_2 \\ t_3 &= t_2 + & 10x_3 - && 6y_3 \end{alignat*}$$
Then, we define the bounds to the \( t \) variables:
$$\begin{align*}t_1 &\geq -40 \\ t_2 &\geq -60 \\ t_3 &\geq -80 \end{align*}$$
Note that we have to use two separate constraints for each time period: one for setting the \( t \) variable, and another for setting its lower bound.
Eli
0 -
Hi Eli,
I tried the suggestion and modified my LP file (with appropriate introduction of variable t#1 and t#2 in Generals section , however it now makes the model infeasible. Not sure , why it would since the problem is still the same with rearrangement of terms around equations to introduce new variable
C0: - t#1 + 5 x#1 - 2 y#1 =0C1: -t#2 + t#1 + 15 x#2 - 4 y#2 =0
C3: t#1 >= -40
C4: t#2 >= -60
0 -
Hi Sneha,
I think there should be a space between \( \texttt{=} \) and \( \texttt{0} \) in constraints \( \texttt{C0} \) and \( \texttt{C1} \). There may be other similar spacing problems in the LP file. Though I don't recommend trying to manually edit LP model files like this. LP files are meant more for visually inspecting a model written using a solver API, rather than as a framework for writing models.
Thanks,
Eli
0
投稿コメントは受け付けていません。
コメント
4件のコメント