声振论坛

 找回密码
 我要加入

QQ登录

只需一步,快速开始

查看: 2331|回复: 0

[人工智能] 遗传算法整数规划中变量取整的设置

[复制链接]
发表于 2011-12-23 23:05 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。

您需要 登录 才可以下载或查看,没有账号?我要加入

x
本人在用遗传算法求解非线性整数规划问题,关于变量整数的约束前面看到一个有关的帖子,我发现中间有错误(红色部分),但是不知道怎么修改,请指点。
源程序如下:
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
回复
分享到:

使用道具 举报

您需要登录后才可以回帖 登录 | 我要加入

本版积分规则

QQ|小黑屋|Archiver|手机版|联系我们|声振论坛

GMT+8, 2024-12-23 11:06 , Processed in 0.053451 second(s), 17 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表