メインコンテンツへスキップ

Check if model is unbounded and raise error

回答済み

コメント

4件のコメント

  • Jaromił Najman
    • Gurobi Staff Gurobi Staff

    Could you share a snippet of the code you are using to check your model's status after optimization?

    Please note that the range of your right hand side constants is huge and you should definitely try to improve the numerics of your model, see Guidelines for Numerical Issues for more details.

    Best regards, 
    Jaromił

    0
  • Marloes Remijnse
    • Gurobi-versary
    • First Question
    • First Comment

    Hi Jaromił,

    I use this code to check the optimality:

    print(f"GRB.OPTIMAL {grb.GRB.OPTIMAL}")

    I check the status by printing the output into a file: 

    sys.stdout = open('filename.txt')

    and then solving the model

    opt_model = grb.Model(name="MIP Model")
    # variables and constraints are added
    opt_model.ModelSense = grb.GRB.MAXIMIZE
    opt_model.setObjective(objective)
    opt_model.setParam('MIPGap', OPT_MODEL_GAP)
    opt_model.setParam('Worklimit', WORK_LIMIT)
    prob_obj = opt_model.optimize()

    I agree that the model should not be unbounded at all and I will check the data, but I want to generate a message in case the model is still unbounded.

     

    0
  • Jaromił Najman
    • Gurobi Staff Gurobi Staff

    The line

    print(f"GRB.OPTIMAL {grb.GRB.OPTIMAL}")

    will always print

    GRB.OPTIMAL 2

    because you are literally requesting the value of the enumerator \(\texttt{grb.GRB.OPTIMAL}\.)

    To get the current model status, you have to retrieve its attribute

    print(f"GRB.OPTIMAL {opt_model.Status}")

    Best regards, 
    Jaromił

    0
  • Marloes Remijnse
    • Gurobi-versary
    • First Question
    • First Comment

    Thank you very much! That helped me a lot.

    0

サインインしてコメントを残してください。