📄 sgalab_demo_mo_muga.m
字号:
% /*M-FILE SCRIPT SGALAB_demo_MO_muGA MMM SGALAB */ %% /*==================================================================================================% Simple Genetic Algorithm Laboratory Toolbox for Matlab 7.x%% Copyright 2009 The SxLAB Family - Yi Chen - leo.chen.yi@gmail.com% ====================================================================================================%File description:% Micro-GA method (muGA)%Input(1):% options[8]:% options(1)-- en-/de-coding method% 'Binary' ,'b' : binary encoding method% 'Real' ,'r' : real number encoding method% 'Literal','l' : literal permutation encoding method% 'Gray' ,'g' : Gray encoding method% 'DNA' ,'d' : DNA encoding method% 'Messy' ,'m' : Messy encoding method%% options(2)-- selection method% 'Roulettewheel', 'Roulette','Wheel','r' : Roulette wheel selection method% 'Stochastic','s' : Stochastic selection method% 'TSP_Roulettewheel','tsp_rw','tsprw' : TSP Roulette wheel selection%% options(3)-- crossover method% 'singlepoint','single'% 'twopoint','two'% 'N = n','n'% 'random','r'% 'EAX': Travel Salesman Problem--TSP Operator% Edge Assembly Crossover( EAX ) is to do% Edge Recombination Crossover(ERX) With double edge marker,% Briefly:% EAX = ERX + Edge_Marker% 'CX' : TSP - Cycle Crossover, CX% 'OX' : TSP - Ordered Crossover operation, OX% 'PMX': TSP - Partially Matched Crossover, PMX% 'BOOLMATRIX': TSP - Matrix Representations and Operators% options(4)-- mutation method% 'singlepoint','single'% 'twopoint','two'% 'N = n','n'% 'random','r'% 'ReciprocalExchange', (Reciprocal% Exchange. Swap two cities.)% 'Displacement' , Displacement. Select a% subtour and insert it in a random place.% 'Insertion', Select a city and% insert it in a random place% 'Inversion', Select two points along the permutation, cut it at these points and re-insert the reversed string.% (1 2 | 3 4 5 6 | 7 8 9) ? (1 2 | 6 5 4 3 | 7 8 9)% options(5)-- constraint_status% 'with' ,'1'--have constraint conditions% 'without' ,'0'--have no constraint% conditions% options(6)-- Multi-Objects option% 'NON_MO' -- Non-Multi-Objective problem% 'VEGA' -- Vector Evaluated Genetic Algorithms,J. D. Schaffer% 'MOGA' -- Multiobjective Genetic Algorithm (moGA: Fonseca and Fleming, 1993)% 'NSGA' -- Non-dominated Sorting Genetic Algorithm(NSGA Srinivas, N. and K. Deb -1994 )% 'NSGAII' -- Non-dominated Sorting Genetic Algorithm - II% 'MUGA',% 'Micro', % 'Micro-GA',% 'microga'% 'muga','mu' -- Micro-GA% options(7)-- Pareto ranking method% 'Goldberg','G' -- Goldberg's method: rank = rank + 1;% 'Fonceca','Fleming','MO','F' -- Fonceca and Fleming's ranking method% current rank% = the number of its dominating individulas + 1% options(8)-- Save each generation fitness data% '1', -- Save; Pareto front neet this% '0', -- Not Save,only get last results%Appendix comments:%%Usage:% We can run SGALAB by key-in "SGALAB_demo_MO_muGA" in Matlab command% window%===================================================================================================% See Also: SGALAB_demo_math% SGALAB_demo_MO_VEGA% SGALAB_demo_MO_NPGA% SGALAB_demo_MO_NSGA% SGALAB_demo_MO_NSGAII% SGALAB_demo_MO_VEGA% SGALAB_demo_TSP_13cities%%===================================================================================================%%===================================================================================================%Revision -% Date Name Description of Change Email % 30-Mar-2009 Chen Yi Initial version leo.chen.yi@gmail.com %HISTORY$%==================================================================================================*/% SGALAB_demo_MO_muGA Begin%% set screen% freshclear ;close ('all');warning off% to delete old output_*.txt!del OUTPUT_*.txt% set working path%cd SGALAB_Funcs% SGA_set_working_paths%% begin to count time during calculatinghome ;tic % timer start >>% data preparation%% open data files%%%input data filesfid1 = fopen('INPUT_min_confines.txt' , 'r' );fid2 = fopen('INPUT_max_confines.txt' , 'r' );fid3 = fopen('INPUT_probability_crossover.txt' , 'r' );fid4 = fopen('INPUT_probability_mutation.txt' , 'r' );fid5 = fopen('INPUT_population.txt' , 'r' );fid6 = fopen('INPUT_steps.txt' , 'r' );fid7 = fopen('INPUT_max_generation.txt' , 'r' );fid8 = fopen('INPUT_convergence_method.txt' , 'r' );fid9 = fopen('INPUT_max_no_change_probability_crossover_generation.txt','r');fid10 = fopen('INPUT_deta_fitness_max.txt','r');fid11 = fopen('INPUT_max_probability_crossover.txt','r');fid12 = fopen('INPUT_probability_crossover_step.txt','r');fid13 = fopen('INPUT_max_no_change_fitness_generation.txt','r');%Micro-GAfid14 = fopen('INPUT_muGA_population_internal_number.txt','r'); % 5, in defaultfid15 = fopen('INPUT_muGA_population_replaceable_number.txt','r'); % 2, in defaultfid16 = fopen('INPUT_muGA_exchangeable_number.txt','r'); % 2, in defaultfid17 = fopen('INPUT_muGA_cycle.txt','r'); % 2, in default%output data filesfid101 = fopen('OUTPUT_maxfitness.txt','w+');fid102 = fopen('OUTPUT_minfitness.txt','w+');fid103 = fopen('OUTPUT_meanfitness.txt','w+');fid104 = fopen('OUTPUT_best_result_space.txt','w+');fid105 = fopen('OUTPUT_best_coding_space.txt','w+');fid106 = fopen('OUTPUT_now_generation.txt','w+');fid107 = fopen('OUTPUT_now_probability_crossover.txt','w+');% begin to load data from fileSGALAB_versionSGALAB_status_info%% read data from these filesmin_confines = fscanf( fid1 , '%g' ); min_confines = min_confines' ;max_confines = fscanf( fid2 , '%g' ); max_confines = max_confines';probability_crossover = fscanf( fid3 , '%g' ); probability_mutation = fscanf(fid4,'%g');population = fscanf( fid5 , '%g' );decimal_step = fscanf( fid6 , '%g' );max_generation = fscanf( fid7 , '%g' );convergence_method = fscanf( fid8 , '%g' );max_no_change_probability_crossover_generation = fscanf( fid9 , '%g' );deta_fitness_max = fscanf( fid10 , '%g' );max_probability_crossover = fscanf( fid11,'%g' );probability_crossover_step = fscanf(fid12,'%g');max_no_change_fitness_generation = fscanf(fid13,'%g');%Micro-GA internal populationinternal_number = fscanf(fid14,'%g');replaceable_number = fscanf(fid15,'%g');exchangeable_number = fscanf(fid16,'%g');muGA_cycle = fscanf(fid17,'%g');decimal_step = decimal_step' ;now_probability_crossover = probability_crossover;%disp(' >>>>')disp('End Evaluating, List of results :')% Step into SGALAB()options = { 'Binary', 'Roulettewheel', 'singlepoint', 'singlepoint', '0', 'muga', % will check inside SGA_entry_MO_Pareto_muGA() 'Goldberg', '1', '1'}; % Micro-GA option: % 1 - invoke mutation operator % 0 - NOT invoke mutation operator % Output[ maxfitness ,... minfitness ,... meanfitness ,... now_generation , ... now_probability_crossover,... best_decimal_space ,... best_coding_space ,... error_status ]= SGA_entry_MO_Pareto_muGA... ( options,... min_confines ,... max_confines ,... probability_crossover ,... probability_mutation ,... population ,... decimal_step , ... max_generation ,... convergence_method ,... max_no_change_probability_crossover_generation ,... deta_fitness_max ,... max_probability_crossover ,... max_no_change_fitness_generation ,... probability_crossover_step,... internal_number,... replaceable_number,... muGA_cycle);if ( error_status ~= 0 ) return ; end%write data to output files% fprintf( fid8 , '\n the max value of fitness function:\n' );fprintf( fid101 , '%f\n' , maxfitness);%fprintf( fid9, '\n the min value of fitness function:\n');fprintf( fid102 , '%f\n' ,minfitness);%fprintf(fid10,'\n the mean value of fitness function:\n');fprintf(fid103,'%f\n', meanfitness);%fprintf( fid11,'\nthe best decimal space(x1 x2 x3...):\n');fprintf( fid104,'%f\n',best_decimal_space );fprintf( fid105 , '%f\n' , best_coding_space );%fprintf( fid12, '\nthe generation number when end GAs:\n' );fprintf( fid106, '%f\n' , now_generation );fprintf( fid107, '%f\n' , now_probability_crossover );%close filesstatus = fclose( 'all' ); SGALAB_output_info % timer endtoc% SGALAB_demo_MO_muGA End
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -