# Is there a way to stop optimization process when feasible solution is found?

**URL:** https://discourse.julialang.org/t/is-there-a-way-to-stop-optimization-process-when-feasible-solution-is-found/81025
**Category:** Optimization (Mathematical)
**Tags:** question, jump, optimization
**Created:** [May 13, 2022, 2:43pm UTC](https://discourse.julialang.org/t/is-there-a-way-to-stop-optimization-process-when-feasible-solution-is-found/81025 "2022-05-13T14:43:58Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![afazevedo](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/afazevedo/32/16394_2.png) [@afazevedo](https://discourse.julialang.org/u/afazevedo)
#### Post date: [May 13, 2022, 2:43pm UTC](https://discourse.julialang.org/t/is-there-a-way-to-stop-optimization-process-when-feasible-solution-is-found/81025/1 "2022-05-13T14:43:58Z")

</div>

Hey there.

I am solving a problem with lazy constraints using MOI callback interface. I want to know if there is a way to stop the branch-and-bound process when finding a new incumbent solution that is feasible? I don’t want to close the gap down.

I appreciate any help you can provide!

---

<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: [May 14, 2022, 10:07pm UTC](https://discourse.julialang.org/t/is-there-a-way-to-stop-optimization-process-when-feasible-solution-is-found/81025/2 "2022-05-14T22:07:37Z")

</div>

Hi there. I just moved this to the “Optimization (mathematical)” section.

No, there is no generic way to terminate the solution process. But you can write a solver-dependent callback to do so. Which solver are you using?

If Gurobi, see the `GRBterminate` call here: [GitHub - jump-dev/Gurobi.jl: Julia interface for Gurobi Optimizer](https://github.com/jump-dev/Gurobi.jl#callbacks)

---

<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: [May 16, 2022, 11:57pm UTC](https://discourse.julialang.org/t/is-there-a-way-to-stop-optimization-process-when-feasible-solution-is-found/81025/3 "2022-05-16T23:57:33Z")

</div>

If you do not care about the objective value, you can zero-out the objective. Any solver should terminate as soon as one feasible solution is found.

If you are using Gurobi, you can also use the parameter [`SolutionLimit`](https://www.gurobi.com/documentation/9.5/refman/solutionlimit.html). Setting it to `1` will make Gurobi terminate as soon as the first feasible solution is found (note that “feasible” includes “must satisfy all lazy constraints”). Other solvers may have a similar parameter, but I do know those as well.

---

<div class="post-metadata">

### Author: ![afazevedo](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/afazevedo/32/16394_2.png) [@afazevedo](https://discourse.julialang.org/u/afazevedo)
#### Post date: [May 19, 2022, 2:43pm UTC](https://discourse.julialang.org/t/is-there-a-way-to-stop-optimization-process-when-feasible-solution-is-found/81025/4 "2022-05-19T14:43:37Z")

</div>

Hey odow, thanks!

I am using Gurobi as solver. Thanks for the suggestions.

---

<div class="post-metadata">

### Author: ![afazevedo](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/afazevedo/32/16394_2.png) [@afazevedo](https://discourse.julialang.org/u/afazevedo)
#### Post date: [May 19, 2022, 2:44pm UTC](https://discourse.julialang.org/t/is-there-a-way-to-stop-optimization-process-when-feasible-solution-is-found/81025/5 "2022-05-19T14:44:23Z")

</div>

The parameter works! Thank youuuuuu
