Solver via VBA IE 469 Spring 2018.

Slides:



Advertisements
Similar presentations
Denise Sakai Troxell (2000) Handling Some of the Problems Encountered When Using Excel Solver for Microsoft Excel 2000.
Advertisements

Corso MAE Metodi Quantitativi per il Management Quantitative methods for Management Roma, 18 settembre - 24 ottobre 2003 Prof. Gianni Di Pillo Prof. Laura.
Decision Analysis Tools in Excel
Microsoft Office 2007 Excel Chapter 8 Formula Auditing, Data Validation, and Complex Problem Solving.
458 Quantifying Uncertainty using Classical Methods (Likelihood Profile, Bootstrapping) Fish 458, Lecture 12.
SOLVING LINEAR PROGRAMS USING EXCEL Dr. Ron Lembke.
© 2007 Pearson Education Chapter 14: Solving and Analyzing Optimization Models.
Lecture 7: Linear Programming in Excel AGEC 352 Spring 2011 – February 9, 2011 R. Keeney.
Example 4.7 Data Envelopment Analysis (DEA) | 4.2 | 4.3 | 4.4 | 4.5 | Background Information n Consider a group of three hospitals.
QM B Linear Programming
Formula Auditing, Data Validation, and Complex Problem Solving
Computational Methods for Management and Economics Carla Gomes Module 4 Displaying and Solving LP Models on a Spreadsheet.
Microsoft Office Excel 2003
Solver & Optimization Problems n An optimization problem is a problem in which we wish to determine the best values for decision variables that will maximize.
 Explore the principles of cost-volume-profit relationships  Perform a basic what-if analysis  Use Goal Seek to calculate a solution  Create a one-variable.
3 Components for a Spreadsheet Linear Programming Problem There is one cell which can be identified as the Target or Set Cell, the single objective of.
COMPREHENSIVE Excel Tutorial 10 Performing What-If Analyses.
456/556 Introduction to Operations Research Optimization with the Excel 2007 Solver.
Lab 8 Solver In VBA ► Review – Solver Add-in In Excel ► Solver Add-in In VBA.
START EXCEL BUILD OR RETRIEVE YOUR OPTIMIZATION MODEL SAVE YOUR WORKBOOK!! CHOOSE “Solver…” IN THE “Tools” MENU SPECIFY IN SOLVER DIALOG BOX: 1.CELL TO.
Solver & Optimization Problems n An optimization problem is a problem in which we wish to determine the best values for decision variables that will maximize.
INSERT BOOK COVER 1Copyright © 2011 Pearson Education, Inc. Publishing as Prentice Hall. Exploring Microsoft Office Excel 2010 by Robert Grauer, Keith.
Chapter 19: Solver Re-Visited Spreadsheet-Based Decision Support Systems Prof. Name Position (123) University Name.
Linear Programming: Basic Concepts
We can make Product1 and Product2. There are 3 resources; Resource1, Resource2, Resource3. Product1 needs one hour of Resource1, nothing of Resource2,
Appendix B A BRIEF TOUR OF SOLVER Prescriptive Analytics
LP: Summary thus far Requirements Graphical solutions Excel Sensitivity Analysis.
Linear Programming with Excel Solver.  Use Excel’s Solver as a tool to assist the decision maker in identifying the optimal solution for a business decision.
Linear Programming Copyright © 2015 McGraw-Hill Education. All rights reserved. No reproduction or distribution without the prior written consent of McGraw-Hill.
DAY 10: EXCEL CHAPTER 8, 9, 10 Tazin Afrin September 23,
Chapter 19: The Solver Re-Visited Spreadsheet-Based Decision Support Systems Prof. Name Position (123) University Name.
CTS130 Spreadsheet Lesson 19 Using What-If Analysis.
Goal Seek and Solver. Goal seeking helps you n Find a specific value for a target cell by adjusting the value of one other cell whose value is allowed.
 Review the principles of cost-volume-profit relationships  Discuss Excel what-if analysis tools 2.
