Complexity of using the max constraint
AnsweredI have a few gurobi boolean/indicator variables \(x_{i} \forall i \in (1,\dots,n)\). I have to compute the following variables \(X_{\text{first}}\) and \(X_{\text{last}}\) based on which \(x_i\)'s are set to \(\mathrm{True}\). For e.g., if \(n=3\) and \(x_1=1, x_2=1,x_3=0\) then \(X_{\text{first}}=1\) and \(X_{\text{last}}=2\).
I have the following two methods to compute the first and last variables.
- Use of max constraint. I create "helper" variables \(y_i\) such that \(x_i=1 \implies y_i = i\) and \(x_i=0 \implies y_i = \text{some large number}\). Now, the first variable can be computed by a taking a \(\mathrm{min}\) over \(y_i\)'s, i.e., \(X_{\text{first}}=\mathrm{min}_i y_i \). We can similarly compute the last variable.
- Not using max constraint. A simpler way would be to use the general constraints - \(x_i=1 \implies X_{\text{first}} \geq i\). Granted that such a way is sloppy because I wouldn't get exact values for first and last rather just bounds. But, my optimization objective is such that under optimality first and last will take their actual values.
So, my question is that which of the above two is a better way to model such a constraint?
Thanks!
-
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 Rohan,
I would prefer the second option. I don't see why \(X_{\text{first}}\) would not be "exact". Just use integer variables and then minimize/maximize them via the objective function, so they will have the correct value.
To be sure about the performance, I would try both approaches and see which one can be handled better by Gurobi.
Cheers,
Matthias0
Post is closed for comments.
Comments
2 comments