knapsack_class: Knapsack Algorithms

Description Arguments Details Value Author(s) References Examples

Description

This class will generate a dataset for knapsack in initialized function

Arguments

ks_dataset

is a data.frame generated by initialzed function which contain variables W and V, weights and values

ks_size

is the total size of the knapsack

Details

Bruteforce, dynamimc programming and greedy algorithm for the knapsack problem

This algorithm gives all possbile values with good accuracy, and also gives the maximum value for the knapsack

This algorithm gives all possbile values with good accuracy, and also gives the maximum value for the knapsack

This algorithm gives all possbile values with good accuracy, and also gives the maximum value for the knapsack

Value

This function will return a list of selected elements and their total values

This function will return a list of selected elements and their total values

This function will return a list of selected elements and their total values

Author(s)

Mahmood Siddique

References

https://en.wikipedia.org/wiki/Knapsack_problem

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
## Not run: 
obj <- knapsack_class$new()

## End(Not run)
## Not run: 
obj$brute_force_knapsack(obj$ks_dataset[1:8,],3500)
obj$brute_force_knapsack(obj$ks_dataset[1:12,],3500)
obj$brute_force_knapsack(obj$ks_dataset[1:8,],3500,Paral = TRUE)

## End(Not run)
## Not run: 
obj$knapsack_dynamic(obj$ks_dataset[1:8,],3500)
obj$knapsack_dynamic(obj$ks_dataset[1:12,],3500)
obj$knapsack_dynamic(obj$ks_dataset[1:8,],2000)

## End(Not run)
## Not run: 
obj$greedy_knapsack(obj$ks_dataset[1:8,],3500)
obj$greedy_knapsack(obj$ks_dataset[1:12,],3500)
obj$greedy_knapsack(obj$ks_dataset[1:8,],2000)

## End(Not run)

Mahmood1s/lab6 documentation built on Oct. 30, 2019, 9:09 p.m.