Gurobi status code
AnsweredHi everyone,
I would like to know if there is a proper way to convert the integer status codes into strings ?
I'm using a handmade dictionary (in Python), but would like to know if there is a pre-built feature to do this.
Thank you!
-
Official comment
The full list of status codes is documented at https://www.gurobi.com/documentation/current/refman/optimization_status_codes.html. There is nothing wrong with writing your own dictionary to convert the code values to strings. The status codes are normally hardcoded during compilation and the values (e.g, OPTIMAL=2) will not be changed in the future. However, we have occasionally extended the list in the past with additional values for new major releases.
The Gurobi Python API provides class constants that can also be used (GRB.OPTIMAL, etc.) so your dictionary definition could look like this:
status = { "LOADED" : GRB.LOADED, "OPTIMAL" : GRB.OPTIMAL, .... }
-
You can hack this using the Python
__dict__
method:
sc = gurobipy.StatusConstClass
d = {sc.__dict__[k]: k for k in sc.__dict__.keys() if k[0] >= 'A' and k[0] <= 'Z'}Then the dictionary `d` is now:
{1: 'LOADED', 2: 'OPTIMAL', 3: 'INFEASIBLE', 4: 'INF_OR_UNBD', 5: 'UNBOUNDED', 6: 'CUTOFF', 7: 'ITERATION_LIMIT', 8: 'NODE_LIMIT', 9: 'TIME_LIMIT', 10: 'SOLUTION_LIMIT', 11: 'INTERRUPTED', 12: 'NUMERIC', 13: 'SUBOPTIMAL', 14: 'INPROGRESS', 15: 'USER_OBJ_LIMIT'}
2
Please sign in to leave a comment.
Comments
2 comments