遗传算法

两篇介绍遗传算法不错的博客:

点击打开链接1

点击打开链接2


基于遗传算法的多目标优化问题实例:
遗传算法_第1张图片


function f = my_first_multi(x)
 
f(1) = x(1)^4 - 10*x(1)^2+x(1)*x(2) + x(2)^4 - (x(1)^2)*(x(2)^2);
f(2) = x(2)^4 - (x(1)^2)*(x(2)^2) + x(1)^4 + x(1)*x(2);




fitnessfcn = @my_first_multi;   % Function handle to the fitness function
nvars = 2;                      % Number of decision variables
lb = [-5,-5];                   % Lower bound
ub = [5,5];                     % Upper bound
A = []; b = [];                 % No linear inequality constraints
Aeq = []; beq = [];             % No linear equality constraints
options = gaoptimset('ParetoFraction',0.3,'PopulationSize',100,'Generations',...
200,'StallGenLimit',200,'TolFun',1e-100,'PlotFcns',@gaplotpareto);

[x,fval] = gamultiobj(fitnessfcn,nvars, A,b,Aeq,beq,lb,ub,options);

基于遗传算法的有约束单目标优化问题实例:

遗传算法_第2张图片

function y = simple_fitness(x)
y = 100 * (x(1)^2 - x(2))^2 + (1 - x(1))^2;


function [c, ceq] = simple_constraint(x)
c = [1.5+x(1)*x(2)+x(1)-x(2);
-x(1)*x(2)+10];
ceq =[];





ObjectiveFunction = @simple_fitness;
nvars = 2;
LB = [0 0];
UB = [1 13];
ConstraintFunction = @simple_constraint;
[x,fval] = ga(ObjectiveFunction,nvars,[],[],[],[],LB,UB,ConstraintFunction)


你可能感兴趣的:(Matlab学习)