15.01.2015 Views

using excel solver in optimization problems - Mathematics Archives

using excel solver in optimization problems - Mathematics Archives

using excel solver in optimization problems - Mathematics Archives

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

USING EXCEL SOLVER IN OPTIMIZATION PROBLEMS<br />

Leslie Chandrakantha<br />

John Jay College of Crim<strong>in</strong>al Justice of CUNY<br />

<strong>Mathematics</strong> and Computer Science Department<br />

445 West 59 th Street, New York, NY 10019<br />

lchandra@jjay.cuny.edu<br />

Abstract<br />

We illustrate the use of spreadsheet model<strong>in</strong>g and Excel Solver <strong>in</strong> solv<strong>in</strong>g l<strong>in</strong>ear and<br />

nonl<strong>in</strong>ear programm<strong>in</strong>g <strong>problems</strong> <strong>in</strong> an <strong>in</strong>troductory Operations Research course. This is<br />

especially useful for <strong>in</strong>terdiscipl<strong>in</strong>ary courses <strong>in</strong>volv<strong>in</strong>g <strong>optimization</strong> <strong>problems</strong>. We work<br />

through examples from different areas such as manufactur<strong>in</strong>g, transportation, f<strong>in</strong>ancial<br />

plann<strong>in</strong>g, and schedul<strong>in</strong>g to demonstrate the use of Solver.<br />

Introduction<br />

Optimization <strong>problems</strong> are real world <strong>problems</strong> we encounter <strong>in</strong> many areas such as<br />

mathematics, eng<strong>in</strong>eer<strong>in</strong>g, science, bus<strong>in</strong>ess and economics. In these <strong>problems</strong>, we f<strong>in</strong>d<br />

the optimal, or most efficient, way of <strong>us<strong>in</strong>g</strong> limited resources to achieve the objective of<br />

the situation. This may be maximiz<strong>in</strong>g the profit, m<strong>in</strong>imiz<strong>in</strong>g the cost, m<strong>in</strong>imiz<strong>in</strong>g the<br />

total distance travelled or m<strong>in</strong>imiz<strong>in</strong>g the total time to complete a project. For the given<br />

problem, we formulate a mathematical description called a mathematical model to<br />

represent the situation. The model consists of follow<strong>in</strong>g components:<br />

• Decision variables: The decisions of the problem are represented <strong>us<strong>in</strong>g</strong> symbols<br />

such as X 1 , X 2 , X 3 ,…..X n . These variables represent unknown quantities (number<br />

of items to produce, amounts of money to <strong>in</strong>vest <strong>in</strong> and so on).<br />

• Objective function: The objective of the problem is expressed as a mathematical<br />

expression <strong>in</strong> decision variables. The objective may be maximiz<strong>in</strong>g the profit,<br />

m<strong>in</strong>imiz<strong>in</strong>g the cost, distance, time, etc.,<br />

• Constra<strong>in</strong>ts: The limitations or requirements of the problem are expressed as<br />

<strong>in</strong>equalities or equations <strong>in</strong> decision variables.<br />

If the model consists of a l<strong>in</strong>ear objective function and l<strong>in</strong>ear constra<strong>in</strong>ts <strong>in</strong> decision<br />

variables, it is called a l<strong>in</strong>ear programm<strong>in</strong>g model. A nonl<strong>in</strong>ear programm<strong>in</strong>g model<br />

consists of a nonl<strong>in</strong>ear objective function and nonl<strong>in</strong>ear constra<strong>in</strong>ts. L<strong>in</strong>ear programm<strong>in</strong>g<br />

is a technique used to solve models with l<strong>in</strong>ear objective function and l<strong>in</strong>ear constra<strong>in</strong>ts.<br />

The Simplex Algorithm developed by Dantzig (1963) is used to solve l<strong>in</strong>ear programm<strong>in</strong>g<br />

<strong>problems</strong>. This technique can be used to solve <strong>problems</strong> <strong>in</strong> two or higher dimensions.<br />

42


In this paper we show how to use spreadsheet model<strong>in</strong>g and Excel Solver for solv<strong>in</strong>g<br />

l<strong>in</strong>ear and nonl<strong>in</strong>ear programm<strong>in</strong>g <strong>problems</strong>.<br />

Spreadsheet Model<strong>in</strong>g and Excel Solver<br />

A mathematical model implemented <strong>in</strong> a spreadsheet is called a spreadsheet model.<br />

Major spreadsheet packages come with a built-<strong>in</strong> <strong>optimization</strong> tool called Solver. Now<br />

we demonstrate how to use Excel spreadsheet model<strong>in</strong>g and Solver to f<strong>in</strong>d the optimal<br />

