Mixed Integer Optimization of Rastrigin's Function
This example shows how to find the minimum of Rastrigin's function restricted so the first component of x is an integer. The components of x are further restricted to be in the region .
Set up the bounds for your problem
lb = [5*pi,-20*pi]; ub = [20*pi,-4*pi];
Set a plot function so you can view the progress of ga
opts = optimoptions('ga','PlotFcn',@gaplotbestf);
Call the ga solver where x(1) has integer values
rng(1,'twister') % for reproducibility IntCon = 1; [x,fval,exitflag] = ga(@rastriginsfcn,2,,,,,... lb,ub,,IntCon,opts)
Optimization terminated: average change in the penalty fitness value less than options.FunctionTolerance and constraint violation is less than options.ConstraintTolerance. x = 16.0000 -12.9325 fval = 424.1355 exitflag = 1
ga converges quickly to the solution.