Skip to contents

Generate functions that calculate a revenue (based on the price calculator) or a share for the given candidate.

Usage

tabu_fitness(
  candidate,
  utils,
  prohibitions,
  price_calculator,
  top_level = "top_level",
  measure = c("share", "revenues"),
  concepts = NULL,
  meta_design,
  toplevel_related_variables,
  utils_none_name = "NONE"
)

tabu_fitness_generator(
  utils,
  prohibitions,
  price_calculator,
  top_level = "top_level",
  measure = c("share", "revenues"),
  concepts = NULL,
  meta_design,
  toplevel_related_variables,
  utils_none_name = "NONE"
)

Arguments

candidate

A candidate to calculate the measurement.

utils

A data.frame containing variables and indyvidual level utilities. If a variable is a top level related variable, it needs to have the top name string included in the name. For categorical the name should include the level that represents the utility for the level.

prohibitions

A NULL to allow every candidate to be scored or a set of possible candidates to restrict to during the scoring process.

price_calculator

A function to be used to calculate the revenue.

top_level

The name of the top level attribute. If there is none such an attribute in the design, adjust the candidate to that it has a dummy variable that has the same top_level value in each cell. Create one general input in the meta_design with the name used in the top_level.

measure

Whether use a share or the revenue as a main measure.

concepts

A vector of intigers specyfing for which concept numbers the revenue should be only calculated.

meta_design

The meta_design. The format explained in details.

Specify the name of the top level related variables so the look up into the utilities table known that it should also use the top level name when extracting proper column from utilities table

utils_none_name

The name of the column containing NONE utilities. Used to reduce the overall share by the NONE option.

Details

tabu_fitness_generator works the way it sets tabu_fitness function parameters for specific value and returns that function with the changed default values. tabu_fitness is a workhorse here however tabu_fitness_generator is a convenient way to specify the input for tabu_search.

Examples


# prepare the data

data(ds_bain_candidate, package = "g6tr.tabu")
data(ds_bain_utilities, package = "g6tr.tabu")

library(dplyr)

ds_bain_candidate_many_multiple_toplevels <-
  ds_bain_candidate %>%
  bind_rows(
    tibble(
      top_level = "value",
      message = 4,
      quality = 1,
      embellish = 1,
      money_option = 3,
      fake_numeric = 8
    )
  )

ds_bain_candidate_thesame_toplevel <-
  ds_bain_candidate_many_multiple_toplevels %>%
  filter(top_level == "value")

bain_meta_design <-
  list(
    value = list(
      message = c(1:2, 4),
      quality = 1,
      embellish = 1,
      money_option = 1:6,
      fake_numeric = c(3, 6, 8, 10)
    ),
    standard = list(
      message = c(1:4),
      quality = 1:2,
      embellish = 1:2,
      money_option = 1:6,
      fake_numeric = c(3, 6, 10)
    ),
    premium = list(
      message = c(1:4),
      quality = 2:4,
      embellish = 2:4,
      money_option = 1:6,
      fake_numeric = c(3, 8, 10)
    )
  )


attr(bain_meta_design, "classes") <-
  list(
    message = "ordered",
    quality = "categorical",
    embellish = "categorical",
    money_option = "ordered",
    fake_numeric = "numeric"
  )

# set the price calculator
bain_price_calculator <- function(candidate) {
  candidate %>%
    mutate(money_option = as.integer(money_option)) %>%
    mutate(
      price = case_when(
        top_level == "value" & money_option == 1 ~ 0.7,
        top_level == "value" & money_option == 2 ~ 0.9,
        top_level == "value" & money_option == 3 ~ 1.1,
        top_level == "value" & money_option == 4 ~ 1.25,
        top_level == "value" & money_option == 5 ~ 1.75,
        top_level == "value" & money_option == 6 ~ 1.99,
        top_level == "standard" & money_option == 1 ~ 2.99,
        top_level == "standard" & money_option == 2 ~ 4.1,
        top_level == "standard" & money_option == 3 ~ 4.5,
        top_level == "standard" & money_option == 4 ~ 4.75,
        top_level == "standard" & money_option == 5 ~ 4.99,
        top_level == "standard" & money_option == 6 ~ 5.15,
        top_level == "premium" & money_option == 1 ~ 5.5,
        top_level == "premium" & money_option == 2 ~ 6.99,
        top_level == "premium" & money_option == 3 ~ 7.95,
        top_level == "premium" & money_option == 4 ~ 8.65,
        top_level == "premium" & money_option == 5 ~ 8.99,
        top_level == "premium" & money_option == 6 ~ 9.75
      )
    ) %>%
    pull(price)
}

# execute fintess generator functions
fitness_share <-
  tabu_fitness_generator(
    ds_bain_utilities,
    prohibitions = NULL,
    price_calculator = bain_price_calculator, top_level = "top_level",
    measure = "share",
    concepts = NULL, #' should we calculate the share for specific concepts
    meta_design = bain_meta_design,
    toplevel_related_variables = "money_option",
    utils_none_name = "NONE"
  )

fitness_share_concepts <-
  tabu_fitness_generator(
    ds_bain_utilities,
    prohibitions = NULL,
    price_calculator = bain_price_calculator,
    top_level = "top_level",
    measure = "share",
    concepts = c(1, 3), #' should we calculate the share for specific concepts
    meta_design = bain_meta_design,
    toplevel_related_variables = "money_option",
    utils_none_name = "NONE"
  )

fitness_revenue <-
  tabu_fitness_generator(
    ds_bain_utilities,
    prohibitions = NULL,
    price_calculator = bain_price_calculator, top_level = "top_level",
    measure = "revenues",
    concepts = NULL, #' should we calculate the share for specific concepts
    meta_design = bain_meta_design,
    toplevel_related_variables = "money_option",
    utils_none_name = "NONE"
  )

fitness_share(ds_bain_candidate)
#> [1] 0.5220385
fitness_share_concepts(ds_bain_candidate)
#> [1] 0.4492139
fitness_revenue(ds_bain_candidate)
#> [1] 1.324997