```r knitr::opts_chunk$set( collapse = TRUE, comment = "#>" )

---
  ```r
knitr::opts_chunk$set(
  collapse = TRUE,
  comment = "#>",
  echo = TRUE
)
library(parallel)
library(AdvRLab6)

1.1.2 Brute force search

How much time does it takes to run the algorithm for n = 16 objects?

Answer:

We will use the function system.time to measure the time that it takes to evaluate this function:

system.time(brute_force_knapsack(x = knapsack_objects[1:16,], W = 3500))

1.1.3 Dynamic Programming

How much time does it takes to run the algorithm for n = 500 objects?

Answer:

system.time(knapsack_dynamic(x = knapsack_objects[1:500,], W = 3500))

1.1.4 Greedy heuristic

How much time does it takes to run the algorithm for n = 1000000 objects?

system.time(greedy_knapsack(x = knapsack_objects[1:1000000,], W = 3500))

Answer:

3. Profiling and optimization.

NOTE: Package lineprof is not available for R version 3.6.1, so we will use package profvis instead.

3.1. Brute force search algorithm.

#profvis::profvis(brute_force_knapsack(x = knapsack_objects[1:100,], W = 3500))

Reference

DataSet knapsack_objects



nourqweder/AdvRLab6 documentation built on Nov. 4, 2019, 10:09 p.m.