# Cleaning information to solve multiple instances of a JuMP model

**URL:** https://discourse.julialang.org/t/cleaning-information-to-solve-multiple-instances-of-a-jump-model/43930
**Category:** Optimization (Mathematical)
**Created:** [July 29, 2020, 11:33pm UTC](https://discourse.julialang.org/t/cleaning-information-to-solve-multiple-instances-of-a-jump-model/43930 "2020-07-29T23:33:14Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![afazevedo](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/afazevedo/32/16394_2.png) [@afazevedo](https://discourse.julialang.org/u/afazevedo)
#### Post date: [July 29, 2020, 11:33pm UTC](https://discourse.julialang.org/t/cleaning-information-to-solve-multiple-instances-of-a-jump-model/43930/1 "2020-07-29T23:33:14Z")

</div>

Hi all.  
I created an extensive program using JuMP library, to solve a specific model. To solve instances, I did make a routine to run for each instance all at once, using a loop and include to run. But I notice that it becomes slower than running it once at time. Is there any way to clear the information and reset the julia to do this faster?

Best Regards.

---

<div class="post-metadata">

### Author: ![joaquimg](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/joaquimg/32/223_2.png) [@joaquimg](https://discourse.julialang.org/u/joaquimg)
#### Post date: [July 29, 2020, 11:50pm UTC](https://discourse.julialang.org/t/cleaning-information-to-solve-multiple-instances-of-a-jump-model/43930/2 "2020-07-29T23:50:02Z")

</div>

Do you have an MWE ? Check: [Please read: make it easier to help you](https://discourse.julialang.org/t/psa-make-it-easier-to-help-you/14757))

Are you using:  
`include(SCRIPT_PATH)` inside a loop?

---

<div class="post-metadata">

### Author: ![afazevedo](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/afazevedo/32/16394_2.png) [@afazevedo](https://discourse.julialang.org/u/afazevedo)
#### Post date: [July 30, 2020, 12:19am UTC](https://discourse.julialang.org/t/cleaning-information-to-solve-multiple-instances-of-a-jump-model/43930/3 "2020-07-30T00:19:40Z")

</div>

> Are you using:  
> `include(SCRIPT_PATH)` inside a loop?

yes!

here is an MWE:

```julia
for w in 1:16
   
    for k in 2:a+1

        i = readdlm(files_even[w])[k, 1]

        j = readdlm(files_even[w])[k, 2]

        i = Int(i)

        j = Int(j)

        c[i+1,j+1] = readdlm(files_even[w])[k, 3]

        c[i+1,j+1] = Int(c[i+1,j+1])

        c[j+1, i+1] = c[i+1, j+1]

    end

    include("main.jl")

end

```

I’m doing loops over the instances and calling main to solve it inside the loop

---

<div class="post-metadata">

### Author: ![joaquimg](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/joaquimg/32/223_2.png) [@joaquimg](https://discourse.julialang.org/u/joaquimg)
#### Post date: [July 30, 2020, 1:02am UTC](https://discourse.julialang.org/t/cleaning-information-to-solve-multiple-instances-of-a-jump-model/43930/4 "2020-07-30T01:02:15Z")

</div>

In order to reproduce we would actually need the script `main.jl`.  
However,  
The problem might be just that.  
You should move what you are doing in `main.jl` to a function:

```julia
function main(w,i,j,k,c)
...
end

```

for instance.  
In this case you only need to `include("main.jl")` once, and outside the loop.  
In the loop you just call the `main(w,i,j,k,c)` function.

This section in the manual is very good for performance tips: [Performance Tips · The Julia Language](https://docs.julialang.org/en/v1/manual/performance-tips/index.html)

Following performance tips, you might want to put your loops inside another function as well.
