# Efficient way to solve similar optimization problems with JuMP

**URL:** <https://discourse.julialang.org/t/efficient-way-to-solve-similar-optimization-problems-with-jump/62793>\
**Category:** Optimization (Mathematical)\
**Tags:** question, jump, first-steps\
**Created:** [June 12, 2021, 1:22pm UTC](https://discourse.julialang.org/t/efficient-way-to-solve-similar-optimization-problems-with-jump/62793 "2021-06-12T13:22:13Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![AtsushiSakai](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/atsushisakai/32/6559_2.png) [@AtsushiSakai](https://discourse.julialang.org/u/AtsushiSakai)\
**Post date:** [June 12, 2021, 1:22pm UTC](https://discourse.julialang.org/t/efficient-way-to-solve-similar-optimization-problems-with-jump/62793/1 "2021-06-12T13:22:13Z")

</div>

I would like to solve some similar optimization problems, which are mathematical formulation (cost and constraints) are same, but just model parameter values or size of model parameters are different, in JuMP.  
Currently, I’m rebuilding each model from scratch for each problem, but it  
Is there any efficient way to solve these problems (e.g. reusing model, caching modeling result, etc)

---

<div class="post-metadata">

**Author:** ![Elmo](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/elmo/32/17979_2.png) [@Elmo](https://discourse.julialang.org/u/Elmo)\
**Post date:** [June 12, 2021, 1:54pm UTC](https://discourse.julialang.org/t/efficient-way-to-solve-similar-optimization-problems-with-jump/62793/2 "2021-06-12T13:54:05Z")

</div>

Which parts of the formulation are similar? When it comes to constraints you can delete them, modify them etc. pretty easily. Check out the docs [here](https://jump.dev/JuMP.jl/stable/manual/constraints/#Modify-a-constraint).

Also check out the warm start functionality [here](https://jump.dev/JuMP.jl/stable/manual/variables/#Start-values), although to be honest I have not found this to really speed up solving (I usually work with LPs of ~3000 variables)

---

<div class="post-metadata">

**Author:** ![AtsushiSakai](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/atsushisakai/32/6559_2.png) [@AtsushiSakai](https://discourse.julialang.org/u/AtsushiSakai)\
**Post date:** [June 13, 2021, 1:49pm UTC](https://discourse.julialang.org/t/efficient-way-to-solve-similar-optimization-problems-with-jump/62793/3 "2021-06-13T13:49:12Z")

</div>

Thanks you for your comment.

> Which parts of the formulation are similar?

Both cost and constraints. I modified my question. Deleting constraints looks useful, I will try it.

---

<div class="post-metadata">

**Author:** ![blegat](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/blegat/32/217090_2.png) [@blegat](https://discourse.julialang.org/u/blegat)\
**Post date:** [June 13, 2021, 3:04pm UTC](https://discourse.julialang.org/t/efficient-way-to-solve-similar-optimization-problems-with-jump/62793/4 "2021-06-13T15:04:51Z")

</div>

It’s usually best to modify a constraint rather than deleting it when possible. For modifying the cost/objetive, see [here](https://jump.dev/JuMP.jl/stable/manual/objective/#Modify-an-objective).  
Note that if the solver does not support your modification, it maybe be discarded and recreated from scratch silently. You could use the [MANUAL mode](https://jump.dev/JuMP.jl/stable/manual/models/#CachingOptimizer) to control this and get an error instead of being silently discarded. See also [Direct mode](https://jump.dev/JuMP.jl/stable/manual/models/#Direct-mode) for even more control.

---

<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:** [June 13, 2021, 10:06pm UTC](https://discourse.julialang.org/t/efficient-way-to-solve-similar-optimization-problems-with-jump/62793/5 "2021-06-13T22:06:16Z")

</div>

@Elmo most (all?) solvers ignore warm-starts for LPs. They are used when starting MILPs.

---

<div class="post-metadata">

**Author:** ![Elmo](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/elmo/32/17979_2.png) [@Elmo](https://discourse.julialang.org/u/Elmo)\
**Post date:** [June 14, 2021, 9:54am UTC](https://discourse.julialang.org/t/efficient-way-to-solve-similar-optimization-problems-with-jump/62793/6 "2021-06-14T09:54:00Z")

</div>

Ah, I didn’t know that. I thought LPs can use a previous solution as a starting feasible point if, e.g. only the objective changes. Shouldn’t that be more efficient in theory since the solver can skip the initialization (feasibility problem) step?

---

<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:** [June 14, 2021, 5:09pm UTC](https://discourse.julialang.org/t/efficient-way-to-solve-similar-optimization-problems-with-jump/62793/7 "2021-06-14T17:09:34Z")

</div>

In some cases the solver may warm-start from a previous basic feasible solution contained within the solver from a previous solve. But this is independent of `set_warm_start`.

```nohighlight
using JuMP, Gurobi
model = Model(Gurobi.Optimizer)
@variable(model, x >= 0)
@constraint(model, 2x >= 1)
@objective(model, Min, x)
optimize!(model)
@objective(model, Min, 2x)
optimize!(model) # Warmstarts from previous solve

```

---

<div class="post-metadata">

**Author:** ![cvanaret](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/cvanaret/32/11594_2.png) [@cvanaret](https://discourse.julialang.org/u/cvanaret)\
**Post date:** [June 14, 2021, 5:16pm UTC](https://discourse.julialang.org/t/efficient-way-to-solve-similar-optimization-problems-with-jump/62793/8 "2021-06-14T17:16:04Z")

</div>

A precision: if the new problem has the same feasible set as the previous one, yes the solution to the previous problem should be used as feasible initial point. If the feasible set changes (for example, cuts are added in MINLP frameworks), the previous solution may not be feasible any more, however it stays dual feasible.  
This is the reason why MINLP frameworks usually work with the dual simplex (= simplex applied to the dual problem). In this case, you maintain dual feasibility throughout and converge when primal feasibility is attained.  
Dual active-set methods are brilliant in this regard 🙂

---

<div class="post-metadata">

**Author:** ![AtsushiSakai](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/atsushisakai/32/6559_2.png) [@AtsushiSakai](https://discourse.julialang.org/u/AtsushiSakai)\
**Post date:** [June 14, 2021, 11:36pm UTC](https://discourse.julialang.org/t/efficient-way-to-solve-similar-optimization-problems-with-jump/62793/9 "2021-06-14T23:36:55Z")

</div>

Thank you. Your answer is what I want, I will try it.
