简体   繁体   English

Gurobi-通过状态码获取状态消息?

[英]Gurobi - Get status message by status code?

Is there a way to get the status message using a status code? 有没有办法使用状态码来获取状态消息? For error codes I can easily get the message by catching the exception and accessing its .message attribute, however for statuses I only get the code from: 对于错误代码,我可以通过捕获异常并访问其.message属性来轻松获取消息,但是对于状态,我只能从以下位置获取代码:

model.status

It seems like the messages are stored in the Gurobi library since it prints out a message when something happens, for example encountering an infeasible model, but I don't see a way of accessing the message itself, ie storing it in a variable. 消息似乎存储在Gurobi库中,因为它会在发生某些情况(例如遇到不可行的模型)时打印出消息,但我看不到访问消息本身的方法,即将其存储在变量中。

There is no API function to retrieve the internal status message, but it's fairly simple to set up a message dict yourself for that purpose. 没有API函数可以检索内部状态消息,但是为此目的设置消息dict很简单。 Assuming that you have imported GRB , one could do: 假设您已导入GRB ,则可以执行以下操作:

>>> # TODO add more status codes here...
>>> msgdict = {GRB.OPTIMAL : 'Optimal', GRB.INFEASIBLE : 'Infeasible model'}
>>> model.optimize()
>>> print msgdict[m.status]
Optimal

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM