matka/dokumentumok/optimizationwith... · web viewafter entering the formulae, their initial value...

21
SOLVER, THE OPTIMIZATION TOOL OF MS EXCEL Solver is an add-in program in Microsoft Excel. Using Solver general optimization problems can be solved, so the constraints and the objective function of the problems are not necessarily linear. LOADING SOLVER Before the first use of Solver you need to load it in Excel. Click the File Button, and then choose Options. Click Add-Ins, and then in the Manage box, select Excel Add- ins and click Go. From the dialogue box presented check the box for Solver Add-In and click OK. After you load Solver, the Solver command is available in the Analysis group on the Data tab. GIVING DATA Before starting Solver we have to give the data of the problem to be solved. In order to enter

Upload: others

Post on 03-Apr-2020

1 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: matka/Dokumentumok/Optimizationwith... · Web viewAfter entering the formulae, their initial value are 0. If you would like to check the expressions, click on the Show Formulas button

SOLVER, THE OPTIMIZATION TOOL OF MS EXCEL

Solver is an add-in program in Microsoft Excel. Using Solver general optimization problems can be solved, so the constraints and the objective function of the problems are not necessarily linear.

LOADING SOLVER

Before the first use of Solver you need to load it in Excel.

Click the File Button, and then choose Options. Click Add-Ins,

and then in the Manage box, select Excel Add-ins and click Go.

From the dialogue box presented check the box for Solver Add-In and click OK.

After you load Solver, the Solver command is available in the Analysis group on the Data tab.

GIVING DATA

Before starting Solver we have to give the data of the problem to be solved.  In order to enter the problem into Excel, the decision variables, the constraints and the objective function are to be defined. 

First n adjacent cells in a sheet are dedicated to the n decision variables. These cells are referred as Changing Cells because their value can vary during the solution process.   

Then we give the left-hand-side part of the constraints  again in adjacent cells. We can use the cell references of the changing cells explicitly in writing  the formulae for the constraints , remembering to start each formula with an '='.

Page 2: matka/Dokumentumok/Optimizationwith... · Web viewAfter entering the formulae, their initial value are 0. If you would like to check the expressions, click on the Show Formulas button

We need a separate cell for the objective function, the Target Cell in Solver terminology.  Write the equation of the objective function into this cell referring again the changing cells as before. After solving the problem the value of the optimum will be placed in the target cell.

For example formulate in Excel the following (previously solved) problem:

7x1+9x2+5x3⟶max

x1+x2+2x3≤5

2x1+x2+3x3≤11

2x1+3x2+2x3≤12

x1,x2,x3 ≥0

The problem contains three decision variable, so we have three changing cells: A1, A2 and A3.

The three constraints are formulated in B1, B2 and B3. 

The objective function is written in  C1. 

After entering the formulae, their initial value are 0. If you would like to check the expressions, click on the Show Formulas button on the Formulas Tab.

Page 3: matka/Dokumentumok/Optimizationwith... · Web viewAfter entering the formulae, their initial value are 0. If you would like to check the expressions, click on the Show Formulas button

We are now ready to start to solve the problem with Solver. Start the program from Analysis group of Data tab. The dialogue box Solver Parameters should be filled. 

First fill the Set Objective box by clicking on the cell in our sheet that contains the  objective function. In this case, Cell C1.

Next, we use the radio buttons below to identify the type of problem we are solving, a Max or Min or we can optimize for achieving a given value. Here we have a maximization problem so we select Max.

Next, click into the By Changing Variable Cells box, and give the decision variable cells of the problem, A1:A3 in our case. These cells will contain the optimal solution of the problem, when Solver finishes the optimization process.

Page 4: matka/Dokumentumok/Optimizationwith... · Web viewAfter entering the formulae, their initial value are 0. If you would like to check the expressions, click on the Show Formulas button

We can now enter constraints by clicking the 'Add' button. The cell reference means the cell containing the constraint, and we have to select the type of the constraint  and give its right-hand-side value. 

After adding all constraints, check the box titled Make Unconstrained Variables NonNegative. (If there are variables which are not restricted to be nonnegative, we have to add their restrictions in the box titled Subject to the Constraints.) Additionally, we should change the Select a Solving Method to Simplex LP because whe are solving a linear program.

