Softball.app Lineup Optimizer Gallery

https://i.imgur.com/35aPFzD.jpg
Monte Carlo Exhaustive
Speed:
0.0
Quality:
0.9577839039835323
This optimizer iterates over all possible batting lineups and simulates some number of games for each of them (See the 'games' parameter). All the simulated game scores for each lineup are then averaged together. The lineup with the highest mean simulated score is selected as the best

Options:

Games (G) - Number of games to simulate for each lineup. An optimization run with more games will take longer but be more accurate.
Innings (I) - Number of innings to be played in each simulated game. More innings will increase the estimated completion time.
Lowest (L) - If this field is true, the optimizer will attempt to provide the lowest scoring lineup instead of the highest.

Description:

Runs Monte Carlo simulations of games for all possible lineups. The optimizer then averages the runs scored acrosss all possible lineups and returns the lineup with the highest average runs scored. This is likely the slowest optimizer available,

Overview

Simulation flow. This flowchart refers to the parameter g which is a configurable value indicating the number of games to simulate. The stages with thick black outlines have sections w/ additional details below.

flowchart TD; A[Select a lineup from<br> the lineup pool.]:::addtDoc-->B; B[Simulate a game,<br>remember the number<br> of runs scored.]:::addtDoc-->D D{Have we simulated<br>more than *g* games?}--yes-->E D--no-->B E[Compute the mean <br>score of all simulated<br> games using this lineup.]-->F F{Is this lineup's <br>mean game score better <br>than all the others we<br> have simulated?}--yes-->G F--no-->I G[Remember this lineup<br> as bestLineup and its<br> mean score as bestScore.]-->I I{Is the lineup pool<br> depleted?}--yes-->J I--no-->A J[Done! Print the bestLineup <br>and bestScore that we<br> remembered earlier.] classDef addtDoc stroke:#333,stroke-width:4px;

The Lineup Pool

This optimizer simulates games for all possible lineups. The number of possible lineups for each lineup type is given by these equations where 'm' is the number of male batters and 'f' is the number of female batters:

Standard

numberOfLineups = (m+f)!

Alternating Gender

numberOfLineups = (m! + f!) * 2

No Consecutive Females

numberOfLineups = m! * f! * (\\binom{m}{f} + \\binom{m-1}{f-1})

Performance

Because of the factorial nature of these equations, adding even one more player to the lineup can make the optimizer take significantly longer to run.

Example simulation (7 innings, 10000 games)

# players in lineuppossible lineupsruntime (ms)~runtime (human)
672019582 seconds
75,0401598216 seconds
840,3201352552 minutes
9362,88083290214 minutes
103,628,80066134842 hours

Simulating a game

This flowchart refers to the parameter i which is a configurable value indicating the number of innings to simulate (typically 9 for baseball, 7 for softball, but can be anything). Same as before, the stage with the thick black outline has a section w/ additional details below. Simulate a game

flowchart TD; B[Set active batter to<br>the first player <br>in the lineup.]-->C C{Simulate a <br> plate appearance <br> for the active batter.}:::addtDoc--Result: 0-->D C--Result: 1,2,3,4-->E D[Increment the<br> number of outs <br>by one]-->F E["Advance the runners. <br> Increase score if the<br>plate appearance <br>drove home (a) run(s)."]-->G F[>= 3 outs?]--no--> G F--yes-->I G[Set active batter to<br>the next batter <br>in the lineup.] G-->C I{Have we <br>simulated more <br>than *i* innings?}--yes-->J I--no--> K J[Done! Return the score<br> for this simulated game.] K[Increment the <br>number of innings<br> simulated by one. <br> Clear the bases. <br> Clear the outs.]-->G classDef addtDoc stroke:#333,stroke-width:4px;

Simulate a Plate Appearance

Each plate appearance result (Out, SAC, E, BB, 1B, 2B, 3B, HRi, HRo) is mapped to a number indicating the number of bases awarded for that plate appearance. The mapping is illustrated in this table:

ResultBases
Out, SAC*, E, K0
1B, BB*1
2B2
3B3
HRi, HRo4

We can then use the frequency of each type of hit to build a distribution that reflects the way any given player is likely perform when they get a plate appearance. Whenever we need to simulate a hit for that player, we draw a random sample from that player's distribution.

An Example

Tim's historical at bats are as follows: Out,1B,2B,SAC,E,HRo,3B,1B,1B,Out,Out,2B,1B,Out,Out

First we translate those hits to number of bases using our mapping from the table above: 0,1,2,0,0,4,3,1,1,0,0,2,1,0,0

Then we determine the histogram and chance of each hit:

# of bases# of times% of plate appearances
0747
1427
2213
317
417

And every time we simulate a plate appearance for Tim, we'll draw a random hit with that distribution. That is to say, for every simulated plate appearance, Tim has a 47% of getting out, 27% chance of getting a single, a 13% chance of getting a double, a 7% chance of getting a triple, and a 7% chance of getting a home run. Of course, other players will have their own distribution of hits to draw from based of their historical performance.

Other Notes

Things that are not accounted for in the simulation:

  • Double/triple plays
  • Stolen bases
  • Players who were on base advancing more bases than the hitter
  • Any pitching data

*We can debate about how walks or sacrifices should be counted. It probably depends on what flavor of the sport you are playing. IMHO sacrifices should be counted as outs in slowpitch softball and kickball, but not baseball or fastpitch. In any event, these mapping are configurable (or will be configurable soon). So you are welcome to impose your own philosophy.

+ Add
https://cdn.pixabay.com/photo/2019/09/24/16/32/chameleon-4501712_1280.jpg
Monte Carlo Adaptive
Speed:
0.7469382304692735
Quality:
1.0
Employs the same approach as the Monte Carlo Exhaustive optimizer but instead of simulating a fixed number of games for each lineup, performs a variable number of simulated games. The exact number of games simulated for each lineup is determined by continuing to do simulations on a lineup until a statistical t-test determines that the expected run totals for two lineups are significantly different (by some configurable alpha value). The lineup with the lower mean is then rejected and the larger one remembered as the best so far.

Options:

Innings (I) - Number of innings to be played in each simulated game. More innings will increase the estimated completion time.
Lowest (L) - If this field is true, the optimizer will attempt to provide the lowest scoring lineup instead of the highest.

Description:

An optimization engine that uses statistical techniques to reduce the number of game simulations required to determine optimal batting lineups. Intended to be a faster version of the Monte Carlo Exhaustive optimizer.

Overview

The Monte Carlo Exhaustive optimizer

The exact number of games simulated for each lineup is determined by continuing to do simulations on a lineup until a statistical t-test determines that the expected run totals for two lineups are significantly different (by some configurable alpha value). The lineup with the lower mean is then rejected and the larger one remembered as the best so far.

+ Add
https://upload.wikimedia.org/wikipedia/commons/f/f8/Fotothek_df_n-08_0000320.jpg
Monte Carlo Annealing
Speed:
0.7608774616580631
Quality:
0.9910791549544197
A faster but less accurate optimizer that doesn't test the entire search space of possible lineups. Instead, it employs [simulated annealing](https://en.wikipedia.org/wiki/Simulated_annealing) to seaerch only a subset of possible lineups. If you have 11 or more batters in your lineup, this is most likely the optimizer you'll want to use.

Options:

Alpha (A) - Confidence value at which point to reject the null hypotheses (lineups have equal means). Lower alpha will give more accurate results but take longer to run.
Duration (D) - How long should this optimization run for (in seconds)? Longer times will produce better results.
Innings (I) - Number of innings to be played in each simulated game. More innings will increase the estimated completion time.
Lowest (L) - If this field is true, the optimizer will attempt to provide the lowest scoring lineup instead of the highest.

Description:

A faster but less accurate optimizer that doesn't test the entire search space of possible lineups.

Instead, it employs simulated annealing, a global optimization technique inspired by heating and controlled cooling of a material to alter its physical properties, to search only a subset of possible lineups.

If you have 11 or more batters in your lineup, this is most likely the optimizer you'll want to use.

Overview

Dispite this optimizer's much shorter runtime, it's results are quite good.

In tests on "STANDARD", "ALTERNATING_GENDER", "NO_CONSECUTIVE_FEMALES", "NO_CONSECUTIVE_FEMALES_AND_NO_THREE_CONSECUTIVE_MALES" lineup types, the optimizer generally obtains the theoretically optimal lineup when run for at least 30 seconds.

That's a high quality answer in a fraction of the time. It's also currently the only viable optimizer for larger lineups (11+ batters).

Because simulated annealing is a stochastic process (relies on random numbers) you may get different results with each run, particularly if your selected time durations are low.

This optimizer is also multi-threaded. It will run several instances of itself simultaneously and, after each instance has completed, it will select the highest scoring lineup.

Related Optimizers

This optimizer uses multiple game simulations (see Monte Carlo Exhaustive) and statistical t-tests (see Monte Carlo Adaptive) to determine whether a particular lineup is better or worse than another.

+ Add
https://upload.wikimedia.org/wikipedia/commons/3/33/CEP1710-58.jpg
Sort By Average
Speed:
1.0
Quality:
0.0
Sorts the batters in descending order by batting average

Options:

There are no options for this optimizer

Description:

Sorts lineup in descending order by batting average.

If that's not possible (based on the lineupType), this optimizer selects the lineup with the minimum sum of the squares of each set of two consecutive batters with decreasing batting average.

i.e.

  1. For every lineup...
  2. For every two consecutive batters in the lineup for which the second batter has a lower batting average than the first, square then sum the difference in batting average, call this value the lineup's "score"
  3. Choose the lineup with the lowest "score".
+ Add
×