您好,欢迎访问三七文档
当前位置:首页 > 行业资料 > 交通运输 > ga遗传算法工具箱求解0-1整数规划问题
%*********************************************************%*********************************************************%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)%%*********************************************************%MatlabProgram:%GAfor0-1IntegerProgrammingfunction[x,fval]=ga001(fitnessFcn,numberOfVariables,options)%Fitnessfunctionandnumberofvariables%[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=[11111];Beq=[2];options=gaoptimset('CreationFcn',@int_pop,'MutationFcn',@int_mutation,'PlotFcns',{@gaplotbestf,@gaplotbestindiv});[x,fval]=ga(fitnessFcn,numberOfVariables,[],[],Aeq,Beq,[],[],[],options);%---------------------------------------------------%Mutationfunctiontogeneratechildrenssatisfyingtherangeandinteger%constraintsondecisionvariables.functionmutationChildren=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);%TheuseofROUNDfunctionwillmakesurethatchildrensareintegers.mutationChildren=repmat(lower,mutationPop,1)+...round(repmat(scale,mutationPop,1).*rand(mutationPop,GenomeLength));%Endofmutationfunction%---------------------------------------------------functionPopulation=int_pop(GenomeLength,FitnessFcn,options)totalpopulation=sum(options.PopulationSize);range=options.PopInitRange;lower=range(1,:);span=range(2,:)-lower;%TheuseofROUNDfunctionwillmakesurethatindividualsareintegers.Population=repmat(lower,totalpopulation,1)+...round(repmat(span,totalpopulation,1).*rand(totalpopulation,GenomeLength));%Endofcreationfunction%*********************************************************
本文标题:ga遗传算法工具箱求解0-1整数规划问题
链接地址:https://www.777doc.com/doc-2873149 .html