www.gusucode.com > globaloptim 案例源码程序 matlab代码 > globaloptim/MixedIntegerOptimizationOfRastriginsFunctionExample.m
%% 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 $5 \pi\le x(1) \le 20\pi,\ % -20\pi\le x(2)\le -4\pi$ . % %% 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) %% % ga converges quickly to the solution.