• 沒有找到結果。

ӵҡސၥଉሴ୿ϛȂငலю౪NP-hard ୰ᚠȂоЅሯौσ໔ၥਟ೎౩ޟ୰

ᚠȄӰԪȂငலሯौૉາ೨ӻॎᆗਢ໢ᇄ଄ᏹᓽԆު໢Ȅ࣏Οᅖٗ೻ٲሯؑȂϷ ඹԒ೎౩ޟճԙҏȃଽॎᆗ૖໔ᇄ଄ᏹު໢ޟϷඹᓽԆ้੫ܒȂխн࢐௰ଢ଼ҡސ ၥଉޟंـᇄᔖҢޟശٹᒵᐅȄ

ี৤DDP ޟ GA แԒȂ࢐רঈंـҡސၥଉሴ୿ޟ಑Ι؏ȄڏҬޟ࢐הఖ ᙤҥ೻ԩޟკၐȂี௨ҡސၥଉޟϷඹԒ೎౩ӵ฽ᡝȃ೺ᡝᕗცܖᅋᆗݲϚٗϞ

೎Ȃоୈ࣏Ґپี৤ޟஅᙃᇄငᡛȄᄇܻРࡣޟี৤Ȃҏ፣Мඪюоή࡚ដȈ

6-1 計算大量人口的分散式系統

ԃ5-3-1 ܚक़ȂΡοஅӰޟӻኺܒ࢐ёഀᅋϽଢ଼ΨپྛϞΙȂ࢈ቨёΡοኵ ໔૖ёഀᅋϽȄծ࢐Ⴋသॎᆗ໔ོᓍ๿Ροኵ໔ቨёՄᡐσȂؑ၌ഀ࡙Ϛَுོ

ᡐפȄषี৤ϷඹԒفಛȂ஠σ໔ΡοϷඹڗυفಛॎᆗȂᔖ၎૖၌ؚ೻এ୰ᚠȄ ϷඹԒհཾᕗცȂڏ೺ᡝᕗცശலَޟMPI ᇄ PVM فಛȄPVM فಛඪټ к჊(master-slave)ϷඹԒ೎౩ޟ࢜ᄺȄߨலᎌӫี৤ϷඹԒ GAȄڏϛк՗แ (master process)џо॒೰౰ҡଔۖΡοȃ௃ӒഋΡοϛᒵᐅ଩ᆍфߒᇄоཱིҡф ڥф଩ᆍфߒоѴޟഋϷএᡝ้ώհȇ჊՗แ(slave process)џо॒೰ॎᆗഋϷএ ᡝޟᎌᔖڒኵ঄ȃஅӰҺ඲ȃஅӰएᡐ้ώհȄкȃ჊՗แϞ໢ޟၥਟ೽ଉȂџ оٺҢPVM ޟ༈ଚ(send)ᇄ௥ԝ(receive)ࡾхׇԙȄ૭஠кȃ჊՗แޟຎᔣแԒ ጆ(pseudo code)Ϸտਪቸܻყ 12 ᇄყ 13Ȅ

Procedure master

Generate initial population.

For I = 1 to NG do /* NG is the number of generations */

Send 1/n of individuals to each slave. /* n is the number of slaves */

Receive the fitness values of the individuals from slaves.

Select a given number pairs of individuals from the population.

Send 1/n of selected pairs of individuals to each slave.

Receive individuals from slaves. /* genetic operators are applied */

Select other individuals at random and replace them.

End For

Output the fittest individual as the answer.

End master

ყ12Ȉॎᆗσ໔ΡοޟϷඹԒفಛк՗แޟຎᔣแԒጆ

Procedure slave

Receive individuals from master.

Compute the fitness value for each individual.

Send the fitness values to master.

Receive the pairs of individuals from master.

Apply the crossover operator to the pairs of individuals.

Apply the mutation operator to individuals randomly.

Send these individuals to master.

End slave

ყ13Ȉॎᆗσ໔ΡοޟϷඹԒفಛ჊՗แޟຎᔣแԒጆ

6-2 育種式的分散式系統

ԤᠧܻىᆍџоԤਝёפᅋϽഀ࡙Ȃҏ፣МඪюѪΙᆍϷඹԒفಛ࢜ᄺȂ஠

