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)
%
% *********************************************************
% 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,@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
%*********************************************************

本文发布于:2024-09-20 15:00:43,感谢您对本站的认可!

本文链接:https://www.17tex.com/xueshu/536892.html

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。

标签:约束   变量   矩阵   常量   系数
留言与评论(共有 0 条评论)
   
验证码:
Copyright ©2019-2024 Comsenz Inc.Powered by © 易纺专利技术学习网 豫ICP备2022007602号 豫公网安备41160202000603 站长QQ:729038198 关于我们 投诉建议