# LP Warm Starts - using Gurobi with JuMP

**URL:** <https://discourse.julialang.org/t/lp-warm-starts-using-gurobi-with-jump/73840>\
**Category:** Optimization (Mathematical)\
**Created:** [December 30, 2021, 10:11pm UTC](https://discourse.julialang.org/t/lp-warm-starts-using-gurobi-with-jump/73840 "2021-12-30T22:11:42Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![bjr221](https://avatars.discourse-cdn.com/v4/letter/b/bcef8e/32.png) [@bjr221](https://discourse.julialang.org/u/bjr221)\
**Post date:** [December 30, 2021, 10:11pm UTC](https://discourse.julialang.org/t/lp-warm-starts-using-gurobi-with-jump/73840/1 "2021-12-30T22:11:42Z")

</div>

Is there any way to warm start (choose initial vertex for dual simplex algorithm) for a linear program that you’ve created? I have tried using the “PStart” attribute for LPs to no avail, and the “.start” attribute is for MIPs only.

Any help or guidance would be appreciated.

Thanks!

---

<div class="post-metadata">

**Author:** ![mtanneau](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mtanneau/32/17787_2.png) [@mtanneau](https://discourse.julialang.org/u/mtanneau)\
**Post date:** [December 31, 2021, 11:44am UTC](https://discourse.julialang.org/t/lp-warm-starts-using-gurobi-with-jump/73840/2 "2021-12-31T11:44:57Z")

</div>

Hi, and welcome!

Long story short: (i) yes there is, but (ii) it depends on the LP solver (and algorithm) you use.  
The JuMP function that does so is [`set_start_value`](https://jump.dev/JuMP.jl/stable/reference/variables/#JuMP.set_start_value).

> I have tried using the “PStart” attribute for LPs to no avail

Can you give more details about what happened there? For instance, did you encounter an error? Did the code run smoothly but the provided warm-start changed nothing?  
Providing a minimal working example would help giving specific feedback and identifying the issue: see [Please read: make it easier to help you](https://discourse.julialang.org/t/please-read-make-it-easier-to-help-you/14757).

There is a lot that may be happening: could be an issue with how you call JuMP, it could be a bug in JuMP itself, it could be that Gurobi silently rejects your warm-start, or that the warm-start you provide is actually detrimental to Gurobi’s performance, etc.  
Without a working example one can only speculate which it is.

---

<div class="post-metadata">

**Author:** ![Henrique\_Becker](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/henrique_becker/32/15443_2.png) [@Henrique\_Becker](https://discourse.julialang.org/u/Henrique_Becker)\
**Post date:** [December 31, 2021, 3:01pm UTC](https://discourse.julialang.org/t/lp-warm-starts-using-gurobi-with-jump/73840/3 "2021-12-31T15:01:53Z")

</div>

It is news to me that `set_start_value` can be used this way, until now I was only able to initialize MIP models with a MIP-start using it, never an LP. Even the documentation pointed in this direction with:

> Note: VariablePrimalStarts are sometimes called “MIP-starts” or “warmstarts”.

---

<div class="post-metadata">

**Author:** ![mtanneau](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mtanneau/32/17787_2.png) [@mtanneau](https://discourse.julialang.org/u/mtanneau)\
**Post date:** [December 31, 2021, 4:15pm UTC](https://discourse.julialang.org/t/lp-warm-starts-using-gurobi-with-jump/73840/4 "2021-12-31T16:15:35Z")

</div>

> It is news to me that `set_start_value` can be used this way, until now I was only able to initialize MIP models with a MIP-start using it, never an LP

I wrote so because, in [this JuMP tutorial](https://jump.dev/JuMP.jl/stable/tutorials/nonlinear/space_shuttle_reentry_trajectory/#Optimal-control-for-a-Space-Shuttle-reentry-trajectory) it’s used for a continuous problem (with Ipopt).

Back to Gurobi, the [MOI wrapper](https://github.com/jump-dev/Gurobi.jl/blob/1008e8cf2e11ec0e8ed846f55757ffe9aefd5c14/src/MOI_wrapper/MOI_wrapper.jl#L3254) for `VariablePrimalStart` falls back to Gurobi’s [`Start` attribute](https://www.gurobi.com/documentation/9.5/refman/start.html#attr:Start), which is indeed for MIP problems only.

---

<div class="post-metadata">

**Author:** ![odow](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/odow/32/28685_2.png) [@odow](https://discourse.julialang.org/u/odow)\
**Post date:** [January 2, 2022, 8:56pm UTC](https://discourse.julialang.org/t/lp-warm-starts-using-gurobi-with-jump/73840/5 "2022-01-02T20:56:34Z")

</div>

How did you set the attributes?

You probably need to set `PStart` for _every_ variable and `DStart` for _every_ constraint.

---

<div class="post-metadata">

**Author:** ![bjr221](https://avatars.discourse-cdn.com/v4/letter/b/bcef8e/32.png) [@bjr221](https://discourse.julialang.org/u/bjr221)\
**Post date:** [January 3, 2022, 2:59am UTC](https://discourse.julialang.org/t/lp-warm-starts-using-gurobi-with-jump/73840/6 "2022-01-03T02:59:34Z")

</div>

Hi, thank you very much for your response!

I have been trying to solve an LP with the dual simplex method. I’d like to have a warm start that is not necessarily feasible. I’ll provide a simple code example that shows what I’m trying to do.

import Clp  
import Gurobi  
import Random  
using JuMP  
using Gurobi

model = Model(Gurobi.Optimizer)  
@variable(model, x[1:2] \>= 0)  
@objective(model, Max, 2\*x[1] + x[2])

@constraint(model, c1, x[1] \<= 1)  
@constraint(model, c3, x[2] \<= 1)  
set\_optimizer\_attribute(model, “Method”, 1) #use dual simplex  
set\_optimizer\_attribute(model, “Presolve”, 0)

set\_start\_value(x[1], 0.75)  
set\_start\_value(x[2], 0.75)

print(model)  
optimize!(model)

The output indicates that the warm start is being ignored. I tried to work around this by adding a superfluous binary variable to the model. This actually worked, and seemed to provide warm starts given that they were feasible. However, when I tried to provide an infeasible initial solution (1.5, 1.5), an error message appears indicating that the warm start is being ignored:

“User MIP start did not produce a new incumbent solution  
User MIP start violates constraint R0 by 0.500000000”

Also, regarding PStart - I will try setting the DStart values as well as the previous user suggested. However, it seems like the attribute is unrecognized. When I try “x[1].Start(0.5)” I get the error message “type VariableRef has no field Start”, and a similar message when trying to use PStart.

Thanks again for you help and advice!

---

<div class="post-metadata">

**Author:** ![dschermer](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/dschermer/32/32093_2.png) [@dschermer](https://discourse.julialang.org/u/dschermer)\
**Post date:** [January 3, 2022, 11:48pm UTC](https://discourse.julialang.org/t/lp-warm-starts-using-gurobi-with-jump/73840/7 "2022-01-03T23:48:32Z")

</div>

The key is in the Gurobi documentation for [PStart](https://www.gurobi.com/documentation/9.5/refman/pstart.html#attr:PStart), DStart, et cetera:

> _Note that a **ny model modifications** which are pending or are made after setting `PStart` (adding variables or constraints, changing coefficients, etc.) **will discard the start**. You should only set this attribute after you are done modifying your model._

Check the following minimal working example (note the use of `direct_model` and the corresponding update). For the primal simplex (`Method = 0`), it appears sufficient to specify the `PStart`; conversely, for the dual simplex (`Method = 1`), it appears sufficient to specify just the `DStart`). If these values are not specified in the corresponding cases the solver outputs `LP warm-start: discard starts`.

```julia
using JuMP
using Gurobi

model = direct_model(Gurobi.Optimizer())

@variable(model, x[1:2] >= 0)
@objective(model, Max, 2*x[1] + x[2])
@constraint(model, c1, x[1] <= 1)
@constraint(model, c3, x[2] <= 1)
set_optimizer_attribute(model, "Method", 0) # Primal Simplex
set_optimizer_attribute(model, "Presolve", 0)

grb = backend(model)
@show(grb.needs_update) # This yields true
Gurobi.GRBupdatemodel(grb) # Thus, we need to do this

MOI.set(model, Gurobi.VariableAttribute("PStart"), x[1], 0.75)
MOI.set(model, Gurobi.VariableAttribute("PStart"), x[2], 0.75)
#MOI.set(model, Gurobi.ConstraintAttribute("DStart"), c1, 2.0)
#MOI.set(model, Gurobi.ConstraintAttribute("DStart"), c3, 1.0)

optimize!(model)

```

Output (using Gurobi 9.5):

```julia
Optimize a model with 2 rows, 2 columns and 2 nonzeros
Coefficient statistics:
  Matrix range [1e+00, 1e+00]
  Objective range [1e+00, 2e+00]
  Bounds range [0e+00, 0e+00]
  RHS range [1e+00, 1e+00]
Primal warm-start: 2 superbasic variables.
Iteration Objective Primal Inf. Dual Inf. Time
       0 2.2500000e+00 0.000000e+00 3.000000e+00 0s
       2 3.0000000e+00 0.000000e+00 0.000000e+00 0s

Solved in 2 iterations and 0.00 seconds (0.00 work units)
Optimal objective 3.000000000e+00

```
