# Tinkering with values of variables in a solved JuMP model

**URL:** <https://discourse.julialang.org/t/tinkering-with-values-of-variables-in-a-solved-jump-model/140164>\
**Category:** Optimization (Mathematical)\
**Created:** [October 22, 2026, 8:59pm UTC](https://discourse.julialang.org/t/tinkering-with-values-of-variables-in-a-solved-jump-model/140164 "2026-10-22T20:59:04Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![araujoms](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/araujoms/32/217734_2.png) [@araujoms](https://discourse.julialang.org/u/araujoms)\
**Post date:** [October 22, 2026, 8:59pm UTC](https://discourse.julialang.org/t/tinkering-with-values-of-variables-in-a-solved-jump-model/140164/1 "2026-10-22T20:59:05Z")

</div>

I’d like to solve a JuMP model, use `primal_feasibility_report` to check which constraints are violated, tweak the variable values until the constraints are all strictly respected, and then compute the new objective value with the new variables. Is it possible to do so?

I can pass a `Dict` to `primal_feasiblity_report` with the new values. That’s a bit inconvenient as it seems I have to do scalar by scalar, I can’t pass a vector or a matrix at once, but it works. I see no way to recompute the objective value, though.

---

<div class="post-metadata">

**Author:** ![sandyspiers](https://avatars.discourse-cdn.com/v4/letter/s/6a8cbe/32.png) [@sandyspiers](https://discourse.julialang.org/u/sandyspiers)\
**Post date:** [October 23, 2026, 12:30am UTC](https://discourse.julialang.org/t/tinkering-with-values-of-variables-in-a-solved-jump-model/140164/2 "2026-10-23T00:30:44Z")

</div>

Does something like this work for you?

```julia-repl
julia> using JuMP, HiGHS

julia> profit = [5, 4, 3, 7, 6];

julia> weight = [2, 3, 1, 4, 3];

julia> capacity = 8;

julia> N = length(profit);

julia> model = Model(HiGHS.Optimizer);

julia> set_silent(model);

julia> @variable(model, x[1:N], Bin);

julia> @objective(model, Max, profit' * x);

julia> @constraint(model, c, weight' * x <= capacity);

julia> optimize!(model);

julia> x_sol = value.(x)
5-element Vector{Float64}:
 0.0
 0.0
 1.0
 1.0
 1.0

julia> x_new = copy(x_sol);

julia> x_new[1] = 1.0;

julia> x_new[2] = 0.5;

julia> d = Dict(x .=> x_new)
Dict{VariableRef, Float64} with 5 entries:
  x[4] => 1.0
  x[1] => 1.0
  x[3] => 1.0
  x[2] => 0.5
  x[5] => 1.0

julia> f = v -> d[v]
#14 (generic function with 1 method)

julia> value(f, objective_function(model))
23.0

julia> value(f, c)
11.5

julia> primal_feasibility_report(f, model)
Dict{Any, Float64} with 2 entries:
  x[2] binary => 0.5
  c : 2 x[1] + 3 x[2] + x[3] + 4 x[4] + 3 x[5] ≤ 8 => 3.5

```

If the `Dict` is annoying to construct in your case, maybe there are better ways to construct the variable to value function (in this case `f`)?

---

<div class="post-metadata">

**Author:** ![zchenytt](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/zchenytt/32/223795_2.png) [@zchenytt](https://discourse.julialang.org/u/zchenytt)\
**Post date:** [October 23, 2026, 1:47am UTC](https://discourse.julialang.org/t/tinkering-with-values-of-variables-in-a-solved-jump-model/140164/3 "2026-10-23T01:47:41Z")

</div>

If the solver says it’s `OPTIMAL` or it has a suboptimal solution, then that solution is already deemed feasible.

> [@araujoms](#):
>
> then compute the new objective value with the new variables. Is it possible to do so?

> [@araujoms](#):
>
> I see no way to recompute the objective value, though.

It’s fairly easy and you don’t have to resort to `primal_feasibility_report`. You only need to fix the variable’s `lower_bound` and `upper_bound` to your candidate solution and call `optimize!` again, the solver will help you compute the objective value, and you fetch that value through `objective_value(model)`.

But the bigger issue is that, just as you’ve used the word “tinker”—it may not be helpful to tweak the solution returned from the solver (What’s the purpose? You typically get inferior objective values).
