0

I've just tried using the mmKnapsack function to solve a multi-dimensional knapsack problem in R. I noticed that the solution seemed a bit suspect, so I tried a very simple 2-d problem:the 2-d problem. It returned an optimal profit of 720, which I can easily see is not the optimal profit of the 2-d problem(the optimal profit is 740). It returns a solution of items 2 and 1 as shown here, but the optimal solution is items 1, 4 and 6. Here is the code I ran

  • Welcome to SO. To get help on this site, you should include a portion of your data and your code, something that can be easily copy-pasted (no pics of code or data). Also, this site is focused on programming issues, if you have modeling questions they're better directed to [Cross Validated](https://stats.stackexchange.com/). Check out [this post](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) for more info. – astrofunkswag Mar 19 '20 at 03:45

1 Answers1

0

Probably it just depends on the argument len of the function. For example, if I run the following code

# packages
library(FLSSS)

# data
prof <- c(400, 320, 230, 210, 190, 130)
costs <- cbind(
  c(6, 3, 2, 2, 2, 1), 
  c(8, 8, 7, 6, 5, 4)
)

capac <- c(9, 18)

then I get your current optimal sack

mmKnapsack(
  maxCore = 3, 
  len = 2, 
  itemsProfits = prof, 
  itemsCosts = costs, 
  capacities = capac
)
#> Updated profit = 720
#> $solution
#> [1] 2 1
#> 
#> $selectionCosts
#> [1]  9 16
#> 
#> $budgets
#> [1]  9 18
#> 
#> $selectionProfit
#> [1] 720
#> 
#> $unconstrainedMaxProfit
#> [1] 720

but if I increase the maximum subsize size (i.e. please note that I set len = 3), the I get another optimal solution.

mmKnapsack(
  maxCore = 3, 
  len = 3, 
  itemsProfits = prof, 
  itemsCosts = costs, 
  capacities = capac
)
#> Updated profit = 630
#> Updated profit = 660
#> Updated profit = 720
#> Updated profit = 740
#> $solution
#> [1] 6 4 1
#> 
#> $selectionCosts
#> [1]  9 18
#> 
#> $budgets
#> [1]  9 18
#> 
#> $selectionProfit
#> [1] 740
#> 
#> $unconstrainedMaxProfit
#> [1] 950

Created on 2020-03-19 by the reprex package (v0.3.0)

From the package docs you can read that if you set len = 0, then FLSSS function tries to look for the optimal solution for all subset sizes, i.e.

mmKnapsack(
  maxCore = 3, 
  len = 0, 
  itemsProfits = prof, 
  itemsCosts = costs, 
  capacities = capac
)
#> Updated profit = 630
#> Updated profit = 740
#> $solution
#> [1] 1 4 6
#> 
#> $selectionCosts
#> [1]  9 18
#> 
#> $budgets
#> [1]  9 18
#> 
#> $selectionProfit
#> [1] 740
#> 
#> $unconstrainedMaxProfit
#> [1] NA

Created on 2020-03-19 by the reprex package (v0.3.0)

agila
  • 3,289
  • 2
  • 9
  • 20