Global Optimization Toolbox User's Guide R2016a How to Contact MathWorks Latest news: www.mathworks.com Sales and services: www.mathworks.com/sales_and_services User community: www.mathworks.com/matlabcentral Technical support: www.mathworks.com/support/contact_us Phone: 508-647-7000 The MathWorks, Inc. 3 Apple Hill Drive Natick, MA 01760-2098 Global Optimization Toolbox User's Guide © COPYRIGHT 2004–2016 by The MathWorks, Inc. The software described in this document is furnished under a license agreement. The software may be used or copied only under the terms of the license agreement. No part of this manual may be photocopied or reproduced in any form without prior written consent from The MathWorks, Inc. FEDERAL ACQUISITION: This provision applies to all acquisitions of the Program and Documentation by, for, or through the federal government of the United States. By accepting delivery of the Program or Documentation, the government hereby agrees that this software or documentation qualifies as commercial computer software or commercial computer software documentation as such terms are used or defined in FAR 12.212, DFARS Part 227.72, and DFARS 252.227-7014. Accordingly, the terms and conditions of this Agreement and only those rights specified in this Agreement, shall pertain to and govern the use, modification, reproduction, release, performance, display, and disclosure of the Program and Documentation by the federal government (or other entity acquiring for or through the federal government) and shall supersede any conflicting contractual terms or conditions. If this License fails to meet the government's needs or is inconsistent in any respect with federal procurement law, the government agrees to return the Program and Documentation, unused, to The MathWorks, Inc. Trademarks MATLAB and Simulink are registered trademarks of The MathWorks, Inc. See www.mathworks.com/trademarks for a list of additional trademarks. Other product or brand names may be trademarks or registered trademarks of their respective holders. Patents MathWorks products are protected by one or more U.S. patents. Please see www.mathworks.com/patents for more information. Revision History January 2004 Online only New for Version 1.0 (Release 13SP1+) June 2004 First printing Revised for Version 1.0.1 (Release 14) October 2004 Online only Revised for Version 1.0.2 (Release 14SP1) March 2005 Online only Revised for Version 1.0.3 (Release 14SP2) September 2005 Second printing Revised for Version 2.0 (Release 14SP3) March 2006 Online only Revised for Version 2.0.1 (Release 2006a) September 2006 Online only Revised for Version 2.0.2 (Release 2006b) March 2007 Online only Revised for Version 2.1 (Release 2007a) September 2007 Third printing Revised for Version 2.2 (Release 2007b) March 2008 Online only Revised for Version 2.3 (Release 2008a) October 2008 Online only Revised for Version 2.4 (Release 2008b) March 2009 Online only Revised for Version 2.4.1 (Release 2009a) September 2009 Online only Revised for Version 2.4.2 (Release 2009b) March 2010 Online only Revised for Version 3.0 (Release 2010a) September 2010 Online only Revised for Version 3.1 (Release 2010b) April 2011 Online only Revised for Version 3.1.1 (Release 2011a) September 2011 Online only Revised for Version 3.2 (Release 2011b) March 2012 Online only Revised for Version 3.2.1 (Release 2012a) September 2012 Online only Revised for Version 3.2.2 (Release 2012b) March 2013 Online only Revised for Version 3.2.3 (Release 2013a) September 2013 Online only Revised for Version 3.2.4 (Release 2013b) March 2014 Online only Revised for Version 3.2.5 (Release 2014a) October 2014 Online only Revised for Version 3.3 (Release 2014b) March 2015 Online only Revised for Version 3.3.1 (Release 2015a) September 2015 Online only Revised for Version 3.3.2 (Release 2015b) March 2016 Online only Revised for Version 3.4 (Release 2016a) Contents Getting Started Introducing Global Optimization Toolbox Functions 1 Global Optimization Toolbox Product Description . . . . 1-2 Key Features . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-2 Solution Quality . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-3 Comparison of Five Solvers . . . . . . . . . . . . . . . . . . . . . . . 1-4 Function to Optimize . . . . . . . . . . . . . . . . . . . . . . . . . . 1-4 Five Solution Methods . . . . . . . . . . . . . . . . . . . . . . . . . 1-5 Compare Syntax and Solutions . . . . . . . . . . . . . . . . . . 1-10 What Is Global Optimization? . . . . . . . . . . . . . . . . . . . . 1-12 Local vs. Global Optima . . . . . . . . . . . . . . . . . . . . . . . 1-12 Basins of Attraction . . . . . . . . . . . . . . . . . . . . . . . . . . 1-13 Optimization Workflow . . . . . . . . . . . . . . . . . . . . . . . . . . 1-16 Choosing a Solver . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-17 Table for Choosing a Solver . . . . . . . . . . . . . . . . . . . . . 1-17 Solver Characteristics . . . . . . . . . . . . . . . . . . . . . . . . . 1-21 Why Are Some Solvers Objects? . . . . . . . . . . . . . . . . . 1-23 v Write Files for Optimization Functions 2 Compute Objective Functions . . . . . . . . . . . . . . . . . . . . . 2-2 Objective (Fitness) Functions . . . . . . . . . . . . . . . . . . . . 2-2 Write a Function File . . . . . . . . . . . . . . . . . . . . . . . . . . 2-2 Write a Vectorized Function . . . . . . . . . . . . . . . . . . . . . 2-3 Gradients and Hessians . . . . . . . . . . . . . . . . . . . . . . . . 2-4 Maximizing vs. Minimizing . . . . . . . . . . . . . . . . . . . . . . 2-5 Write Constraints . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-6 Consult Optimization Toolbox Documentation . . . . . . . . 2-6 Set Bounds . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-6 Ensure ga Options Maintain Feasibility . . . . . . . . . . . . 2-7 Gradients and Hessians . . . . . . . . . . . . . . . . . . . . . . . . 2-7 Vectorized Constraints . . . . . . . . . . . . . . . . . . . . . . . . . 2-7 Set and Change Options . . . . . . . . . . . . . . . . . . . . . . . . . 2-10 View Options . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-11 Using GlobalSearch and MultiStart 3 Problems That GlobalSearch and MultiStart Can Solve . . . . 3-2 Optimization Workflow . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-3 Inputs for Problem Structure . . . . . . . . . . . . . . . . . . . . . . . . . 3-5 Create Problem Structure . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-6 About Problem Structures . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-6 Using the createOptimProblem Function . . . . . . . . . . . . . . . 3-6 Exporting from the Optimization app . . . . . . . . . . . . . . . . . . 3-9 Create Solver Object . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-14 What Is a Solver Object? . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-14 Properties (Global Options) of Solver Objects . . . . . . . . . . . 3-14 Creating a Nondefault GlobalSearch Object . . . . . . . . . . . . 3-16 vi Contents Creating a Nondefault MultiStart Object . . . . . . . . . . . . . . 3-16 Set Start Points for MultiStart . . . . . . . . . . . . . . . . . . . . . . . 3-17 Four Ways to Set Start Points . . . . . . . . . . . . . . . . . . . . . . 3-17 Positive Integer for Start Points . . . . . . . . . . . . . . . . . . . . . 3-17 RandomStartPointSet Object for Start Points . . . . . . . . . . . 3-18 CustomStartPointSet Object for Start Points . . . . . . . . . . . 3-18 Cell Array of Objects for Start Points . . . . . . . . . . . . . . . . . 3-19 Run the Solver . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-20 Optimize by Calling run . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-20 Example of Run with GlobalSearch . . . . . . . . . . . . . . . . . . . 3-21 Example of Run with MultiStart . . . . . . . . . . . . . . . . . . . . . 3-22 Single Solution . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-24 Multiple Solutions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-25 About Multiple Solutions . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-25 Change the Definition of Distinct Solutions . . . . . . . . . . . . . 3-28 Iterative Display . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-30 Types of Iterative Display . . . . . . . . . . . . . . . . . . . . . . . . . . 3-30 Examine Types of Iterative Display . . . . . . . . . . . . . . . . . . 3-30 Global Output Structures . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-33 Visualize the Basins of Attraction . . . . . . . . . . . . . . . . . . . . . 3-34 Output Functions for GlobalSearch and MultiStart . . . . . . 3-37 What Are Output Functions? . . . . . . . . . . . . . . . . . . . . . . . 3-37 GlobalSearch Output Function . . . . . . . . . . . . . . . . . . . . . . 3-37 No Parallel Output Functions . . . . . . . . . . . . . . . . . . . . . . . 3-39 Plot Functions for GlobalSearch and MultiStart . . . . . . . . . 3-40 What Are Plot Functions? . . . . . . . . . . . . . . . . . . . . . . . . . . 3-40 MultiStart Plot Function . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-41 No Parallel Plot Functions . . . . . . . . . . . . . . . . . . . . . . . . . 3-43 How GlobalSearch and MultiStart Work . . . . . . . . . . . . . . . 3-44 Multiple Runs of a Local Solver . . . . . . . . . . . . . . . . . . . . . 3-44 Differences Between the Solver Objects . . . . . . . . . . . . . . . . 3-44 GlobalSearch Algorithm . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-46 MultiStart Algorithm . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-50 vii Bibliography . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-52 Can You Certify a Solution Is Global? . . . . . . . . . . . . . . . . . 3-53 No Guarantees . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-53 Check if a Solution Is a Local Solution with patternsearch . 3-53 Identify a Bounded Region That Contains a Global Solution 3-54 Use MultiStart with More Start Points . . . . . . . . . . . . . . . . 3-55 Refine Start Points . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-57 About Refining Start Points . . . . . . . . . . . . . . . . . . . . . . . . 3-57 Methods of Generating Start Points . . . . . . . . . . . . . . . . . . 3-58 Example: Searching for a Better Solution . . . . . . . . . . . . . . 3-60 Change Options . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-65 How to Determine Which Options to Change . . . . . . . . . . . 3-65 Changing Local Solver Options . . . . . . . . . . . . . . . . . . . . . . 3-66 Changing Global Options . . . . . . . . . . . . . . . . . . . . . . . . . . 3-67 Reproduce Results . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-69 Identical Answers with Pseudorandom Numbers . . . . . . . . . 3-69 Steps to Take in Reproducing Results . . . . . . . . . . . . . . . . . 3-69 Example: Reproducing a GlobalSearch or MultiStart Result 3-69 Parallel Processing and Random Number Streams . . . . . . . 3-71 Find Global or Multiple Local Minima . . . . . . . . . . . . . . . . . 3-72 Function to Optimize . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-72 Single Global Minimum Via GlobalSearch . . . . . . . . . . . . . . 3-74 Multiple Local Minima Via MultiStart . . . . . . . . . . . . . . . . 3-76 Optimize Using Only Feasible Start Points . . . . . . . . . . . . . 3-80 MultiStart Using lsqcurvefit or lsqnonlin . . . . . . . . . . . . . . 3-85 Parallel MultiStart . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-89 Steps for Parallel MultiStart . . . . . . . . . . . . . . . . . . . . . . . . 3-89 Speedup with Parallel Computing . . . . . . . . . . . . . . . . . . . . 3-91 Isolated Global Minimum . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-92 Difficult-To-Locate Global Minimum . . . . . . . . . . . . . . . . . . 3-92 Default Settings Cannot Find the Global Minimum — Add Bounds . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-93 GlobalSearch with Bounds and More Start Points . . . . . . . . 3-94 MultiStart with Bounds and Many Start Points . . . . . . . . . 3-95 viii Contents MultiStart Without Bounds, Widely Dispersed Start Points . 3-95 MultiStart with a Regular Grid of Start Points . . . . . . . . . . 3-96 MultiStart with Regular Grid and Promising Start Points . . 3-97 Using Direct Search 4 What Is Direct Search? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-2 Optimize Using Pattern Search . . . . . . . . . . . . . . . . . . . . . . . . 4-3 Call patternsearch at the Command Line . . . . . . . . . . . . . . . 4-3 Pattern Search on Unconstrained Problems . . . . . . . . . . . . . 4-3 Pattern Search on Constrained Problems . . . . . . . . . . . . . . . 4-4 Additional Output Arguments . . . . . . . . . . . . . . . . . . . . . . . . 4-5 Use the Optimization App for Pattern Search . . . . . . . . . . . . 4-5 Optimize Using the GPS Algorithm . . . . . . . . . . . . . . . . . . . . . 4-8 Objective Function . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-8 Finding the Minimum of the Function . . . . . . . . . . . . . . . . 4-10 Plotting the Objective Function Values and Mesh Sizes . . . . 4-11 Pattern Search Terminology . . . . . . . . . . . . . . . . . . . . . . . . . 4-13 Patterns . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-13 Meshes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-14 Polling . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-15 Expanding and Contracting . . . . . . . . . . . . . . . . . . . . . . . . . 4-15 How Pattern Search Polling Works . . . . . . . . . . . . . . . . . . . . 4-16 Context . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-16 Successful Polls . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-17 An Unsuccessful Poll . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-20 Displaying the Results at Each Iteration . . . . . . . . . . . . . . . 4-21 More Iterations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-21 Poll Method . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-22 Complete Poll . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-24 Stopping Conditions for the Pattern Search . . . . . . . . . . . . 4-24 Robustness of Pattern Search . . . . . . . . . . . . . . . . . . . . . . . 4-26 Searching and Polling . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-27 Definition of Search . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-27 ix How to Use a Search Method . . . . . . . . . . . . . . . . . . . . . . . 4-29 Search Types . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-30 When to Use Search . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-30 Setting Solver Tolerances . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-32 Search and Poll . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-33 Using a Search Method . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-33 Search Using a Different Solver . . . . . . . . . . . . . . . . . . . . . 4-36 Nonlinear Constraint Solver Algorithm . . . . . . . . . . . . . . . . 4-38 Custom Plot Function . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-40 About Custom Plot Functions . . . . . . . . . . . . . . . . . . . . . . . 4-40 Creating the Custom Plot Function . . . . . . . . . . . . . . . . . . . 4-40 Setting Up the Problem . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-41 Using the Custom Plot Function . . . . . . . . . . . . . . . . . . . . . 4-42 How the Plot Function Works . . . . . . . . . . . . . . . . . . . . . . . 4-43 Set Options . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-45 Set Options Using optimoptions . . . . . . . . . . . . . . . . . . . . . 4-45 Create Options and Problems Using the Optimization App . 4-47 Polling Types . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-48 Using a Complete Poll in a Generalized Pattern Search . . . . 4-48 Compare the Efficiency of Poll Options . . . . . . . . . . . . . . . . 4-52 Set Mesh Options . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-59 Mesh Expansion and Contraction . . . . . . . . . . . . . . . . . . . . 4-59 Mesh Accelerator . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-66 Constrained Minimization Using patternsearch . . . . . . . . . 4-70 Linearly Constrained Problem . . . . . . . . . . . . . . . . . . . . . . . 4-70 Nonlinearly Constrained Problem . . . . . . . . . . . . . . . . . . . . 4-73 Use Cache . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-76 Vectorize the Objective and Constraint Functions . . . . . . . 4-81 Vectorize for Speed . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-81 Vectorized Objective Function . . . . . . . . . . . . . . . . . . . . . . . 4-81 Vectorized Constraint Functions . . . . . . . . . . . . . . . . . . . . . 4-84 Example of Vectorized Objective and Constraints . . . . . . . . 4-84 x Contents