# Optimization Tool

The Optimization tool solves linear programming (LP), mixed-integer linear programming (MILP), and quadratic programming (QP) optimization problems using matrix, manual, and file input modes.

This tool uses the R tool. Go to **Options** > **Download Predictive Tools** and sign in to the Alteryx Downloads and Licenses portal to install R and the packages used by the R tool. Go to Download and Use Predictive Tools for more information.

## What is Optimization?

Optimization has wide applications in many industries, like supply chain, transportation, financial services, retail, telecommunications, and energy. Application areas include supply chain optimization, assortment optimization, portfolio optimization, workforce scheduling, and sports scheduling.

An optimization problem typically has the following mathematical form, consisting of an objective function (1st equation), a set of constraints (2nd equation), and a specification of the types (continuous, integer, binary) and bounds of the decision variables (3rd equation.) The goal is usually to find the values of the decision variables that maximize or minimize the objective while satisfying all the underlying constraints, types, and bounds.

## Connect Inputs

No inputs are required for the manual or file input modes. For the matrix input mode, inputs **O** and **A** are required, but **B** and **Q** are optional. Input **B** is only optional in some cases. You can't always provide the information in input **A**, only if you have selected constraints in rows.

**O**anchor: (Required for matrix input mode) Use this input to provide the names of the decision variables, their coefficients in the objective function, and optionally their bounds and types.*Please note that due to R functionality, field names are case-sensitive.*Beginning with Designer 11.0, you can enable the Display field mapping for Input Anchor O option for more flexibility with field names.**variable**(Required): A string, decision variable names. Corresponds to**x**in the equations.**coefficient**(Required): A number, coefficient of each decision variable in objective function. Corresponds to**c**.**lb**(Optional): A number, lower bound of the decision variable. The default value is 0.**ub**(Optional): A number, upper bound of the decision variable. The default value is Inf (positive infinity.)**type**(Optional): A character, the type of the decision variable, which can be**C**(continuous),**B**(binary), or**I**(integer.) The default value is**C**.

**A**anchor (Required for matrix input mode): Use this input to provide the constraint matrix corresponding to**A**in the equations. You can organize the matrix in two different ways:**Dense matrix**:**Constraints in rows**: Each row corresponds to a constraint.The 1st field can optionally be named

**constraint**to indicate the constraint name in each row, while the remaining field names should correspond to the decision variables defined in**O**.Additionally, you can include the fields

**dir**and**rhs**to combine the**B**input into the**A**input.**dir**: a string, direction of the constraint inequality. It has to be >=, <= or ==.**rhs**: a number, the right hand side of the inequality, corresponding to**b**.

The variable fields (

**x**,**y**, and**z**in the example below) must be numeric.The order of the columns must match the order of the rows for input

**O**.Example: If your constraint equations are:

*x + 2y + 3z <=*4 and*x + y >= 1,*these are all legitimate input for input**A**:With constraint field:

constraint

x

y

z

1

c1

1

2

3

2

c2

1

1

0

Without constraint field:

x

y

z

1

1

2

3

2

1

1

0

Including dir and rhs:

x

y

z

dir

rhs

1

1

2

3

<=

4

2

1

1

0

>=

1

**Variables in rows**: Each row corresponds to a variable.The 1st field should be named

**variable**, while the remaining field names should correspond to the constraint names. Note that this corresponds to the transpose of the**A**matrix in the above equations.The constraint fields (

**c1**and**c2**in the example below) must be numeric.The order of variables for input

**O**and input**A***must*be the same.Example: This is a legitimate input for input A:

variable

c1

c2

1

x

1

1

2

y

2

1

3

z

3

0

Beginning with Designer 11.0, you can use other field names for “constraint” or “variable” and the Optimization tool intelligently infers which field contains constraints and which field contains variables. However, the naming convention is still preferred and recommended.

**Sparse matrix**: For larger constraint sets, you can specify the**A**matrix in its SLAM form. It consists of 3 required fields**i**,**j**, and**v**, where**i**and**j**are row and column indexes, respectively, and**v**is the non-zero value of the matrix element. Sparse matrix mode always assumes constraints in rows.

