Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Setting TimeLimit globally in Gurobi.jl or JuMP.jl #471

Closed
delft52 opened this issue May 4, 2022 · 5 comments
Closed

Setting TimeLimit globally in Gurobi.jl or JuMP.jl #471

delft52 opened this issue May 4, 2022 · 5 comments

Comments

@delft52
Copy link

delft52 commented May 4, 2022

Is there a way to set the Gurobi TimeLimit globally in the code, i.e., not for a specific model? I'm solving a MIP in a loop, and each time, Gurobi 9.5.1 displays the message "Set parameter TimeLimit to value ...", which makes reading my code messages and monitoring the execution progress difficult.

@odow
Copy link
Member

odow commented May 4, 2022

Is there a way to set the Gurobi TimeLimit globally in the code

No. Although you might be able to re-use an Env. (I didn't test this)

env = Gurobi.Env()
GRBsetdblparam(env, "TimelImit", 1.0)

for _ in 1:3
    model = Model(() -> Gurobi.Optimizer(env)
    optimize!(model)
end

which makes reading my code messages and monitoring the execution progress difficult.

Turn off Gurobi logging? set_silent(model).

@delft52
Copy link
Author

delft52 commented May 4, 2022

Is there a way to set the Gurobi TimeLimit globally in the code

No. Although you might be able to re-use an Env. (I didn't test this)

env = Gurobi.Env()
GRBsetdblparam(env, "TimelImit", 1.0)

for _ in 1:3
    model = Model(() -> Gurobi.Optimizer(env)
    optimize!(model)
end

which makes reading my code messages and monitoring the execution progress difficult.

Turn off Gurobi logging? set_silent(model).

Thanks. GRBsetdblparam seems to work for TimeLimit globally, but it gives the following warning: "WARNING: redefinition of constant GRB_ENV. This may fail, cause incorrect answers, or produce other errors." And set_silent didn't stop the loop messages.

@odow
Copy link
Member

odow commented May 4, 2022

WARNING: redefinition of constant GRB_ENV. This may fail, cause incorrect answers, or produce other errors

That wasn't part of my code.

If you copied https://github.com/jump-dev/Gurobi.jl#reusing-the-same-gurobi-environment-for-multiple-solves, then only run const GRB_ENV = Gurobi.Env() once.

And set_silent didn't stop the loop messages.

You can also use env = GurobiEnv(output_flag = 0).

@delft52
Copy link
Author

delft52 commented May 5, 2022

WARNING: redefinition of constant GRB_ENV. This may fail, cause incorrect answers, or produce other errors

That wasn't part of my code.

If you copied https://github.com/jump-dev/Gurobi.jl#reusing-the-same-gurobi-environment-for-multiple-solves, then only run const GRB_ENV = Gurobi.Env() once.

Yes, I already had "const GRB_ENV = Gurobi.Env()" in my code and added "GRBsetdblparam(GRB_ENV, "TimelImit", 1)" after it. I think the warning was because of the "const". After removing it, there's no warning.

And set_silent didn't stop the loop messages.

You can also use env = GurobiEnv(output_flag = 0).

This works, and it resolved the original issue. Even with the local settings (TimeLimit set in the model in the loop rather than globally), there are no messages anymore. It seems that setting the OutputFlag to 0 locally in the model only suppresses the MIPgap update reports but setting it to 0 in ENV globally, suppresses all Gurobi messages.
Many thanks!

@odow
Copy link
Member

odow commented May 5, 2022

but setting it to 0 in ENV globally, suppresses all Gurobi messages

Yes, I think this was a bug in the upstream Gurobi solver that may get fixed in future.

This works, and it resolved the original issue

Great. I'll close this issue then. Please use the community forum if you have other questions, https://discourse.julialang.org/c/domain/opt/13, we try to reserve GitHub issues for bug reports and feature requests.

@odow odow closed this as completed May 5, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

2 participants