# How to iterate the optimization model with the updated bounds of the variables?

**URL:** <https://discourse.julialang.org/t/how-to-iterate-the-optimization-model-with-the-updated-bounds-of-the-variables/46746>\
**Category:** Performance\
**Created:** [September 17, 2020, 4:38am UTC](https://discourse.julialang.org/t/how-to-iterate-the-optimization-model-with-the-updated-bounds-of-the-variables/46746 "2020-09-17T04:38:24Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![mamuniut09](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mamuniut09/32/9991_2.png) [@mamuniut09](https://discourse.julialang.org/u/mamuniut09)\
**Post date:** [September 17, 2020, 4:38am UTC](https://discourse.julialang.org/t/how-to-iterate-the-optimization-model-with-the-updated-bounds-of-the-variables/46746/1 "2020-09-17T04:38:24Z")

</div>

Hello all,

The optimization code is given below.

> x\_min=1; x\_max=7; y\_min=2; y\_max=5;  
> m= Model(with\_optimizer(Ipopt.Optimizer))  
> @variable(m, x\>=0)  
> @variable(m, y\>=0)  
> @variable(m, z)  
> @variable(m, w)  
> @constraint(m, x\_min\<=x\<=x\_max)  
> @constraint(m, w == 12)  
> @constraint(m, w \>= x\_min \* y + x \* y\_min - x\_min \* y\_min)  
> @constraint(m, w \>= x\_max \* y + x \* y\_max - x\_max \* y\_max)  
> @constraint(m, w \<= x\_min \* y + x \* y\_max - x\_min \* y\_max)  
> @constraint(m, w \<= x\_max \* y + x \* y\_min - x\_max \* y\_min)  
> @constraint(m, z == x+y)  
> @objective(m, Min, z)  
> optimize!(m)

After the first run of the above code, the x bounds are updated as below.

> x\_min=JuMP.value(x)  
> x\_max=12/JuMP.value(y)

The code should run for the second time with this updated bounds on x, and this process would continue until a criteria is met.

Now, can anyone please help me how I can iterate the optimization model for 3 or 4 times using `while` loop?

---

<div class="post-metadata">

**Author:** ![tomerarnon](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tomerarnon/32/3170_2.png) [@tomerarnon](https://discourse.julialang.org/u/tomerarnon)\
**Post date:** [September 17, 2020, 7:57pm UTC](https://discourse.julialang.org/t/how-to-iterate-the-optimization-model-with-the-updated-bounds-of-the-variables/46746/2 "2020-09-17T19:57:24Z")

</div>

```julia
criterion = false
i = 1
while !criterion && i < max_i
    optimize!(m)
    x_min=JuMP.value(x)
    x_max=12/JuMP.value(y)
    @constraint( __blah__ )
    criterion = # calculate criterion
    i += 1
end

```
