# Curious about copying a model that has had constraints deleted

**URL:** <https://discourse.julialang.org/t/curious-about-copying-a-model-that-has-had-constraints-deleted/103814>\
**Category:** Optimization (Mathematical)\
**Created:** [September 13, 2023, 2:03pm UTC](https://discourse.julialang.org/t/curious-about-copying-a-model-that-has-had-constraints-deleted/103814 "2023-09-13T14:03:02Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![hdavid16](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/hdavid16/32/11531_2.png) [@hdavid16](https://discourse.julialang.org/u/hdavid16)\
**Post date:** [September 13, 2023, 2:03pm UTC](https://discourse.julialang.org/t/curious-about-copying-a-model-that-has-had-constraints-deleted/103814/1 "2023-09-13T14:03:02Z")

</div>

Here is an interesting scenario. I’m playing around with how copy works in JuMP.

```julia
#make dummy model 
m=Model(); 
@variable(m,x); 
c1=@constraint(m,x<=10); 
c2=@constraint(m,x<=100); 
delete(m,c1) 
delete(m,c2) 

#readd constraints 
c1=@constraint(m,x<=10); 
c2=@constraint(m,x<=100); 
m2=copy(m);

```

The constraint indices for `m` are 3 and 4. On the other hand the constraint indices on `m2` (copy) get reset to 1 and 2. Is this the expected behavior in JuMP? Why not keep the indices from one copy to the other? I’m sure there are good reasons for this, I’m just curious.

---

<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:** [September 13, 2023, 9:44pm UTC](https://discourse.julialang.org/t/curious-about-copying-a-model-that-has-had-constraints-deleted/103814/2 "2023-09-13T21:44:21Z")

</div>

There is `JuMP.copy_model` which additionally returns a map between the indices:

> **[JuMP · JuMP](https://jump.dev/JuMP.jl/stable/api/JuMP/#copy_model)**
>
> Documentation for JuMP.

In most cases though, I would generally recommend against copying a model. There’s almost always no need.
