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
-
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
0
Please sign in to leave a comment.
Comments
1 comment