# Solving a model and its modified copy

**URL:** https://discourse.julialang.org/t/solving-a-model-and-its-modified-copy/9778
**Category:** Optimization (Mathematical)
**Created:** [March 17, 2018, 11:14pm UTC](https://discourse.julialang.org/t/solving-a-model-and-its-modified-copy/9778 "2018-03-17T23:14:24Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![varun7rs](https://avatars.discourse-cdn.com/v4/letter/v/c2a13f/32.png) [@varun7rs](https://discourse.julialang.org/u/varun7rs)
#### Post date: [March 17, 2018, 11:14pm UTC](https://discourse.julialang.org/t/solving-a-model-and-its-modified-copy/9778/1 "2018-03-17T23:14:24Z")

</div>

As a follow-up to IainNZ’s comments on issue #399, I’ve slightly modified the code to experiment with variable fixings. While I only intend to fix variables of the object r, the fixings are applied to object p as well. I don’t quite understand the functioning of the fixings here. Could someone elaborate on what’s happening behind the scenes?

```julia
using JuMP
using CPLEX

type MyProblem
  model
  x
  y
end

function createproblem()
  m = Model(solver=CplexSolver())
  @variable(m, 0 <= x <= 2 )
  @variable(m, 0 <= y <= 30 )

  @objective(m, Max, 5x + 3*y )
  @constraint(m, 2x + 5y <= 3.0 )
  return MyProblem(m, x, y)
end

p = createproblem()
r = p
setlowerbound(r.x, 2)
setupperbound(r.x, 2)

solve(r.model)
solve(p.model)

```

---

<div class="post-metadata">

### Author: ![Nosferican](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/nosferican/32/9275_2.png) [@Nosferican](https://discourse.julialang.org/u/Nosferican)
#### Post date: [March 18, 2018, 1:26am UTC](https://discourse.julialang.org/t/solving-a-model-and-its-modified-copy/9778/2 "2018-03-18T01:26:30Z")

</div>

`setlowerbound(obj, value)` operates in-place. When setting `r = p`, it only sets another pointer to the same memory location. If you want to keep a copy you should use `copy`, but is pretty common not to have that method defined for `MyStructs`. Try modifying the code to,

```julia
r = deepcopy(p)

```

---

<div class="post-metadata">

### Author: ![varun7rs](https://avatars.discourse-cdn.com/v4/letter/v/c2a13f/32.png) [@varun7rs](https://discourse.julialang.org/u/varun7rs)
#### Post date: [March 18, 2018, 7:30pm UTC](https://discourse.julialang.org/t/solving-a-model-and-its-modified-copy/9778/3 "2018-03-18T19:30:08Z")

</div>

Thanks a lot @Nosferican, your solution works for me.