solution of <strong>optimization</strong> <strong>problems</strong>.<br />

If the model has two variables, the graphical method can be used to solve the model.<br />

Very few real world <strong>problems</strong> <strong>in</strong>volve only two variables. For <strong>problems</strong> with more than<br />

two variables, we need to use complex techniques and tedious calculations to f<strong>in</strong>d the<br />

optimal solution. The spreadsheet and <strong>solver</strong> approach makes solv<strong>in</strong>g <strong>optimization</strong><br />

<strong>problems</strong> a fairly simple task and it is more useful for students who do not have strong<br />

mathematics background.<br />

The first step is to organize the spreadsheet to represent the model. We use separate<br />

cells to represent decision variables, create a formula <strong>in</strong> a cell to represent the objective<br />

function and create a formula <strong>in</strong> a cell for each constra<strong>in</strong>t left hand side. Once the<br />

model is implemented <strong>in</strong> a spreadsheet, next step is to use the Solver to f<strong>in</strong>d the<br />

solution. In the Solver, we need to identify the locations (cells) of objective function,<br />

decision variables, nature of the objective function (maximize/m<strong>in</strong>imize) and<br />

constra<strong>in</strong>ts.<br />

Example One (L<strong>in</strong>ear model): Investment Problem<br />

Our first example illustrates how to allocate money to different bonds to maximize the<br />

total return (Ragsdale 2011, p. 121).<br />

A trust office at the Blacksburg National Bank needs to determ<strong>in</strong>e how to <strong>in</strong>vest<br />

$100,000 <strong>in</strong> follow<strong>in</strong>g collection of bonds to maximize the annual return.<br />

Bond<br />

Annual Maturity Risk Tax-Free<br />

Return<br />

A 9.5% Long High Yes<br />

B 8.0% Short Low Yes<br />

C 9.0% Long Low No<br />

D 9.0% Long High Yes<br />

E 9.0% Short High No<br />

The officer wants to <strong>in</strong>vest at least 50% of the money <strong>in</strong> short term issues and no more<br />

than 50% <strong>in</strong> high-risk issues. At least 30% of the funds should go <strong>in</strong> tax-free <strong>in</strong>vestments,<br />

and at least 40% of the total return should be tax free.<br />

Creat<strong>in</strong>g the L<strong>in</strong>ear Programm<strong>in</strong>g model to represent the problem:<br />

Decision variables are the amounts of money should be <strong>in</strong>vested <strong>in</strong> each bond.<br />

X 1 = Amount of money to <strong>in</strong>vest <strong>in</strong> Bond A<br />

43


X 2 = Amount of money to <strong>in</strong>vest <strong>in</strong> Bond B<br />

X 3 = Amount of money to <strong>in</strong>vest <strong>in</strong> Bond C<br />

X 4 = Amount of money to <strong>in</strong>vest <strong>in</strong> Bond D<br />

X 5 = Amount of money to <strong>in</strong>vest <strong>in</strong> Bond E<br />

Objective Function:<br />

Objective is to maximize the total annual return.<br />

Maximize f(X 1 , X 2 , X 3 , X 4 , X 5 ) = 9.5%X 1 + 8%X 2 + 9%X 3 + 9%X 4 + 9%X 5<br />

Constra<strong>in</strong>ts:<br />

Total <strong>in</strong>vestment:<br />

X 1 + X 2 + X 3 + X 4 + X 5 = 100,000.<br />

At least 50% of the money goes to short term issues:<br />

X 2 + X 5 >= 50,000.<br />

No more than 50% of the money should go to high risk issues:<br />

X 1 + X 4 + X 5 = 30,000.<br />

At least 40% of the total annual return should be tax free:<br />

9.5%X 1 + 8%X 2 + 9%X 4 >= 40%(9.5%X 1 + 8%X 2 + 9%X 3 + 9%X 4 + 9%X 5 )<br />

Nonnegativity constra<strong>in</strong>ts (all the variables should be nonnegative):<br />

X 1 , X 2 , X 3 , X 4 , X 5 >= 0.<br />

Complete l<strong>in</strong>ear programm<strong>in</strong>g model:<br />

Max: .095X 1 + .08X 2 + .09X 3 +.09X 4 + .09X 5<br />

Subject to:<br />

X 1 + X 2 + X 3 + X 4 + X 5 = 100,000.<br />

X 2 + X 5 >= 50,000.<br />

X 1 + X 4 + X 5 = 30,000.<br />

9.5%X 1 + 8%X 2 + 9%X 4 >= 40%(9.5%X 1 + 8%X 2 + 9%X 3 + 9%X 4 + 9%X 5 )<br />

