# Multi-cut Benders decomposition?

**URL:** https://discourse.julialang.org/t/multi-cut-benders-decomposition/23472
**Category:** Optimization (Mathematical)
**Created:** [April 24, 2019, 1:57pm UTC](https://discourse.julialang.org/t/multi-cut-benders-decomposition/23472 "2019-04-24T13:57:18Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![deschase](https://avatars.discourse-cdn.com/v4/letter/d/6bbea6/32.png) [@deschase](https://discourse.julialang.org/u/deschase)
#### Post date: [April 24, 2019, 1:57pm UTC](https://discourse.julialang.org/t/multi-cut-benders-decomposition/23472/1 "2019-04-24T13:57:18Z")

</div>

I have coded a Benders decomposition with JuMP, but it is currently running too slow for my needs. I have a way to speed up the process theoretically by collecting several solutions from the solver at each iteration of my algorithm, in order to generate more cuts at each step.  
I am using Gurobi, and I found two parameters that could help me: the PoolSearchMode parameter and the PoolSolutions parameter.  
However, I have not found a way to change those parameters from JuMP and recover several solutions at a time. Is it possible and if it is, how can I do?

---

<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: [April 24, 2019, 3:08pm UTC](https://discourse.julialang.org/t/multi-cut-benders-decomposition/23472/2 "2019-04-24T15:08:55Z")

</div>

> I have not found a way to change those parameters from JuMP

You can set parameters by passing keyword arguments as follows:  
`Model(with_optimizer(Gurobi.Optimizer, OutputFlag=0))`

Unfortunately, there is no easy way to recover several solutions.

You can query attributes as follows:

```julia
model = JuMP.direct_model(Gurobi.Optimizer())
N = 3
@variable(model, x[1:N] >= 0, Int)
Gurobi.set_intattr!(model.inner, "SolutionNumber", 2)
xn = Gurobi.get_dblattrarry(model.inner, "Xn", 1, Gurobi.num_vars(model.inner))

```

But then you need to line up the columns in the Gurobi model with the JuMP variables.

```julia
columns = Dict(
    v => Gurobi.LQOI.get_column(model, JuMP.index(v))
    for v in JuMP.all_variables(model))

```

Then you could look up the solution as follows.

```julia
xN_col = xn[columns[x[N]]]

```

Note: I haven’t tested any of this so there might be typos, etc.

If you get something working, it would be a good addition to the wrapper. Or at least post back here so people can find it in future.

> **[GitHub - jump-dev/Gurobi.jl: Julia interface for Gurobi Optimizer](https://github.com/jump-dev/Gurobi.jl)**
>
> Julia interface for Gurobi Optimizer. Contribute to jump-dev/Gurobi.jl development by creating an account on GitHub.

---

<div class="post-metadata">

### Author: ![deschase](https://avatars.discourse-cdn.com/v4/letter/d/6bbea6/32.png) [@deschase](https://discourse.julialang.org/u/deschase)
#### Post date: [April 29, 2019, 1:09pm UTC](https://discourse.julialang.org/t/multi-cut-benders-decomposition/23472/3 "2019-04-29T13:09:50Z")

</div>

Thanks for your reply, it helped a lot.  
I got something working, so here is a code that gets the `nb_poolsol` best solutions encountered during the branch and bound performed by Gurobi on a toy example:

```julia
# Parameters
nb_poolsol = 10 
Nb_var = 3

```

```julia
# Charging model and solving it
myModel = JuMP.direct_model(Gurobi.Optimizer(PoolSearchMode=2, PoolSolutions=nb_poolsol, SolutionNumber=0))
@variable(myModel, x[1:Nb_var] >= 0, Int)
@objective(myModel, Max, x[1] + x[2] + x[3])
@constraint(myModel, x[1] + x[2] - x[3] <= 8 )
@constraint(myModel, x[1] - x[2] - x[3] <= 10 )
@constraint(myModel, -x[1] + x[2] + x[3] <= 15 )
@constraint(myModel, x[1] + 2*x[2] + 3*x[3] <= 20 )
optimize!(myModel)

```

```julia
# Print the last nb_poolsol solutions
for i in 0:(nb_poolsol-1)
    setparam!(myModel.moi_backend.inner,"SolutionNumber", i)
    xn = Gurobi.get_dblattrarray(myModel.moi_backend.inner, "Xn", 1, Nb_var)
    xn_val = Gurobi.get_dblattr(myModel.moi_backend.inner, "PoolObjVal")
    print(xn)
    print(" -> ")
    println(xn_val)
end

```

---

<div class="post-metadata">

### Author: ![artykbayevk](https://avatars.discourse-cdn.com/v4/letter/a/c6cbf5/32.png) [@artykbayevk](https://discourse.julialang.org/u/artykbayevk)
#### Post date: [May 23, 2019, 8:51am UTC](https://discourse.julialang.org/t/multi-cut-benders-decomposition/23472/4 "2019-05-23T08:51:27Z")

</div>

Hello.

I also tried to find all feasible solutions for linear programming problem. Did you face with problem

 ![%D0%A1%D0%BD%D0%B8%D0%BC%D0%BE%D0%BA](https://global.discourse-cdn.com/julialang/original/3X/a/f/afb15f8885b64ae34dc1bd6f2501ce1b0d991be2.png) ???

Because when I try to find all solutions, gurobi said that there are no any other solutions

---

<div class="post-metadata">

### Author: ![deschase](https://avatars.discourse-cdn.com/v4/letter/d/6bbea6/32.png) [@deschase](https://discourse.julialang.org/u/deschase)
#### Post date: [May 23, 2019, 11:57am UTC](https://discourse.julialang.org/t/multi-cut-benders-decomposition/23472/5 "2019-05-23T11:57:57Z")

</div>

Hello,

I am sorry, I never had this particular problem.  
However, every time I got a problem in the query part of this code, the real issue was in the model or in the resolution, not in the query
