The new Optimization tool has just come out in the Alteryx 10.6 Predictive Release (see Dr Dan's post on prescriptive analytics). With this single tool, we can solve linear programming, mixed integer linear programming and quadratic programming problems. The tool offers 3 input modes (manual input, file input and matrix input) to give you flexibility in defining your model. If you are a baseball fan and Alteryx fan, I have a great news for you! Today I'll show you how to use the Alteryx Optimization tool to solve a fantasy baseball daily lineup problem.

The fantasy baseball daily lineup problem is very straight-forward: given a fixed budget and 6 types of field positions to fill in, how should you draft players based on their projected points, salary and field positions? In other words, we want to

- maximize the total projected points of all drafted players.
- make sure the total salary for the 9 players is under budget.
- make sure each field postion is filled, i.e. we want
- 1 Pitcher (P)
- 1 Base 1 player (1B)
- 1 Base 2 player (2B)
- 1 Short Stopper (SS)
- 1 Base 3 player (3B)
- 1 Catcher (C)
- 3 Out Fielders (OF)

The decision we need to make is: which players to pick.

The tricky part is how to express the objective, constraints and decisions above mathematically.

Let's denote

**x**_{i}: the decision whether we will draft the** i**'th MLB player. For example, if **x**_{6} = 1, then the 6th player will be drafted, if **x**_{6} = 0, then the 6th player won't be drafted.
**Pt**_{i}: the projected points the i'th player will earn.
**S**_{i}: the salary of the **i**'th player.
**P**_{i}: whether the i'th player is a pitcher. For example, if **P**_{5} = 1, then the 5th player is a pitcher, if** P**_{5} = 0, then the 5th player is not a pitcher.
- Similarly,
**1B**_{i}, **2B**_{i, } **SS**_{i}, **3B**_{i}, **C**_{i}, **OF**_{i} : whether the i'th player plays Base 1, Base 2, Short Stop, Base 3, Catcher and Out Field respectively.

where,** i** can be 1, 2, ... 384 (384 is the total number of MLB players in the data set we are going to use in the attached example.) Based on the notations and assume our budget is $25200, the mathematical formulation for the daily fantasy baseball problem is as follows:

Once we have constrcuted the formulation, it is very straight-forward to use the new Optimization tool in Alteryx, since the inputs for Optimization tool are essentially different parts of the formulation.

We first obtain baseball player data from http://www.rotowire.com/daily/mlb/optimizer.htm and load it into Alteryx. Let's take a look the first couple of rows of data:

It is easy to see that only the columns in red circles are relevant to our problem setup. (Note that **Pos** stands for "position" and **Pts** is short for "projected points".) Configuring the Optimization tool is simple. Since we will use the baseball player data as input, instead of an industry standard optimization modelling file (e.g *CPLEX_LP*, *MathProg*, or *MPS *format), we will use "matrix input" mode. Because our decision variables (x_{1}, x_{2 }, ..., x_{384}) can only have values 0 or 1, this is a mixed integer programming problem. We use "Symphony" as the solver, due to its overall better performance on mixed integer linear programming over "GLPK".

For Optimization inputs, please see the comments in the attached workflow for details. Thanks to @ramnath and @cfreeman's hard work, the Optimization tool generates an interactive report of which players you should select, and more.

For more details, see Optimization Tool Help.

Optimization Fantasy Baseball Sample.yxzp