# Optimizer

The SUMO Toolbox contains a whole hierarchy of optimizers that can be used by several components (for instance the EGO algorithm or the OptimizerModelBuilder).

A list of available optimizers is found in `src/matlab/tools/Optimization/optimizers`

. Note that some optimizers need some external code available in the extension pack (or the Matlab Optimization toolbox).

A couple of **example configurations** are found here. These tags can be used in supported components as stated above. When a particular option is not given a sane default will be used. Full information about the several options can be found in the optimizer source code, implementation and corresponding papers.

### Add a custom optimizer

In order to implement a new optimization algorithm one should only create one new class in `src/matlab/tools/Optimization/optimizers`

. The class should be derived from the base class Optimizer and MUST implement at least the following functions:

- A constructor accepting one parameter (the configuration xml tag) OR a varargin
- [this, x, fval] = optimize(this, arg)
- Accepts a function handle OR a SUMO model to optimize. x and fval are the resulting optimum(s) and associated function value(s).

In addition the following methods COULD be implemented if appropriate:

- size = getPopulationSize(this)
- When implementing a population-based optimization algorithm

- this = setInputConstraints( this, con )
- When the algorithm supports constraints

It is advised to copy a simple existing optimizer and work from there. For example implementations, please see the provided optimizers. For instance, DifferentialEvolution is a good starting point. The optimizer can be used like:

<Optimizer type="CLASSNAME"> <Option key="option1" value="1" /> <Option key="option2" value="2" /> ... </Optimizer>