Excel Solver

The Solver Add-in is a Microsoft Office Excel add-in program that is available when you install Microsoft Office or Excel.

To use the Solver Add-in, however, you first need to load it in Excel.

  • Click the Microsoft Office Button Office button image, and then click Excel Options.
  • Click Add-Ins, and then in the Manage box, select Excel Add-ins.
  • Click Go.
  • In the Add-Ins available box, select the Solver Add-in check box, and then click OK.
    • If Solver Add-in is not listed in the Add-Ins available box, click Browse to locate the add-in.
    • If you get prompted that the Solver Add-in is not currently installed on your computer, click Yes to install it.
  • After you load the Solver Add-in, the Solver command is available in the Analysis group on the Data tab.
excel-solver

The key to solving an LP on a spreadsheet is

  • Set up a spreadsheet that tracks everything of interest (e. g., costs, profits, resource usage)
  • Identify the decision variables that can be varied. These are called Changing Cells
  • Identify the cell that contains your objective function as the Target Cell
  • Identify the constraints and tell SOLVER to solve the problem

At this point, the optimal solution to our problem will be placed on the spreadsheet

Example Problem

Consider the problem of diet optimization. There are four different types of food: Brownies, Ice Cream, Cola, and Cheese Cake. The nutrition values and cost per unit are as follows:

excel-solver-01

The objective is to find a minimum -cost diet that contains at least 500 calories, at least 6 grams of chocolate, at least 10 grams of sugar, and at least 8 grams of fat.

STEP 1: Decision Variables

To begin we enter heading for each type of food in B2:E2. In the range B3:E3, we input trial values for the amount of each food eaten. (Any values will work, but at least one should be positive.) For example, here we indicate that we are considering eating three brownies, no scoops

of chocolate ice cream, one bottle of cola, and seven pieces of pineapple cheesecake.

excel-solver-02

STEP 2: Objective Function

To see if the diet is optimal, we must determine its cost as well as the calories, chocolate, sugar, and fat it provides.

In the range B7:E7,we reference the number of units and in B8:E8 we input the per unit cost for each available food. Then we compute the cost of the diet in cell B10 with the formula

= B7*B8 + C7*C8 +D7*D8+ E7*E8

But it is usually easier to enter the formula

= SUMPRODUCT (B7:E7, B8:E8)

And this is much easier to understand for anyone reading the spreadsheet. The =SUMPRODUCT function requires two ranges as inputs. The first cell in the first range is multiplied by the first cell in the second range, then the second cell in the first range is multiplied by the second cell in the second range, and so on. All of these products are then added. Thus, in cell B10 the =SUMPRODUCT function computes total cost as (3)(50 )+(0)(20)+(1)(30)+(7)(80) = 740 cents.

excel-solver-03

STEP 3: Constraints

The final step required to set up our LP in Excel is to set up our constraints for calories, chocolate, sugar, and fat.

To begin, we recreate the table in Excel that defines how many calories and units of chocolate, sugar, and fat are in each type of dessert. We can use this information to calculate the total amount based on the number of items from our decision variables. As an example, we can take the =SUMPRODUCT of the number of items and the number of calories in each to calculate all the calories in our dessert selection.

= SUMPRODUCT (B7:E7 , B14:E14)

Finally, we want to indicate the limitations highlighted in the problem. We add a >= or <= to identify if it is a maximum or minimum constraint in Column G, and use Column H to indicate those limits.

excel-solver-04
excel-solver-05

The problem in total is as –

excel-solver-06

Using Solver

STEP 1:

The SOLVER Parameters Dialog Box is used to describe the optimization problem to Excel.

STEP 2:

The way we set up the problem in Excel will make it easy for us to fill in each of the components of this Parameters Dialog Box so SOLVER can identify the optimal solution.

First, we fill in the Set Objective box by clicking on the cell in our spreadsheet that calculates our objective function. In this case, Cell B10.

Next, we use the radio buttons below to identify the type of problem we are solving, a MAX or MIN. Here we want to minimize total cost and select Min.

excel-solver-07

STEP 3:

Next, we need to identify the decision variables. SOLVER terms these as variable cells. After clicking into the By Changing Variable Cells box, we can select the decision variable cells in our LP, B3:E3. This tells SOLVER that it can change the number of brownies, scoops of ice cream, sodas, and pieces of cheese cake to reach an optimal solution.

excel-solver-08

STEP 4:

We need to add our constraints to SOLVER to ensure our solution does not violate any of them. On the right -hand side of the window, there is a button to Add a constraint. After clicking on this, a box will appear that allows us to add our constraints.

We can use the Cell Reference box to input the totals for each constraint that we calculated. Using Calories as an example, we would click on Cell F14, which computed the total calories from all our desserts.

There are several options for constraint type: <=, >=, =, int (integer), bin (binary), or dif (all different, e.g., assignment, TSP). After adjusting the constraint type to be greater than or equal to (>=) we can click on the cell referencing the minimum quantity permitted, Cell H14. Instead of a reference, we can also enter a specific number. The complete constraint looks as follows:

excel-solver-09

The Add button will allow us to include all the other constraints to SOLVER. When you have constraints structured in the same way (like these are), there is a faster way to add them all to SOLVER. Instead of entering each constraint individually, you can instead add them in one step.

In the Cell Reference box and Constraint box, you can also specify an array of cell references . If both the Cell Reference and Constraint are specified using an array of cell references, the length of the arrays must match and Solver treats this constraint as n individual constraints, where n is the length of each array.

excel-solver-10

We have now created four Constraints. SOLVER will ensure that the changing cells are chosen so F14>=H14, F15>=H15, F16>=H16, and F17>=H17. In short, the diet will be chosen to ensure that enough calories, chocolate, sugar, and fat are eaten.

excel-solver-11

The Change button allows you to modify a constraint already entered and Delete allows you to delete a previously entered constraint. If you need to add more constraints, choose Add .

STEP 5:

After adding all our constraints, here is the SOLVER Parameters Dialog Box:

excel-solver-12

The checked box titled Make Unconstrained Variables Non-Negative, allows us to capture non-negativity constraints. (Actually, all variables will be constrained to be >= 0). Additionally, you should change the Select a Solving Method to SIMPLEX LP when you are solving a linear program. The other options allow for solutions for nonlinear programs. Finally, click Solve for your solution.

After you Solve, the Parameters Dialog Box will close and the decision variables will change to the optimal solution. Because we referenced these cells in all our calculations, the objective function and constraints will also change.

excel-solver-13

OPTIONS:

The Parameters Dialog Box also has a number of options on how to calculate solutions.

  • Constraint Precision is the degree of accuracy of the Solver algorithm (for example, how close does the value of the LHS of a constraint have to be before it is considered equal to the RHS).
  • Max Time allows you to set the number of seconds before Solver will stop.
  • Iterations, similar to Max Time, allows you to specify the maximum number of iterations (steps of the Solver algorithm) before stopping.
Share this post
[social_warfare]
Building Linear Optimization Models
Optimization Models for Prediction and Insight

Get industry recognized certification – Contact us

keyboard_arrow_up