Re: [討論] ga(基因演算法)中如何限制變數為偶數

作者: maplekai (阿凱)   2014-04-22 02:11:56
※ 引述《gn01189425 (GN boy)》之銘言:
: 標題: [討論] ga(基因演算法)中如何限制變數為偶數
: 時間: Thu Jun 20 03:16:02 2013
:
: 大家好,我目前想將變數限制為偶數,目前的程式碼如下
:
: function [c, ceq] = simple_constraint(x)
: a=mod(x,2)
: c = [a]
: ceq = [];
: end
:
:
: x0=[16]; % 初始值
: lb=x0; % 下限
: ub=x0+24; % 上限
: options = gaoptimset('PlotFcns', {@gaplotbestf,@gaplotstopping},...
: 'PopulationSize',10,'Generations',10); %控制選項
: Constraint=@simple_constraint;
: [x,fval,exitflag]=ga(@myFun,1,[],[],[],[],lb,ub,Constraint,[1],options)
:
: ga會將變數代入myfun並傳回目標值
:
: 但是ga仍然會找不是偶數的x代入myfun,有沒有其他方法可以限制變數只選偶數呢?
: 謝謝
:
:
作者: H45 (!H45)   2014-04-22 07:56:00
我可否先確定你的問題?"依舊沒達到只選偶數的變數以進行ga運算的目的" 為什麼這麼說?

Links booklink

Contact Us: admin [ a t ] ucptt.com