knitr::opts_chunk$set( collapse = TRUE, comment = "#>" )
This package has a class which consist of three methods and one constructer. constructer/initialized method is generated a dataset for the class accounding the user requirement. and then user can call any function from knapsack_brute_force, dynamic_programming or greedy_heuristich.
constructer/initialized method is generated a dataset for the class accounding the user requirement.
This method is solving knapsack problem by using set method. there is an optional parameter parallel (Paral) which is by default FALSE and if you pass the value TRUE to this parameter it calculations the combiinations in parallel manner and performance increases exponentially.
this mathod is profilling the code written in brute_force_knapsack mathod.
This method is solving knapsack problem by using tabular method/ dynamic programming.
this mathod is profilling the code written in knapsack_dynamic mathod.
This function is returning a vector of Residuals
this mathod is profilling the code written in greedy_knapsack mathod.
This is how function will called and output the results
devtools::load_all() obj <- knapsack_class$new() obj$brute_force_knapsack(obj$ks_dataset[1:16,],3500) system.time(obj$brute_force_knapsack(obj$ks_dataset[1:16,],3500)) obj$knapsack_brutefore_profiling(obj$ks_dataset[1:16,],3500)
How much time does it takes to run the algorithm for n = 16 objects?
Answer : it will take 2^16 = 65536 iterations
This is how function will called and output the results
obj$brute_force_knapsack(obj$ks_dataset[1:16,],3500,Paral = TRUE) system.time(obj$brute_force_knapsack(obj$ks_dataset[1:16,],3500,Paral = TRUE)) obj$knapsack_brutefore_profiling(obj$ks_dataset[1:16,],3500,para = TRUE)
What performance gain could you get by trying to improving your code? Answer = we have got around 15 percent better performance after optimizing the code.we have filtered the comibations those have comulative sum greater than W.
What performance gain could you get by parallelizing brute force search? Answer = we have got around 80 percent better performance after parallizing the code of computing the combinations in parallel
This is how function will called and output the results
obj$knapsack_dynamic(obj$ks_dataset[1:8,],3500) system.time(obj$knapsack_dynamic(obj$ks_dataset[1:8,],3500)) obj$knapsack_dynamic_profiling(obj$ks_dataset[1:8,],3500)
How much time does it takes to run the algorithm for n = 500 objects? Answer : it will take n X W time, if W =3500 then it will be 500 X 3500 = 1750000 combinations
This is how function will called and output the results
obj$greedy_knapsack(obj$ks_dataset[1:8,],3500) system.time(obj$greedy_knapsack(obj$ks_dataset[1:8,],3500)) obj$knapsack_greedy_profiling(obj$greedy_knapsack(obj$ks_dataset[1:800,],3500))
How much time does it takes to run the algorithm for n = 1000000 objects? Answer : it will take 6000000 time which is nlogn times
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.