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

📄 floatexample.m

📁 遗传算法程序 主要程序 ga.m 遗传算法核心程序 BinaryExample.m 二进制编码应用程序 FloatExample.m 浮点编码的应用程序 相关算子及函数 in
💻 M
字号:
echo on% This script shows how to use the ga using a float representation. global bounds% Setting the seed to the same for binaryrand('seed',156789)% Crossover OperatorsxFns = 'arithXover';xOpts = [4 40];% Mutation OperatorsmFns = 'nonUnifMutation';mOpts = [2 40 3];% Termination OperatorstermFns = 'maxGenTerm';termOps = [40]; % 40 Generations% Selection FunctionselectFn = 'normGeomSelect';selectOps = [0.08];% Evaluation FunctionevalFn = 'exampleFn';evalOps = [];type exampleFn% Bounds on the variablesbounds = [0 10];% GA Options [epsilon float/binar display]gaOpts=[1e-6 1 1];% Generate an intialize population of size 20startPop = initializega(20,bounds,'exampleFn',[1e-6 1])% Lets run the GA% Hit a return to continuepause[x endPop bestPop trace]=ga(bounds,evalFn,evalOps,startPop,gaOpts,...    termFns,termOps,selectFn,selectOps,xFns,xOpts,mFns,mOpts);% x is the best solution foundx% Hit a return to continuepause% endPop is the ending populationendPop% Hit a return to continuepause% bestPop is the best solution tracked over generationsbestPop% Hit a return to continuepause% trace is a trace of the best value and average value of generationstrace% Hit a return to continuepause% Plot the best over timeclfplot(trace(:,1),trace(:,2));% Hit a return to continuepause% Add the average to the graphhold onplot(trace(:,1),trace(:,3));% Hit a return to continuepause% Lets increase the population size by running the defaults% [x endPop bestPop trace]=ga(bounds,evalFn,evalOps,[],gaOpts,...    termFns,termOps,selectFn,selectOps,xFns,xOpts,mFns,mOpts);% x is the best solution foundx% Hit a return to continuepause% endPop is the ending populationendPop% Hit a return to continuepause% bestPop is the best solution tracked over generationsbestPop% Hit a return to continuepause% trace is a trace of the best value and average value of generationstrace% Hit a return to continuepause% Plot the best over timeclfplot(trace(:,1),trace(:,2));% Hit a return to continuepause% Add the average to the graphhold onplot(trace(:,1),trace(:,3));echo off

⌨️ 快捷键说明

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