ىᆍ྅܈ઽΣ೩ॎȄแԒ೩ॎϛ჊՗แџׇӒᐿҳᅋϽȂ౰ҡଔۖΡοȃॎᆗএ ᡝޟᎌᔖڒኵ঄ȃᒵᐅ଩ᆍфߒȃஅӰҺ඲ȃஅӰएᡐȃоཱིҡфڥф଩ᆍфߒȄ ӵк՗แϛёΣىᆍԱȂ஠჊՗แϛޟᓺؾΡο໱ϛܻԪȂк՗แޟߑۖΡο൷ پՌىᆍԱȂؐфᅋϽ഍్؜ܚԤߨ଩ᆍфߒΡοȂ၄шоىᆍԱϱޟΡοȄყ 14 ࣏ىᆍԒϷඹفಛޟҰཎყȄყ 15 ᇄყ 16 ࣏кȃ჊՗แޟຎᔣแԒጆȄ

ყ14ȈىᆍԒϷඹفಛҰཎყ

Procedure master

Send a start command to each slave.

Receive individuals from every slave, store them into the breeding pool.

When all the salves’ generation no. are more than SNG, begin following steps:

/* SNG is a specific value which represents the no. of generation of the slaves */

Generate the initial populations from the breeding pool.

For I = 1 to NG do /* NG is the number of generations */

Compute the fitness value for each individual.

Select a given number pairs of individuals from the population as parents.

Apply the crossover operator to the pairs of individuals.

Apply the mutation operator to individuals randomly.

Eliminate the non-parent individuals and resupply from the breeding pool.

End For

Output the fittest individual as the answer.

Send a stop command to each slave.

End master

ყ15ȈىᆍԒޟϷඹԒفಛк՗แޟຎᔣแԒጆ

Procedure slave

Receive start command from master.

Generate initial population.

Repeat the following procedures until the stop command from master Compute the fitness value for each individual.

Select a given number pairs of individuals from the population.

Apply the crossover operator to the pairs of individuals.

Apply the mutation operator to individuals randomly.

Select other individuals at random and replace them.

Send the best Ns individuals to master’s breeding pool.

/* Ns is a specific value which represents the no. of super individuals */

Send the generation no. to master.

End slave

ყ16ȈىᆍԒޟϷඹԒفಛ჊՗แޟຎᔣแԒጆ

參考文獻

1. A.V. Grigorjev, A.A. Mironov, Mapping DNA by Stochastic Relaxation: A New Approach to Fragment Sizes, Applic. Biosci., pp. 107-111.

2. D. H. Ballard. An Introduction to Natural Computation. The MIT Press, 1997.

3. Davis L., Handbook of genetic algorithms. Van Nostrand Reinhold. 1991.

4. E. Southern. United Kingdom patent application GB8810400. 1988.

5. H.O. Smith and K.W. Wilcox, A restriction enzyme form Hemophilus in fluenzae.

I. P urification and general properties. Journal of Molecular Biology, pp. 51:

379 - 391, 1970.

6. J. Setubal and J. Meidanis. Introduction to Computational Molecular Biology.

PWS Pub lishing Company, 1997.

7. J. Holland. Adaption in Natural and Artificial Systems. The University of Michigan Press, 1975.

8. K.F. Man, K.S. Tang and S. Kwong, Genetic Algorithms Concepts and Designs, Springer-Verlag London Limited, 1999.

9. K.J. Danna, G.H. Sack, and D. Nathans. Studies of simian virus 40 DNA. VII. A cleavage map of the SV40 genome. Journal of Molecular Biology, pp. 78:263 - 276, 1973.

10. L. Goldstein and M. S. Waterman. Mapping DNA by stochastic relaxation.

Advances in Applied Mathematics, pp. 8:194-207, 1987.

11. L.W. Wright, J.B. Lichter, J. Reinitz, M.A. Shifman, K.K. Kidd, and P.L. Miller, Computer-Assisted Restriction Mapping: An Integrated Ap proach to Handling Experimental Uncertainty, CABIOS, Vol. 10, No. 4, pp. 443-450, 1994.

12. M. Krawczak, Algorithms for the Restriction-Site Mapping of DNA Molecules, Proc. Natl. Acad. Sci. USA, 85, pp. 7298-7301, 1988.

13. M. Stefik, Inferring DNA Structures from Segmentation Data, Artif. Intell., 11, pp. 85-114, 1978.

14. M.S. Waterman, Introduction to Computational Biology: Sequences, Maps, and Genomes, Chapman Hall, page 78, 1995.