**B**anchor (Required if not already provided in**A**): Use this input to provide the name, direction, and right hand side of the constraints.**constraint**(Optional): A string, name of the constraint.**dir**: A string, direction of the constraint inequality. It has to be >=, <= or ==.**rhs**: A number, the right hand side of the inequality, corresponding to**b**.

**Q**anchor (Optional): Use this input to provide the quadratic portion of the objective function, for Quadratic Programming problems. It corresponds to**Q**in the equations. You can specify it as a dense matrix or as a sparse matrix.**Dense matrix**: The field names should correspond to the decision variable names defined in O.**Sparse matrix**: The field names are**i**,**j**, and**v**, where**i**and**j**are row and column indexes, respectively, and**v**is the non-zero value of the associated matrix element.

## Input Modes

### Select the Model as Matrices

Matrix mode supports either dense or sparse (slam) matrices. Inputs **O** and **A** are required for matrix input mode.

**Select problem type**:

**Linear Program**: (Default)(LP) Linear objective and linear constraints with continuous decision variables.**Mixed Integer Program**: (MILP) Linear objective and linear constraints with binary or integer decision variables along with continuous decision variables.**Quadratic Program**: (QP) Quadratic objective and linear constraints with continuous decision variables.

**Select solver**:

**Glpk**: (Default) For Linear Programs and Mixed Integer Linear Programs.**Symphony**: For Linear Programs and Mixed Integer Programs. It usually performs better than Glpk for MILP.**Quadprog**: For Quadratic Programs.

**Maximize Objective**?: Enable this option if you want to maximize the objective function. Otherwise, the tool minimizes the objective function.

**Select constraint mode for Input Anchor A**: For details, refer to Connect Inputs above.

**Dense matrix, constraints in rows**(Default)**Dense matrix, variables in rows****Sparse (SLAM) matrix**

**Display field mapping for Input Anchor O**(Optional): Input **O** requires the reserved words **variable**, **coefficient**, **lb**, **ub**, or **type** for the input table's field names. If you use different field names, or if the field names contain leading or trailing white space, errors occur. By enabling this option, you can map your existing fields to corresponding **variable**, **coefficient**, **lb**, **ub**, and **type** fields without the extra step of using a Select Tool to change field names.

### Enter the Model Manually

This mode offers an interactive interface where you can specify objectives and constraints directly. Sensitivity analysis is available for linear programming problems.

**Select problem type**:

**Linear Program**: (LP) Linear objective and linear constraints with continuous decision variables.**Mixed Integer Program**: (MILP) Linear objective and linear constraints with binary or integer decision variables along with continuous decision variables.**Quadratic Program**: (QP) Quadratic objective and linear constraints with continuous decision variables.

**Select solver: Glpk** (for Linear Program and Mixed Integer Program), **Symphony** (for Linear Program and Mixed Integer Program), or Quadprog (for Quadratic Program).

**Maximize Objective?**: Enable this option if this is a maximization problem.

**Variable List**: Specify a comma-separated list of decision variable names.

**Objective**: Specify an objective function to be maximized or minimized.

**Constraints**: Specify the constraints. Ensure that all variables in the constraint are on the left side of the inequality/equality sign. (For example, solver fails for constraint 2x>=y+4 but runs successfully for constraint 2x-y>=4. While both equations are mathematically equivalent, the 2nd meets the solver’s requirements.)

**Bounds & Types**: Specify the bounds and types.

### Specify the Model from a File

This mode supports industry-standard model file input.

**Select file type**: **CLPEX_LP**, **MathProg**, or **MPS_Free**.

**Select solver**: **Glpk** (for Linear Program and Mixed Integer Program), **Symphony** (for Linear Program and Mixed Integer Program), or Quadprog (for Quadratic Program).

**Select file**: Specify an optimization model file.

## View the Output

**I**anchor: This output provides an interactive dashboard of the solution.**D**anchor: This output consists of 3 pipe-separated tables: summary, variables, and constraints. They can be used upstream in the workflow to create reports and dashboards.**S**anchor: This is a simple data output that consists of a single table with the optimal value of the objective function and the decision variables. For problems consisting of only binary decision variables (0/1), this table contains only those values that are 1.