# All solutions of linear program

**URL:** https://discourse.julialang.org/t/all-solutions-of-linear-program/96562
**Category:** Optimization (Mathematical)
**Tags:** linear-programming
**Created:** [March 24, 2023, 1:44pm UTC](https://discourse.julialang.org/t/all-solutions-of-linear-program/96562 "2023-03-24T13:44:55Z")
**Posts on this page:** 7
**Page:** 1

<div class="post-metadata">

### Author: ![ahmad88](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ahmad88/32/32437_2.png) [@ahmad88](https://discourse.julialang.org/u/ahmad88)
#### Post date: [March 24, 2023, 1:44pm UTC](https://discourse.julialang.org/t/all-solutions-of-linear-program/96562/1 "2023-03-24T13:44:55Z")

</div>

if I have the following model

```julia-auto
	VC_model2 = direct_model(Gurobi.Optimizer())
	@variable(VC_model2, y[i=initial:n], binary=true)
	@variable(VC_model2, x[i=initial:n], binary=true)
	################################################
	@constraint(VC_model2, sum(x[j] for j in initial:n) == k_val)
	for j=initial:n
		@constraint(VC_model2,y[j] <= sum(x[i] for (j,i) in E))
	end
	@objective(VC_model2, Max, sum(y[j] for j in initial:n))
	optimize!(VC_model2)

```

there is any way that gurobi can help to get all the possible solutions of the model?

---

<div class="post-metadata">

### Author: ![mike\_k](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mike_k/32/211864_2.png) [@mike\_k](https://discourse.julialang.org/u/mike_k)
#### Post date: [March 24, 2023, 3:24pm UTC](https://discourse.julialang.org/t/all-solutions-of-linear-program/96562/2 "2023-03-24T15:24:20Z")

</div>

I do not know if Gurobi can achieve that. But you could solve your model in a loop, and cut off each found solution by adding no-good-cuts (as new constraints) until the objective value changes (i.e., then you have cut off all optimal solutions of your initial model).

---

<div class="post-metadata">

### Author: ![gdalle](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/gdalle/32/27854_2.png) [@gdalle](https://discourse.julialang.org/u/gdalle)
#### Post date: [March 24, 2023, 7:15pm UTC](https://discourse.julialang.org/t/all-solutions-of-linear-program/96562/3 "2023-03-24T19:15:55Z")

</div>

Perhaps a good question would be: why do you want to get _all_ solutions?

---

<div class="post-metadata">

### Author: ![jbytecode](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jbytecode/32/17719_2.png) [@jbytecode](https://discourse.julialang.org/u/jbytecode)
#### Post date: [March 24, 2023, 7:24pm UTC](https://discourse.julialang.org/t/all-solutions-of-linear-program/96562/4 "2023-03-24T19:24:06Z")

</div>

I think the question is not Gurobi specific. Alternative solutions might be sought by adding extra constraints and checking the objective value in each try.

---

<div class="post-metadata">

### Author: ![jbytecode](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jbytecode/32/17719_2.png) [@jbytecode](https://discourse.julialang.org/u/jbytecode)
#### Post date: [March 24, 2023, 7:28pm UTC](https://discourse.julialang.org/t/all-solutions-of-linear-program/96562/5 "2023-03-24T19:28:19Z")

</div>

In many cases, alternative optimum solutions provide a menu for the decision maker.

---

<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: [March 24, 2023, 9:32pm UTC](https://discourse.julialang.org/t/all-solutions-of-linear-program/96562/6 "2023-03-24T21:32:21Z")

</div>

> [@ahmad88](#):
>
> there is any way that gurobi can help to get all the possible solutions of the model?

JuMP and Gurobi support returning _some_ solutions. Use `result_count(model)` to see how many it found. For details, see: [Solutions · JuMP](https://jump.dev/JuMP.jl/dev/manual/solutions/#Multiple-solutions)

But this isn’t the same as all solutions. As @mike_k suggests, you’d have to do some iterative method, where you added no-good cuts to remove the solution you just found: [valid inequalities - No-good cuts for general integer variables - Operations Research Stack Exchange](https://or.stackexchange.com/questions/6157/no-good-cuts-for-general-integer-variables)

---

<div class="post-metadata">

### Author: ![jd-foster](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jd-foster/32/35824_2.png) [@jd-foster](https://discourse.julialang.org/u/jd-foster)
#### Post date: [March 25, 2023, 4:54am UTC](https://discourse.julialang.org/t/all-solutions-of-linear-program/96562/7 "2023-03-25T04:54:53Z")

</div>

You may find this tutorial post helpful: [Finding multiple feasible solutions](https://jump.dev/tutorials/2021/11/02/tutorial-multi-jdf/).

It could be used in conjunction with first solving the model once and imposing the optimal objective value as new constraint: `objective function == optimal value of first solve`.