15. Ming-Yang Kao, Jared Samet, and Wing-Kin Sung. The Enhanced Double Digest Problem for DNA Physical Mapping. Proceedings of the 9th

Scandinavian Workshop on Algorithm Theory (SWAT 2000), 383--392, 2000.

16. P. Tuffery, P.Dessen, C. Mugnier, and S. Hazout, Restriction Map Construction Using Complete Sentences Compatibility Algorithm, Comput. Applic. Biosci., 4, pp. 103-110,1988.

17. Venter JC, Adams MD, Myers EW, et al. The sequence of the human genome, Science, 291, pp. 1304-1351, 2001.

18. W. R. Pearson. Automatic Construction of Restriction Site Maps, Nucleic Acids Res., 10, pp. 217-227, 1984.

19. W. Schmitt and M.S. Waterman, Multiple Solutions of DNA Restriction Mapping Problems, Adv. Appl. Math., 12, pp. 412-427, 1991.

20. W.M. Fitch, T.F. Smith, and W.W. Ralph, Mapping the Order of DNA Restriction Fragments, Gene, 22, pp. 19-29, 1983.

21. Yanhua Peng, Fuhua Yang, Yipeng Qi, Yongxin Huang, Location, Sequence and Promoter Structure of Apoptosis-Inhibiting Gene of Leucania seperate Nuclear Polyhedrosis Virus, VIROLOGICA SINICA, No.1 vol.14 1999.

22. Yin Zhang and Zhijun Wu, Solving the Double Digestion Problem as a Mixed-Integer Linear Program, Technical Report (TR), Technical Report TR01-12, Department of Computational and Applied Mathematics, Rice University, 2001.

23. Z. Michalewicz. Genetic Algorithms + Data Structures = Evolution Programs.

Third Edition. Springer, 1996.

附錄一

甲組:

n = 16

乙組:

n = 30

丙組:

n = 100

有最佳解 繁殖世代數 執行時間 有最佳解 繁殖世代數 執行時間 有最佳解 繁殖世代數 執行時間

Yes 54 281.05 No 301 5590.8 No 301 29865.4 Yes 27 137.65 Yes 89 1662.6 No 301 23089.4

Yes 18 92.393 No 301 5534.9 No 301 23032.3 Yes 31 160.44 No 301 5585.3 No 301 25189.5 No 101 514.02 No 301 5569.1 No 301 24827.1 Yes 55 283.06 No 301 5884.4 No 301 24360.9 Yes 22 111.87 No 301 5387.7 No 301 23036.4 Yes 33 166.68 No 301 5417.2 No 301 23560.1 Yes 66 337.38 No 301 5323.9 No 301 24966.2 Yes 38 196.22 No 301 5365.2 No 301 25823.8 Yes 28 142.38 No 301 5417.3 No 301 23068.3 Yes 19 95.808 No 301 5400.5 No 301 25139.7 Yes 32 163.78 Yes 170 3078.1 No 301 25628.3 Yes 21 106.4 No 301 5436.6 No 301 25633.9 Yes 72 368.81 No 301 5337.2 No 301 24438.9 Yes 59 303.17 Yes 251 2896.5 No 301 24808.4 Yes 92 473.69 Yes 251 2925.9 No 301 25486.9 Yes 70 353.62 Yes 251 2995.7 No 301 25950.7 Yes 17 85.383 Yes 251 2895.7 No 301 23953.2 Yes 19 97.18 Yes 251 2877.4 No 301 24241.1 Yes 40 199.69

Yes 30 151.47 Yes 9 42.862 Yes 33 168.51 Yes 20 102.13 Yes 93 480.58 Yes 38 195.79 Yes 53 270.44 Yes 28 142.86 Yes 68 350.92 Yes 62 316.07 Yes 39 201.66 Yes 35 177.83 Yes 44 250.29 Yes 54 289.03 Yes 34 175.5 Yes 46 239.09 Yes 32 164.61 Yes 22 113.35 Yes 26 134.48 Yes 44 227.53 Yes 7 32.737 Yes 38 198.01 Yes 4 17.576

No 101 505.84 Yes 43 221.02 Yes 42 216.35 Yes 16 79.995 Yes 21 106.93 Yes 61 313.2 Yes 28 142.43 Yes 40 204.52 Yes 55 281.45 Yes 56 286.85 Yes 47 244.72 Yes 4 17.626

