# Modifying solver parameters in JuMP after building the model

**URL:** <https://discourse.julialang.org/t/modifying-solver-parameters-in-jump-after-building-the-model/59509>\
**Category:** Optimization (Mathematical)\
**Tags:** question\
**Created:** [April 18, 2021, 1:22am UTC](https://discourse.julialang.org/t/modifying-solver-parameters-in-jump-after-building-the-model/59509 "2021-04-18T01:22:14Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![varun7rs](https://avatars.discourse-cdn.com/v4/letter/v/c2a13f/32.png) [@varun7rs](https://discourse.julialang.org/u/varun7rs)\
**Post date:** [April 18, 2021, 1:22am UTC](https://discourse.julialang.org/t/modifying-solver-parameters-in-jump-after-building-the-model/59509/1 "2021-04-18T01:22:14Z")

</div>

I was working on a heuristic where I modify an ILP within a loop and solve it for a certain iterations. As of now, within the loop, I build the model repeatedly during each iteration which is costing me more time. Is there a possibility to not repeatedly build the model while modifying the model and decrementing the timelimit to solve it within the loop? A simple pseudocode below intended to illustrate what I’m trying to do.

```julia
f = 10

for i in 1:10

    m = build_ILP(instance, parameters)
    @constraint(m.model, x + y <= 10*f)
    solve(m.model)
    f -= 1

end

```

---

<div class="post-metadata">

**Author:** ![odow](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/odow/32/28685_2.png) [@odow](https://discourse.julialang.org/u/odow)\
**Post date:** [April 18, 2021, 5:03am UTC](https://discourse.julialang.org/t/modifying-solver-parameters-in-jump-after-building-the-model/59509/2 "2021-04-18T05:03:48Z")

</div>

You can modify a JuMP model by adding additional constraints: just call `@constraint` again. Similarly, to modify the time limit, just call `set_time_limit_sec` again.

Option 1: look up the variables in `m.model`:

```julia
m = build_ILP(instance, parameters)
model = m.model
x = model[:x]
y = model[:y]
f = 1
for i in 1:10
    set_time_limit_sec(model, 10 - i)
    @constraint(mmodel, x + y <= 10 * f)
    optimize!(model)
    f -= 1
end

```

Option 2: return the variables from the `build_ILP` function:

```julia
model, x, y = build_ILP(instance, parameters)
for f in 10:-1:1
    set_time_limit_sec(model, f)
    @constraint(mmodel, x + y <= 10 * f)
    optimize!(model)
end

```

Here’s a Bender decomposition example: [Benders Decomposition · JuMP](https://jump.dev/JuMP.jl/v0.21.7/tutorials/Optimization%20concepts/benders_decomposition/)

---

<div class="post-metadata">

**Author:** ![varun7rs](https://avatars.discourse-cdn.com/v4/letter/v/c2a13f/32.png) [@varun7rs](https://discourse.julialang.org/u/varun7rs)\
**Post date:** [April 18, 2021, 11:34am UTC](https://discourse.julialang.org/t/modifying-solver-parameters-in-jump-after-building-the-model/59509/3 "2021-04-18T11:34:04Z")

</div>

Thanks a lot @odow. But since some of my previous implementation is still using JuMP v0.18, could you please let me know how to replicate this in JuMP v0.18?

---

<div class="post-metadata">

**Author:** ![odow](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/odow/32/28685_2.png) [@odow](https://discourse.julialang.org/u/odow)\
**Post date:** [April 18, 2021, 8:44pm UTC](https://discourse.julialang.org/t/modifying-solver-parameters-in-jump-after-building-the-model/59509/4 "2021-04-18T20:44:30Z")

</div>

> [@varun7rs](#):
>
> my previous implementation is still using JuMP v0.18

Please update to 0.21. There is no reason to stay on 0.18.
