% *********************************************************
% *********************************************************
% 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
% [c,ce]=ga(
函数句柄
,
变量个数
,
不等式约束系数矩阵
,
不等式约束常量向量
,
%
等式约束系数矩阵
,
等式约束常量向量
,
变量上限
,
变量下限
,
非线性约束
)
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,@gap
lotbestindiv});
[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,:);
upper = 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));