我要加入 登录
声振论坛 返回首页

zhlong的个人空间 http://home.vibunion.com/?12612 [收藏] [复制] [分享] [RSS]

日志

(转载)遗传算法整数规划问题

已有 786 次阅读2007-11-21 15:40

论坛有两个关于这方面的帖子,答案还不完整。今日搜得一文,还未及试运行,先与大家分享。
遗传算法如何进行整数规划问题?
如何在遗传算法中限定变量只取整数值?



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 编辑 ]

    评论 (0 个评论)

    facelist doodle 涂鸦板

    您需要登录后才可以评论 登录 | 我要加入

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

    GMT+8, 2024-5-17 17:44 , Processed in 0.035892 second(s), 15 queries , Gzip On.

    Powered by Discuz! X3.4

    Copyright © 2001-2021, Tencent Cloud.

    返回顶部