## Decide Between Problem-Based and Solver-Based Approach

Use a Global Optimization Toolbox solver to optimize a nonsmooth function, search for a global solution, or solve a multiobjective problem. Use the problem-based approach for a simpler way to set up and solve problems.

**Problem-Based Characteristics**

Advantages | Limitations |
---|---|

Easier to set up and debug | No equation problems |

Easier to run different solvers on the same
problem | No custom data types |

Obtain an appropriate solver
automatically | No checkpoint file for
`surrogateopt` |

Automatically speed the solution of problems
where the objective and nonlinear constraints are calculated in the same
time-consuming function (typically simulations) | No vectorization |

You must convert variables for options that relate to the
solver-based approach |

Advantages:

**Easier to set up and debug.**In the problem-based approach, you use symbolic-style variables to create optimization expressions and constraints. See Problem-Based Global Optimization Setup. In the solver-based approach, you must place all variables into a single vector, which can be awkward, especially with variables of large or differing dimensions.**Easier to run different solvers on the same problem.**Some solvers have different calling syntaxes. For example, the syntax for nonlinear constraints in`surrogateopt`

is different from the syntax in all other solvers. To run a problem using both`surrogateopt`

and another solver in the solver-based approach, you have to create different versions of the objective function. In contrast, the problem-based approach takes care of translating syntaxes, so you need to change only the solver name and possibly some options.**Obtain an appropriate solver automatically.**The`solve`

function automatically chooses a solver that can handle your objective and constraints. In the solver-based approach you must choose an appropriate solver.**Automatically speed the solution of problems where the objective and nonlinear constraints are calculated in the same time-consuming function (typically simulations).**Frequently, a simulation or ODE solver calculates the objective and nonlinear constraints in the same function. When you convert the time-consuming function to an optimization expression using`fcn2optimexpr`

, you can save solution time by setting the`'ReuseEvaluation'`

argument to`true`

. This setting causes the solver to avoid recalculating the time-consuming function when evaluating the objective and nonlinear constraints. Achieving this time savings in the solver-based approach can require extra programming, as shown in the example Objective and Nonlinear Constraints in the Same Function.

Limitations:

**No equation problems.**You cannot use a Global Optimization Toolbox solver to solve an equation problem of type`EquationProblem`

. However, you can solve a feasibility problem by specifying a zero objective function and any constraints accepted by the solver. For an example, see Solve Feasibility Problem Using surrogateopt, Problem-Based.**No custom data types.**To use a custom data type with`ga`

or`simulannealbnd`

, you must use the solver-based approach. For examples, see Custom Data Type Optimization Using the Genetic Algorithm and Multiprocessor Scheduling Using Simulated Annealing with a Custom Data Type.**No checkpoint file for**Use the solver-based approach for checkpoint files in`surrogateopt`

.`surrogateopt`

. For details, see Work with Checkpoint Files.**No vectorization**(see Using Vectorization). If your objective function and any nonlinear constraint functions are written in a vectorized fashion, you must use the solver-based workflow to gain the benefits of vectorization. If you set the`UseVectorized`

option in the problem-based approach, you get a warning, not improved performance.**You must convert variables for options that relate to the solver-based approach.**For example, custom output functions use solver-based syntax. Use`varindex`

to convert problem-based variables to solver-based indices. For an example, see Set Options in Problem-Based Approach Using varindex.