青青草原综合久久大伊人导航_色综合久久天天综合_日日噜噜夜夜狠狠久久丁香五月_热久久这里只有精品

posts - 12,  comments - 54,  trackbacks - 0
基因交叉,或者基因重組,就是把兩個父體部分結構加以替換,生成新的個體的操作,習慣上對實數編碼的操作叫做重組(Recombination),對二進制編碼的操作稱為交叉(crossover)。

比較常用的一些算法介紹如下:
1. 重組算法(Recombination)
 實值重組產生子個體一般是用下邊這個算法:
 子個體=父個體1 + a × ( 父個體2 - 父個體1 )
這里a是一個比例因子,可以由[ -d, 1+d] 上邊服從均勻分布的隨機數產生。
不同的重組算法,a的取值是不同的,一般來講,d=0.25是一個比較好的選擇。
下邊一段c++代碼片斷,實現一個中值重組算法,其中d取值為0。

 1 /*
 2 Gene Crossover Algorithm
 3 Linear Recombination Xover Algorithm
 4 
 5 A crossover operator that linearly combines two parent
 6 chromosome vectors to produce two new offspring a
 7 ccording to the following equations:
 8 
 9 Offspring1 = a * Parent1 + (1- a) * Parent2
10 Offspring2 = (1 – a) * Parent1 + a * Parent2
11 
12 
13 where a is a random weighting factor (chosen before each
14 crossover operation).
15 
16 Consider the following 2 parents (each consisting of 4
17 float genes) which have been selected for crossover:
18 
19 Parent 1: (0.3)(1.4)(0.2)(7.4)
20 Parent 2: (0.5)(4.5)(0.1)(5.6)
21 
22 If a = 0.7, the following two offspring would be produced:
23 
24 Offspring1: (0.36)(2.33)(0.17)(6.86)
25 Offspring2: (0.402)(2.981)(0.149)(6.842)
26 */
27 template< class GENE >
28 class Intermediate_Recombination_Gene_Crossover_Algorithm
29 {
30     public:
31             void operator()( GENE& g1, GENE& g2 )const
32             {
33                 assert( g1.Upper == g2.Upper );
34                 assert( g1.Lower == g2.Lower );
35 
36                 const long double Ran = ran();
37                 const long double sum = g1.Value + g2.Value;
38 
39                 if ( sum < g1.Upper )
40                 {
41                     g1.Value = Ran * sum;
42                     g2.Value = sum - g1.Value;
43                 }
44                 else
45                 {
46                     const long double sub = 2.0L * g1.Upper - sum;
47                     g1.Value = g1.Upper - sub * Ran;
48                     g2.Value = g1.Upper - sub + sub * Ran;
49                 }
50             }
51 };

2.  交叉算法
如上文遺傳算法中的數據結構中所講,基因的二進制編碼有直接編碼(Normal)和Gray編碼之分,以下所說算法,均適用于這兩種算法。

假設基因的二進制編碼長度為N,那么這些編碼之間有N-1個空隙,可供交叉使用。
二進制交叉算法就是
如何選擇空隙,選擇多少個空隙。
以下將各走極端的選擇一個空隙交叉的單點交叉算法,和選擇N-1個空隙進行交叉的洗牌交叉算法大致說一下。

(1) 單點交叉
在二進制編碼中,隨機選擇一個點,以這個點為界限,相互交換變量。