附錄二

無育種機制:

n =16

有最佳解 繁殖世代數 執行時間

Yes 43 47.328 Yes 97 108.27 No 101 112.24 Yes 61 68.389 Yes 26 29.392 Yes 73 80.976 Yes 64 72.094 Yes 70 78.003 Yes 56 62.63 Yes 77 84.822 No 101 111.76 Yes 48 53.227 Yes 34 37.995 No 101 111.17 No 101 109.81 No 101 124.16 No 101 114.05 No 101 107.8 Yes 15 17.285

No 101 113.32 Yes 58 65.725 Yes 97 107.86 No 101 112.19 No 101 111.1 Yes 9 10.205

No 101 113.83 Yes 55 62.83 Yes 25 27.82 Yes 53 59.285 No 101 110.7 Yes 85 94.256

No 101 111.09 No 101 111.16 Yes 98 108.72

No 101 110.99 Yes 22 24.666 Yes 79 87.366 Yes 87 95.137 Yes 51 57.552 Yes 6 6.78 Yes 26 29.332 Yes 53 60.657 No 101 111.16 Yes 54 60.266 Yes 20 22.893 Yes 79 88.187 Yes 25 28.331 No 101 112.81 Yes 87 98.341 Yes 27 30.894 Yes 70 78.833 Yes 84 93.935 Yes 60 66.125 No 101 110.54 Yes 81 89.81 Yes 17 19.218

附錄三

1. run.m 主程式

2. GA_for_DDP 基因演算法主程式。以巨集方式描述,由 run.m 主程式呼叫。

3. add_terminator_to_population 將最佳基因與優秀人口加入下一代人口中。

4. breeding.m 繁殖程式(基因交換與突變)。

5. check_repeat.m 巨集-檢查是否為重複向量。

6. clean_matrix.m 刪除人口矩陣內重複的向量。

7. clean_polymophism.m 刪除同值異形向量。

8. clean_zero.m 去掉第一個元素值為零的向量。

9. clean_matrix.m 刪除矩陣中重複的列。

10. crossover.m 染色體交換。

11. eliminate_population.m 淘汰非配種代表。

12. fitness.m 計算適應度值向量。

13. func_value_of_fittness.m 計算每一人口的適應度值。

14. GA_AB_FLA.m 依據 A_SEV 與 B_SEV 向量,計算出對應的 double digest 片段長度向量。

15. gene2road.m 由向量排列基因片段。

16. initial_population.m 產生初始人口。

17. limit_population_no.m 世代交替,維持人口數目 (如果人口數超過人口上 限數,就淘汰適應值低者,直到人口數不超過人口上限)。

18. mutation.m 突變。

19. Noah_ark.m 消滅同質異形的人口,只保留一個同質代表。

20. restriction_map.m 排列出限制輿圖。

21. select_best_gene.m 挑選最佳基因並刪除重複者。

22. select_parent.m 挑選配種代表。

23. select_terminator.m 挑選出優秀人口並刪除重複者。

24. SEV2FO.m 將含基礎參數擴充基因向量(SEV)轉換成片段長度序列。

25. SEV2ROAD.m 將擴充基因向量轉換成片段排列。

26. size2FLA.m 指定一個數字以產生成片段長度集合。

27. size2SEV.m 指定一個數字以產生成擴充基因向量。

28. update_terminator.m 篩選優秀人口。

% 1. DDP-GA 主程式 clear all;

format short;

load GA_DATA;

% 宣告全域變數

% =========================================================================

global total_fregment_length; % <--- DNA 總長 global A_FLA; % <--- A 片段長度集合 global B_FLA; % <--- B 片段長度集合 global AB_FLA; % <--- A+B 片段長度集合 global length_of_A_FLA; % <--- --- A 片段數量 global length_of_B_FLA; % <--- B 片段數量 global length_of_AB_FLA; % <--- A+B 片段數量 global S_crossover_probability; % <--- 基本參數 2 ===> 交換基礎序號之機率 global mutation_probability; % <--- 基本參數 3 ===> 基因突變之機率 global max_fittness; % <--- 最大適應度值 global no_of_terminator; % <--- 繁殖池人口數 global mark_of_to_be_parent; % <--- 選為配種代表標記

global ratio_of_terminator_to_population; % < 基本參數 6 ====> 繁殖池人口占總人口數目的比例上 限

%==============================================================================