X 1 , X 2 , X 3 , X 4 , X 5 >= 0.<br />

Spreadsheet model and Solver implementation:<br />

Implement<strong>in</strong>g the problem <strong>in</strong> an Excel spreadsheet and Solver formulation produces the<br />

follow<strong>in</strong>g spreadsheet and Solver parameters. The cells B6 through B10 represent the<br />

five decision variables. The cell C13 represents the objective function. The cells B11,<br />

E11, G11, I11, B14, and B15 represent the constra<strong>in</strong>t left hand sides. The nonnegativity<br />

constra<strong>in</strong>t is not implemented <strong>in</strong> the spreadsheet and it can be implemented <strong>in</strong> the<br />

Solver. The complete set of constra<strong>in</strong>ts, target cell (objective function cell), variable cells<br />

(chang<strong>in</strong>g cells) and whether to maximize or m<strong>in</strong>imize the objective function are<br />

identified <strong>in</strong> the Solver parameters box.<br />

44


Figure 1: Spreadsheet implementation of example one<br />

Figure 2: Solver implementation of example one<br />

Figure 3: Spreadsheet with optimal solution of example one<br />

45


Optimal money allocation:<br />

Amount <strong>in</strong>vested <strong>in</strong> Bond A = X 1 = $20, 339.<br />

Amount <strong>in</strong>vested <strong>in</strong> Bond B = X 2 = $20, 339.<br />

Amount <strong>in</strong>vested <strong>in</strong> Bond C = X 3 = $29, 661.<br />

Amount <strong>in</strong>vested <strong>in</strong> Bond D = X 4 = $0.<br />

Amount <strong>in</strong>vested <strong>in</strong> Bond E = X 5 = $29, 661.<br />

The Maximum annual return is $8,898.00<br />

Example Two (Nonl<strong>in</strong>ear model): Network Flow Problem<br />

This example illustrates how to f<strong>in</strong>d the optimal path to transport hazardous material (<br />

Ragsdale, 2011, p.367)<br />

Safety Trans is a truck<strong>in</strong>g company that specializes transport<strong>in</strong>g extremely valuable and<br />

extremely hazardous materials. Due to the nature of the bus<strong>in</strong>ess, the company places<br />

great importance on ma<strong>in</strong>ta<strong>in</strong><strong>in</strong>g a clean driv<strong>in</strong>g safety record. This not only helps keep<br />

their reputation up but also helps keep their <strong>in</strong>surance premium down. The company is<br />

also conscious of the fact that when carry<strong>in</strong>g hazardous materials, the environmental<br />

consequences of even a m<strong>in</strong>or accident could be disastrous.<br />

Safety Trans likes to ensure that it selects routes that are least likely to result <strong>in</strong> an<br />

accident. The company is currently try<strong>in</strong>g to identify the safest routes for carry<strong>in</strong>g a load<br />

of hazardous materials from Los Angeles to Amarillo, Texas. The follow<strong>in</strong>g network<br />

summarizes the routes under consideration. The numbers on each arc represent the<br />

probability of hav<strong>in</strong>g an accident on each potential leg of the journey.<br />

Las Vegas<br />

0.003<br />

Los Angeles<br />

1<br />

3<br />

2<br />

0.004 0.002<br />

0.006<br />

0.010 0.006<br />

4<br />

6<br />

5<br />

7<br />

Figure 4: Network diagram of example two<br />

8<br />

0.001<br />

Amarillo<br />

0.002<br />

0.010 0.004<br />

0.006<br />

0.009<br />

Phoenix<br />

San Diego<br />

0.010<br />

Tucson<br />

Flagstaff<br />

0.001<br />

Albuquerque<br />

10<br />

0.005<br />

0.002<br />

0.003<br />

Las Cruces<br />

9<br />

0.003<br />

Lubbock<br />

46


The objective is to f<strong>in</strong>d the route that m<strong>in</strong>imizes the probability of hav<strong>in</strong>g an accident, or<br />

equivalently, the route that maximizes the probability of not hav<strong>in</strong>g an accident.<br />

Creat<strong>in</strong>g the mathematical model to represent the problem:<br />

Each decision variable <strong>in</strong>dicates whether or not a particular route is taken (they are<br />

known as b<strong>in</strong>ary variables). We will def<strong>in</strong>e these variables <strong>in</strong> follow<strong>in</strong>g way:<br />

X ij = 1 , if the route from node i to node j is selected, and X ij = 0 otherwise.<br />

Let P ij be the probability of hav<strong>in</strong>g an accident while travell<strong>in</strong>g from node i to node j<br />

