How to give a parameter list to Gurobi

Hi all,

I use Gurobi to solve an optimization problem. 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)  # I just fabricate params and add functions. Not sure if we have such functions in Julia
end

Do we have such a flexibilty in Julia?

Thank you

I found something called setParam (https://www.gurobi.com/documentation/9.5/refman/py_model_setparam.html), but it does not work in JuMP.

Please, look at the JuMP documentation if you are using JuMP, more specifically: set_optimizer_attributes.

1 Like

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)
end
1 Like

Thank you so much. It looks like you answered the question at the same time that I was typing what I found. Thank you again.

1 Like