https://github.com/anniedotexe/knapsack
https://github.com/anniedotexe/knapsack
Last synced: 7 months ago
JSON representation
- Host: GitHub
- URL: https://github.com/anniedotexe/knapsack
- Owner: anniedotexe
- Created: 2018-05-20T21:05:14.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2019-08-17T00:10:13.000Z (about 6 years ago)
- Last Synced: 2025-01-20T21:11:34.132Z (9 months ago)
- Language: Java
- Size: 32.2 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Knapsack
Given weights and values of n items, we need to put these items in a knapsack of a given capacity
to get the maximum total value in the knapsack.In the Fractional Knapsack Problem, we can break items for maximizing the total value of knapsack.
In the 0/1 Knapsack Problem, we are not allowed to break items. We either take all or nothing.
### The Program
This program will read in an input file that contains the max capacity of the knapsack,
the number of objects, and each object's weight and profit.The user can choose to:
#### Sample Output
```
Which task do you want to run?
1. Fractional Knapsack
2. 0/1 Knapsack
3. Exit
1
Object: 1 Weight: 13 Profit: 32
Object: 3 Weight: 29 Profit: 27
Object: 4 Weight: 23 Profit: 19
Object: 5 Weight: 43 Profit: 15
Object: 6 Weight: 10 Profit: 41
Object: 11 Weight: 21 Profit: 30
Object: 13 Weight: 28 Profit: 34
Object: 14 Weight: 26 Profit: 37
Object: 16 Weight: 44 Profit: 20
Object: 17 Weight: 36 Profit: 15
Object: 18 Weight: 23 Profit: 44
Object: 20 Weight: 38 Profit: 50
Max profit: 364
Which task do you want to run?
1. Fractional Knapsack
2. 0/1 Knapsack
3. Exit
2
Object: 1 Weight: 13 Profit: 32
Object: 3 Weight: 29 Profit: 27
Object: 4 Weight: 23 Profit: 19
Object: 6 Weight: 10 Profit: 41
Object: 7 Weight: 30 Profit: 37
Object: 9 Weight: 18 Profit: 16
Object: 10 Weight: 36 Profit: 38
Object: 11 Weight: 21 Profit: 30
Object: 12 Weight: 17 Profit: 26
Object: 13 Weight: 28 Profit: 34
Object: 14 Weight: 26 Profit: 37
Object: 18 Weight: 23 Profit: 44
Object: 19 Weight: 30 Profit: 17
Object: 20 Weight: 38 Profit: 50
Max profit: 448
Which task do you want to run?
1. Fractional Knapsack
2. 0/1 Knapsack
3. Exit
3
The program has ended.
```