马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
您需要 登录 才可以下载或查看,没有账号?我要加入
x
论坛有两个关于这方面的帖子,答案还不完整。今日搜得一文,还未及试运行,先与大家分享。
遗传算法如何进行整数规划问题?
如何在遗传算法中限定变量只取整数值?
Subject:
How can I perform integer programming using the GA function in the Genetic Algorithm and Direct Search Toolbox?
Problem Description:
I would like to perform integer programming or mixed integer programming using the GA function by constraining certain parameters to be integers.
Solution:
To perform integer programming using the GA function, create a custom mutation function and a creation function that generate only integer outputs.
Then, use the GAOPTIMSET function to set the "MutationFcn" and "CreationFcn" properties to the custom functions, as shown with the following code:
options = gaoptimset('CreationFcn',@your_creationfcn,'MutationFcn',@your_mutationfcn);
[x,fval] = ga(fitnessFcn,nVars,options);
See the attached example file "gainteger_demo.m".
Related Documents/Files:
源程序如下:
function [x,fval] = gainteger_demo
% Fitness function and numver of variables
fitnessFcn = @(x) norm(x);
numberOfVariables = 15;
% If decision variables are bounded provide a bound e.g, LB and UB.
LB = -5*ones(1,numberOfVariables);
UB = 5*ones(1,numberOfVariables);
Bound = [LB;UB]; % If unbounded then Bound = []
% Create an options structure to be passed to GA
% Three options namely 'CreationFcn', 'MutationFcn', and
% 'PopInitRange' are required part of the problem.
options = gaoptimset('CreationFcn',@int_pop,'MutationFcn',@int_mutation, ...
'PopInitRange',Bound,'Display','iter','StallGenL',40,'Generations',150, ...
'PopulationSize',60,'PlotFcns',{@gaplotbestf,@gaplotbestindiv});
[x,fval] = ga(fitnessFcn,numberOfVariables,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));
% 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;
% The use of ROUND function will make sure that individuals are integers.
Population = repmat(lower,totalpopulation,1) + ...
round(repmat(span,totalpopulation,1) .* rand(totalpopulation,GenomeLength));
% End of creation function
转自:http://www.mathworks.com/support/solutions/data/1-10PDHC.html?product=GD&solution=1-10PDHC
http://hi.baidu.com/webooo99/blog/item/ba57ca4b17442cf382025c0b.html
[ 本帖最后由 zhlong 于 2007-11-20 22:47 编辑 ] |