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

📄 orderbasedexample.m

📁 实现遗传算法对于SFAM网络输入模式的序列优化
💻 M
字号:
echo on% This script shows how to use the ga using an order-based representation. % You should see the demos for% more information as well. gademo1, gademo2, gademo3global distMatrix% Setting the seed to the same for binaryrand('seed',156789)% 6 city problemt=[ 92.6112 59.0801; 49.1155 50.0000; 12.5000 57.9436; 75.0000 19.3703;  8.6504 13.7113; 36.8786 92.9628];t=100*rand(15,2);sz=size(t,1);distMatrix=dists(t,t);% Order-based Representation Crossover Operators% cyclicXover.m          % erXover.m              % enhancederXover.m      % linerorderXover.m      % orderbasedXover.m      % partmapXover.m         % singleptXover.m        % uniformXover.m         xFns = 'cyclicXover uniformXover partmapXover orderbasedXover 'xFns =[xFns,'singleptXover linerorderXover'];% xFns = [xFns,'enhancederXover linerorderXover']% xFns = [xFns,'linerorderXover singleptXover']xOpts = [2;2;2;2;2;2];%[ 2; 2; 2; 2; 2; 2; 2];% Order-based Mutation Operators% inversionMutation% adjswapMutation.m      % shiftMutation.m        % swapMutation.m         % threeswapMutation.m    mFns = 'inversionMutation adjswapMutation shiftMutation swapMutation threeswapMutation';mOpts = [2;2;2;2;2];% Termination OperatorstermFns = 'maxGenTerm';termOps = [100]; % 200 Generations% Selection FunctionselectFn = 'normGeomSelect';selectOps = [0.08];% Evaluation FunctionevalFn = 'tspEval';evalOps = [];type tspEval% Bounds on the number of cities in the TSPbounds = [sz];% GA Options [epsilon float/binar display]gaOpts=[1e-6 1 1];% Generate an intialize population of size 20startPop = initializeoga(40,bounds,'tspEval',[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 population%endPop%%Hit a return to continue%pause% 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 timeclftrace(:,2)=100*(trace(:,2)-min(trace(:,2)))/(15+max(trace(:,2))-min(trace(:,2)));plot(trace(:,1),trace(:,2),'r');

⌨️ 快捷键说明

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