ratio_to_be_parent=0.8; % <--- 基本參數 1 ===> 繁殖人口中挑出來當親代的比例 S_crossover_probability=0.01; % <--- 基本參數 2 ===> 交換基礎序號之機率

mutation_probability=0.03; % <--- 基本參數 3 ===> 基因突變之機率 initial_population_no=200; % <--- 基本參數 4 ===> 初始人口數目 uplimit_of_population=200; % <--- 基本參數 5 ===> 人口上限

ratio_of_terminator_to_population=0.3;% <--- 基本參數 6 ==> 繁殖池人口占總人口數目的比例上限 total_generation=100; % <--- 基本參數 7 ==> 繁殖世代上限

% 宣告變數 ===============================================================

value_of_fittness=0;

value_of_fittness_of_terminator=0;

terminators=zeros(1,length_of_A_FLA+length_of_B_FLA+2);

best_gene=zeros(1,1);

average_of_population=0;

average_of_terminator=0;

lowest_of_terminator=0;

no_of_population=0;

no_of_generation=1;

no_of_terminator=0;

no_of_best_gene=0;

% (1) 產生初始人口======================================================

populations=initial_population(initial_population_no);

%======================================================================

save run;

analysis_of_GA=zeros(1,length_of_A_FLA+length_of_B_FLA+2);

analysis_generation=zeros(1,2);

total_no_of_best_gene=0;

for run_no=1:57 tic

GA_for_DDP run_time=toc

[no_of_best_gene temp]=size(best_gene);

for i=1:no_of_best_gene

analysis_of_GA(total_no_of_best_gene+i,:)=best_gene(i,:);

end

total_no_of_best_gene=total_no_of_best_gene+no_of_best_gene;

analysis_of_generation(run_no,1)=no_of_generation;

analysis_of_generation(run_no,2)=run_time;

analysis_of_generation(run_no,3)=no_of_best_gene;

save analysis analysis_of_GA analysis_of_generation run_no total_no_of_best_gene clear all

load run load analysis populations=LALA run_no

end

save ANALYSIS_OF_DDP

% 2. GA_for_DDP GA 主程式。以巨集方式描述,由 run.m 主程式呼叫

while (no_of_generation<=total_generation), %(3) 計算每一人口的適應度

value_of_fittness=func_value_of_fittness(populations);

value_of_fittness_of_terminator=func_value_of_fittness(terminators);

%===================================================================

average_of_population=mean(value_of_fittness);

average_of_terminator=mean(value_of_fittness_of_terminator);

% (4) 挑選出優秀人口並刪除重複者。當優秀人口到達上限時,刪除同型異質基因。

terminators=select_terminator(value_of_fittness_of_terminator,terminators,value_of_fi ttness,populations);

% (4.5) 挑選最佳基因並刪除重複者

best_gene=select_best_gene(no_of_generation,value_of_fittness,populations);

% 如果找到答案就跳出來==============

if best_gene(1,1)~=0 break;

end

%===================================

[no_of_population temp]=size(populations);

% (6) 挑選配種代表

parents=select_parent(value_of_fittness,populations,ratio_to_be_parent);

% (7)(8) 基因交換與突變

new_generation=breeding(populations,parents);

% (9) 淘汰未配種的基因

populations=eliminate_population(new_generation,populations,parents);

% (10) 將優秀人口加入下一代人口中,最佳基因要先加進去

populations=add_terminator_to_population(best_gene,terminators,populations);

