This is the last post in my accidental Fourier-Motzkin trilogy (part one: the method; part two: the baseball lineups), and it’s about the bill coming due. Because when you use elimination to throw variables out of a model, the mathematics is very clear about what you keep — and very quiet about what you lose. I found out exactly what I’d lost the first time DraftKings rejected a lineup my spreadsheet swore was legal. The story runs straight through a beautiful piece of combinatorics called Hall’s marriage theorem, so we’ll pick that up along the way.
The lineup was right. The upload wasn’t.
Where we left off: my Excel optimizer picks DraftKings baseball lineups using 63 counting constraints instead of player-slot assignment variables. Fourier-Motzkin elimination guarantees those 63 checks are exactly equivalent to “a legal way to slot these players exists.” The solver hands me eight hitters and two pitchers, every count checks out, projected points maximized. Wonderful.
Then you go to enter the thing. DraftKings’ upload file has ten columns, in a fixed order: P, P, C, 1B, 2B, 3B, SS, OF, OF, OF. One player per column. The website does not want to know that my counts are consistent across all 63 subsets of the position set. It wants to know who is my shortstop. And my model — by design! — no longer knows. I threw that information away on purpose, back when I eliminated the assignment variables. The optimizer tells me who’s in the lineup; the entry form demands to know where each one goes; and there’s a gap between those two answers that somebody has to close (that somebody being me, ideally before first pitch, with a Fiverr customer or two wondering why the “easy” spreadsheet won’t upload).
Existence is not construction
Here’s the elegant part. The reason I can be certain a valid slotting exists is a hundred-year-old result about weddings. Hall’s marriage theorem says: suppose each member of one group is compatible with some members of another, and you want to pair everyone off. A perfect pairing exists if and only if every subset of the first group collectively knows enough counterparts — no clique of k members sharing fewer than k acquaintances between them. Swap “members” for roster slots and “acquaintances” for eligible players, and the theorem’s condition becomes precisely my 63 counting constraints. That’s not a coincidence: run Fourier-Motzkin elimination on the assignment model and Hall’s condition is what falls out the other side. The 19th-century algebra and the 20th-century combinatorics are two doors into the same room.
But notice what the theorem promises: a pairing exists. It doesn’t hand you the pairing. This distinction between knowing a solution exists and holding one in your hand is one of those things mathematicians shrug at and practitioners lose sleep over. My 63 constraints are a certificate of existence. The DraftKings form wants the object itself. In the assignment-variable formulation the solver would have produced the object for free — the y’s were the slotting. Elimination traded that away for a model that never needed rebuilding. Great trade, but the debt gets collected at upload time.
My fix: one shamelessly greedy formula
The textbook answer here is a proper matching algorithm — augmenting paths, a few dozen lines of careful code. What I actually wrote is one Excel formula. In my defense, it’s a formula with thirteen nested IFs.
It works like this. Every player in a saved lineup gets a sort key. Single-position players get whole numbers that mirror the upload column order: pitchers 0, the catcher 1, first baseman 2, second baseman 3, third baseman 4, shortstop 5, outfielders 6. These players have no choice about where they go, so they claim their columns immediately. Multi-position players get half-step keys — 1.5, 2.5, 3.5 and so on — by scanning their eligible positions in column order and taking the first hit, with an extra guard on first base (the slot that burned me most): a 1B-eligible flex player only takes the 2.5 key if no single-position first baseman is already in the lineup. So a 1B/OF guy alongside a pure first baseman gets pushed toward the outfield; the same guy in a lineup with no pure 1B slides in at 2.5, right where a first baseman would sit. Then a macro sorts the lineup by key and writes the names left to right into the ten template columns. Sort order is the position assignment. That’s the whole trick.
Is this a correct algorithm? No, and I want to be honest about that. It’s first-come-first-served with good manners. If two flexible players both want the same leftover slot, the sort can jam them into the same column and the upload comes out wrong — greedy matching has known failure cases, which is exactly why the augmenting-path algorithms exist. But here’s the practitioner’s arithmetic: a DraftKings lineup has eight hitters, of which typically zero, one, or two are multi-position, and the outfield has three slots absorbing overflow like a sponge. The pathological case needs multiple flex players fighting over the same scarce position, and in a couple of seasons of daily lineups I hit it rarely enough that “fix it by hand and grumble” was cheaper than writing real matching code in VBA. The formula handled the boring 95% so I only had to be smart on the weird 5%. For a tool I was selling to Fiverr buyers who would never look under the hood, that was the right engineering call — though the tuition wasn’t free: I had my own lineups rejected more than once because players got loaded in the wrong order, which is a special kind of embarrassing for the guy selling the shovel.
What the trilogy adds up to
Step back and the three posts tell one story. Fourier-Motzkin elimination is a projection: it squashes a model down to the variables you care about, and the shadow it casts — the 63 constraints — is faithful to feasibility. But a shadow is flat. The information about how the solid stood in space is gone, and if you later need it back (because a website form insists), you have to rebuild it: properly with a matching algorithm, or cheaply with a greedy sort key and a tolerance for the occasional weird Tuesday.
I set out to sell picks and shovels to fantasy baseball miners, and ended up with Fourier’s algebra deciding who bats where and a Victorian wedding theorem certifying my roster. Nobody who bought that spreadsheet on Fiverr ever knew any of this was inside. That might be my favorite part.
Things that I use, like, and am affiliated with:
Mint Mobile offers great cell phone service for $15 flat, get $15 off using the link. Get discounted phones with service activation and no contract.
I never spend money before I check Mr Rebates or Rakuten to get cashbacks, rebates, discounts, coupons or cheaper gift cards.
