How to give a parameter list to Gurobi
AnsweredHi all,
I use Gurobi to solve an optimization problem in Julia. I might need to try different Gurobi parameters.
Currently, I write parameters and their values inside the model directly, like
Expansion_Model = Model(optimizer_with_attributes(Gurobi.Optimizer, "MIPGap" => 0.01, "TimeLimit" => 91800, "Method" => 2))
I do not want to do this inside the model. Instead, I want to create a list of parameters and add this to the model with a for loop, or with something similar. For instance, by using the same example above,
paramname = ["MIPGap", "TimeLimit", "Method"]paramvalue = [0,01, 91800, 2]Expansion_Model = Model(optimizer_with_attributes(Gurobi.Optimizer, paramname => paramvalue))
Or, something like
Expansion_Model = Model(optimizer_with_attributes(Gurobi.Optimizer))for (x,y) in zip(paramname, paramvalue)Expansion_Model.params.add(x,y)end
In the above example, I just fabricate params and add functions. I am not sure if we have something similar in Julia. Do we have such a flexibilty in Julia?
Thank you
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 try Gurobot, our chatbot interface offering instant, expert-level support. -
Okay, I found the solution. The following works for me:
paramname = ["MIPGap", "TimeLimit", "Method"]paramvalue = [0,01, 91800, 2]Expansion_Model = Model(optimizer_with_attributes(Gurobi.Optimizer))for (x,y) in zip(paramname, paramvalue)set_optimizer_attribute(Expansion_Model, x, y)end0
Post is closed for comments.
Comments
2 comments