📄 fitness.m
字号:
function [fitness_value]=fitness(decimal_space);
%Fitness Function Of Simple Genetic Algorithm Program (Version 1.0.0.1 )
%support multi-parameters
%By chen yi ,CQU .QQ:2376635 Email:cdey@10mail.net (April,19th,2002,AAPP day)
%~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
%
% This function is to work out the Fitness after decoded from
% binary_space to decimal_space.
%
% so,you should first define the fitness_function.m
% usage:
% fitness_value=fitness(decimal_space)
%
%before you use this function,
%you should give your fitness_function.m first!!
%
%e.g.
%f(x)=1./a+sin(b)+exp(c)+log2(d)+10 , a,b,c,d belong to [1,7],[2,8],[3,9],[4,10]
%[binary_space,bits_sum,bits]=coding([1,2,3,4],[7,8,9,10],10,[0.01,0.01,0.01,0.01])
%[decimal_space]=decoding([1,2,3,4],[7,8,9,10],binary_space,bits)
%[fitness_value]=fitness(decimal_space)
%
%See Also DECODING,CODING ,SELECTION ,CROSSOVER,MUTATION
% FITNESS_FUNCTION, SGA,FITNESS
%
%~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
[population,parameter_numbers]=size(decimal_space);
decimal_space_cell=cell(population,parameter_numbers);
%transfor matrix to cell as the input parameter list
for i=1:1:population
for j=1:1:parameter_numbers
decimal_space_cell{i,j}=decimal_space(i,j);
end
fitness_value(i)=fitness_function(decimal_space_cell{i,1:1:parameter_numbers});
end
%end of fitness
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -