About
Softball positions. "RV" stands for "Rover."
The last couple of years, I've been playing in a coed recreational softball league in Chicago. There are about 20 people on the team, and each week we have to decide on a batting order and fielding positions. The league has specific rules about how many men and women must be on the field at all times, and we want to make sure our friends get equal playing time.
Figuring this out manually and sharing the details was a headache, so I decided to create this web app to help automate and optimize the creation of our lineup and fielding assignments. The app displays the results in a mobile-friendly way, so we can easily reference them during games on our phones.
The automation is done using linear programming. The constraints are the league rules, along with some equal playing time preferences. The objective function tries to maximize win probability.
Note: This is more of an academic exercise than anything. The app's output is useful, but you'll have more fun with your friends if you just show up and play!
Jump Right In
Simply start at step one below, and you'll be walked through the entire process.
- Input player names, genders, and positions.
- Rank the players by their skill levels (ranks are NOT displayed in final results, to avoid hurting any feelings).
- View the output with the optimal batting order and fielding positions.
League Rules (Problem Constraints)
The league rules define the constraints of the optimization problem. The league is primarily concerned with women getting sufficient playing time.
I have added an additional constraint that ensures players (my friends) get fair playing time.
- At least four women must be on the field at all times.
- Two women must make a plate appearance every five batters.
- No player sits out two consecutive innings.
Strategy (Objective Function)
In addition to meeting the minimal problem constraints, we want to maximize "skill utilization" in our lineups. I've defined this as the following:
- Highly ranked players appear earlier in the lineup.
- Players only ever play positions they are comfortable with.
- Players change position as little as possible.
Blog Post (Extensive Explanation)
This web app was built as a personal project, but I wrote a detailed blog post explaining the problem and why linear programming is so powerful.
The blog is math heavy, but I strongly encourage other developers to become familiar with linear programming. It can solve a wide variety of problems essentially for free, as long as the problem can be expressed as a system of linear equations. Linear programming problems are easier to document, maintain, and test than bespoke solutions. Software Engineers should be comfortable with a table of linear equations. 🙂
TODOPulp (Software Library)
Pulp is a linear programming library for Python. It provides an interface for defining linear programming problems. It then delegates finding a solution to its various solvers.
I translated the constraints and objective function above into a Pulp problem, then used the default solver to find the optimal solution. This is much simpler than a bespoke algorithm, assuming you are comfortable with a bit of linear math.