The Solver dialogue box should look like this: 

Page 5: matka/Dokumentumok/Optimizationwith... · Web viewAfter entering the formulae, their initial value are 0. If you would like to check the expressions, click on the Show Formulas button

If you click on the Options button of Solver Parameters Dialogue Box you can set a number of options on how to calculate solutions. For example the degree of accuracy of the Solver algorithm (Constraint Precision), the number of seconds and the  maximum number of steps before Solver will stop (Max Time and Iterations).  

Our problems can be managed by the default options:

Page 6: matka/Dokumentumok/Optimizationwith... · Web viewAfter entering the formulae, their initial value are 0. If you would like to check the expressions, click on the Show Formulas button

After giving the data of the problem in the spreadsheet and in Solver Parameters box, click Solve for the solution of the problem. If the solution process is succesful we get the following message: 

Page 7: matka/Dokumentumok/Optimizationwith... · Web viewAfter entering the formulae, their initial value are 0. If you would like to check the expressions, click on the Show Formulas button

It is useful to check the option titled Keep Solver Solution, because it makes visible the final solution in the spreadsheet. In addition  select the three offered reports in order to study them later. 

After clicking OK, we are in the original spreadsheet again, where we can see the optimal solution of the problem. (If you see formulae instead of numbers change the option on Formulas tab.) 

Page 8: matka/Dokumentumok/Optimizationwith... · Web viewAfter entering the formulae, their initial value are 0. If you would like to check the expressions, click on the Show Formulas button

Cells A1:A3 contain the coordinates of the optimal solution: x1=3, x2=2 ,x3=0.

In column  B the value of the constraints are calculated with the optimal solution coordinates.

The target cell C1 shows the optimum: zmax=39.

Page 9: matka/Dokumentumok/Optimizationwith... · Web viewAfter entering the formulae, their initial value are 0. If you would like to check the expressions, click on the Show Formulas button

REPORTS OF SOLVER

The reports of Solver are generated in new sheets in the current workbook of Excel.

The first of them is the Answer Report which gives details of the solution. The original value of each variable is 0 because we did not give any initial values for them. 

The table titled Constraints gives  information concerning the status of each constraint. If a constraint is satisfied by equality it is referred as 'Binding', otherwise 'Not Binding'. Column Slack shows how much is missing to reach equality in the corresponding constraint. It is the amount of the unused capacity of the source given by the constraint.

The Sensitivity Report consists of two parts. 

The table titled Variable Cells contains the result of the sensitivity analysis concerning the objective function coefficients while the other table provides information about the sensitivity analysis for the right-hand-side constants.

Page 10: matka/Dokumentumok/Optimizationwith... · Web viewAfter entering the formulae, their initial value are 0. If you would like to check the expressions, click on the Show Formulas button

In both cases the numbers in  Allowable Increase and Decrease columns show the lower and upper limits of parameter  λ, which denotes the extent of changing. Notion 1E+30 means infinity.

Notice that the shadow prices of the constraints are also presented, Remember that the shadow price of a constraint is the amount that the objective function value would change if the named constraint changed by one unit.

The Limits Report provides sensitivity information on the changing variables. It gives the lower and upper limits of a variable supposing that the other variables remained unchanged and all constraints are satisfied. The Objective Result is the value of the objective function with the lower and upper limits of the studied variable. 

For example the least feasible value of the first decision variable is zero, and the objective function value is 18 with this choice (the other two coordinates of the optimal solution are not changed).

Page 11: matka/Dokumentumok/Optimizationwith... · Web viewAfter entering the formulae, their initial value are 0. If you would like to check the expressions, click on the Show Formulas button

SOLVING THE TRANSPORTATION PROBLEM BY SOLVER

The transportation problem is a special LP problem, which was solved by the distribution method.

In order to solve the problem with Solver we have to formulate the problem as a standard LP problem. This problem contains n∗m decision variables, where m is the number of factories and n is the number of the warehouses.

The steps of the solution will be illustrated on a previously solved problem:

The need for concrete of three buildings (B1, B2, B3) is supplied by three concrete factories (C1, C2, C3). 

