# Workaround for modifying coefficients in constraints in JuMP?

**URL:** <https://discourse.julialang.org/t/workaround-for-modifying-coefficients-in-constraints-in-jump/27123>\
**Category:** Optimization (Mathematical)\
**Created:** [August 3, 2019, 12:21am UTC](https://discourse.julialang.org/t/workaround-for-modifying-coefficients-in-constraints-in-jump/27123 "2019-08-03T00:21:40Z")\
**Posts on this page:** 1\
**Showing post:** 5

<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:** [August 6, 2019, 4:55pm UTC](https://discourse.julialang.org/t/workaround-for-modifying-coefficients-in-constraints-in-jump/27123/5 "2019-08-06T16:55:15Z")

</div>

Is there any reason why `set_coefficient` doesn’t work?

We try to discourage the use of `deepcopy`. Instead, you could use a function to rebuild the base model:

```nohighlight
function base_model()
    model = Model()
    @variable(model, x)
    @variable(model, y)
    @constraint(model, x >= 0)
    return model
end

for c in 1:3  
    m = base_model()
    @constraint(m, m[:x] + c * m[:y] <= 1)
    optimize!(m)
end

```

---

_[View the full topic](https://discourse.julialang.org/t/workaround-for-modifying-coefficients-in-constraints-in-jump/27123)._
