printing the solution (Error message)
AnsweredI keep getting this error and I would be glad if someone could clarify for me please:
AttributeError
Traceback (most recent call last) <ipython-input-52-d02cc29c68fa> in <module> 234 # Printing results 235 for v in opt_model.getVars(): --> 236 if(v.x > 0): 237 print('%s %g' % (v.varName, v.x)) var.pxi in gurobipy.Var.__getattr__() var.pxi in gurobipy.Var.getAttr() attrutil.pxi in gurobipy.__getattr() AttributeError: Unable to retrieve attribute 'x'
0
-
Official comment
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?. -
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,
Matthias0
Post is closed for comments.
Comments
2 comments