24小时热门版块排行榜    

查看: 1718  |  回复: 0

zongshengl

木虫 (小有名气)

[求助] 遗传算法整数规划中变量取整的设置

本人在用遗传算法求解非线性整数规划问题,关于变量整数的约束前面看到一个有关的帖子,我发现中间有错误(红色部分),但是不知道怎么修改,请指点。
源程序如下:
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
回复此楼
An important thing in ones life is to have a dream and to achive it!
已阅   回复此楼   关注TA 给TA发消息 送TA红花 TA的回帖

智能机器人

Robot (super robot)

我们都爱小木虫

相关版块跳转 我要订阅楼主 zongshengl 的主题更新
最具人气热帖推荐 [查看全部] 作者 回/看 最后发表
[找工作] 售SCI一区文章,我:8.O.55.1.O.54,科目齐全,可伽急 +4 1uaZt2kAZj2S 2026-10-31 7/350 2026-11-01 12:45 by BCdvBAEpt3zm
[考研] 售SCI一区T0P文章,我:8.O.55.1.O54,科目全,可伽急 +4 1uaZt2kAZj2S 2026-10-31 8/400 2026-11-01 12:38 by BCdvBAEpt3zm
[考博] 售SCI文章,我:8O5.5.1.O.54,科目齐全,可+急 +3 1uaZt2kAZj2S 2026-10-30 10/500 2026-11-01 12:27 by BCdvBAEpt3zm
[公派出国] 售SCI-T0P文章,我:8O.5.5.1.O.54,科目齐全,可+急 +3 1uaZt2kAZj2S 2026-10-30 7/350 2026-11-01 12:27 by BCdvBAEpt3zm
[基金申请] 售SCI一区T0P文章,我:8.O.55.1.O.54,科目齐全,可+急 +4 1uaZt2kAZj2S 2026-10-30 11/550 2026-11-01 12:24 by BCdvBAEpt3zm
[论文投稿] 售SCI-T0P文章,我:8O.5.5.1.O.54,科目齐全,可+急 +3 1uaZt2kAZj2S 2026-10-30 12/600 2026-11-01 12:19 by BCdvBAEpt3zm
[公派出国] 售SCI一区T0P文章,我:8.O.55.1.O54,科目全,可伽急 +3 hKe7U1kad5Sg 2026-10-31 5/250 2026-11-01 11:14 by BCdvBAEpt3zm
[考博] 售SCI一区文章,我:8.O.55.1.O.54,科目齐全,可伽急 +3 xvJS1BYDxvBS 2026-10-31 4/200 2026-11-01 11:01 by BCdvBAEpt3zm
[考研] 售SCI一区文章,我:8O5.5.1.O5.4,科目全,可伽急 +4 xvJS1BYDxvBS 2026-10-31 9/450 2026-11-01 10:56 by BCdvBAEpt3zm
[论文投稿] 售SCI文章,我:8O5.5.1.O.54,科目齐全,可+急 +3 xvJS1BYDxvBS 2026-10-31 6/300 2026-11-01 10:53 by BCdvBAEpt3zm
[博后之家] 售SCI一区文章,我:8O5.5.1.O5.4,科目全,可伽急 +4 1uaZt2kAZj2S 2026-10-31 7/350 2026-11-01 10:48 by BCdvBAEpt3zm
[基金申请] 售SCI-T0P文章,我:8O.5.5.1.O.54,科目齐全,可+急 +3 1uaZt2kAZj2S 2026-10-30 14/700 2026-11-01 10:43 by BCdvBAEpt3zm
[公派出国] 售SCI-T0P文章,我:8O.5.5.1.O.54,科目齐全,可+急 +3 1uaZt2kAZj2S 2026-10-30 13/650 2026-11-01 10:27 by BCdvBAEpt3zm
[论文投稿] 售SCI文章,我:8O.5.5.1O.54,科目全,可十急 +5 X5bHxOULxFqb 2026-10-30 26/1300 2026-11-01 10:22 by BCdvBAEpt3zm
[考博] 售SCI一区T0P文章,我:8.O.55.1.O.5.4,科目全,可+急 +4 X5bHxOULxFqb 2026-10-30 21/1050 2026-11-01 06:46 by YXM1FDCSE8Bn
[博后之家] 售SCI文章,我:8O5.5.1.O.54,科目齐全,可+急 +3 1uaZt2kAZj2S 2026-10-30 15/750 2026-11-01 05:22 by YXM1FDCSE8Bn
[找工作] 售一区SCI文章T0P,我:8O.551.O54,科目全,可十急 +3 1uaZt2kAZj2S 2026-10-31 6/300 2026-11-01 03:56 by YXM1FDCSE8Bn
[考博] 2027博士申请-临床检验诊断学、病原生物学、微生物方向 50+3 yyh@ 2026-10-28 4/200 2026-10-31 12:47 by 可淡不可忘
[文学芳草园] 闲聊 +3 myrtle 2026-10-25 6/300 2026-10-29 15:28 by myrtle
[考博] 申博求助 20+3 Katrinae 2026-10-26 4/200 2026-10-27 09:56 by 北京莱茵编辑
信息提示
请填处理意见