calculateBestDiscount: calculate the best discount

Description Usage Arguments Details Value Examples

Description

This function calculates the best discount based on analyseShoppingCart(), enumerateCombinations() and extractDiscountSets(). It needs the output of the last mentioned function. Additionally information are required about the price of one item and the discount prices.

Usage

1
2
calculateBestDiscount(discountSets, discountInfos, pricePerItem,
  intermediateSteps = FALSE)

Arguments

discountSets

matrix as it comes from extractDiscountSets()

discountInfos

tibble or data.frame which contains information about the sets and their discount; read details

pricePerItem

numerical price for one item; Currently only one price is allowed

intermediateSteps

logical; if it's set to TRUE, intermediate steps are shown; default is FALSE

Details

Currently the argument discountInfos needs one special format: It needs two columns: 1. The first one is called set and contains numerical information about the discount sets' possibilities (read examples) 2. The second one is called discount and contains numerical information about the discount.

Value

Depending on intermediateSteps, only a numerical vector is returned or a list which additionally contains the intermediate steps.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
```
# These books are available in the shop
books <- dplyr::tibble(
  itemID = 1:5,
  name = c(
    "Stein der Weisen",
    "Kammer des Schreckens",
    "Gefangene von Askaban",
    "Feuerkelch",
    "Orden des Phönix"
  )
)

set.seed(1)
shoppingCart <- dplyr::sample_n(books, 15, replace = TRUE) %>%
  dplyr::arrange(itemID)

ls <- analyseShoppingCart(shoppingCart, itemID, name)
alternatives <- enumerateCombinations(ls)
discountSets <- extractDiscountSets(alternatives)

discountInfos <- dplyr::tibble(
  set = 1:5,
  discount = c(0, 5, 10, 20, 25)
)
calculateBestDiscount(
   correctDiscountSets, discountInfos, pricePerItem = 8
)
```

frumentum/BuyPotterSaveMoney documentation built on May 15, 2019, 10:49 a.m.