Chapter 8 Using Excel Solver Solve Mathematical Model Modul Dss
Chapter 8 Using Excel Solver Solve Mathematical Model Modul Dss
handaru@uny.ac.id
Chapter 8
Chapter Overview
8.1 Introduction
8.2 Formulating Mathematical Programs
8.2.1 Parts of the Mathematical Program
8.2.2 Linear, Integer, and Nonlinear Programming
8.3 The Excel Solver
8.3.1 The Solver Steps
8.3.1.1 Standard Solver
8.3.1.2 Premium Solver
8.3.2 A Solver Example
8.3.2.1 Product Mix
8.3.2.2 Infeasibility
8.3.2.3 Unboundedness
8.3.3 Understanding Solver Reports
8.4 Applications of the Solver
8.4.1 Transportation Problem
8.4.2 Workforce Scheduling
8.4.3 Capital Budgeting
8.4.4 Warehouse Location
8.5 Limitations and Manipulations of the Solver
8.6 Summary
8.7 Exercises
Chapter 8: Using The Excel Solver To Solve Mathematical Programs
8.1 Introduction
This chapter illustrates how to use the Excel Solver as a tool to solve mathematical
programs. We review the basic parts of formulating a mathematical program and present
several examples of how the Solver interprets these parts of the program from the
spreadsheet. We give examples of linear, integer, and non-linear programming problems
to show how the Solver can be used to solve a variety of mathematical programs. We
also give an overview of the Premium Solver and its benefits. This chapter is important
for the reader to understand as many DSS applications involve solving optimization
problems, which are mathematical programs. The reader should be comfortable with
preparing the spreadsheet for use with the Solver. In Chapter 19, we revisit the Solver
using VBA commands. We have several examples of DSS applications which use the
Solver to solve optimization problems, such as Portfolio Management and Optimization.
A mathematical program consists of three main parts. The first is the decision
variables. Decision variables are assigned to a quantity or response that we must
determine in a problem. For example, if a toy manufacturer wants to determine how
many toy boats and toy cars to produce, we assign a variable to represent the quantity
of toy boats produced, x1, and the quantity of toy cars produced, x2. Decision variables
are defined as negative, non-negative, or unrestricted. An unrestricted variable can be
either negative or non-negative. These variables represent all other relationships in a
mathematical program, including the objective, the limitations, and the requirements.
The second part of the math program, called the objective function, is an equation that
states the goal, or objective, of the model. In the same example of the toy manufacturer,
we want to know the quantities of toy boats and toy cars to produce. However, the goal
of the manufacturing plant’s production may be to increase profit. If we know that we can
profit $5 for every toy boat and $4 for every toy car, then our objective function is:
In other words, we want profit to drive us in determining the quantity of boats and cars to
produce. Objective functions are either maximized or minimized; most applications
involve maximizing profit or minimizing cost.
The third part of the math progam, the constraints, are the limitations of the problem.
That is, if we want to maximize our profit, as in the toy manufacturer example, we could
produce as many toys as possible if we did not have any limits. However, in most
2
Chapter 8: Using The Excel Solver To Solve Mathematical Programs
realistic situations, there are certain limitations, or constraints, that we must consider.
Constraints can be a limited amount of resources, labor, or requirements for a particular
demand. These constraints are also written as equations, or inequalities in terms of the
decision variables. That is, if we can only use 20 hours of labor in a week and we need
0.5 hours to produce each toy boat and 0.3 hours to produce each toy car, then we write
our constraint as follows:
0.5x1 + 0.3x2 ≤ 20
There are three main categories of problems for which we can use the above
mathematical program parts: Linear Programming (LP), Integer Programming (IP),
and Nonlinear Programming (NLP).
Linear programming problems have a linear objective function and linear constraints.
That is, there are no variables of multiple powers such as x2 and x3, and no terms
involving two variables such as x1x2. In addition, LP problems consist of decision
variables with any range or interval of values, x ≥ 0 or x ≤ 0. An example of an LP would
be a production problem in which we want to maximize profit by determining how many
of several different product types we want to produce. The objective function could
therefore be expressed as:
n
z= ∑ px
i =1
i i
Where i = product number for n products, pi = profit per product i, xi = amount produced
of product i. This is therefore a linear objective function. If we assume that the
constraints are also linear, then this is a linear programming problem. We will revisit this
example in more detail in section 8.2.2.
Integer Programming is related to linear programming in that both the objective function
and constraints are linear; however, the decision variables can have only integer values
in a given range. Integer programming is also applied when decision variables are
Boolean, which means that they only take the values true or false, yes or no, go or no
go − all of which are mathematically represented as 0 or 1, respectively. An example of
an IP would be a capital budgeting problem in which we want to decide which projects to
invest in and which not to invest in. This decision is a yes/no decision that can be
represented by the following objective function:
n
z= ∑ yx
i =1
i i
3
Chapter 8: Using The Excel Solver To Solve Mathematical Programs
Where i = project number for n projects, yi = NPV per project i, xi = decision to invest per
project i. This is therefore a linear objective function. What makes it an integer
programming problem is that we limit the values of xi to 1 or 0 to reflect whether or not
we have or have not invested in a project, respectively. We will revisit this example as
well in more detail in section 8.3.2.
n
z= ∑
i =1
( xi − xw) 2 + ( yi − yw) 2
Where i = facility number for n facilities, xi and yi = coordinates of each facility i, xw and
yw = coordinates of the warehouse. This is therefore a nonlinear objective function. Even
if the constraints are all linear, it is still a nonlinear programming problem. We will also
revisit this example in more detail in section 8.3.3.
Linear Programming Both the objective function and the constraints are
linear. Decision variables can have any range or
interval of values.
Summary Integer Programming An LP in which decision variables can only take
integer values in a given range or Boolean values.
(Note: To find the Solver, go to Tools > Solver from the menu options. If you do not see
Solver in the Tools menu, you must first choose the Solver Add-In. To do so, select the
Add-In option from the Tools menu. A small dialog box will appear; from there, select
Solver Add-In from the list. If you do not see Solver Add-In in the Add-In list, click
Browse and look for the Solver.xla file from the following directory: C Drive > Program
Files > Microsoft Office > Office (or Office10) > Library > Solver. Double-click this file.
Now you should find Solver Add-In in the list; check the box next to it. Restart Excel. If
you do not find the Solver.xla file, go to the Add-Ins window as explained above; select
Solver Add-in and press OK. Insert the MS Office CD in CD-ROM drive when asked.)
To operate the Solver, we must follow a short sequence of steps: 1) read and interpret
the problem; 2) prepare the spreadsheet; and 3) solve the model and review the results.
We will now describe these steps in detail for both the Standard Solver and the Premium
Solver.
5
Chapter 8: Using The Excel Solver To Solve Mathematical Programs
Another important consideration when laying out the constraints in preparation for the
Solver is that there must be individual cells for the right-hand side (RHS) values as well.
We should also place all inequality signs in their own cells. This organization will become
clear once we explain how the Solver interprets our model.
Another advantageous way to keep our constraints organized as we use the Solver is to
name cells. We can also group constraints that have the same inequality signs. The
benefit of this habit will become apparent once we input the model parts for the Solver.
6
Chapter 8: Using The Excel Solver To Solve Mathematical Programs
Figure 8.3 The Solver Parameters window reads the decision variables, constraints,
and objective function as parameters of the model.
Figure 8.4 Adding Constraints involves selecting the cell with the equation formula,
choosing the inequality or equality sign, and selecting the cell with the RHS value.
Comment and Report are optional.
Excel also allows us to define more than one constraint at a time. By grouping
constraints that have the same inequality signs, we can select an entire range of
constraint formulas and RHS values and choose the common inequality sign. Naming
7
Chapter 8: Using The Excel Solver To Solve Mathematical Programs
constraints with the same inequality can also clarify what we add to the Solver and
prevent us from making any mistakes. If multiple ranges are not adjacent, we can select
them by holding down the CTRL key or by separating them with commas in the
Constraint window.
We have now added all of our constraints, so we press OK and return to the Solver
window. We can observe all of our constraints in the Constraint textbox. Note that we
can press the Change button to edit any of the constraints and the Delete button to
erase them.
Figure 8.5 The Options window allows a user to specify how Solver will work with a
model.
For now, we leave the Estimates, Derivatives, and Search options at their default values.
Assuming a Linear Model and Assuming Non-Negative decision variables are essential
options to consider. It is important to always check the Assume a Linear Model option
when solving a Linear programming problem in order to guarantee an optimal solution.
8
Chapter 8: Using The Excel Solver To Solve Mathematical Programs
solution”; or “Target Cell values (or Set Cell values) could not converge.” The
spreadsheet cells we set when formulating the model now have values for the decision
variable cells. Therefore, they also have values in the constraint and objective function
cells since they contain formulas referencing the decision variable cells. We can confirm
that all constraints have been satisfied by noting that the values in the constraint cells
with the Solver solution are all less than or equal to, or greater than or equal to the RHS
values, respectively.
Figure 8.6 Excel displays this window after we run Solver and find a solution.
After reviewing this solution, we can choose to Keep the Solver Solution or Restore our
Original Values. We can also opt to have some extra reports made from the Solver
solution: the Answer report, the Sensitivity report, and the Limits report. We will discuss
these reports in more detail later.
Premium Solver
Steps 1 and 2 are exactly the same when using the Premium Solver. Even the sub-steps
3.1, 3.2, and 3.3 are no different. However, depending on which algorithm we choose to
use, there is a different set of Options for sub-step 3.4.
To use the Premium Solver, we simply press the Premium button on the Solver window.
(Note that the Premium button now becomes a Standard button to allow us to switch
back to the standard Solver.) The main Solver window has a drop down list to select
9
Chapter 8: Using The Excel Solver To Solve Mathematical Programs
which Solver version, or which set of algorithms, we want to use to solve our problem
(see Figure 8.7). The Standard GRG Nonlinear and the Standard Simplex LP
versions are basically the same as the Standard Solver for LP, IP, and NLP models. We
use the Standard Evolutionary version to solve our more complex NLP models; we will
refer to it as the Premium Solver.
Figure 8.7 The Premium Solver offers three different Solver methods.
The Evolutionary Solver employs the Genetic Algorithm to solve Nonlinear problems.
(We will discuss this in more detail in a later section.) Once we select this version, we
click on the Options button to see the window shown in Figure 8.8. We can observe
several similar options as in the Standard Solver such as Max Time, Iterations,
Precision, and Assume Non-Negative.
The Population Size and Mutation Rate are parameters associated with the Genetic
Algorithm. The Population Size basically sets the initial number of feasible solutions. The
Mutation Rate determines how often the “Mutation” part of the Genetic Algorithm is
performed. We recommend setting the Population Size to at least 50; if there are several
variables and constraints, it may be wiser to have a Population Size of 100 or 1,000. The
Mutation Rate can be small, but it usually performs better at 0.25 than at 0.075. The
Local Search options can be specified to further determine the behavior of the Genetic
Algorithm. At this point, we will not further discuss this algorithm.
10
Chapter 8: Using The Excel Solver To Solve Mathematical Programs
After we have specified these options, we can press Solve to run the Solver. The Solver
Results window as shown in Figure 8.9 then appears. We may see “Solver found
Solution” or “Stop chosen when…” as possible messages in this window. We also have
a different list of available Solver Reports, including the Population Report. This report
provides the best, mean, maximum, and minimum values along with the standard
deviation of the Changing Cells, or decision variable, values across all iterations.
Figure 8.9 The Solver Reports for the Evolutionary Solver include a Population
Report.
Now that we are familiar with the three steps of using the Solver to determine the
solution of a mathematical model, let’s work through a more complicated example.
11
Chapter 8: Using The Excel Solver To Solve Mathematical Programs
Problem Description:
A company produces six different types of products. They want to schedule their
production to determine how much of each product type should be produced in order to
maximize their profits. This situation is known as the “Product Mix” problem.
Production of each product type requires labor and raw materials, but the company is
limited by the amount of resources available. There is also a limited demand for each
product, and no more than this demand per product type should be produced. Input
tables for the necessary resources and the demand are provided.
This is a Linear programming problem, as the constraints and objective function are
linear with respect to the decision variables, as we will see below. We therefore decide
to use the Standard Solver. Let’s now outline the model parts.
Decision Variables:
For the amount produced of each product type, we use the following variable
representation:
Objective Function:
Maximize Profit. Profit is calculated as the sum of the array multiplication of the unit
profit, p, and the amount produced of each product type. We write this equation as
follows:
z = ∑i pixi for i = 1 to 6
Here, p1 is the amount of profit gained per unit of product 1. Therefore, p1*x1 is the
amount of profit per unit of product 1 times the number of units produced of product 1,
thus yielding the total profit from product 1. The same follows for the other products, 2
through 6.
Constraints:
There are two resource constraints: labor, l, and raw material, r. Available amounts are
provided for each resource, and required amounts are provided for the production of
each product type. We therefore say that the sum of the array multiplication of the
resource requirements and the amount produced of each product type must be less than
or equal to the amounts available of each resource. These equations are written:
Labor Constraint:
= ∑i lixi <= available labor = 4500
12
Chapter 8: Using The Excel Solver To Solve Mathematical Programs
Here l1 is the amount of labor required per unit produced of product 1. Similarly, r1 is the
amount of raw material required per unit produced of product 1. Therefore, the equations
represent the total labor and raw material needed for all products.
There is also a constraint that all demand, D, should be met (but is not enforced), and no
extra amount should be produced. Therefore, the amount produced of each product type
must be less than or equal to the given demand quantities. This constraint can be written
as follows:
Demand Constraint:
xi <= Di for i = 1 to 6
Next, we set up the spreadsheet to list these parts of the model in such a way that the
Solver can read them clearly.
The Spreadsheet:
In Figure 8.10, we observe the overall spreadsheet layout. We have organized our cells
by Input, Decision Variables, Constraints, and Objective Function. The Input table was
given. We calculate the Unit Profit row by subtracting the Variable Cost from the Unit
Price.
We have also labeled some ranges on the spreadsheet. We have named the Decision
Variable range “PMDecVar,” the Labor resource requirement row “PMLabor,” the Raw
Material resource requirement row “PMRawMat,” and the Unit Profit row “PMUnitProfit.”
These names will be helpful for writing the constraint and objective function formulas as
well as for inserting cell references in the Solver.
To prepare the constraint and objective function formulas, we use the SUMPRODUCT
function. Remember from Chapter 4 that this function takes two arrays, or ranges, as
13
Chapter 8: Using The Excel Solver To Solve Mathematical Programs
parameters for which it will multiply and sum all values. Referring to the equations
written above and the range names created, we write the constraint formulas as follows:
Labor Constraint:
=SUMPRODUCT(PMDecVar, PMLabor)
The right-hand side values are equal to the “Available” amounts from the Input table (see
Figure 8.11).
Figure 8.11 The Labor and Raw Material constraint formulas use the SUMPRODUCT
function.
For the demand constraint, we simply need to ensure that the values in our decision
variable range are less than each of the corresponding values in the “Demand” range.
We do not require a formula for this constraint (see Figure 8.12).
The objective function formula is also written with the SUMPRODUCT function (see
Figure 8.13). Referring to the equation and range names above, we type the following
formula:
=SUMPRODUCT(PMUnitProfit, PMDecVar)
14
Chapter 8: Using The Excel Solver To Solve Mathematical Programs
Figure 8.13 The objective function formula employs the SUMPRODUCT function.
After appropriately preparing the cells, we can now use the Solver to find our solution. In
Figure 8.14, the Solver dialog box appears. We have set the Target Cell to the location
of the objective function formula, the Changing Cells are set to the empty decision
variable cells, which we named “PMDecVar,” and the “Constraints” box shows the left
and right sides of the constraint equations with the corresponding inequalities. Here, the
labor and raw material constraints are listed first, then the demand constraint is listed
with the decision variable cells. We have also selected the two options Assume Linear
Model and Assume Non-Negative.
The Solver Results window reveals that a solution was successfully found (see Figure
8.15). We can view the final results in Figure 8.16. Notice that all constraints are met.
The company now knows how much to produce of each product type and what their
maximum profit will be. (There may be multiple solutions, but we cannot find them or
determine if there are more solutions with the Standard Solver.)
15
Chapter 8: Using The Excel Solver To Solve Mathematical Programs
Infeasibility
An infeasible problem is one in which at least one of the constraints cannot be met. For
this example, we consider infeasibility based on the “Demand” Constraint. Note in the
solution above that some of the product types did not meet their demand since the
“Demand” Constraint inequalities were <= in order to avoid the cost of over-production.
Now let’s assume that the company insists that demand is always met, even if some
waste is produced. We now need to change the “Demand” Constraint inequality from <=
to >=. To do so, we select the “Demand” Constraint in the Solver window from the list of
constraints and use the Change button (see Figure 8.17).
16
Chapter 8: Using The Excel Solver To Solve Mathematical Programs
However, now when we press Solve, the Solver Results window conveys that the Solver
could not find a feasible solution with this modified constraint (see Figure 8.18). If there
are not enough resources available to meet the demand, then the solution is infeasible.
The result of this infeasible solution is shown in Figure 8.19.
17
Chapter 8: Using The Excel Solver To Solve Mathematical Programs
Unboundedness
An unbounded problem is one in which the objective function can reach an unreasonably
large number (if we are maximizing) or small number (if we are minimizing). Such a
situation implies that the constraints are not inclusive enough. We consider
unboundedness for this example in the case where we are able to maximize the profit to
an unreasonably huge value. Now, let’s suppose that there are no “Demand”
Constraints. We select the “Demand” Constraint from the constraint list in the Solver
window and press Delete. Let’s also assume at this point that negative decision variable
values are allowed. To do so, we re-visit the Options window and uncheck the Assume
Non-Negative option. The updated model now appears in the Solver window, displayed
in Figure 8.20.
Figure 8.20 The updated Solver model does not have the “Demand” Constraints.
This time, after pressing Solve, the Solver Results window tells us that a solution did not
converge (see Figure 8.21). That means that without the “Demand” Constraints or non-
negativity assumption we are able to achieve extremely large profit values.
Figure 8.21 The Solver solution did not converge without the “Demand” Constraints
and non-negativity assumption.
18
Chapter 8: Using The Excel Solver To Solve Mathematical Programs
The three main reports available when using the Standard Solver are the Answer report,
the Sensitivity report, and the Limits report. We will now briefly review what information
is contained in these reports. (Note that there are some limitations to the Solver Reports
that we will discuss in the “Limitations and Manipulations” section.)
The Answer Report provides the original and final values of the Target Cell, Changing
Cells, or Adjustable Cells, and the Constraints (see Figure 8.22). It also gives the
reference of all of these cells on the spreadsheet. The names for each cell are based on
the row and column labels next to the tables on our spreadsheet. The formulas for the
constraints are provided only as references for where they formulas are held; in other
words, any functions used are not reported here. The Status of the Constraint part of the
report conveys whether or not a constraint is binding. A constraint is binding when its
slack value is zero.
19
Chapter 8: Using The Excel Solver To Solve Mathematical Programs
The Sensitivity Report provides information about the Changing Cells and the
Constraints (see Figure 8.23) as well as their final values. The reduced cost or shadow
price and the allowable increase and decrease indicate how much flexibility can be
allowed with any of these values in order to achieve the desired objective function value.
The Limits Report provides information about the Target Cell and the Changing Cells
(see Figure 8.24); it also includes the value of each cell. The lower and upper limits of
the Changing Cells are listed next to the corresponding Target Cell value that would
result if the Changing Cell had the limit value.
20
Chapter 8: Using The Excel Solver To Solve Mathematical Programs
The Input for this problem is in the first table in Figure 8.25. It contains the transportation
cost between each city and each region. It also displays the capacity per plant and the
demand per region.
The decision variables are the amount to ship from each plant to each region. We have
created a table with empty cells for these decision variables.
There are two constraints for this problem: “Demand” and “Capacity.” We need to ensure
that the total number of products shipped from a plant (to each region) is less than or
equal to its capacity, and we also need to ensure that the total number of products
received by a region (from each plant) is greater than or equal to its demand. We have
used the SUM function to create a column and row for these respective constraints. We
have then copied the capacity and demand from the Input table as the RHS value.
The objective function is to minimize the total transportation costs. We need to sum the
array multiplication between the given costs between each plant and region with the
amount shipped between each plant and region. To do so, we use the SUMPRODUCT
function. We have actually also named the range of decision variables as
“TransShipped” and the range of input costs as “TransCosts,” so the formula for the
objective function is simply:
=SUMPRODUCT(TransShipped, TransCosts)
21
Chapter 8: Using The Excel Solver To Solve Mathematical Programs
We are now ready to use the Solver (see Figure 8.26). We set the Target Cell and
choose Min for our objective function. We then set the Changing Cells (notice that the
name of this range appears in the Solver window). We add both the capacity and
demand constraints to the constraint list. It is also very important that we specify two
Options for this Linear programming problem as well: Assume Linear Model and Assume
Non-Negative.
Figure 8.26 Completing the Solver window and specifying the Options.
The Solver solution appears in Figure 8.27. We have found the number of products to be
shipped from each plant to each region and the value of the resulting minimal
transportation cost. We can also check that all constraints have been met.
22
Chapter 8: Using The Excel Solver To Solve Mathematical Programs
Shown in the first table of Figure 8.28, the main Input for this problem is the number of
workers needed for each day of the week.. We also know that each employee works 5
consecutive days. We have represented this schedule in the second table by recording a
sequence of 1’s beginning on the day listed in each row. So, the Monday row has a 1 in
the Monday, Tuesday, Wednesday, Thursday, and Friday columns. The Tuesday row
has a 1 in the Tuesday, Wednesday, Thursday, Friday, and Saturday columns, and so
on. This table of consecutive 1’s will be used for the constraint formula.
The decision variables for this problem are the number of employees who will begin
working (for 5 consecutive days) on each day of the week. The column next to the
second table with empty cells is for the decision variables. We have also named this
range “SchedDecVar.”
There is only one constraint for this problem, which is to ensure that the total number of
employees working on a given day (regardless of which day they started working) is
greater than or equal to the number of employees needed on that particular day. To
achieve this, we again use the SUMPRODUCT function. We sum the array multiplication
of the decision variable column with the column of 1’s for each day. Since we have
named our decision variable range, this formula is:
23
Chapter 8: Using The Excel Solver To Solve Mathematical Programs
=SUMPRODUCT(SchedDecVar, DayColumn9:DayColumn15)
The DayColumn letter value would change from D to J for Monday through Sunday
respectively. This formula appears in Figure 8.28.
=SUM(SchedDecVar)
Figure 8.28 The spreadsheet preparation for the Workforce Scheduling problem.
We are now ready to use the Solver (see Figure 8.29), so we specify the Target Cell and
choose Min for the objective function. We then set the Changing Cells. (Notice that the
name of this range appears in the Solver window.) We add the one constraint to the
constraint list. It is also very important that we specify two Options for this Linear
programming problem: Assume Linear Model and Assume Non-Negative.
24
Chapter 8: Using The Excel Solver To Solve Mathematical Programs
Figure 8.29 Completing the Solver window and specifying the Options.
The Solver’s solution, shown in Figure 8.30 reveals the number of employees who will
start work on each day of the week. We can also check that the constraint is met.
However, we notice that some of the results of the decision variables and objective
function are non-integer. Technically, this solution is correct for the way we
communicated with the Solver, but it does not make much realistic sense to hire a total
of 19.33 employees.
Therefore, we need to enforce integer decision variables, thus making this an integer
programming problem. So, we actually need to add a constraint in the Solver window.
For this new constraint, we highlight the range of decision variables as the constraint
formula and choose int from the list of inequalities (see Figure 8.31). The RHS value
then automatically becomes “integer.”
25
Chapter 8: Using The Excel Solver To Solve Mathematical Programs
Figure 8.31 The additional constraint enforces the decision variables to be integers.
Note that an extra constraint has been added to the constraint list in the Solver window
(see Figure 8.32). Since we named our decision variable range, this new constraint is
displayed in the constraint list simply as:
SchedDecVar = integer
The updated solution now has integer values for the decision variables and an objective
function that is more realistic (see Figure 8.33).
26
Chapter 8: Using The Excel Solver To Solve Mathematical Programs
Figure 8.33 The updated Solver solution for the Scheduling problem.
The Input table lists the NPV and yearly costs for each project (see Figure 8.34).
27
Chapter 8: Using The Excel Solver To Solve Mathematical Programs
Figure 8.34 The Input table for the Capital Budgeting problem.
The decision variables for this problem are the projects that we do and do not invest in.
These will have yes,no or go,no go values. We represent these binary options using 1’s
and 0’s. We have to ensure that the decision variables are only given binary values
when we add constraints to the Solver. We name this range “CBDecVar.”
There is only one constraint for this problem, which is that no more than the yearly
available funds can be spent annually. Since each project has associated yearly costs,
we must sum the costs of all of the projects that we have invested in each year to
determine if this constraint is met. To do so, we again use the SUMPRODUCT function.
The arrays for this function are the decision variables and the column of yearly costs
from the input table. Since the decision variable values are binary, only the costs for the
projects in which we will invest will be summed. Applying the range name given to the
decision variables, the formula is:
=SUMPRODUCT(CBDecVar, CostColumn4:CostColumn24)
The objective function is to maximize the total NPV. To determine this, we sum the array
multiplication of the decision variables and the column of NPV values for each project.
We have named this NPV column “CB_NPV.” Using this range name and the name of
the decision variable range, this formulas is:
=SUMPRODUCT(CBDecVar, CB_NPV)
See Figure 8.35 for the location and formulation of these model parts.
28
Chapter 8: Using The Excel Solver To Solve Mathematical Programs
Now we are ready to use the Solver. After specifying the Target Cell and Max for the
objective function, the Changing Cells, and the one constraint, we must also include the
additional binary variable constraint. To do so, we list the decision variables as a
constraint formula and choose “bin” from the list of inequalities. The word “binary”
automatically appears as the RHS value (see Figure 8.36). Now, when we return to the
Solver window (see Figure 8.37), we can see that this additional constraint has been
added as:
CBDecVar = binary
We also still specify the two Options: Assume Linear Model and Assume Non-Negative.
29
Chapter 8: Using The Excel Solver To Solve Mathematical Programs
Figure 8.37 The completed Solver window for the Capital Budgeting problem with
binary decision variables.
Note that it takes a slightly longer time for the Solver to ascertain a solution, which is
provided as 1’s and 0’s in the column of decision variables (see Figure 8.38). This result
can be interpreted as: invest in the projects with 1’s; do not invest in the projects with
0’s. Therefore, in order to maximize NPV, we should only invest in 12 of the projects.
Figure 8.38 The Solver solution for the Capital Budgeting problem.
30
Chapter 8: Using The Excel Solver To Solve Mathematical Programs
The Input for this problem is the location of each city identified by its latitude and
longitude. We are also provided with the number of shipments made to each city. This
input is illustrated in the first table of Figure 8.39. We have named the column of
shipments “WHShipments.”
The decision variables are the latitude and longitude values of the warehouse location.
We have created two empty cells for these and named each one “WHLat” and
“WHLong,” respectively.
There is only one constraint for this problem, which is that the latitude and longitude for
the warehouse location must be between the values of 0 and 120. We only need to add
the constraint that they be less than or equal to 120 since non-negativity is a Solver
option.
31
Chapter 8: Using The Excel Solver To Solve Mathematical Programs
We now need to keep track of the distances between each city and the possible
warehouse location. These distances are calculated using the following Nonlinear
equation:
The CityLatitude and CityLongitude are calculated from the columns of the input table for
each city row. The SQRT function calculates the square root, which is a Nonlinear
manipulation of the decision variables. This column of distances appears in Figure 8.40.
We have named this column “WHDist.” (Note: The value 69 is based on the earth’s
curvature and is only used when computing latitude and longitude distances for US
cities.)
Figure 8.40 Calculating the distance between each city and the possible warehouse
location.
The objective function is to minimize the total distance traveled from the warehouse to
each city. It is the sum of the array multiplication between this column of distances and
the column of shipments made to each city from the input table. Since we have named
both of these ranges, the formula for the objective function is:
=SUMPRODUCT(WHDist, WHShipments)
32
Chapter 8: Using The Excel Solver To Solve Mathematical Programs
Figure 8.41 The objective function formula for the Warehouse Location problem.
Let’s now use the Premium Solver, or Evolutionary Solver, to solve this nonlinear
programming problem. We begin by setting the Target Cell and choosing Min for the
objective function. Then, we set the Changing Cells and the Constraints. We next
choose Standard Evolutionary from the list of Solver versions (see Figure 8.42).
We now click on Options to view the Evolutionary Solver Options shown in Figure 8.43.
Here, we want to check Assume Non-Negative. (Note that Assume Linear Model is not
an option here.) We set the Population Size and Mutation Rate as shown.
33
Chapter 8: Using The Excel Solver To Solve Mathematical Programs
Now, when we operate the Solver, we find that several iterations of the Genetic
Algorithm are being run. After several seconds, the message in Figure 8.44 appears.
One of our option parameters has been reached, in this case the Maximum Iteration,
and we are given the choice to Continue or Stop. In this case, we stop here, but we
could continue for a more accurate solution.
Figure 8.44 The Show Trial Solution message offers the choice to stop or continue.
Since we chose to stop, the Solver Results window indicates when and why we stopped
(see Figure 8.45).
34
Chapter 8: Using The Excel Solver To Solve Mathematical Programs
Figure 8.45 The Solver Results window explains when and why the Solver stopped.
The solution appears in Figure 8.46. The latitude and longitude for the warehouse
location are displayed with the corresponding total minimal distance to be traveled to
each city for all shipments.
Figure 8.46 The Solver solution for the Warehouse Location problem.
35
Chapter 8: Using The Excel Solver To Solve Mathematical Programs
Let’s first discuss problem size limitations. We are referring to the summarized table in
Figure 8.47 (from www.solver.com). The Standard Solver has a limit of 200 variables
and 200 constraints for LP problems, and 200 variables and 100 constraints for NLP
problems. We have also noted that it takes a long time for IP problems to be solved with
the Standard Solver.
The Premium Solver, on the other hand, has a limit of 1000 variables and 8000
constraints for LP problems, and 400 variables and 200 constraints for NLP problems.
Therefore, all large problems should be solved with the Premium Solver. The time for
solving IP problems with the Premium Solver is 10 to 20 times faster than the Standard
Solver.
The Standard Solver faces other problems in addition to size limitations. One error that
can occur involves scaling the related model parts. If there is a mixture of small and
large coefficient values in the constraints or the objective function and the possible
values that the decision variable can take, rescaling is necessary. For example, if we are
solving a binary IP problem whose decision variable values can only be 0 or 1 and
whose constraint coefficients are in the hundreds of thousands, the Solver will not be
able to recognize the problem as an LP model if we choose Assume Linear Model from
the Solver Options. To correct this error, we must first re-scale the problem by dividing
the constraint coefficients by 1000 and adjusting the costs to maintain proportionality.
The Standard Solver is then able to recognize the linearity of the problem and find a
solution, which should then be re-scaled again to find a solution proportional to the initial
coefficient values.
Another error that can occur with the Standard Solver involves the Sensitivity Report. If
the decision variables or Changing Cells have additional bound constraints and the
solution value of one of these variables is at its bound, then the reduced cost on the
Sensitivity Report becomes equal to the dual values of these variables. The additional
36
Chapter 8: Using The Excel Solver To Solve Mathematical Programs
bound constraints will not be listed and no shadow price for these constraints will appear
either. For example, if we consider the Product Mix problem discussed in the Solver
Example section above, the “Demand” Constraints are additional bound constraints on
the decision variables. Therefore, if the solution to this problem has one of the decision
variable values at its demand bound, its reduced cost will become its dual value in the
Sensitivity Report and the “Demand” Constraint will not be listed. This is not correct, but
it happens.
The Premium Solver has corrected some of these and other problems of the Standard
Solver. There are additionally technical benefits to using the Premium Solver, including
the algorithms. The main algorithmic difference between the Standard Solver and the
Premium Solver is that the Standard Solver is limited by a slope-based algorithm for
solving NLP problems. This algorithm works well for convex maximization or concave
minimization problems; however, when neither of these is the structure of the problem,
there can be multiple optima that the Standard Solver will not recognize. Such examples
include problems with fixed charges or absolute values. Therefore, the Genetic
Algorithm of the Premium Solver is much better for solving NLP problems.
Aside from the Excel Solver, there are other optimization software packages available to
use with Excel. Frontline Systems, the developers of the Excel Solver, have developed
improved software for solving IP problems, called the XPress Solver. They have also
developed several large-scale solvers. Lindo Systems has additionally developed some
solvers, including What’s Best. What’s Best is a popular alternative to the Excel Solver;
however, it requires more optimization knowledge from the user in order to model the
problem directly in the spreadsheet. We have chosen to work with the Excel Solver for
this book since it is easier to use and learn in both the Excel spreadsheet and in VBA for
Excel.
8.6 Summary
¾ The three parts of a mathematical model are decision variables, objective
function, and constraints.
¾ The three primary types of mathematical models are linear, integer, and
nonlinear programming problems.
¾ Using Solver involves three main steps: reading and interpreting the problem to
determine the three parts of the model; preparing the spreadsheet so that Solver
can read the data; and running the Solver.
¾ Several applications of mathematical modeling exist for which Solver can be a
useful tool. Some LP examples are Transportation and Workforce Scheduling.
An IP example is Capital Budgeting, and an NLP example is the Warehouse
Location problem.
¾ We use the Premium Solver to solve NLP problems since the Genetic Algorithm
is more accurate.
37
Chapter 8: Using The Excel Solver To Solve Mathematical Programs
8.7 Exercises
8.7.1 Review Questions
1. Use the Excel Solver to determine the solution to the following LP model:
Maximize Q = 3X + 4Y – 5Z
Subject to: 5X + Z ≤ 150
2X + 4Y ≤ 100
10Z – 2X – 3Y ≥ 20
X,Y,Z ≥ 0
2. A distribution center for a department store has four trucks available to deliver
products to retail stores. The company accrues shipping costs for all boxes that it
ships and losses for all boxes that cannot fit on one of the four trucks and must
be shipped later. Use the information below to construct a model formulation that
minimizes the total cost by determining the optimal number of boxes of each
product to be delivered by each truck. Each truck has a trailer volume of 1000 ft3
and a weight limit of 50,000 lbs.
38
Chapter 8: Using The Excel Solver To Solve Mathematical Programs
3. Referring to the model formulated in the previous problem, use the Solver to find
the optimal number of boxes of each product to ship in each truck. Adjust the
values for amount, size, weight, cost of shipping, and loss if shipped late, and
use the Solver again to find the optimal solution.
4. A toy company is expanding its toy vehicle product line. The company formerly
produced only toy trains but now is expanding the line to include toy cars, trucks,
and airplanes. The amount of each type of vehicle to produce must now be
determined. The table below displays the expected production cost, sales price,
required machine hours, and required labor hours to produce a single unit of
each type of toy vehicle. It costs $200 an hour to run the machine that produces
cars, trucks, and trains and $250 an hour to run the machine that produces
airplanes. All toy assembly workers are paid a wage of $7.25 an hour. Based on
historical data, the product line manager forecasts that the demand for trains,
cars and trucks will be at least 500 units, while the demand for airplanes will be
at least 250 units. The production cost of all toy vehicles cannot exceed $10,000,
and no more than 1,000 labor hours can be spent on production. Formulate this
problem as an integer programming model that will maximize the profit earned by
the company’s toy vehicle product line.
Now use this formulation to create an Excel spreadsheet of your model. Then,
use the Solver to find the optimal number of each type of toy vehicle to produce.
39
Chapter 8: Using The Excel Solver To Solve Mathematical Programs
6. Using the Solver model that you developed in the previous exercise, perform the
following:
a. Trace the dependents of each decision variable.
b. Trace the precedents of the target cell and the constraint cells.
7. A hardware manufacturer uses four workstations to produce nuts and bolts. The
following table provides the number of minutes required to create a batch of nuts
or bolts at each workstation:
Workstation
1 2 3 4
Nuts 2 8 7 8
Bolts 3 9 7 5
The following table lists the cost of machining a batch of nuts or bolts:
The machines at each workstation run for 16 hours a day, 5 days a week. A
minimum of 700 batches of nuts and 1000 batches of bolts must be produced
each week. Use the Solver to determine the optimal number of batches of nuts
and bolts to produce at each workstation in order to minimize the cost of
machining.
8. Suppose you have $0.97 worth of coins in your pocket. You know that you have
three times as many nickels as there are dimes. You also know that you have at
least five pennies and no more than two quarters. Use the solver to determine
the optimal number of batches of nuts and bolts to be produced per week at each
workstation in order to minimize production costs.
40
Chapter 8: Using The Excel Solver To Solve Mathematical Programs
binary programming model, and use the solver to find the optimal combination of
projects for the capitalist to finance.
11. During each 4-hour period, a small town’s police force requires the following
number of on-duty police officers: 8 from midnight to 4 AM, 7 from 4 AM to 8 AM,
6 from 8 AM to noon, 6 from noon to 4 PM, 5 from 4 PM to 8 PM, and 4 from 8
PM to midnight. Each police officer works two consecutive 4-hour shifts.
Formulate and solve an LP that can be used to minimize the number of police
officers needed to meet the daily requirements.
12. A retailer store accepts orders made by telephone 7 days a week, from 8 a.m. to
5 p.m. The management has estimated that the following number of people is
needed daily in the call center to cover incoming orders:
The employees work 5 consecutive days per week. The salary is $100/day to
work on Monday through Friday and $150/day to work on the weekend.
Formulate the problem as an integer programming problem that minimizes the
cost of staffing the call center. Use Excel solver to optimize this problem.
13. Read hands-on exercise 12. Suppose part-time staff working 3 consecutive days
during Monday to Friday can be hired at a cost of $110/day. The higher cost
reflects the higher training and turnover costs associated with part-time
employees. The number of such staff cannot exceed 5. Extend the integer
programming model to incorporate this option. Use Excel solver to optimize the
problem.
41
Chapter 8: Using The Excel Solver To Solve Mathematical Programs
14. A production company blends silicon and nitrogen to produce two types of
fertilizers. Fertilizer 1 contains 40% nitrogen and 60% silicon. Fertilizer 2 contains
30% nitrogen and 70% silicon. The selling price for fertilizer 1 is $70/lb and for
fertilizer 2 is $40/lb. The company can purchase up to 80lbs of nitrogen at $15/lb
and up to 100lbs of silicon at $10/lb. The company should produce at least 80lbs
of fertilizer 1 and at least 30lbs of fertilizer 2.
Identify the amount of fertilizer 1 and 2 that maximize the profits. Formulate this
problem as a linear programming problem and use Excel solver to find the
solution
15. A local bakery sells blueberry and chocolate muffins in packs of four. In a week
the bakery bakes at most 65 packs of muffins. The cost and demands per pack
are presented in the table below. It costs $.50 to hold a pack of blueberry muffins
and $.40 to hold a pack of chocolate muffins in inventory for a week. Formulate
and solve an LP to minimize total cost of meeting next three weeks’ demands.
16. A company supplies goods to three customers, each of whom require 30 units.
The company has two warehouses. Warehouse 1 has 40 units available and
warehouse 2 has 30 units available. The costs of shipping 1 unit from the
warehouse to a customer are shown below. There is a penalty for each unmet
customer unit of demand. With customer 1, a penalty cost of $90 is incurred, with
customer 2, $80, and with customer 3, $110. Formulate and solve a
transportation problem to minimize the sum of shortage and shipping costs.
17. Referring to the above problem, suppose that extra units could be purchased and
shipped to either warehouse for a total cost of $100 per unit and that all customer
demand must be met. Formulate and solve this transportation problem to
minimize the sum of purchasing and shipping costs.
18. Currently, the exchange rate is 100 yen per dollar. In Japan, you sell a product
that costs $5 to produce at a price of 700 yen. The product has an elasticity of 3.
With exchange rates varying from 70 to 130 yen per dollar, determine the optimal
product price in Japan and the profit in US dollars. Assume a Linear demand
curve. The current demand is 100.
A currency trader faces the following 1-day currency exchange problem that
involves U.S. dollars, English pounds and Japanese yen. In the beginning of the
day, he has an inventory of 40,000 dollars, 90,000 pounds and 100,000 yen. By
the end of the day, the he must have an inventory of at least 50,000 dollars,
42
Chapter 8: Using The Excel Solver To Solve Mathematical Programs
95,000 pounds and 90,000 yen. The exchange rates are given below (for
example, one can exchange 1 U.S. dollars for 0.61 English pounds).
During the day, the currency trader exchanges the starting inventory for different
currencies to create the required ending inventory while maximizing the surplus
inventory of U.S. dollars. Formulate this problem as a linear program and use the
Excel solver to find the solution.
19. A computer company must purchase 700 customized hard drivers for the new
model that is planning to launch next year. The following table presents the
quotes received from three different vendors:
For example, Company C will require a fixed cost of $9,000 to set-up the
machines to produce the drivers. In addition, it will charge $270 per unit sold.
20. Read hands-on exercise 8.19. Reformulate the problem and re-optimize using
Excel solver under the additional constraint that no vendor is allowed to supply
more than 65% of the total number of units required.
21. A manufacturing company uses trucks to ship products from the production plant
to the warehouse. The following network represents the available routes between
the plant and the warehouse. The numbers in brackets (d, t) present the length of
the route d and the time t it takes to cross the road segment.
2 (1, 5)
(1,3)
4 (7, 12)
1 (2, 7) (6, 8)
(3, 20) 6
(3, 4)
(5, 15)
(4, 10)
3 (1, 2) 5
Find the shortest path (in terms of distance) from the plant (node 1) to the
warehouse (node 6). Formulate the problem as an integer program and use
Excel solver to find the solution.
43
Chapter 8: Using The Excel Solver To Solve Mathematical Programs
22. Read hands-on exercise 8.22. Find the longest path (in terms of time) that
connects the plant (node 1) with the warehouse (node 6). Formulate the problem
as an integer programming problem and use Excel solver to find the solution.
23. The Markowitz problem provides the foundations for single-period investment
theory. The problem is stated as follow: “Given that an investor has n assets. The
r , r ,..., r
n and the co-variances are ij σ
corresponding mean rates of return are: 1 2
for i, j = 1,…,n. The problem is to find a minimum-variance portfolio for a given
r w
fixed mean value returns ( ).” A portfolio is defined by a set of weights i , i =
1,…, n, that sum to 1 (Luenberger 1998). The following is a NLP formulation of
the problem:
1 n
Min : ∑ wi w jσ ij
2 i , j =1
Subject to :
n
∑ wi ri = r
i =1
n
∑ wi = 1
i =1
Given the covariance matrix and the rates of return for three assets, find the
minimum variance portfolio that gives an expected return equal to 0.5.
2 1 0
V = 1 2 1
0 1 2
44