父個體1      011111110000000000
父個體2      000000001111111111
如粗體前邊位置為所選擇的交叉點,那么生成的子個體為:
子個體1      011111111111111111
子個體2      000000000000000000
以下為c++實現,采用Gray編碼,直接編碼的類似。
 1 /*
 2 Gene crossover algorithm
 3 One Point Crossover using Gray binary encoding
 4 
 5 A crossover operator that randomly selects a crossover point
 6 within a chromosome then interchanges the two parent chromosomes
 7 at this point to produce two new offspring.
 8 
 9 Consider the following 2 parents which have been selected for
10 crossover. The “|” symbol indicates the randomly chosen
11 crossover point.
12 
13 Parent 1: 11001|010
14 Parent 2: 00100|111
15 
16 After interchanging the parent chromosomes at the crossover
17 point, the following offspring are produced:
18 
19 Offspring1: 11001|111
20 Offspring2: 00100|010
21 */
22 template< class GENE >
23 class Gray_Binary_Single_Point_Xover_Gene_Crossover_Algorithm
24 {
25     public:
26             void operator()( GENE& g1, GENE& g2 )const
27             {
28                 encoding( g1 );
29                 encoding( g2 );
30                 assert( g1.Binary_Array.size() == g2.Binary_Array.size() );
31 
32                 normal2gray( g1 );
33                 normal2gray( g2 );
34 
35                 const unsigned int Pos = static_cast<unsigned int>
36                                 ( g1.Binary_Array.size() * ran() );
37 
38                 for ( unsigned int i = 0; i < Pos; ++i )
39                 {
40                     if ( g1.Binary_Array[i] xor g2.Binary_Array[i] )
41                     {
42                         if ( g1.Binary_Array[i] )
43                             {
44                                 g1.Binary_Array[i] = 0;
45                                 g2.Binary_Array[i] = 1;
46                             }
47                             else
48                             {
49                                 g1.Binary_Array[i] = 1;
50                                 g2.Binary_Array[i] = 0;
51                             }
52                     }
53                 }
54 
55                 gray2normal( g1 );
56                 gray2normal( g1 );
57                 decoding( g1 );
58                 decoding( g2 );
59             }
60 };
61 
62 
63 

(2)洗牌交叉
洗牌交叉就是,將一個父基因取一半,再上來自另外一個父基因的一半,構成一個新的子基因。
算法代碼如下:

 1 template< class GENE >
 2 class Gray_Binary_Shuffle_Xover_Gene_Crossover_Algorithm
 3 {
 4     public:
 5             void operator()( GENE& g1, GENE& g2 )const
 6             {
 7                 encoding( g1 );
 8                 encoding( g2 );
 9                 assert( g1.Binary_Array.size() == g2.Binary_Array.size() );
10 
11                 normal2gray( g1 );
12                 normal2gray( g2 );
13 
14                 const unsigned int Size = g1.Binary_Array.size();
15 
16                 for ( unsigned int i = 0; i < Size; ++i )
17                 {
18                     if ( ( i & 1&&
19                          ( g1.Binary_Array[i] xor g2.Binary_Array[i] )
20                         )
21                     {
22                         if ( g1.Binary_Array[i] )
23                             {
24                                 g1.Binary_Array[i] = 0;
25                                 g2.Binary_Array[i] = 1;
26                             }
27                             else
28                             {
29                                 g1.Binary_Array[i] = 1;
30                                 g2.Binary_Array[i] = 0;
31                             }
32                     }
33                 }
34 
35                 gray2normal( g1 );
36                 gray2normal( g1 );
37                 decoding( g1 );
38                 decoding( g2 );
39             }
40 };
41 
42 

3.  另外的一些代碼
(1)群體中的交叉算法
將經過選擇考驗的個體放入一個群體,當放入的個體數量達到要求后,對里邊的個體進行兩兩交叉。

 1 //Population Crossover Algorithm
 2 //1. get the number of Chromosomes in the Population
 3 //2. get the number of Gens in a Chromosome
 4 //3. generate a random number
 5 //4. if the random number is bigger than the probability, skip
 6 //5. if the selected two genes are of the same value, skip
 7 //6. crossover the two genes using the selected Gene crossover algorithm
 8 template< class POPULATION, class GENE_CROSSOVER_ALGORITHM >
 9 class Population_Crossover_Algorithm
10 {
11     public:
12         void operator()( POPULATION& population ) const
13         {
14             //1
15             const unsigned int C_Size = population.Chromosome_Array.size();
16             assert( C_Size > 1 );
17 
18             //2
19             const unsigned int G_Size = population.Chromosome_Array[0].Gene_Array.size();
20 
21             for ( unsigned int i = 0; i < C_Size / 2++i )
22             {
23                 for( unsigned int j = 0; j < G_Size; ++j )
24                 {
25                     //3
26                     const long double Ran = ran();
27                     //4
28                     if ( Ran > population.Crossover_Probability )
29                         continue ;
30                     //5
31                     if ( population.Chromosome_Array[i].Gene_Array[j].Value ==
32                          population.Chromosome_Array[C_Size-i-1].Gene_Array[j].Value
33                         )
34                         continue;
35                     //6
36                     crossover(
37                             population.Chromosome_Array[i].Gene_Array[j],
38                             population.Chromosome_Array[C_Size-i-1].Gene_Array[j],
39                             GENE_CROSSOVER_ALGORITHM()
40                                 );
41                 }
42             }
43         }
44 };




(2) 交叉函數定義
種群的交叉只涉及一個交叉主體,而基因/個體的交叉涉及兩個交叉主體,定義如下:

 1 //Population crossover only
 2 template<class POPULATION, class ALGORITHM>
 3 void crossover( POPULATION& p,          //the Population to perform crossover
 4                 const ALGORITHM& a )    //the Algorithm used for the crossover
 5 {
 6     assert( p.Chromosome_Array.size() > 1 );
 7     a( p );
 8 }
 9 
10 
11 //gene crossover algorithm
12 template<class GENE, class ALGORITHM>
13 static void crossover(  GENE &g1,               //Gene1 to perform crossvoer
14                         GENE &g2,               //Gene2 to perform crossvoer
15                         const ALGORITHM& a )    //the Algorithm employed
16 {
17     a( g1, g2 );
18 }
19 




posted on 2008-06-18 15:56 Wang Feng 閱讀(12131) 評論(1)  編輯 收藏 引用 所屬分類: Numerical C++

FeedBack:
# re: 遺傳算法系列 (3) 交叉算法
2010-02-12 00:32 | hello
請教:“洗牌交叉”如果按該文的代碼,和單點交叉又有何區別呢?
“洗牌交叉”應該在交叉之前在父代中有shuffle運算,交叉后在子代中有unshuffle運算,但不知道是如何進行的,作者如有知曉,不吝賜教,謝謝:)
email: hwei2007@qq.com  回復  更多評論
  