1 Analyzing Data Using Goal Seek & Solver Applications of Spreadsheets.
Lab 3 Solver Add-In In Excel ► Lab 2 Review ► Solver Add-in Introduction ► Practice Solver following Instructor » Saferly Inc.
Decision Making Using Excel
Highline Class, BI 348 Basic Business Analytics using Excel Chapter 08 & 09: Introduction to Linear Programing 1.
DAY 9: MICROSOFT EXCEL – CHAPTER 6 Sravanthi Lakkimsetty Sept 16, 2015.
McGraw-Hill/Irwin Copyright © 2009 by The McGraw-Hill Companies, Inc. All Rights Reserved. Supplement 6 Linear Programming.
3 Components for a Spreadsheet Optimization Problem  There is one cell which can be identified as the Target or Set Cell, the single objective of the.
Linear Programming II. George Dantzig 1947 Narendra Karmarkar Pioneers of LP.
Chapter 15: Sub Procedures and Function Procedures Spreadsheet-Based Decision Support Systems Prof. Name Position (123) University.
1 Visual Basic for Applications - VBA IE What is VBA?  VBA comes with Office u Objects (e.g. of Excel) are exposed for use by VBA u Visual Basic.
Linear Programming McGraw-Hill/Irwin Copyright © 2012 by The McGraw-Hill Companies, Inc. All rights reserved.
OpenSolver Introduction. Table of Contents About OpenSolver – Slide 3 Installing OpenSolver – Slide 4: For Windows OS – Slide 13: For Mac OS Using OpenSolver.
Excel’s Solver Use Excel’s Solver as a tool to assist the decision maker in identifying the optimal solution for a business decision. Business decisions.
Formula Auditing, Data Validation, and Complex Problem Solving
Exploring Microsoft Office Exploring Excel Appendix C
Setting up Solver Add-in for Excel
Session 9.
Problem 1 Demand Total There are 20 full time employees, each can produce 10.
Solver & Optimization Problems
Excel Solver IE 469 Spring 2017.
Spreadsheet-Based Decision Support Systems
Excel Solver IE 469 Spring 2018.
Wyndor Example; Enter data
Solver via VBA IE 469 Fall 2017.
Navya Thum February 13, 2013 Day 7: MICROSOFT EXCEL Navya Thum February 13, 2013.
Excel Solver IE 469 Fall 2018.
Excel: Solver Participation Project
Solver via VBA IE 469 Spring 2018.
Chapter 5. The Duality Theorem
Modeling and Solving LP Problems in a Spreadsheet
Linear Programming Excel Solver.
Excel Solver IE 469 Spring 2019.
BUS-221 Quantitative Methods
Solver via VBA IE 469 Spring 2019.
Presentation transcript:

Solver via VBA IE 469 Spring 2018

Why do we need to use VBA to call solver? When you work with more complex codes that includes optimization, it is a good idea to embed solver commands into the VBA code. VBA has functions to run Solver. BUT! You need to have the problem setup on the worksheet – just as we did before. Afterwards, you can use the VBA Solver functions to setup the solver i.e., filling in the parameters in the Solver Dialog Box via VBA

Solver via VBA Before using Solver commands in VBA, you must reference the Solver library in the VBE. To do this, go to Tools > References and choose Solver from the list.

Solver via VBA Previously, when using the Solver from the Tools menu in Excel, we identified the cells which contain the decision variables, objective function, and constraint equations to the Solver using the Changing Cells, Target Cell, and Add Constraint inputs, respectively. We now learn how to identify these parts of the model as Solver input using VBA code.

Solver via VBA There are two main Solver functions used to input the Solver parameters in VBA. These are SolverOK and SolverAdd. SolverOK is used to set the objective function (or Target Cell) and decision variables (or Changing Cells). The format of this function and argument titles are: SolverOK SetCell, MaxMinVal, ValueOf, ByChange, Engine

