# Enumerating all possible solutions of Knapsack problem

**URL:** <https://discourse.julialang.org/t/enumerating-all-possible-solutions-of-knapsack-problem/61800>\
**Category:** Optimization (Mathematical)\
**Created:** [May 25, 2021, 5:42pm UTC](https://discourse.julialang.org/t/enumerating-all-possible-solutions-of-knapsack-problem/61800 "2021-05-25T17:42:04Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Tomas\_Pevny](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tomas_pevny/32/25466_2.png) [@Tomas\_Pevny](https://discourse.julialang.org/u/Tomas_Pevny)\
**Post date:** [May 25, 2021, 5:42pm UTC](https://discourse.julialang.org/t/enumerating-all-possible-solutions-of-knapsack-problem/61800/1 "2021-05-25T17:42:04Z")

</div>

Dear All,

I would like to ask, if anyone has experimented with an algorithm to enumerate all possible solutions of the knapsack problem. I have seen scientific papers solving this problem and would like to know, if someone has tackled this.

Thank you very much in advance.

Tomas

---

<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 25, 2021, 8:03pm UTC](https://discourse.julialang.org/t/enumerating-all-possible-solutions-of-knapsack-problem/61800/2 "2021-05-25T20:03:57Z")

</div>

> all possible solutions

All possible _optimal_ solutions?

This came up a few days ago:

> [@Right solver for JuMP to find every solution of a linear system of equations with integer solutions](https://discourse.julialang.org/t/right-solver-for-jump-to-find-every-solution-of-a-linear-system-of-equations-with-integer-solutions/44709/22):
>
> No problem. While it’s fresh in my mind, here is a more general solution for future reference: ## Packages using JuMP using Gurobi function example\_big\_sum(rowsum, colsum; verbose::Bool = true) ## Model: model = Model(Gurobi.Optimizer) @assert length(rowsum) == length(colsum) N = length(rowsum) INDEX = 1:N @variable(model, y[INDEX,INDEX] \>= 0, Int) @constraint(model, rowCons[i=INDEX], sum(y[i,j] for j in INDEX) == rowsum[i]) @constraint(model, colCons[j=INDEX…

See the JuMP documentation:

> **[Solutions · JuMP](https://jump.dev/JuMP.jl/stable/manual/solutions/#Multiple-solutions)**
>
> Documentation for JuMP.

---

<div class="post-metadata">

**Author:** ![ccoffrin](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ccoffrin/32/400_2.png) [@ccoffrin](https://discourse.julialang.org/u/ccoffrin)\
**Post date:** [May 26, 2021, 1:42am UTC](https://discourse.julialang.org/t/enumerating-all-possible-solutions-of-knapsack-problem/61800/3 "2021-05-26T01:42:45Z")

</div>

I will also note if you would like to roll your own algorithm to do this the following online course can provide some good ideas for how to approach it.

> **[Discrete Optimization](https://www.coursera.org/learn/discrete-optimization)**
>
> Offered by The University of Melbourne. Tired of solving Sudokus by hand? This class teaches you how to solve complex search problems with ... Enroll for free.

---

<div class="post-metadata">

**Author:** ![Tomas\_Pevny](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tomas_pevny/32/25466_2.png) [@Tomas\_Pevny](https://discourse.julialang.org/u/Tomas_Pevny)\
**Post date:** [May 26, 2021, 3:57am UTC](https://discourse.julialang.org/t/enumerating-all-possible-solutions-of-knapsack-problem/61800/4 "2021-05-26T03:57:36Z")

</div>

Thank you very much both. I would not kind to follow the course, but there are many things I need to follow. But the course looks amazing.

Tomas

I knew that this forum will not let me down.
