| 1 | 1/1 | 返回列表 |
| 查看: 1627 | 回復(fù): 0 | ||
zongshengl木蟲 (小有名氣)
|
[求助]
遺傳算法整數(shù)規(guī)劃中變量取整的設(shè)置
|
|
本人在用遺傳算法求解非線性整數(shù)規(guī)劃問題,關(guān)于變量整數(shù)的約束前面看到一個有關(guān)的帖子,我發(fā)現(xiàn)中間有錯誤(紅色部分),但是不知道怎么修改,請指點。 源程序如下: 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 |

找到一些相關(guān)的精華帖子,希望有用哦~
| 1 | 1/1 | 返回列表 |
| 最具人氣熱帖推薦 [查看全部] | 作者 | 回/看 | 最后發(fā)表 | |
|---|---|---|---|---|
|
[考研] 265求調(diào)劑 +4 | 梁梁校校 2026-03-19 | 4/200 |
|
|---|---|---|---|---|
|
[考研] 286分人工智能專業(yè)請求調(diào)劑愿意跨考! +3 | lemonzzn 2026-03-17 | 3/150 |
|
|
[考研] 329求調(diào)劑 +5 | 想上學(xué)吖吖 2026-03-19 | 5/250 |
|
|
[考研] 296求調(diào)劑 +3 | www_q 2026-03-18 | 6/300 |
|
|
[考研] 085600材料與化工 求調(diào)劑 +14 | enenenhui 2026-03-13 | 15/750 |
|
|
[考研] 286求調(diào)劑 +6 | lemonzzn 2026-03-16 | 10/500 |
|
|
[考研] 324分 085600材料化工求調(diào)劑 +3 | llllkkkhh 2026-03-18 | 3/150 |
|
|
[考研] 材料080500調(diào)劑求收留 +4 | 一顆meteor 2026-03-13 | 4/200 |
|
|
[考研] 材料工程專碩調(diào)劑 +5 | 204818@lcx 2026-03-17 | 6/300 |
|
|
[考研] 085410人工智能專碩317求調(diào)劑(0854都可以) +3 | xbxudjdn 2026-03-18 | 3/150 |
|
|
[考研] 材料專業(yè)求調(diào)劑 +5 | hanamiko 2026-03-18 | 5/250 |
|
|
[考研] 0703化學(xué)求調(diào)劑 總分331 +3 | ZY-05 2026-03-13 | 3/150 |
|
|
[考研] 268求調(diào)劑 +8 | 一定有學(xué)上- 2026-03-14 | 9/450 |
|
|
[考研] 材料與化工專碩調(diào)劑 +5 | heming3743 2026-03-16 | 5/250 |
|
|
[考研] 一志愿南京大學(xué),080500材料科學(xué)與工程,調(diào)劑 +4 | Jy? 2026-03-16 | 4/200 |
|
|
[考研] 一志愿211 0703方向310分求調(diào)劑 +3 | 努力奮斗112 2026-03-15 | 3/150 |
|
|
[考研] 277材料科學(xué)與工程080500求調(diào)劑 +3 | 自由煎餅果子 2026-03-16 | 3/150 |
|
|
[考研] 326求調(diào)劑 +3 | mlpqaz03 2026-03-15 | 3/150 |
|
|
[考研] 085601材料工程315分求調(diào)劑 +3 | yang_0104 2026-03-15 | 3/150 |
|
|
[考研] 266求調(diào)劑 +4 | 學(xué)員97LZgn 2026-03-13 | 4/200 |
|