声振论坛

 找回密码
 我要加入

QQ登录

只需一步,快速开始

查看: 2620|回复: 3

[人工智能] (转载)遗传算法整数规划问题

[复制链接]
发表于 2007-11-20 22:45 | 显示全部楼层 |阅读模式

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

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

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:
  • gainteger_demo.m (1.98 KB, 下载次数: 38)

源程序如下:
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 编辑 ]

评分

1

查看全部评分

回复
分享到:

使用道具 举报

发表于 2008-3-5 10:32 | 显示全部楼层
很好,谢谢楼主
发表于 2008-3-28 00:10 | 显示全部楼层
一直在找变量是整数时如何在matlab工具箱中进行分析,本以为是很简单的一个设置而已,原来这么复杂啊:@L
发表于 2008-3-28 09:35 | 显示全部楼层
利用上面的方法,设置种群类型时应该采用bitstring还是custom?
您需要登录后才可以回帖 登录 | 我要加入

本版积分规则

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

GMT+8, 2024-11-17 17:32 , Processed in 0.099576 second(s), 22 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

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