遗传算法

  1. 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
  2. 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
  3. 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。

ห้องสมุดไป่ตู้
遗传算法编程
——张军
遗传算法工具箱
主要函数
GA Genetic algorithm solver. X = GA(FITNESSFCN,NVARS) finds the minimum of FITNESSFCN using GA. NVARS is the dimension (number of design variables) of the FITNESSFCN. FITNESSFCN accepts a vector X of size 1-byNAVRS, and returns a scalar evaluated at X. X = GA(FITNESSFCN,NAVRS,OPTIONS) finds the minimum for FITNESSFCN with the default optimization parameters replaced by values in the structure OPTIONS. OPTIONS can be created with the GAOPTIMSET function.
FitnessLimit: -Inf StallGenLimit: Inf StallTimeLimit: Inf InitialPopulation: [] InitialScores: [] PlotInterval: 1 CreationFcn: @gacreationuniform FitnessScalingFcn: @fitscalingrank SelectionFcn: @selectionstochunif CrossoverFcn: @crossoverscattered MutationFcn: @mutationgaussian HybridFcn: [] Display: 'final' PlotFcns: @gaplotbestf OutputFcns: [] Vectorized: 'off'
计算结果
x= -0.0014 fval = -1.0000 reason = Optimization terminated: maximum number of generations exceeded.
进一步分析
options = PopulationType: 'doubleVector' PopInitRange: [2x1 double] PopulationSize: 100 EliteCount: 2 CrossoverFraction: 0.8000 MigrationDirection: 'forward' MigrationInterval: 20 MigrationFraction: 0.2000 Generations: 50 TimeLimit: Inf
GA
[X,FVAL,REASON,OUTPUT] = GA(FITNESSFCN, ...) returns a structure OUTPUT with the following information: randstate: <State of the function RAND used before GA started> randnstate: <State of the function RANDN used before GA started> generations: <Total generations, excluding HybridFcn iterations> funccount: <Total function evaluations> message: <GA termination message> [X,FVAL,REASON,OUTPUT,POPULATION] = GA(FITNESSFCN, ...) returns the final POPULATION at termination. [X,FVAL,REASON,OUTPUT,POPULATION,SCORES] = GA(FITNESSFCN, ...) returns the SCORES of the final POPULATION.
例子(寻找最小值)
函数: function y = two_min(x) if x<20 y = -exp(-(x/20).^2); else y = -exp(-1)+(x-20)*(x-22); end
求解最小值程序
options = gaoptimset; options. PopulationType='doubleVector'; options. PopulationSize=100; options.StallGenLimit=inf; options.StallTimeLimit=inf; options.PlotFcns=@gaplotbestf; options.Generations=50; [x, fval, reason]=ga(@two_min, 1, options)
作业提示
数据
D001 10 6 0 0 0 0 0 0 0 0 D002 40 0 0 0 0 0 0 0 0 0 D003 15 0 0 0 0 0 0 0 0 0 D004 20 0 0 3 0 0 0 0 10 0 D005 20 0 5 0 0 0 0 0 0 0 D006 12 0 1 0 0 0 0 0 0 0 D007 30 8 0 0 1 0 0 9 0 0 D008 33 1 0 0 0 0 0 2 8 0 D009 35 0 0 0 0 0 0 0 0 0
GA
X = GA(PROBLEM) finds the minimum for PROBLEM. PROBLEM is a structure that has the following fields: fitnessfcn: <Fitness Function> nvars: <Number of design variables> options: <Options structure created with GAOPTIMSET> randstate: <Optional field to reset rand state> randnstate: <Optional field to reset randn state> [X, FVAL] = GA(FITNESSFCN, ...) returns FVAL, the value of the fitness function FITNESSFCN at the solution X. [X,FVAL,REASON] = GA(FITNESSFCN, ...) returns the REASON for stopping.
指定变量的上、下界
options.PopInitRange=[-11;26] options. PopulationSize=300;%扩大人口 [x, fval, reason]=ga(@two_min, 1, options)
遗传算法工具菜单
GATOOL Genetic Algorithm Tool. GATOOL starts a graphical user interface window for editing the default Genetic Algorithm options and running the Genetic Algorithm solver.
将有约束的规划转成无约束规划
参考代码
%计算优化问题 aifa=100; beita=100; fit=sum(sum(m.*n))+aifa*norm((max([zeros( 1,100);sum(m)D])))+beita*norm((max([zeros(1000,1) (sum(m')-3)'])));
相关文档
最新文档