<2008年6月>
25262728293031
1234567
891011121314
15161718192021
22232425262728
293012345

常用鏈接

留言簿(4)

隨筆分類

隨筆檔案

Link List

搜索

  •  

最新評論

閱讀排行榜

評論排行榜

青青草原综合久久大伊人导航_色综合久久天天综合_日日噜噜夜夜狠狠久久丁香五月_热久久这里只有精品
  • <ins id="pjuwb"></ins>
    <blockquote id="pjuwb"><pre id="pjuwb"></pre></blockquote>
    <noscript id="pjuwb"></noscript>
          <sup id="pjuwb"><pre id="pjuwb"></pre></sup>
            <dd id="pjuwb"></dd>
            <abbr id="pjuwb"></abbr>
            亚洲一区二区三区在线看| 欧美一区二区三区免费在线看| 亚洲激精日韩激精欧美精品| 韩日成人在线| 国产亚洲午夜高清国产拍精品| 国产精品久久久久aaaa樱花| 国产精品国产三级国产普通话三级| 女生裸体视频一区二区三区| 你懂的国产精品| 欧美日韩亚洲一区二| 国产欧美日韩视频一区二区| 精品成人一区二区三区四区| 亚洲国产成人91精品| 一本一本久久a久久精品综合麻豆| 一区二区三区日韩欧美精品| 欧美一区=区| 亚洲国产第一| 亚洲一区二区在| 欧美日韩1区2区| 精品动漫3d一区二区三区免费版| 99这里只有久久精品视频| 午夜精品免费视频| 亚洲美女网站| 欧美顶级少妇做爰| 黄色成人免费网站| 亚洲欧美日韩在线播放| 亚洲九九爱视频| 欧美自拍偷拍| 欧美国产日韩亚洲一区| 日韩天天综合| 欧美日韩在线视频一区| 亚洲欧洲中文日韩久久av乱码| 久久久www成人免费无遮挡大片| 一区二区不卡在线视频 午夜欧美不卡'| 久久免费99精品久久久久久| 精品电影一区| 欧美高清成人| 免费在线观看一区二区| 在线精品国产欧美| 亚洲黄色三级| 欧美日韩精品福利| 亚洲欧美国产高清| 西瓜成人精品人成网站| 尤物yw午夜国产精品视频明星| 免费亚洲一区| 欧美日韩精品一区二区三区四区| 亚洲精品国产精品国自产观看浪潮 | 亚洲视频在线观看网站| 欧美第十八页| 国产精品v欧美精品v日韩精品| 亚洲欧美在线x视频| 欧美一区二区高清在线观看| 亚洲第一搞黄网站| 一区二区免费在线观看| 国产一区二区三区直播精品电影| 欧美激情视频在线免费观看 欧美视频免费一 | 亚洲视频欧美视频| 午夜精品久久久久久99热软件| 亚洲福利视频一区| 亚洲欧美日韩网| 一本色道久久综合亚洲精品小说| 久久爱www.| 久久久人成影片一区二区三区| 欧美精品一区二区蜜臀亚洲| 久久先锋影音av| 国产精品综合av一区二区国产馆| 91久久久在线| 99亚洲精品| 免费在线成人| 亚洲日韩欧美视频| 亚洲国产精品一区二区尤物区 | 亚洲一区二区3| 欧美搞黄网站| 亚洲精品久久在线| 一区二区动漫| 国产精品久久久久久av福利软件| 亚洲精品一区二区三区不| 99日韩精品| 国产精品一区二区久久久久| 亚洲精品中文在线| 香蕉久久一区二区不卡无毒影院| 国产精品中文字幕欧美| 欧美一级视频精品观看| 免费观看欧美在线视频的网站| 亚洲精品国产精品国自产在线| 欧美精品二区| 欧美一区二区精品在线| 亚洲高清不卡在线| 亚洲一区二区三区在线观看视频| 国产精品视频99| 狼狼综合久久久久综合网| 国际精品欧美精品| 欧美日韩精品欧美日韩精品| 亚洲一区二区三| 久久综合九色九九| 国产精品99久久不卡二区| 国产伦精品一区二区三区照片91 | 欧美高清不卡在线| 亚洲一区二区三区在线| 亚洲国产精品一区二区第四页av| 中文有码久久| 亚洲精品网站在线播放gif| 国产一区二区三区高清播放| 欧美日韩在线播放三区四区| 久久这里只精品最新地址| 欧美一区视频| 香蕉尹人综合在线观看| 日韩小视频在线观看专区| 亚洲国产乱码最新视频| 久久久亚洲午夜电影| 亚洲欧美激情四射在线日| 亚洲一区二区视频| 在线中文字幕日韩| 一本久久a久久免费精品不卡| 国语自产精品视频在线看8查询8| 国产视频在线一区二区| 国产精品永久入口久久久| 国产精品一区二区欧美| 国产麻豆日韩| 亚洲国产成人午夜在线一区| 亚洲二区在线| 亚洲一区二区三区在线视频| 亚洲在线观看视频网站| 久久久99免费视频| 欧美福利视频在线观看| 一本色道久久综合亚洲91| 正在播放欧美视频| 六月天综合网| 国产精品五月天| 午夜精品区一区二区三| 久久久夜色精品亚洲| 久久综合激情| 国产欧美一区二区三区国产幕精品 | 亚洲深夜福利| 国产精品电影网站| 欧美精品一区二| 国产精品乱看| 亚洲成人资源| 亚洲春色另类小说| 欧美不卡一区| 国产在线拍揄自揄视频不卡99| 一区在线播放视频| 另类激情亚洲| 欧美一区亚洲二区| 国产精品久久久久久久久久ktv| 日韩亚洲欧美一区| 欧美激情按摩在线| 久久理论片午夜琪琪电影网| 国产三级精品三级| 久久久久国产精品一区二区| 欧美专区日韩视频| 欧美日韩综合另类| 久久久久久婷| 欧美日韩 国产精品| 久久aⅴ国产紧身牛仔裤| 久久精品99久久香蕉国产色戒 | aa国产精品| 国产乱码精品一区二区三区忘忧草 | 免费一级欧美片在线播放| 亚洲国产精品嫩草影院| 亚洲精品自在久久| 久久成人精品视频| 一区二区三区四区国产精品| 日韩视频久久| 另类成人小视频在线| 玖玖玖国产精品| 精品88久久久久88久久久| 亚洲欧洲一区二区在线播放| 国产日韩免费| 一区二区电影免费观看| 91久久精品国产| 欧美一级午夜免费电影| 亚洲免费观看| 久久综合久久综合久久| 亚洲色图在线视频| 久久精品国产91精品亚洲| 亚洲天堂av在线免费观看| 欧美在线免费观看亚洲| 日韩亚洲国产欧美| 免费中文字幕日韩欧美| 麻豆成人综合网| 亚洲国产免费看| 一二三区精品| 亚洲欧美色婷婷| 国产综合18久久久久久| 久久亚洲电影| 亚洲看片免费| 亚洲欧美区自拍先锋| 欧美日韩影院| 亚洲一区在线免费观看| 欧美一区二区观看视频| 国产欧美一区二区在线观看| 亚洲欧美国产另类| 久久久国产视频91| 亚洲国产精品黑人久久久| 欧美fxxxxxx另类| 一区二区三区高清不卡| 亚洲免费视频网站| 国产日韩欧美综合| 欧美三区在线视频|