Live since

Softball Pulp

Auto-generate a winning softball lineup using linear programming and PuLP.

Softball Pulp on a phone
What it does

A Fair Lineup in Three Steps

Player form for Mike Chen with a male or female choice and a grid of ten positions, with C and 3B selected
01

List Who Showed Up

Enter each player's name, gender, and every position they're comfortable playing. A demo button fills in a sample team of 14.

A drag and drop list of players, each with a rank number and their position chips
02

Rank by Skill

Drag players into order from most to least skilled. The ranking only feeds the optimizer and never appears in the results, so nobody's feelings get hurt.

Batting order table with the women highlighted in pink
03

Get the Lineup

Two solvers return a batting order with two women in every five batters, and a fielding chart for every inning with at least four women on the field and nobody sitting out twice in a row.

By the numbers

At a Glance

2solvers per lineup
9innings scheduled
10positions, rover included
1,800yes or no variables, at most
How it's built

From Roster to Lineup

  1. Player InputPug Templating
  2. ValidationDry Run of Solvers
  3. Batting OrderPuLP Model, CBC Solver
  4. Fielding ChartPuLP Model, Nine Innings
  5. ResultsFlask Page

Built with

PythonFlaskPuLPPugPico CSSSortableJSuv
Key takeaway

League rules map cleanly onto linear constraints, so adding a rule means adding a constraint instead of rewriting a custom algorithm.

Build Notes

Challenges, learnings, and what's next

Challenges

  • Each step is a full page form POST, so the roster travels between pages as hidden form fields. localStorage keeps the roster and ranking order so a refresh does not wipe them.
  • Keeping players in the same position between innings needs extra helper variables to stay linear. The current attempt compares variables with Python ==, which PuLP evaluates to a constant, and adding it with += replaces the skill objective. The fielding chart is a valid assignment, not an optimized one.
  • The rule of two women in every five batters applies to each group of five except the last, which is left unconstrained. This lets a roster of up to 15 players with only four women still produce a batting order.

Learnings

  • PuLP with the CBC solver handles 20 players × 9 innings × 10 positions fast enough that the solver is never the bottleneck.
  • Expressing lineup rules as LP constraints is more maintainable than a custom heuristic.
  • Documenting even a simple web app is time consuming. AI can scaffold the writing, but it still needs manual rework to keep your own voice.
  • Drawing the field diagram as an SVG in Figma keeps it sharp at any size.

Next

  • Move output data into the URL so lineups can be shared directly from the results page.
  • Allow configuration before optimization, such as an all-male roster, adjusted gender ratios, or different league rules.
  • Lower the minimum player count from 10 to 8 to support smaller rosters.
  • Allow a female player to bat multiple times when the roster is short on women.
Keep exploring

More Apps