⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 floatexample.m

📁 genetic遗传算法
💻 M
字号:
% This script shows how to use the ga using a float representation. % You should see the demos for% more information as well. gademo1, gademo2, gademo3global bounds% Setting the seed to the same for binaryrand('seed',156789)% Crossover OperatorsxFns = 'arithXover heuristicXover simpleXover';xOpts = [1 0; 1 3; 1 0];% Mutation OperatorsmFns = 'boundaryMutation multiNonUnifMutation nonUnifMutation unifMutation';mOpts = [2 0 0;3 200 3;2 200 3;2 0 0];% Termination OperatorstermFns = 'maxGenTerm';termOps = [200]; % 200 Generations% Selection FunctionselectFn = 'normGeomSelect';selectOps = [0.08];% Evaluation FunctionevalFn = 'gaMichEval';evalOps = [];% Bounds on the variablesbounds = [-3 12.1; 4.1 5.8];% GA Options [epsilon float/binar display]gaOpts=[1e-6 1 0];% Generate an intialize population of size 20startPop = initializega(20,bounds,evalFn,[1e-6 1]);% Lets run the GA% Hit a return to continue[x endPop bestPop trace]=ga(bounds,evalFn,evalOps,startPop,gaOpts,...    termFns,termOps,selectFn,selectOps,xFns,xOpts,mFns,mOpts);% x is the best solution foundx% % endPop is the ending population% endPop% % bestPop is the best solution tracked over generations% bestPop% % trace is a trace of the best value and average value of generations% trace% % Plot the best over timeclfplot(trace(:,1),trace(:,2));hold onplot(trace(:,1),trace(:,3));[x endPop bestPop trace]=ga(bounds,evalFn,evalOps,[],gaOpts);% x is the best solution foundx% % endPop is the ending population% endPop% % bestPop is the best solution tracked over generations% bestPop% % trace is a trace of the best value and average value of generations% trace% % Plot the best over timefigureplot(trace(:,1),trace(:,2));hold onplot(trace(:,1),trace(:,3));

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -