# Updating the value of a variable before a solve

**URL:** <https://discourse.julialang.org/t/updating-the-value-of-a-variable-before-a-solve/115882>\
**Category:** Optimization (Mathematical)\
**Created:** [June 19, 2024, 8:21pm UTC](https://discourse.julialang.org/t/updating-the-value-of-a-variable-before-a-solve/115882 "2024-06-19T20:21:21Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Mitch\_Phillipson](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mitch_phillipson/32/42883_2.png) [@Mitch\_Phillipson](https://discourse.julialang.org/u/Mitch_Phillipson)\
**Post date:** [June 19, 2024, 8:21pm UTC](https://discourse.julialang.org/t/updating-the-value-of-a-variable-before-a-solve/115882/1 "2024-06-19T20:21:21Z")

</div>

I am solving a model that sets a numeraire based on the previous solution values (or starting values for the first solve). I am running into an issue where I fix a variable, but the value is still the old value.

Here is a small example:

```julia
using JuMP
using PATHSolver

M = direct_model(PATHSolver.Optimizer())

@variable(M, x>=0, start = 1)
@variable(M, y>=0, start = 1)

fix(y,2; force=true)

@constraint(M, (x-y) ⟂ x)

optimize!(M)

```

This code works and the value of x is 2, as expected.

Before the next solve I need to do the following

```julia
fix(y, 20; force=true)
value(x*y)

```

and would like to get 40, but get 4. Even though y is fixed to 20, the value is still 2.

Is there a way to do this? Any help would be greatly appreciated.

---

<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:** [June 19, 2024, 8:32pm UTC](https://discourse.julialang.org/t/updating-the-value-of-a-variable-before-a-solve/115882/2 "2024-06-19T20:32:03Z")

</div>

`value` always queries the solution obtained by the solver. It does not treat `fix`ed variables as special.

I didn’t test so I might have made a typo, but perhaps you need:

```julia
my_value(x) = is_fixed(x) ? fix_value(x) : value(x)
value(my_value, x * y)

```

---

<div class="post-metadata">

**Author:** ![Mitch\_Phillipson](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mitch_phillipson/32/42883_2.png) [@Mitch\_Phillipson](https://discourse.julialang.org/u/Mitch_Phillipson)\
**Post date:** [June 19, 2024, 8:38pm UTC](https://discourse.julialang.org/t/updating-the-value-of-a-variable-before-a-solve/115882/3 "2024-06-19T20:38:53Z")

</div>

I like this and it seems pretty great.

Having also not tested it I’ll say:

Thanks as always Oscar!
