% *********************************************************
张哲源
% *********************************************************
% Problem:
%
% Minf(x)=-(0.644*x(1)+0.707*x(2)+0.713*x(3)+0.735*x(4)
% +0.745*x(5)+0.1755*x(1)*x(2)-0.8916*x(4)*x(5)
%
% s.t. x(1)+x(2)+x(3)+x(4)+x(5)=2
% x(i)={0,1}(i=1,2,3,4,5)
%
% *********************************************************
% Matlab Program:
% GA for 0-1 Integer Programming
function [x,fval] = ga001(fitnessFcn,numberOfVariables,options)
% Fitness function and number of variables
%等式约束系数矩阵,等式约束常量向量,变量上限,变量下限,非线性约束)
fitnessFcn = @(x) -(0.644*x(1)+0.707*x(2)+0.713*x(3)+0.735*x(4)+0.745*x(5)+0.1755*x(1)*x(2)-0.8916*x(4)*x(5));
numberOfVariables = 5;
Aeq=[1 1 1 1 1];
Beq=[2];
options = gaoptimset('CreationFcn',@int_pop,'MutationFcn',@int_mutation,'PlotFcns',{@gaplotbestf,@gaplotbestindiv});
[x,fval] = ga(fitnessFcn,numberOfVariables,[],[],Aeq,Beq,[],[],[],options);
%---------------------------------------------------
% Mutation function to generate childrens satisfying the range and integer
% constraints on decision variables.
function mutationChildren = int_mutation(parents,options,GenomeLength, ...
FitnessFcn,state,thisScore,thisPopulation)
shrink = .01;
scale = 1;
scale = scale - shrink * scale * state.Generation/options.Generations;
range = options.PopInitRange;
lower = range(1,:);
crj-200upper = range(2,:);
scale = scale * (upper - lower);
mutationPop = length(parents);
% The use of ROUND function will make sure that childrens are integers.
mutationChildren = repmat(lower,mutationPop,1) + ...
round(repmat(scale,mutationPop,1) .* rand(mutationPop,GenomeLength));
% End of mutation function
超导磁流体
%---------------------------------------------------
function Population = int_pop(GenomeLength,FitnessFcn,options)
totalpopulation = sum(options.PopulationSize);
range = options.PopInitRange;
春暖花开 亚洲lower= range(1,:);
span = range(2,:) - lower;
2013年7月1日% The use of ROUND function will make sure that individuals are integers.
1999年虎门大桥事故Population = repmat(lower,totalpopulation,1) + ...
round(repmat(span,totalpopulation,1) .* rand(totalpopulation,GenomeLength));
% End of creation function
%*********************************************************