# Function with Gurobi model and optional solver parameters

**URL:** <https://discourse.julialang.org/t/function-with-gurobi-model-and-optional-solver-parameters/28327>\
**Category:** Optimization (Mathematical)\
**Tags:** question\
**Created:** [September 3, 2019, 2:53pm UTC](https://discourse.julialang.org/t/function-with-gurobi-model-and-optional-solver-parameters/28327 "2019-09-03T14:53:03Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![ibabeo](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ibabeo/32/9788_2.png) [@ibabeo](https://discourse.julialang.org/u/ibabeo)\
**Post date:** [September 3, 2019, 2:53pm UTC](https://discourse.julialang.org/t/function-with-gurobi-model-and-optional-solver-parameters/28327/1 "2019-09-03T14:53:04Z")

</div>

I’m trying to make a function with arguments that I can pass to the model if any, otherwise stay default.

```julia
function mymip(; verbose = true, timelimit=false, mipfocus=false, rins=false)

    model = Model(with_optimizer(Gurobi.Optimizer, TimeLimit=timelimit, MIPFocus=mipfocus, RINS=rins))

```

When I call `mymip()`, if I give any value to the keywords then they pass on to gurobi model, otherwise they keep the default value, but I don’t know how to set those keywords with their own default values in the function arguments. I’ve tried that “fault” will pass “0” to the keywords and “nothing” doesn’t work either…

Does anyone know if this is possible? Thanks in advance.

---

<div class="post-metadata">

**Author:** ![ExpandingMan](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/expandingman/32/866_2.png) [@ExpandingMan](https://discourse.julialang.org/u/ExpandingMan)\
**Post date:** [September 3, 2019, 2:59pm UTC](https://discourse.julialang.org/t/function-with-gurobi-model-and-optional-solver-parameters/28327/2 "2019-09-03T14:59:49Z")

</div>

Are you asking how to set the default values of your keyword arguments to the Gurobi defaults? The only way of doing this would be to actually set them that way. You can find a complete list of Gurobi paramters together with their defaults [here](https://www.gurobi.com/documentation/7.5/refman/parameter_descriptions.html).

Something else you might consider is simply passing the keyword arguments in their entirety into the Gurobi model. For example

```julia
function mymip(;kwargs...)
    model = Model(with_optimizer(Gurobi.Optimizer; kwargs...))
end

```

Of course, in that case you’d have to use exactly the same variable names in your function as Gurobi takes.

---

<div class="post-metadata">

**Author:** ![ibabeo](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ibabeo/32/9788_2.png) [@ibabeo](https://discourse.julialang.org/u/ibabeo)\
**Post date:** [September 5, 2019, 7:43am UTC](https://discourse.julialang.org/t/function-with-gurobi-model-and-optional-solver-parameters/28327/3 "2019-09-05T07:43:36Z")

</div>

Hi ExpandingMan  
Thanks for the answer.

One more question, for some parameters, the default in Gurobi is infinity, for example Time Limit. What is the proper way to default that? A very large value?

---

<div class="post-metadata">

**Author:** ![ExpandingMan](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/expandingman/32/866_2.png) [@ExpandingMan](https://discourse.julialang.org/u/ExpandingMan)\
**Post date:** [September 5, 2019, 1:05pm UTC](https://discourse.julialang.org/t/function-with-gurobi-model-and-optional-solver-parameters/28327/4 "2019-09-05T13:05:44Z")

</div>

If Gurobi lists a value as infinite, they are referring to floating point infinity, which in Julia is represented as `Inf`.