The buildings require 30,40,40 tons of concrete per day, respectively; the daily capacities of the factories are 60, 50 and 20 tons of concrete, respectively. The following table shows the shipping cost of one ton of concrete from each factory to each building:

The nine decision variables of the problem are located in a 3x3 field B7:D9. The table B2:D4 contains the transportation costs, and in separate vectors the demands and capacities are also given. In this problem total supply and total demand is not balanced, but in Solver it is not necessary to introduce a fictitious building. The question of

Page 12: matka/Dokumentumok/Optimizationwith... · Web viewAfter entering the formulae, their initial value are 0. If you would like to check the expressions, click on the Show Formulas button

unbalancing and the other restrictions given in the problem will be managed by setting the relations in the constraints. 

The spreadsheet after typing initial data:

We have to calculate the sum of the decision variables by rows and by columns, because these sums form the left-hand-side values of the constraints. The objective function is presented in cell F11, as an elementwise product of the matrices of costs and decision variables.

The Solver Parameters dialogue box is filled in as follows:

Page 13: matka/Dokumentumok/Optimizationwith... · Web viewAfter entering the formulae, their initial value are 0. If you would like to check the expressions, click on the Show Formulas button

The extremum is set to be minimum.

The first constraint deals with the demands of the buildings. It is formulated by equalling the suitable vectors, because all demands can be satisfied. Similarly, equalities have to be written concerning the supply of the first and the third factory, because they are required to work at full capacity.  The second factory is restricted by  ≤, this factory will satisfy the fictitious demand (the amount of the fictitious demand will not be produced).After clicking the Solve button, the solution appears in the spreadsheet:

Page 14: matka/Dokumentumok/Optimizationwith... · Web viewAfter entering the formulae, their initial value are 0. If you would like to check the expressions, click on the Show Formulas button

The minimal transportation cost is 670, and it is presented in cell F11.

The optimal shipping plan is the following: 

30 tons of concrete have to be transported from factory  C1 to the buildings B1 and B3 and from factory C2 to the building B2.10 tons of concrete have to be transported from factory C3 to the buildings  B2 and B3 .

Page 15: matka/Dokumentumok/Optimizationwith... · Web viewAfter entering the formulae, their initial value are 0. If you would like to check the expressions, click on the Show Formulas button

SOLVING LFP PROBLEMS BY SOLVER

The objective function of a linear-fractional programming problem is nonlinear, it is a ratio of two linear functions. Solver is a general optimization software, so it is able to solve nonlinear problems as well. 

The steps of solving an LFP problem with Solver will be illustrated by the folowing problem:

(7x1+5x2+2x3−1)/(x1+x2+x3+5) →max

x1+3x3≥15

2x1−x2≤10

x2−2x3=20

x1,x2,x3 ≥0

We have 3 decision variables, they are located in cells A1:A3.

The constraints are formulated in cells B1:B3, the objective function is written in C1.

Page 16: matka/Dokumentumok/Optimizationwith... · Web viewAfter entering the formulae, their initial value are 0. If you would like to check the expressions, click on the Show Formulas button

In Solver Parameters window LP Simplex can not be selected as a solvig method, because our problem is nonlinear. These kind of problems are solved by the GRG method (GRG means Generalized Reduced Gradient). 

Page 17: matka/Dokumentumok/Optimizationwith... · Web viewAfter entering the formulae, their initial value are 0. If you would like to check the expressions, click on the Show Formulas button

After clicking the Solve button a solution is found. Ask an Answer Report for reading the optimal solution:

Page 18: matka/Dokumentumok/Optimizationwith... · Web viewAfter entering the formulae, their initial value are 0. If you would like to check the expressions, click on the Show Formulas button

The optimal solution of the problem: x1=15, x2=20, x3=0, zmax=5.1

SOLVING AN NLO PROBLEM BY SOLVER

As Solver is a general optimization tool, you can use it to solve nonlinear problems, where neither the objective function nor the constraints are linear.

x12 - 12x1 +x2

2 - 4x2 +5 → min

x1+4x2=16

x12+x2

2 ≤ 25

Optimal solution is: x1=4, x2=3, zmin= -30.