## Integer Constraints in Nonlinear Problem-Based Optimization

To solve a nonlinear optimization problem with integer constraints using the problem-based approach, follow one of these processes:

• If you have a Global Optimization Toolbox license, formulate the problem as usual for the problem-based approach. `ga` (Global Optimization Toolbox) is the default solver for a nonlinear problem with integer constraints. You can also specify `surrogateopt` (Global Optimization Toolbox) as the solver in the `Solver` argument of `solve`.

• Use the solver-based approach with `ga` or `surrogateopt` as the solver. The solver-based approach requires you to modify the objective function and nonlinear constraint function when switching between these solvers.

• Convert the problem to a structure using `prob2struct`, and then use an external solver.

• Sometimes, you can iteratively approximate a nonlinear integer problem using `intlinprog`. For an example of this approach, see Mixed-Integer Quadratic Programming Portfolio Optimization: Problem-Based.

When you use an external solver and call `prob2struct`, you might need to specify the `Solver` name-value argument.

Note

For a nonlinear problem with integer constraints, if you do not have a Global Optimization Toolbox license, you must include the `Solver` argument.

Even if you have a Global Optimization Toolbox license, you still might need to specify the `Solver` name-value argument. An external solver can expect the problem structure to be in a form that corresponds to a particular solver. For example, for a problem with linear and integer constraints and a quadratic objective function, an external solver might require the objective function to be expressed as matrices H and f in the expression ½xTHx + fTx. To obtain these matrices, specify the `'quadprog'` solver by using the `Solver` name-value argument.

`problem = prob2struct(prob,"Solver","quadprog");`

If you do not specify the `quadprog` solver, the resulting problem structure can contain a function handle for the objective function rather than matrices. In either case, the resulting problem structure contains the integer variables in the `intcon` field.

Note

For a nonlinear problem with integer constraints, when you specify a solver that does not handle integer constraints, `prob2struct` issues a warning that the solver cannot solve the resulting structure. If you then try to solve the problem by calling the solver on the problem structure, the solver ignores the integer constraints. In this case, the solution is not the solution to the original problem, but is instead the solution to the problem without integer constraints.