How do I close gurobi log text file
AnsweredHi,
I am creating my log file under the following setup
Model.Params.LogToConsole = 0
Model.Params.LogFile = ''filepath.txt''
, so there is no log on the console but have a separate text file saved.
Now, I want to make some changes to that text file (e.g., delete the file or change the name of the file), but since the text file is not closed (like how the text file object is closed after writing) I cannot do such actions before I end Python.
Is there a way to access the Gurobi log text file object?
-
Unfortunately not; logs are written by the underlying Gurobi C library. However, you could use a message callback to capture the Gurobi output line by line, then do whatever you want with it. For example:
def cb(model, where):
if where == GRB.Callback.MESSAGE:
msg = model.cbGet(GRB.Callback.MSG_STRING)
# do something with msg here
model.optimize(cb)The callback.py example is a good place to start. It uses a message callback to write and manage its own log file.
0
Please sign in to leave a comment.
Comments
1 comment