Finding the Sweet Spot in a Roast
First crack arrived with a flurry of tiny pops. I noted the time, listened for the pace to slow, and stopped three small batches at different points. The next day, a comparative tasting produced two scores for each: sweetness and aroma, both out of ten.
Which roast wins? That depends on what you value. A batch scores 7 for sweetness and 8 for aroma; B scores 9 and 6. Neither is better on both measures, so choosing between them requires a preference. C, at 6 and 5, has a clearer fate: both A and B beat it on every measure.
This is Pareto dominance, a way to discard choices that are no better on any measure and worse on at least one. It became a practical tool in multi-objective optimization during the 1970s, when researchers were developing methods for problems with competing goals. The surviving choices form a Pareto frontier.
const roasts = [
{ name: "A", scores: [7, 8] },
{ name: "B", scores: [9, 6] },
{ name: "C", scores: [6, 5] },
];
const dominates = (a: number[], b: number[]) =>
a.every((score, i) => score >= b[i]) &&
a.some((score, i) => score > b[i]);
const frontier = roasts.filter(candidate =>
!roasts.some(other => dominates(other.scores, candidate.scores))
);
console.log(frontier.map(roast => roast.name).join(", "));
The OCaml version uses pairs for the two scores, keeping the comparison explicit:
let roasts = [("A", (7, 8)); ("B", (9, 6)); ("C", (6, 5))]
let dominates (a, b) (c, d) =
a >= c && b >= d && (a > c || b > d)
let frontier = List.filter (fun (_, scores) ->
not (List.exists (fun (_, other) -> dominates other scores) roasts)
) roasts
let () = print_endline (String.concat ", " (List.map fst frontier))
Both programs print A, B. The strict improvement clause matters: two roasts with identical scores do not dominate each other. The examples also assume higher scores are better; a measure such as bitterness might need a different direction.
With only three batches, comparing every candidate with every other candidate is easy. For a large collection, those pairwise comparisons grow quadratically. More fundamentally, the frontier cannot tell me whether sweetness matters more than aroma. It leaves that pleasant decision to the next cup.