Updating the value of a variable before a solve

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:

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)


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

Before the next solve I need to do the following

fix(y, 20; force=true)

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.

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

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

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

I like this and it seems pretty great.

Having also not tested it I’ll say:

Thanks as always Oscar!

1 Like