Solver via VBA SetCell argument is used to specify the range of the objective function. This cell should contain the formula of the objective function which references the decision variable cells. The MaxMinVal argument specifies objective type 1 (= maximize) 2 (= minimize) 3 (= value). If this is selected, then the ValueOf argument is used to set this value; if the objective function will be maximized or minimized, then this argument is ignored. Some examples would be solving a problem to a break-even point ByChange argument specifies the range which contains the decision variables. This range of cells should not have any values in it

Solver via VBA Objective Function Changing Cells Simplex LP Maximize SolverOk Range("D14"), 1, , Range("D10:H10"), 2 Objective Function Changing Cells Simplex LP Maximize

Solver via VBA The second main Solver function will be used to input constraints; this is the SolverAdd which should be used to add each individual constraint or each group of similar constraints. The SolverAdd function has three arguments: SolverAdd CellRef, Relation, FormulaText

Solver via VBA CellRef argument specifies the range which contains a constraint equation. This equation should reference the decision variable cells. The Relation argument specifies the inequality of the constraint: 1 is <= 2 is = 3 is >= 4 is int (integer values) and 5 is bin (binary, 0/1, values). The FormulaText argumentspecifies the range which contains the RHS value of the constraint.

Solver via VBA SolverAdd Range("D12"), 1, Range("F12") LHS RHS <=

Solver via VBA There are two more functions which can be used to modify constraints: they are SolverChange and SolverDelete. These functions will allow you to modify or delete a constraints, respectively. They both have the same arguments as the SolverAdd function. If CellRef and Relation do not match an existing constraint, you must use the SolverDelete and SolverAdd functions to change the constraint. SolverChange Range("D12"), 1, Range("F15")

Solver via VBA To set the Solver options in VBA, we use the SolverOptions function. This function has many arguments for each of the options we have seen previously in the Solver Options dialog box. SolverOptions( MaxTime, Iterations, Precision, AssumeLinear,  StepThru, Estimates, Derivatives, SearchOption, IntTolerance,  Scaling, Convergence, AssumeNonNeg, PopulationSize, RandomSeed,  MultiStart, RequireBounds, MutationRate, MaxSubproblems,  MaxIntegerSols, SolveWithout, MaxTimeNoImp)

Solver via VBA There are two arguments which we will use more frequently, which are AssumeLinear and AssumeNonNeg. Both of these arguments take True/False values; True makes the corresponding assumption. For most of our models, we will set both of these arguments to true as follows: SolverOptions AssumeLinear:=True, AssumeNonNeg:=True

Solver via VBA After the Solver input has been entered and any options have been set, we are ready to run the Solver. To run the Solver in VBA, we use the function SolverSolve. This function has two arguments and is written as follows: SolverSolve(UserFinish, ShowRef)

Solver via VBA The UserFinish argument uses a True/False value to determine whether to return the Solver results with or without showing the Solver Results dialog box. We will usually set this argument value to True; if the value is False then the Solver Results dialog box will appear after the Solver has run the model. The ShowRef argument is used when the StepThru option is set; hence, we will usually ignore this argument. For the above example, we would type the following: SolverSolve True

Solver via VBA The SolverSolve function also returns an integer value classifying the result. Solver found a solution. All constraints and optimality conditions are satisfied. 1 Solver has converged to the current solution. All constraints are satisfied. 2 Solver cannot improve the current solution. All constraints are satisfied. 4 The Objective Cell values do not converge. 5 Solver could not find a feasible solution.

Solver via VBA Dim result As Integer result = SolverSolve (True) If result = 5 Then MsgBox “Your problem was infeasible. Please modify your model.” End If

Other VBA Commands The fullset of possible commands to run Solver via VBA: SolverAdd Function SolverChange Function SolverDelete Function SolverFinish Function SolverFinishDialog Function SolverGet Function SolverLoad Function SolverOk Function SolverOkDialog Function SolverOptions Function SolverReset Function SolverSave Function SolverSolve Function

OpenSolver OpenSolver also has similar commands. Check www.opensolver.org

NEXT TIME Improvement Heuristics with VBA