Replace a JuMP variable by a number

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

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?

Is this what you’re looking for?


That’s great. Thank you for your answer.

1 Like

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 …

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

1 Like

Use JuMP.value(::Function,::GenericAffExpr) to evaluate the affine expressions using a function that provides a value for each variable.

1 Like