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

📄 floatexample.m

📁 运用遗传算法的工具箱解决宽带雷达吸波结构的优化问题
💻 M
字号:
echo on% 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',2131415161)% Crossover OperatorsxFns = 'arithXover heuristicXover simpleXover';xOpts = [2 0; 3 3; 2 0];% Mutation OperatorsmFns = 'boundaryMutation multiNonUnifMutation nonUnifMutation unifMutation';mOpts = [3 0 0;4 120 3;4 120 3;3 0 0];% Termination OperatorstermFns = 'maxGenTerm';termOps = [50]; % 100 Generations% Selection FunctionselectFn = 'normGeomSelect';selectOps = [0.8];% Evaluation FunctionevalFn = 'gaRadarEval1';evalOps = [];% type gaRadarEval% Bounds on the variablesbounds = [1 16; 0.001 10; 1 16; 0.001 10; 1 16; 0.001 10;1 16;0.001 10;1 16; 0.001 10];% GA Options [epsilon float/binar display]gaOpts=[1e-6 1 1];% Generate an intialize population of size 100startPop = initializega(600,bounds,'gaRadarEval1',[1e-6 1])% Lets run the GA% Hit a return to continuepause[x endPop1 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 populationendPop1% Hit a return to continue%pausexFns = 'arithXover heuristicXover simpleXover';xOpts = [40 0;60 4;40 0];% Mutation OperatorsmFns = 'boundaryMutation multiNonUnifMutation nonUnifMutation unifMutation';mOpts = [5 0 0;6 30 3;6 30 3;5 0 0];% Termination OperatorstermFns = 'maxGenTerm';termOps = [20]; % 100 Generations% Selection FunctionselectFn = 'normGeomSelect';selectOps = [0.85];evalFn = 'gaRadarEval1';evalOps = [];bounds = [1 16; 0.001 10; 1 16; 0.001 10; 1 16; 0.001 10;1 16;0.001 10;1 16; 0.001 10];gaOpts=[1e-6 1 1];startPop = endPop1pause[x endPop2 bestPop trace]=ga(bounds,evalFn,evalOps,startPop,gaOpts,...    termFns,termOps,selectFn,selectOps,xFns,xOpts,mFns,mOpts);xpause% endPop is the ending populationendPop2xFns = 'arithXover heuristicXover simpleXover';xOpts = [6 0;8 4;6 0];% Mutation OperatorsmFns = 'boundaryMutation multiNonUnifMutation nonUnifMutation unifMutation';mOpts = [8 0 0;9 30 3;9 30 3;8 0 0];% Termination OperatorstermFns = 'maxGenTerm';termOps = [20]; % 100 Generations% Selection FunctionselectFn = 'normGeomSelect';selectOps = [0.75];evalFn = 'gaRadarEval1';evalOps = [];bounds = [1 16; 0.001 10; 1 16; 0.001 10; 1 16; 0.001 10; 1 16; 0.001 10; 1 16; 0.001 10];gaOpts=[1e-6 1 1];startPop = endPop2pause[x endPop3 bestPop trace]=ga(bounds,evalFn,evalOps,startPop,gaOpts,...    termFns,termOps,selectFn,selectOps,xFns,xOpts,mFns,mOpts);xpause% endPop is the ending populationendPop3xFns = 'arithXover heuristicXover simpleXover';xOpts = [8 0;9 4; 8 0];% Mutation OperatorsmFns = 'boundaryMutation multiNonUnifMutation nonUnifMutation unifMutation';mOpts = [9 0 0;10 30 3;10 30 3;9 0 0];% Termination OperatorstermFns = 'maxGenTerm';termOps = [100]; % 100 Generations% Selection FunctionselectFn = 'normGeomSelect';selectOps = [0.85];evalFn = 'gaRadarEval1';evalOps = [];bounds = [1 16; 0.001 10; 1 16; 0.001 10; 1 16; 0.001 10; 1 16; 0.001 10; 1 16;  0.001 10];gaOpts=[1e-6 1 1];startPop = endPop3pause[x endPop4 bestPop trace]=ga(bounds,evalFn,evalOps,startPop,gaOpts,...    termFns,termOps,selectFn,selectOps,xFns,xOpts,mFns,mOpts);xpause% endPop is the ending populationendPop4% bestPop is the best solution tracked over generations% bestPop is the best solution tracked over generations%bestPop% Hit a return to continue%pause% trace is a trace of the best value and average value of generations%trace% Hit a return to continue%pause% Plot the best over time%clf%plot(trace(:,1),trace(:,2));% Hit a return to continue%pause% Add the average to the graph%hold on%plot(trace(:,1),trace(:,3));% Hit a return to continue%pause% Lets increase the population size by running the defaults% %[x endPop bestPop trace]=ga(bounds,evalFn,evalOps,[],gaOpts);% x is the best solution found%x% Hit a return to continue%pause% endPop is the ending population%endPop% Hit a return to continue%pause% bestPop is the best solution tracked over generations%bestPop% Hit a return to continue%pause% trace is a trace of the best value and average value of generations%trace% Hit a return to continue%pause% Plot the best over time%clf%plot(trace(:,1),trace(:,2));% Hit a return to continue%pause% Add the average to the graph%hold on%plot(trace(:,1),trace(:,3));echo off

⌨️ 快捷键说明

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