How to ensure consistent values of .PI when the dual problem has multiple optimal solutions?
OngoingHello,
I'm encountering an issue while using .PI to obtain the values of dual variables. I ran the same code multiple times without making any changes, yet the results of .PI turned out to be different. After comparing all the output values, I found that the optimal solution (obj and the values of the decision variables) of the primal problem were exactly the same, but the results obtained by .PI were different. I suspect this is due to the dual problem having multiple optimal solutions.
In such a situation, how can I ensure that the values of .PI remain consistent every time I run the code repeatedly?
I would really appreciate any suggestions or insights you could provide. Thank you in advance!
-
Hi Yiran,
I found that the optimal solution (obj and the values of the decision variables) of the primal problem were exactly the same
You need to check the optimal basis information by querying the attributes VBasis and CBasis. For optimal solutions to have the same dual values, it is important to have the same basis not necessarily the same values for non-slack variables.
For example, let us consider the example model below:
\begin{align} \min~~ & x_1 + x_2 \\ \mbox{s.t:} ~~ & x_1 + x_2 \geq 2 \\ & 2x_1 + x_2 \ge3 \\ & x_1 \leq 1\ \\ & x_2 \geq 0 \end{align}The optimal solution for this problem would always be reported as \((x_1 = 1, x_2=1)\) with the objective value 2. However, depending on which one of the following is the optimal basis, the dual solution might differ:
- Basic variables: \((x_1, x_2)\), non-basic variables: \((s_1, s_2)\) where \(s_1\) and \(s_2\) are the slack variables associated with the first and the second constraints.
- Basic variables: \((x_2, s_1)\), non-basic variables: \((x_1, s_2)\) where \(x_1\) would be a non-basic variable at its upper bound 1.
- Basic variables: \((x_2, s_2)\), non-basic variables: \((x_1, s_1)\) with \(x_1\) non-basic at its upper bound.
If you see different dual values, it is likely because you get a different basis at each run. I assume that you are running Gurobi via Python. Does your code include any non-deterministic data structures such as Python unordered Sets() which might change the ordering via which the variables/constraints are added to the model? Do you see the same fingerprint value every time you run Gurobi?
To ensure that the issue is not related to having different ordering, you can write the model into an MPS file. You can then run the model multiple times by reading it from the MPS file.
Best regards,
Maliheh
0 -
Thank you, Maliheh. I'm glad to receive your message.
Yes, I am running Gurobi via Python. The model has been written the model into an MPS file and run by reading it from the MPS file. But the problem still exists, that is why I am confused...
0 -
I hope you don't mind me adding some more details to the question I asked earlier.
The specific situation I've encountered is as follows:When I run the code to solve the same model without making any changes, I can get the same obj and vars values, but there are differences in the .PI values. The model is saved to an MPS file and then read from it. The two MPS files obtained from the repeated runs are: RMP_4_ccount(4779) and RMP_123_ccount(4779). Here's the comparison of their fingerprints and the output results.FIGURE : model finger printLink: results comparison between two models (same solutions but different .PI)Sometimes, it happens that the same model fingerprint generates different optimal solutions with the same obj value, as shown in the figure.Link: results comparison between two models (same obj but different variable values)0
Please sign in to leave a comment.
Comments
3 comments