?? floatexample.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 binary% rand('seed',sd)% 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 = [];type gaMichEval% Bounds on the variablesbounds = [-3 12.1; 4.1 5.8];% GA Options [epsilon float/binar display]gaOpts=[1e-6 1 1];% Generate an intialize population of size 20startPop = initialize(20,bounds,'gaMichEval',[1e-6 1]);% Lets run the GApause[x endPop bestPop trace]=ga(bounds,evalFn,evalOps,startPop,gaOpts,... termFns,termOps,selectFn,selectOps,xFns,xOpts,mFns,mOpts);pause% x is the best solution foundxpause% endPop is the ending populationendPoppause% bestPop is the best solution tracked over generationsbestPoppause% trace is a trace of the best value and average value of generationstracepause% Plot the best over timeclgplot(trace(:,1),trace(:,2));pause% Add the average to the graphhold onplot(trace(:,1),trace(:,3));pause% Lets increase the population size by running the defaults% [x endPop bestPop trace]=ga(bounds,evalFn,evalOps,[],gaOpts);% x is the best solution foundxpause% endPop is the ending populationendPoppause% bestPop is the best solution tracked over generationsbestPoppause% trace is a trace of the best value and average value of generationstracepause% Plot the best over timeclgplot(trace(:,1),trace(:,2));pause% Add the average to the graphhold onplot(trace(:,1),trace(:,3));pause
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -