Skip to content

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

Notifications You must be signed in to change notification settings

yfe404/not-so-slow-knapsack

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

22 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Not-So-Slow-Knapsack

img/meme.jpg

Overview

Installation

Build binary

mkdir bin; g++ --std=c++11 src/bb_knap.cpp -o bin/knapsack

Usage CLI

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

$ python cli/main.py 
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
1
./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

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

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

Input Example

4 11 
84 10 
5 15 
8 43

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

obj opt
x_0 x_1 x_2 ... x_n-1

Output Format

19 0 
0 0 1 1

Releases

No releases published

Packages

No packages published