源码简介

%GADEMO1 Introduction to the Genetic Optimization Toolbox

clf;
figure(gcf);
more on
echo on
clc
%    ==========================================================
%    ==========================================================

%    INITIALIZE - Initialize a poplutaton of solutions
%    GA         - Simulates evolution

pause % Strike any key for the introduction to Genetic Algorithms
clc

%    Genetic algorithms

%    A genetic algorithm is a simulation of evolution where the
%    rule of survival of the fittest is applied to a population
%    of individuals.
%    The basic genetic algorithm is as follows:
%      1. Create an initial population (usually a randomly
%         generated string)
%      2. Evaluate all of the individuals (apply some function
%         or formula to the individuals)
%      3. Select a new population from the old population based
%         on the fittness of the individuals as given by the
%         evaluation function.
%      4. Apply some genetic operators (mutation & crossover)
%         to members of the population to create new solutions.
%      5. Evaluate these newly created individuals.
%      6. Repeat steps 3-6 (one generation) until the
%         termination criteria has been satisfied (usually
%         perform for a certain fixed number of generations)
%
%    Let's look at an example

pause % Strike any key to define the problem...
clc

%   Let's consider the maximization of the following function:
%   f(x) = x + 10*sin(5*x)+7*cos(4*x) over the interval (0,9)
fplot('x + 10*sin(5*x)+7*cos(4*x)',[0 9])

%   Now, let's set up a genetic algorithm to find the maximum
%   of this problem.  First, we need to create the evaluation
%   function .m file, here is gademo1eval1.m

pause     % Strike any key to look at gademo1eval1.m
pause      % Strike any key to continue
clc

%   Note that the evaluation function must take two parameters,
%   sol and options.  Sol is a row vector of n+1 elements where
%   the first n elements are the parameters of interest.  The
%   n+1'th element is the value of this solution.  The options
%   matrix is a row matrix of
%   [current generation, eval options]
%   The eval function must return both the value of the sting,
%   val and the string itself, sol.  This is done so that
%   your evaluation can repair and/or improve the string.

pause      % Strike any key to continue
clc

%   Now that we have defined the evaluation function, we now
%   have to create an initial population.  The most common way
%   to generate an initial population is to randomly generate
%   solutions within the range of interest, in this case 0-9.
%   The initializega routine will do this for you.

pause     % Strike any key for help on initializega
clc
help initializega
pause      % Strke any key to continue.
clc
%   Let's create a random starting popluation of size 10.
pause      % Strke any key to continue.

%   We can now take a look at this population.
hold on
plot (initPop(:,1),initPop(:,2),'g+')
pause % Strike any key to continue
clc
%  We can now run the evolutionary procedure on this
%  population.
help ga
pause      % Strike any key to continue

% Now let's run the ga for one generation.
[x endPop] = ga([0 9],'gademo1eval1',[],initPop,[1e-6 1 1],'maxGenTerm',1,...
'normGeomSelect',[0.08],['arithXover'],[2 0],'nonUnifMutation',[2 1 3]);

x %The best found
%And plot the resulting the resulting population
plot (endPop(:,1),endPop(:,2),'ro')
pause      % Strike any key to continue

% Now let's run the ga for 25 generations
[x endPop] = ga([0 9],'gademo1eval1',[],initPop,[1e-6 1 1],'maxGenTerm',25,...
'normGeomSelect',[0.08],['arithXover'],[2],'nonUnifMutation',[2 25 3]);
x %The best found
% And plot the resulting the resulting population
plot (endPop(:,1),endPop(:,2),'y*')

本站长期招聘程序代写高手，欢迎加入华南地区matlab团队

 想创业却没有经验的人 无论你是否有过网上开店的经验，都可以随时联系在线客服，建立自己独立的网站 想开网店却不知道如何入手 淘宝创业成本低而且风险小，如果想开淘宝店的朋友可以联系在线客服。 想兼职创业，却不擅长交际与服务的人 在家创业月入5000元。网站程序+百套群发工具+网赚资料+域名+空间+本站终身代理资格，这样你网赚的条件全具备了。每天3小时管理、推广、收钱。 缺乏能快速赢利型产品的人 导入多种最新流行营销软件+网赚教程，让入驻者轻松加盟、复制有效成交技巧、快速赚钱。

源码评论评论内容只代表网友观点，与本站立场无关！

评论摘要(共 0 条，得分 0 分，平均 0 分) 查看完整评论

浏览说明

* 本站所有源码全部公开，随时随地浏览!
* MATLAB软件如用于商业用途，请购买正版!
* 如果您发现下载链接错误，请点击报告错误谢谢！
* 站内提供的所有软件包含破解及注册码均是由网上搜集，若侵犯了你的版权利益，敬请来信通知我们!