% (11) 世代交替,維持人口數目 (如果人口數超過人口上限數,就淘汰適應值低者,直到人口數不超過人口上限 '

populations=limit_population_no(populations,uplimit_of_population);

%=========================================================================

% 顯示每一代的數據

[no_of_population temp]=size(populations);

[no_of_best_gene temp]=size(best_gene);

if best_gene(1,1)==0 no_of_best_gene=0;

end

[int32(no_of_generation) int32(no_of_population) int32(no_of_terminator) int32(no_of_best_gene)]

a=average_of_population/max_fittness;

b=average_of_terminator/max_fittness;

[a b]

aaa(no_of_generation,1)=average_of_population/max_fittness;

aaa(no_of_generation,2)=average_of_terminator/max_fittness;

aaa(no_of_generation,3)=max(value_of_fittness)/max_fittness;

%===============================================================================

no_of_generation=no_of_generation+1;

end

% 3. 將最佳基因與優秀人口加入下一代人口中 ========================

function

populations=add_terminator_to_population(best_gene,terminators,old_populations);

global no_of_terminator;

[no_of_population temp]=size(old_populations);

[no_of_terminator temp]=size(terminators);

[no_of_best_gene temp]=size(best_gene);

if (terminators(1,1)~=0) & ~(isempty(terminators)) %有優秀人口才加上去 for i=1:no_of_terminator

old_populations(no_of_population+i,:)=terminators(i,:);

end end

[no_of_population temp]=size(old_populations);

if (best_gene(1,1)~=0) & ~(isempty(best_gene)) %有最佳基因才加上去 for i=1:no_of_best_gene

old_populations(no_of_population+i,:)=best_gene(i,:);

end end

[row_size temp]=size(old_populations);

old_populations=sortrows(old_populations);

% 去掉都為 0 的列 zero_row=1;

while old_populations(zero_row,1)==0, zero_row=zero_row+1;

end

populations=old_populations(zero_row:row_size,:);

if isempty(terminators) terminators=0;

end

% 4. 繁殖程式(基因交換與突變)

function new_generation=breeding(populations,parents);

global length_of_A_FLA;

global length_of_B_FLA;

[parent_couple temp]=size(parents);

for i=1:parent_couple

% 基因交換 ====================================

A_SEV1=populations(parents(i,1),1:length_of_A_FLA+1);

A_SEV2=populations(parents(i,2),1:length_of_A_FLA+1);

[crossover_A_SEV1,crossover_A_SEV2]=crossover(A_SEV1,A_SEV2);

B_SEV1=populations(parents(i,1),length_of_A_FLA+2:length_of_A_FLA+length_of_B_FLA+2);

B_SEV2=populations(parents(i,2),length_of_A_FLA+2:length_of_A_FLA+length_of_B_FLA+2);

[crossover_B_SEV1,crossover_B_SEV2]=crossover(B_SEV1,B_SEV2);

% 基因突變 ==================================

mutation_A_SEV1=mutation(crossover_A_SEV1);

mutation_A_SEV2=mutation(crossover_A_SEV2);

mutation_B_SEV1=mutation(crossover_B_SEV1);

mutation_B_SEV2=mutation(crossover_B_SEV2);

% ++++++++++++++++++++++++++++++++++++++++++

new_generation(i,1:length_of_A_FLA+1)=mutation_A_SEV1;

new_generation(i,length_of_A_FLA+2:length_of_A_FLA+length_of_B_FLA+2)=mutation_B_SEV1

;

new_generation(i+parent_couple,1:length_of_A_FLA+1)=mutation_A_SEV2;

new_generation(i+parent_couple,length_of_A_FLA+2:length_of_A_FLA+length_of_B_FLA+2)=m utation_B_SEV2;

end

% 5. 巨集-檢查是否為重複向量 check_repeat = 0;

for ii=2:7;

for jj=1:ii-1

if balls(ii)==balls(jj) check_repeat =1;

end end end

──────────────────────────────────

% 6. 刪除人口矩陣內重複的向量

function matrix=clean_matrix(old_matrix) [row_size column_size]=size(old_matrix);

if row_size<=1

matrix=old_matrix;

return;

old_matrix=sortrows(old_matrix);

% 去掉都為 0 的列 zero_row=1;

while old_matrix(zero_row,1)==0, zero_row=zero_row+1;

end

old_matrix=old_matrix(zero_row:row_size,:);

[row_size column_size]=size(old_matrix);

new_matrix=zeros(1,column_size);

new_matrix(1,:)=old_matrix(1,:);

is_the_same=zeros(row_size,1);

j=2;i=1;

while i<row_size while j<=row_size

if mean(new_matrix(i,:)==old_matrix(j,:))==1 j=j+1;

if j>row_size break;

end else

new_matrix(i+1,:)=old_matrix(j,:);

i=i+1;

end end

if j>row_size break;

end end

matrix=new_matrix;

──────────────────────────────────

% 7. 去掉同值異形向量

function cleaned_gene=clean_polymophism(gene) global length_of_A_FLA;

global length_of_B_FLA;

global A_FLA;

global B_FLA;

[no_of_gene column_no]=size(gene);

gene_FO_index=zeros(no_of_gene,length_of_A_FLA+length_of_B_FLA+1);

for i=1:no_of_gene

A_SEV=gene(i,1:length_of_A_FLA+1);

B_SEV=gene(i,length_of_A_FLA+2:length_of_A_FLA+length_of_B_FLA+2);

A_FO=SEV2FO(A_SEV,A_FLA);

B_FO=SEV2FO(B_SEV,B_FLA);

gene_FO_index(i,1:length_of_A_FLA)=A_FO;

gene_FO_index(i,length_of_A_FLA+1:length_of_A_FLA+length_of_B_FLA)=B_FO;

gene_FO_index(i,length_of_B_FLA+length_of_B_FLA+1)=i;

end

gene_FO_index=sortrows(gene_FO_index);

flag1=1;

flag2=2;

flag3=1;

index_of_reserve(1)=1;

while flag2<=no_of_gene, if

mean(gene_FO_index(flag1,1:length_of_A_FLA+length_of_B_FLA)==gene_FO_index(flag2,1:le ngth_of_A_FLA+length_of_B_FLA))==1

flag2=flag2+1;

else

flag1=flag2;

flag2=flag2+1;

flag3=flag3+1;

index_of_reserve(flag3)=flag1;

end end

no_of_cleaned_gene=length(index_of_reserve);

for i=1:no_of_cleaned_gene

cleaned_gene(i,:)=gene(index_of_reserve(i),:);

end

% 8. 去掉第一個值為零的向量

function new_matrix=clean_zero(old_matrix) [row_size column_size]=size(old_matrix);

row_of_new_matrix=0;

new_matrix=zeros(1,column_size);

for i=1:row_size

if old_matrix(i,1)~=0

row_of_new_matrix=row_of_new_matrix+1;

new_matrix(row_of_new_matrix,:)=old_matrix(i,:);

end end

% 9. 刪除矩陣中重複的列

function new_matrix=clear_matrix(old_matrix) [row_size column_size]=size(old_matrix);

old_matrix=sortrows(old_matrix);

new_matrix(1,:)=old_matrix(1,:);

is_the_same=zeros(row_size,1);

j=2;i=1;

while i<row_size while j<=row_size

if mean(new_matrix(i,:)==old_matrix(j,:))==1 j=j+1;

if j>row_size break;

end else

new_matrix(i+1,:)=old_matrix(j,:);

i=i+1;

end end

if j>row_size break;

end end end

% 10. 染色體交換

function [crossover_SEV1,crossover_SEV2]=crossover(SEV1,SEV2) global S_crossover_probability

% (0)

crossover_point=0;

n=length(SEV1);

while crossover_point==0,

crossover_point=ceil(n*rand)-1;

end

% (1)

crossover_SEV1=SEV1;

crossover_SEV2=SEV2;

for i=crossover_point+2:n crossover_SEV1(i)=SEV2(i);

crossover_SEV2(i)=SEV1(i);

end

% (2)

if S_crossover_probability==0

else if abs(double((rand-0.5)))/S_crossover_probability<=0.5 crossover_SEV1(1)=SEV2(1);

crossover_SEV2(1)=SEV1(1);

end end

% 11. 淘汰非配種代表==========================

function populations=eliminate_population(new_generation,old_populations,parents);

global length_of_A_FLA;

global length_of_B_FLA;

global mark_of_to_be_parent;

[no_of_population temp]=size(old_populations);

[parent_couple temp]=size(parents);

j=1;

next_generation=zeros(1,length_of_A_FLA+length_of_B_FLA+2);

for i=1:no_of_population

if mark_of_to_be_parent(i)>0

next_generation(j,:)=old_populations(i,:);

j=j+1;

end end

n=2*parent_couple;

[nextone temp]=size(next_generation);

for i=1:n

next_generation(nextone+i,:)=new_generation(i,:);

end

clear populations;

populations=next_generation;

% 12. 計算適應度值向量

function fittness_value=fittness(A_SEV,B_SEV) global A_FLA;

global B_FLA;

global AB_FLA;

global length_of_AB_FLA;

% (1)

if mean(A_SEV)==0 fittness_value=0;

return;

end

comp_AB_FLA=GA_AB_FLA(A_SEV,B_SEV);

% (2)

flag1=1;flag2=1;fittness_value=0;

length_of_comp_AB_FLA=length(comp_AB_FLA);

while (flag1<=length_of_AB_FLA)&(flag2<=length_of_comp_AB_FLA), if AB_FLA(flag1)>comp_AB_FLA(flag2)

flag2=flag2+1;

else if AB_FLA(flag1)<comp_AB_FLA(flag2) flag1=flag1+1;

else

fittness_value=fittness_value+1;

flag1=flag1+1;

flag2=flag2+1;

end end end

% (3)

fittness_value=fittness_value*fittness_value;

% 13. 計算每一人口的適應度值

function value_of_fittness=func_value_of_fittness(populations) global length_of_A_FLA;

global length_of_B_FLA;

if populations(1,1)==0 value_of_fittness=0;

return;

end

for i=1:no_of_population

A_SEV=populations(i,(1:length_of_A_FLA+1));

B_SEV=populations(i,length_of_A_FLA+2:length_of_A_FLA+length_of_B_FLA+2);

value_of_fittness(i)=fittness(A_SEV,B_SEV);

end

% 14. 此函數會依據 A_SEV 與 B_SEV 向量,計算出對應的 double digest 片段長度向量 function comp_AB_FLA=GA_AB_FLA(A_SEV,B_SEV)

global A_FLA;

global B_FLA;

global length_of_A_FLA;

global length_of_B_FLA;

% (1)

A_FO=SEV2FO(A_SEV,A_FLA);

B_FO=SEV2FO(B_SEV,B_FLA);

length_of_A_FO=length_of_A_FLA;

length_of_B_FO=length_of_B_FLA;

AB_mile_stone=zeros((length_of_A_FO+length_of_B_FO),1);

% (2) temp=0;

for i=1:length_of_A_FO A_FO(i)=temp+A_FO(i);

temp=A_FO(i);

end temp=0;

for i=1:length_of_B_FO B_FO(i)=temp+B_FO(i);

temp=B_FO(i);

end

% (3)

for i=1:(length_of_A_FO) AB_mile_stone(i)=A_FO(i);

end

for i=1:(length_of_B_FO)

AB_mile_stone(length_of_A_FO+i)=B_FO(i);

end

% (4)

AB_mile_stone=sort(AB_mile_stone);

% (5) j=1;i=2;

comp_AB_FLA(1)=AB_mile_stone(1);

n=length_of_A_FO+length_of_B_FO;

while i<=n,

if AB_mile_stone(j)==AB_mile_stone(i);

i=i+1;

else j=j+1;

comp_AB_FLA(j)=AB_mile_stone(i);

i=i+1;

end end

% (6)

temp=comp_AB_FLA;

n=length(comp_AB_FLA);

for i=2:n

comp_AB_FLA(i)=temp(i)-temp(i-1);

end

% (7)

comp_AB_FLA=sort(comp_AB_FLA);

no_of_comp_AB_FLA=length(comp_AB_FLA);

i=1;

while comp_AB_FLA(i)==0, i=i+1;

end

temp=comp_AB_FLA(i:no_of_comp_AB_FLA);

clear comp_AB_FLA;

comp_AB_FLA=temp;

% 15. 由向量排列基因片段

function AB_road=gene2road(gene)

global length_of_A_FLA;

global length_of_B_FLA;

global A_FLA;

global B_FLA;

A_SEV=gene(1:length_of_A_FLA+1);

B_SEV=gene(length_of_A_FLA+2:length_of_A_FLA+length_of_B_FLA+2);

A_road=SEV2ROAD(A_SEV,A_FLA);

B_road=SEV2ROAD(B_SEV,B_FLA);

AB_road=[A_road B_road];

AB_road=sort(AB_road);

no_of_milestone=length(AB_road);

flag1=1;

flag2=2;

milestone=zeros(no_of_milestone,1);

milestone(1)=1;

while flag2<=no_of_milestone

if AB_road(flag1)==AB_road(flag2) flag2=flag2+1;

else

flag1=flag2;

milestone(flag1)=1;

flag2=flag2+1;

end end

flag1=1;

for i=1:no_of_milestone if milestone(i)==1

temp(flag1)=AB_road(i);

flag1=flag1+1;

end end

clear AB_road;

AB_road=temp;

% 16. 產生初始人口

function populations=initial_population(initial_population_no) global A_FLA;

global B_FLA;

global length_of_A_FLA;

global length_of_B_FLA;

length_of_A_SEV=length_of_A_FLA+1;

length_of_B_SEV=length_of_B_FLA+1;

% (2)

populations=zeros(2*initial_population_no,(length_of_A_SEV+length_of_B_SEV));

% (3)

相關文件