Skip to main content

printing the solution (Error message)

Answered

Comments

2 comments

  • Official comment
    Simranjit Kaur
    • Gurobi Staff
    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?.
  • Matthias Miltenberger
    • Gurobi Staff

    Hi,

    Please check the solution status before querying the solution values. Most likely, the problem was not solved so there is no solution to display.

    Here is some example code snippet:

    model.optimize()
    
    if model.status == GRB.OPTIMAL:
        print('Optimal objective: %g' % model.objVal)
    elif model.status == GRB.INF_OR_UNBD:
        print('Model is infeasible or unbounded')
        sys.exit(0)
    elif model.status == GRB.INFEASIBLE:
        print('Model is infeasible')
        sys.exit(0)
    elif model.status == GRB.UNBOUNDED:
        print('Model is unbounded')
        sys.exit(0)
    else:
        print('Optimization ended with status %d' % model.status)
        sys.exit(0)

    Cheers,
    Matthias

    0

Post is closed for comments.