MATLAB: How to include a nonlinear constraint in the fmincon when it is a hybrid function in the particle swarm optimization

fminconnonlinear constraintparticleswarm

Hey!
I'm writing up a code to find a set of parameters using the particle swarm, besides I'm using fmincon as hybrid function. I want to include a nonlinear inequality constraint but I don't know in which part of the problem set-up should I do it.
fun=@solutions; % "model data base"
% Parameter search space
ub=[1,1,1,1,1,1,1,1,1,1,1,1];
lb=[-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1];
options=optimoptions('particleswarm','SwarmSize',100,'HybridFcn',@fmincon,'Display','iter');
rng default % For reproducibility
nvars = 12; % Number of parameters to estimate
[param] = particleswarm(fun,nvars,lb,ub,options);
I really appreciate all your comments.

Best Answer

The short answer is that you cannot. particleswarm does not accept nonlinear constraints. A hybrid function uses exactly the problem as the original solver, particleswarm in this case, and you can only change hybrid options, not the problem (constraints are part of the problem).
If for some reason you want to run fmincon with nonlinear constraints after particleswarm, you'll just have to call it in another line of code.
Alan Weiss
MATLAB mathematical toolbox documentation