For each attribute level, count how often it occurs in the design candidate and find the distance to the nearest allowed number of occurrences. Levels that do not occur in the design candidate are counted as zero occurrences.

lvl_violation(
  utility,
  x,
  rows,
  ranges = occurrences(utility, rows),
  lvls = expand_attribute_levels(utility)
)

Arguments

utility

A named list of utility functions. See the examples and the vignette for examples of how to define these correctly for different types of experimental designs.

x

A design candidate with one column per attribute

rows

Number of rows in the design

ranges

Level occurrences as returned by occurrences. Pass these in when calling repeatedly to avoid parsing the utility functions each time

lvls

Attribute levels as returned by expand_attribute_levels

Value

The total distance summed over all attribute levels. A value of 0 means that the design candidate satisfies all level occurrence constraints.