Skip to main content

Questions about conditional statements in gurobi

Answered

Comments

8 comments

  • Jaromił Najman
    Gurobi Staff Gurobi Staff

    Hi Kewei,

    The implementation of \(C_{reh}\) looks correct. You are using indicators which is the correct way to implement \(C_{reh}\).

    For \(x_t\), it is a bit more complicated because you have strict inequalities in your conditions. We describe a way to deal with if-conditions with strict inequalities in the Knowledge Base article How do I model conditional statements in Gurobi? If I understand the code correctly, you used the idea described in the Knowledge Base article already. At a first glance it looks correct.

    For \(RD_t\), you are using variables \(z_{ij}\) but I cannot find those in your screenshots. If you used the addGenConstrAnd method to determine the value of each \(z_{ij}\) variable then the code should be correct as well.

    In order to debug your model, I recommend having a look at the Knowledge Base article How do I determine why my model is infeasible?

    Best regards, 
    Jaromił

    0
  • Kewei Fan
    First Question
    Conversationalist

    Thank you very much for your answer!This problem has been bothering me for a long time, and I have just solved it. I have another small question to consult. As shown in the figure, TSAL_t is a continuous variable, and I have certain constraints on YSAL_t[1] for subsequent optimization. But if it works without this constraint, if it doesn't work with this constraint, where's the problem?

    0
  • Jaromił Najman
    Gurobi Staff Gurobi Staff

    But if it works without this constraint, if it doesn't work with this constraint, where's the problem?

    What exactly do you mean by "it doesn't work". In the following, I will assume that it means that the model is declared infeasible

    The values for the bounds of the YSAL_t variable are quite big so numerical issues might be a problem. You could try experimenting with the NumericFocus parameter and have a look at our Guidelines for Numerical Issues.

    You should try to determine why the model is infeasible as explained in the Knowledge Base article How do I determine why my model is infeasible?

    Best regards, 
    Jaromił

    0
  • Kewei Fan
    First Question
    Conversationalist

    Thank you very much for your answer. It's true that the value is too large, but I had to use a larger range of variables due to the requirements of the actual problem. Is there any way to avoid infeasibility caused by numerical problems?

    0
  • Kewei Fan
    First Question
    Conversationalist

    I changed the unit of the variable to control the variable between 10 and 40, but the same problem still occurred. And when I reduced the range of variables by a factor of 100, the model is feasible. I suspect something is wrong with my addGenConstrPow(). I use the above code to calculate the RDt and make conditional judgments.

    0
  • Jaromił Najman
    Gurobi Staff Gurobi Staff

    Did you try to compute an IIS as discussed in How do I determine why my model is infeasible?

    Is there any way to avoid infeasibility caused by numerical problems?

    The only way is to improve the numerics of your model. Possibly tightening tolerance FeasibilityTol and then computing an IIS might help. Other than that I can only recommend to re-scale your model as described in the Guidelines for Numerical Issues. You say that you already did that and it seems to help.

    0
  • Kewei Fan
    First Question
    Conversationalist

    yes,as described in the screenshot

    0
  • Jaromił Najman
    Gurobi Staff Gurobi Staff

    You can write the IIS to a human readable model file by using the write method.

    model.computeIIS()
    model.write("model.ilp")

    You can open the file \(\texttt{model.ilp}\) in any standard text editor. From here you can try to understand why the computed constraints and bounds define an infeasible model.

    0

Please sign in to leave a comment.