An open API service indexing awesome lists of open source software.

https://github.com/yfe404/not-so-slow-knapsack

Multi-threaded Knapsack Solver - uses branch and bound and/or dynamic programming
https://github.com/yfe404/not-so-slow-knapsack

knapsack knapsack-problem knapsack-solver multithreading operations-research optimization optimization-algorithms

Last synced: 5 months ago
JSON representation

Multi-threaded Knapsack Solver - uses branch and bound and/or dynamic programming

Awesome Lists containing this project

README

          

* Not-So-Slow-Knapsack

[[file:img/meme.jpg]]

** Overview

*** Installation

Build binary
#+BEGIN_SRC sh
mkdir bin; g++ --std=c++11 src/bb_knap.cpp -o bin/knapsack
#+END_SRC

*** Usage CLI

Note: tested on =python3.6=, the only requirement is =click= library.

#+BEGIN_SRC sh
$ python cli/main.py
#+END_SRC

#+BEGIN_SRC
Choose a problem instance:

1) ks_60_0
2) ks_4_0
3) ks_45_0
4) ks_30_0
5) ks_lecture_dp_2
6) ks_10000_0
7) ks_300_0
8) ks_200_0
9) ks_100_1
10) ks_100_0
11) ks_200_1
12) ks_500_0
13) ks_400_0
14) ks_lecture_dp_1
15) ks_19_0
16) ks_100_2
17) ks_106_0
18) ks_40_0
19) ks_82_0
20) ks_50_0
21) ks_50_1
22) ks_1000_0
#+END_SRC

#+BEGIN_SRC sh
1
#+END_SRC

#+BEGIN_SRC sh
./data/ks_60_0
99837 1
0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 1 0 1 0 1 0 1 0 0 0 1 0 1 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
#+END_SRC

** Input Format

The first line contains 2 integers: =n= the number of lines i.e. the number of items and =K= the capacity of the knapsack.
The =n= next lines contain 2 integers: the *value* and the *weight* of an item.

*** Format
#+BEGIN_SRC sh

n K
v_0 w_0
v_1 w_1
...
v_n-1 w_n-1

#+END_SRC

*** Input Example
#+BEGIN_SRC sh
4 11
84 10
5 15
8 43
#+END_SRC

** Output Format

The first line contains 2 integers =obj= which is the value of the knapsack i.e. the sum of the values of each items in the knapsack. The second integer =opt=
is either 0 or 1, 1 if =obj= is the global optimum (proven), 0 else. The second (and last) line contains =n= integers (the number of items) with a value of
1 if the item is in the knapsack or 0 else.

*** Format
#+BEGIN_SRC sh
obj opt
x_0 x_1 x_2 ... x_n-1
#+END_SRC

*** Output Format
#+BEGIN_SRC sh
19 0
0 0 1 1
#+END_SRC