Excel Solver
Excel Solver
Linear programs (LPs) can take many forms. In ENGR62 we will often be dealing with LPs that can be represented mathematically as maximize cT x subject to Ax b, where the matrices A, b, and c comprise the problem data. Our goal is to maximize the value of the objective function, cT x, by choosing an appropriate vector of decision variables, x. The matrices A and b specify a set of linear inequality constraints that reect the requirements of the problem.
Page 2 of 6
Ax
Page 3 of 6
The arguments of SUMPRODUCT and MMULT can be either ranges of cells or range names. It is more concise and descriptive to use names. For a pair of ranges named S and T, entering SUMPRODUCT(S,T) into the Formula Bar returns i,j sij tij , i.e., the sum of the products of corresponding elements of S and T. Entering MMULT(S,T) into the Formula Bar returns the matrix whose ij th element is k sik tkj , i.e., normal matrix multiplication. SUMPRODUCT(S,T) will return an error unless S and T have the same dimensions. Similarly, MMULT(S,T) will return an error unless the number of columns of S equals the number of rows of T. If you need to take the transpose of a matrix, use the TRANSPOSE function. Important note: If a matrix function returns a matrix larger a single element, you must rst use the mouse to select the cells that will contain the result, then type the matrix function into the Formula Bar, and nally type CTRL SHIFT ENTER (COMMAND ENTER on a Mac) to evaluate the matrix function. For example, if S and T are 3 5 and 5 4 matrices, respectively, then the result of MMULT(S,T) will be a 34 matrix. To perform this calculation and display the result in the worksheet, rst highlight a 34 range of cells, type MMULT(S,T) into the Formula Bar, then type CTRL SHIFT ENTER to display the result in the highlighted area. With regard to LPs, two of the most important matrix calculations are computing the objective function value, cT x, and the constraint function, Ax. The objective function value cT x is the scalar product of two vectors, and so can be computed using either SUMPRODUCT(c,x) (as long as c and x are both either row or column vectors) or MMULT(cT,x.1 The constraint function Ax is a matrix, so MMULT(A,x) must be used. Select ranges of cells to contain cT x and Ax and compute their values using the Excel matrix functions. As the following section will make clear, it is helpful to give these ranges names such as cTx or OF for cT x, and Ax for Ax. Also remember that neither SUMPRODUCT nor MMULT will work properly if either of the two arguments are empty. For this reason, you must provide dummy valuessuch as zerosfor the decision variables, x.
The MMULT command shown here assumes that the objective function coecients, c, have been entered as a row matrix and named cT. Of course, how you issue matrix function commands in Excel will depend on how you entered the data into your worksheet. If you entered c as a column, then you would compute cT x as MMULT(TRANSPOSE(c),x).
1
Page 4 of 6
Using Solver
Page 5 of 6
An Example
Consider the following linear program: max 50x1 + 30x2 + 25x3 + 30x4 subject to 2x1 + 2.5x2 + 3x3 + 1.8x4 800 1.2x1 + 1x2 + 2x3 + 0.8x4 400 1.5x1 + 1.2x2 + 1.5x3 + 0.8x4 380 x2 50 x3 30 x 1 , x2 , x3 , x4 0 This problem can easily be represented as an LP of the form maximize cT x subject to Ax b x 0,
Page 6 of 6
cT = 50 30 25 30 .
Note that two of the inequality constraints have been reversed to become constraints. In an Excel worksheet, identify ranges of cells to accommodate A, b, cT , and x, and name the ranges appropriately. In this example we will assume these ranges have been named A, b, cT, and x, respectively. Initialize the vector of decision variables x with some dummy values such as zeros. Select a position for the objective function, dene it using the function MMULT(cT,x), and name it cTx, say. Similarly, dene the constraint function Ax using MMULT(A,x) and name the result Ax.3 Open Solver from the Tools Solver... menu. Enter the following information into the dialog box: Set Target Cell: cTx Equal to: check Max radio button By Changing Cells: x Subject to the Constraints: Ax b and x 0 Before pressing Solve, make sure that Assume Linear Model has been checked in the Options... dialog box. Then press Solve. Generate Answer and Sensitivity reports, and examine your solution. For another example of how to set up a linear program in Excel/Solver, download the telecommunications example (teleco.xls) from the course website. Observe how ranges are named, and how the names are used in the Solver window.
Remember that since Ax is a 5 1 matrix, you will rst have to highlight a 5 1 range of cells and press CTRL SHIFT ENTER to evaluate MMULT(A,x).