(1- P ij is the probability of not hav<strong>in</strong>g an accident).<br />

Objective function:<br />

M<strong>in</strong>imize the probability of hav<strong>in</strong>g an accident or equivalently, maximize the probability<br />

of not hav<strong>in</strong>g an accident. Note that this objective function is nonl<strong>in</strong>ear.<br />

Maximize f(X 12 , X 13 ,….) = (1-P 12 *X 12 ) (1-P 13 *X 13 ) (1 – P 14 *X 14 ) (1 – P 24 *X 24 ) ………. (1 -<br />

P 9.10 *X 9,10 )<br />

Constra<strong>in</strong>ts:<br />

We use the follow<strong>in</strong>g strategy to construct constra<strong>in</strong>ts: That is, supply one unit at the<br />

start<strong>in</strong>g node and demand one unit at the end<strong>in</strong>g node, and for every other node,<br />

demand or supply is zero. We f<strong>in</strong>d the route <strong>in</strong> which the one unit travels.<br />

Total supply = 1, and total demand = 1, so for each node,<br />

Net flow (Inflow – Outflow) = demand or supply for that node (Balance of flow rule).<br />

Then we have follow<strong>in</strong>g set of constra<strong>in</strong>ts:<br />

Node 1: - X 12 – X 13 – X 14 = -1<br />

Node 2: + X 12 – X 24 – X 26 = 0<br />

Node 3: + X 13 – X 34 – X 35 = 0<br />

Node 4: + X 14 + X 24 + X 34 – X 45 – X 46 – X 48 = 0<br />

Node 5: + X 35 + X 45 – X 57 = 0<br />

Node 6: + X 26 + X 46 - X 67 – X 68 = 0<br />

Node 7: + X 57 + X 67 – X 78 – X 7,10 = 0<br />

Node 8: + X 48 + X 68 + X 78 – X 8,10 = 0<br />

Node 9: + X 79 – X 9,10 = 0<br />

Node 10: + X 7,10 + X 8,10 + X 9,10 = 1<br />

Complete nonl<strong>in</strong>ear Programm<strong>in</strong>g model:<br />

Maximize: (1-P 12 *X 12 ) (1-P 13 *X 13 ) (1 – P 14 *X 14 ) (1 – P 24 *X 24 ) ………. (1-P 9.10 *X 9,10 )<br />

Subject to:<br />

- X 12 – X 13 – X 14 = -1<br />

+ X 12 – X 24 – X 26 = 0<br />

+ X 13 – X 34 – X 35 = 0<br />

47


+ X 14 + X 24 + X 34 – X 45 – X 46 – X 48 = 0<br />

+ X 35 + X 45 – X 57 = 0<br />

+ X 26 + X 46 - X 67 – X 68 = 0<br />

+ X 57 + X 67 – X 78 – X 7,10 = 0<br />

+ X 48 + X 68 + X 78 – X 8,10 = 0<br />

+ X 79 – X 9,10 = 0<br />

+ X 7,10 + X 8,10 + X 9,10 = 1<br />

All X ij are b<strong>in</strong>ary.<br />

Spreadsheet model and Solver implementation:<br />

Figure 5: Spreadsheet implementation of example Two<br />

Figure 6: Solver implementation of example two<br />

48


Figure 7: Spreadsheet with optimal solution of example two<br />

The optimal path:<br />

The route that m<strong>in</strong>imizes the probability of hav<strong>in</strong>g an accident is given below:<br />

Los Angeles to Phoenix<br />

Phoenix to Flagstaff<br />

Flagstaff to Albuquerque<br />

Albuquerque to Amarillo.<br />

Conclusion:<br />

Optimization <strong>problems</strong> <strong>in</strong> many fields can be modeled and solved <strong>us<strong>in</strong>g</strong> Excel Solver. It<br />

does not require knowledge of complex mathematical concepts beh<strong>in</strong>d the solution<br />

algorithms. This way is particularly helpful for students who are non math majors and<br />

still want to take theses courses.<br />

References:<br />

1) Cliff T. Ragsdale, 2011, Spreadsheet Model<strong>in</strong>g and Decision Analysis, 6 th Edition.<br />

SOUTH-WESTERN, Cengage Learn<strong>in</strong>g.<br />

2) Dantzig, G. B. 1963, L<strong>in</strong>ear Programm<strong>in</strong>g and Extensions, Pr<strong>in</strong>ceton University<br />

Press, Pr<strong>in</strong>ceton, NJ.<br />

3) John Walkenbach, 2007, Excel 2007 Formulas, John Wiley and Sons.<br />

49

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!