Is there a way to delete old solutions from a JuMP model?

I am working on a problem where I am solving a model and then trying to get an additional feasible solution for the model by reseting the objective function (there are more details behind this, but the general idea will suffice for my question). I am finding that the model seems to hold onto a solution even after changing the objective so that I am not getting a different feasible solution after reseting the objective. Is there a way to delete the existing solution from a JuMP model without deleting any of the model components (e.g., without deleting variables and constriants)?

For instance, in the code below, I reset the objective function after calling optimize!. I even make sure start values are set (it is redundant with the variable call) and even try resetting to a different optimizer. However, sols1 and sols2 are still equal to each other. Any ideas of how to get the solver to ignore the previous solution?

using JuMP, Random, HiGHS, Gurobi
Random.seed!(10)
m = Model()
N = 100

r = rand(N)
@variable(m, x[1:N], start = 0)
@constraint(m, con1[i = 1:N], x[i] >= -r[i])

@objective(m, Min, sum(x))

set_optimizer(m, HiGHS.Optimizer)
optimize!(m)
sols1 = value.(x)
@objective(m, Min, sum(0.0 * x[i] for i in 1:N))
for i in 1:N
    set_start_value(x[i], 0)
end
set_optimizer(m, Gurobi.Optimizer)
optimize!(m)

sols2 = value.(x)

For reference, I am using Julia 1.10 and JuMP v1.21.1

You cannot control what solutions are returned like this. If sols1 is a feasible solution to the second problem, it is a valid solution for Gurobi to return.

The only way to get a “different” solution is to:

  1. Add a constraint that invalidates the first solution, or
  2. Change the objective function so that the first solution is not optimal

You have changed the objective, but the first solution is still optimal (because any feasible solution is optimal).

Gurobi returns you the same solution because, by default, it will return a basic solution, so it does not return the feasible x = 0 solution, even though it is feasible.

1 Like