# Replace a JuMP variable by a number

**URL:** <https://discourse.julialang.org/t/replace-a-jump-variable-by-a-number/78158>\
**Category:** Optimization (Mathematical)\
**Tags:** jump\
**Created:** [March 20, 2022, 7:47am UTC](https://discourse.julialang.org/t/replace-a-jump-variable-by-a-number/78158 "2022-03-20T07:47:59Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![wujinq](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/wujinq/32/22221_2.png) [@wujinq](https://discourse.julialang.org/u/wujinq)\
**Post date:** [March 20, 2022, 7:48am UTC](https://discourse.julialang.org/t/replace-a-jump-variable-by-a-number/78158/1 "2022-03-20T07:48:00Z")

</div>

I have a large optimization problem written in `JuMP.jl` and do not get the expected results. To debug my program, I want to replace the variables in constraints by their values found by an analytical calculation. That is, I want to replace the variables in

```julia
2×2 Array{GenericAffExpr{Float64,VariableRef},2}:
 xpopstr_expected[21] -xpopstr_expected[22]
 xpopstr_expected[22] xpopstr_expected[21]

```

by actual numbers. Is this supported by `JuMP`?

---

<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:** [March 20, 2022, 8:22am UTC](https://discourse.julialang.org/t/replace-a-jump-variable-by-a-number/78158/2 "2022-03-20T08:22:16Z")

</div>

Is this what you’re looking for?

[https://jump.dev/JuMP.jl/stable/manual/solutions/#Checking-feasibility-of-solutions](https://jump.dev/JuMP.jl/stable/manual/solutions/#Checking-feasibility-of-solutions)

---

<div class="post-metadata">

**Author:** ![wujinq](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/wujinq/32/22221_2.png) [@wujinq](https://discourse.julialang.org/u/wujinq)\
**Post date:** [March 20, 2022, 9:31am UTC](https://discourse.julialang.org/t/replace-a-jump-variable-by-a-number/78158/3 "2022-03-20T09:31:10Z")

</div>

That’s great. Thank you for your answer.

---

<div class="post-metadata">

**Author:** ![wujinq](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/wujinq/32/22221_2.png) [@wujinq](https://discourse.julialang.org/u/wujinq)\
**Post date:** [March 21, 2022, 3:52pm UTC](https://discourse.julialang.org/t/replace-a-jump-variable-by-a-number/78158/4 "2022-03-21T15:52:40Z")

</div>

Oh, there is still a problem: feasibility checking for SDP constraints is not supported yet, so still I need to replace a JuMP variable by a number …

---

<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:** [March 21, 2022, 5:48pm UTC](https://discourse.julialang.org/t/replace-a-jump-variable-by-a-number/78158/5 "2022-03-21T17:48:37Z")

</div>

Yes, there’s no easy way to do this just yet for non-trivial constraints. You’d have to manually come up with something.

---

<div class="post-metadata">

**Author:** ![miles.lubin](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/miles.lubin/32/279_2.png) [@miles.lubin](https://discourse.julialang.org/u/miles.lubin)\
**Post date:** [March 23, 2022, 4:58pm UTC](https://discourse.julialang.org/t/replace-a-jump-variable-by-a-number/78158/6 "2022-03-23T16:58:41Z")

</div>

> [@wujinq](#):
>
> That is, I want to replace the variables in
> 
> ```julia
> 2×2 Array{GenericAffExpr{Float64,VariableRef},2}:
> xpopstr_expected[21] -xpopstr_expected[22]
> xpopstr_expected[22] xpopstr_expected[21]
> 
> ```
> 
> by actual numbers. Is this supported by `JuMP` ?

Use [`JuMP.value(::Function,::GenericAffExpr)`](https://jump.dev/JuMP.jl/stable/reference/solutions/#JuMP.value) to evaluate the affine expressions using a function that provides a value for each variable.
