# Deleting containerized constraints

**URL:** <https://discourse.julialang.org/t/deleting-containerized-constraints/21971>\
**Category:** Optimization (Mathematical)\
**Created:** [March 17, 2019, 7:49pm UTC](https://discourse.julialang.org/t/deleting-containerized-constraints/21971 "2019-03-17T19:49:57Z")\
**Posts on this page:** 1\
**Showing post:** 13

<div class="post-metadata">

**Author:** ![tkoolen](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tkoolen/32/1603_2.png) [@tkoolen](https://discourse.julialang.org/u/tkoolen)\
**Post date:** [March 22, 2019, 2:28pm UTC](https://discourse.julialang.org/t/deleting-containerized-constraints/21971/13 "2019-03-22T14:28:20Z")

</div>

Alternatively, you could use Parametron, which I built for these kinds of parameterized problems.

```julia
using Parametron, CPLEX
using Random

const C = 30000#300000
const N = 10

# Basic problem setup. Mostly the same as with JuMP, except
# the @constraint macro isn't quite as advanced.
const m = Model(CPLEX.Optimizer(CPX_PARAM_SCRIND=0))
x = [Variable(m) for i in 1 : N]
Θ = Variable(m)
@constraint m 0 <= Θ
@constraint m Θ <= 1000
for i in 1 : N
    @constraint m 0 <= x[i]
    @constraint m x[i] <= 1
end

# Now the interesting part: you can explicitly create a Parameter
# with an update function that will be called before each solve. Here
# create an update function that is a closure over a pre-allocated matrix
# using the standard `do` syntax.
const coef_val = zeros(C, N)
const coef = Parameter(coef_val, m) do coef_val
    rand!(coef_val)
end
@constraint m fill(Θ, C) <= coef * x

# Solve the first time
@time solve!(m) # currently produces some warnings...

# solving a second time will call the update function for the `coef`
# parameter and update the corresponding constraints in place.
@time solve!(m)

```

---

_[View the full topic](https://discourse.julialang.org/t/deleting-containerized-constraints/21971)._
