GithubHelp home page GithubHelp logo

yfe404 / not-so-slow-knapsack Goto Github PK

View Code? Open in Web Editor NEW
2.0 0.0 0.0 191 KB

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

C++ 91.76% Python 8.24%
knapsack knapsack-problem knapsack-solver optimization optimization-algorithms operations-research multithreading

not-so-slow-knapsack's Introduction

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

not-so-slow-knapsack's People

Stargazers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.