← Back to Sweat Equity
← Labs
29 October 2026ProductShipped6 min read

The optimizer: utility, a budget and a Lagrangian

How we decide the best month of wellness for a whole group at once — with a utility function, a budget, and some economics borrowed from Lagrange.

Overhead shot of four people training in a circlemember_01 · U=?member_02 · U=?member_03member_04pod · N = 4
one pack, four people
Reference frame. Our own photography replaces it before launch.

A stack isn’t a product we design. It’s an answer to a question: given what these people want, what we can buy, and what they’ll pay, what’s the best month we can put together for the group? We wrote that question down as maths — and then let a computer answer it.

Start with what each person wants

Every member answers a short survey, and every answer becomes a number. For each thing she might get — a reformer class, a sauna session, a blood panel — we learn three things: how many a month she’d really use, whether extras beyond that are still worth anything, and how much one is worth to her compared with paying at the door.

Together those make her utility function: how much a month of wellness is worth to her, in dollars. It isn’t a straight line. The first few classes are worth their full price. Past her sweet spot, each extra one is worth less. Past twice that, nothing at all.

utility · diminishing returns r d·r 0 12345678 K · sweet spot 2K classes a month
One member, one kind of class. Illustrative: the steps come from her answers.

This is the oldest idea in economics — diminishing marginal utility — and it does real work here. It stops the optimizer from stuffing a stack with twenty yoga classes because yoga happens to be cheap.

Then the economics of the pack

We can only buy whole packs, and a pack is shared across a pod of members — no more than the studio allows. So every member gets a whole number of units a year. Her price is what those units would cost her at drop-in rates. Our cost is what the packs cost us in bulk. The difference is the spread, and a share of it comes back to her as rewards.

pack math · illustrative
One 20-class pack type, bought twice a year, shared by four
Podmin(share limit, N)4 members
Units each a yeara = ⌊X × s ÷ pod⌋2 packs × 20 ÷ 4 = 10
Her price a monthR = a × r ÷ 12at drop-in
Our cost a monthC = packs × P ÷ (12 × N)at the bulk rate
SpreadR − Cthe gap

The objective, and the Lagrangian

Now the whole problem fits on one card. Maximise the group’s total value plus the spread, subject to three rules: the price has to land in the band, enough people have to want it, and packs come whole.

objective · per person surveyed
What the optimizer maximises
max
Score = average of joins × (U + θ·spread − λ·no-share)
Value to each member, plus the spread, minus a small fine for packs a vendor doesn’t allow us to share. Non-joiners count as $0.
s.t.
Price inside the band R ∈ [$280, $320]
Or $500–600 for the larger tier.
s.t.
Enough people join take-up ≥ 25%
A member joins only if U + ρ × her rewards ≥ R.
s.t.
Whole packs only X = 0, 1, 2 …
Shared in pods no bigger than the vendor allows.
The Lagrangian, for the price limit𝓛 = Score − μ (R − Rmax)

This is where Lagrange comes in. The classic consumer problem — get the most utility from a fixed budget — has a famous answer: at the optimum, the last dollar spent on every good buys the same amount of utility. Spend a dollar more on sauna and a dollar less on yoga, and nothing improves. The multiplier μ is the exchange rate: how much score one more dollar of budget would buy.

We don’t solve it with calculus, because packs are lumpy. But the search follows the same rule. Each turn, it looks at every product and every next pack, throws out moves that break a rule, and adds the one with the most score per dollar of price. That’s the Lagrangian condition, taken one step at a time. It stops when no move earns its cost — then tries taking each thing back out and refilling, from many starting points, so it doesn’t settle on the first good answer.

Who actually joins

A member only joins if the stack is worth its price to her: her value from it, plus her rewards (counted at how much she says a rewards dollar is worth to her), has to beat what she pays. Anyone it doesn’t win over counts as zero. So the optimizer can’t cheat by building a stack only one person loves.

How big should the group be?

Bigger groups split packs more evenly, but they’re harder to fill. So a quick version of the search runs at every group size from 4 to 24, and we keep the smallest size within 2% of the best. Then it searches hard at that size.

cohort sweep · N = 4…24 within 2% of the best 4812162024 picked: smallest good N cohort size, N
The shape, not real scores. The flat part is why we don’t chase the biggest group.

What it gave us

A ranked list of stacks per persona, each one explainable line by line: why every pack is in it, what it costs, who joins and why. It’s also why a person, not the optimizer, makes the final call — the bundle planner came next, and lets us lock in the stacks we like.

Every symbol: K sweet spot · d value of extras · m worth versus drop-in · r drop-in price · s, P pack size and price · X packs per pod a year · a units each a year · N group size · R her price · C our cost · U her value · ρ what a rewards dollar is worth to her · θ weight on the spread · λ fine for unshareable packs · μ the Lagrange multiplier.