Retrieve current solution when termination_status is TIME_LIMIT

marilena
Wed, 10 Dec 2025 09:56:59 +0000
Optimization (Mathematical)

Hello to the community!

I am using Julia v1.9.3 , with packages JuMP v1.23.2 and Gurobi v1.3.1. I am solving an LP using Barrier, and I specify a time limit.

gurobi_env = Gurobi.Env()
Solver = optimizer_with_attributes(() -> Gurobi.Optimizer(gurobi_env), "Method" => 2, "TimeLimit" => time_limit)
model = Model(Solver)
# ... create model, assume a variable my_x
optimize!(model)
termination_status(model)
primal_status(model)
x0 = value(my_x)

Barrier iterates within the feasible region, therefore when the time limit is enforced (termination_status(model) returns TIME_LIMIT), while the optimal solution is still not found, a feasible solution should be available. Nevertheless, primal_status(model) returns NO_SOLUTION and value(my_x) returns an error.

In order to retrieve the solution at the time of termination, I need to use the gurobi backend:

model = direct_model(Solver)
# ...
x0 = MOI.get(backend(model), Gurobi.VariableAttribute("X"), index(my_x))

This allows me to retrieve the values (and proves that they are somehow availble). However, I am not sure I could use it; I have not fully explored the implications of using direct_model for my application, which involves an iterative approach (Benders’ decomposition type) where several model modifications are required. I understand from the JuMP documentation that direct_model has limitations on the types of modificiations allowed.

I guess my questions are the following:

1. do I have other options that I have missed?

2. would Julia (JuMP, MOI or Gurobi) development team consider to ensure that the current solution is available when termination status is TIME_LIMIT?

3. is this maybe addressed in updated versions of the relative packages?

Many thanks for reading!
Marilena

8 posts - 3 participants