• 沒有找到結果。

第五章 基因演算法與結果分析

5.1 基因演算法的流程

本章節可以分為兩小節;第一節描述基因演算法的搭配 Sold的流程,命名為 GA_Sold;而基因演算法搭配 Snew 命名為 GA_Snew,此種演算法流程基本上與 GA_Sold相同,所以 GA_Snew可以視為是 GA_Sold的特例;因此,第二節介紹 GA_Snew 的流程。

5.1.1 GA_Sold的進化流程

GA_Sold的進化流程是根據 Lin et al. (2009a)所發展的基因演算法而來,本研 究將其分成兩個部份來做描述;首先是先描述其主要的三種運算模組,接下來是 介紹其主要的流程。

此三種運算模組主要是用來從母代染色體產生新的子代染色體。而為了挑選 到良好的母代染色體(parent),因此其還使用二擇一的競賽法則(binary tournament selection; Brindle 1981)來挑選母代,其方法是先隨機從母代染色體群中挑選兩條 染色體,然後選擇其績效較佳的一條作為進化用的母代染色體。

此三個運算模組分別屬於基因演算法中的交配與突變兩種類別。首先為 Syswerda (1989)所提出的 PBX(position-based crossover)交配方法,屬於二對一的

33

運算模組,也就是用兩條母代染色體只會產生一條子代染色體(offspring)。而其 他兩種運算模組分別是交換(swap)與插入(insert)兩種運算模組屬於一對一的運 算模組;也就是一個母代染色體會產生單一個子代染色體。而這兩種運算模組都 是屬於突變方法。

如圖 5.1,本研究將以實際例子來解釋 PBX 方法。圖中有兩個母代染色體區 段(Parent 1 和 Parent 2),而每個母代染色體區段中各有 10 個工件,而每個工件 各表示一個基因。而 PBX 的三個步驟解釋如下:首先,對 Parent 1 的每個基因 隨機產生相對應的二元位數(0 或 1),而這一系列的二元位數稱為遮罩(mask)。接 下來依序將此遮罩中數值為「1」的相對應基因(工件)填入相對應的子代染色體 位置中。最後,將子代還沒填入的基因由 Parent 2 填入,其填入順序依照其在 Parent 2 由左到右的順序依序填入,就可以得到完整的子代染色體。

圖 5.1 PBX 交配運算模組【資料來源:戴邦豪(2010)】

而交換的運算模組實例如圖 5.2,針對某個染色體區段,隨機選取兩個基因 (例如:J4 和 J7)來進行交換的步驟。而插入的運算模組是採用兩步驟的方法,如 圖 5.3。首先隨機選兩個基因(例如:J4 和 J7);然後將排序較後面的基因(J7)插入 到排序比較前面的基因(J4)之前。

J1 J2 J3 J4 J5 J6 J7 J8 J9 J10 Parent 1

Offspring J3 J2 J7 J4 J5 J6 J8 J1 J9 J10

J3 J7 J6 J2 J8 J1 J4 J9 J5 J10 Parent 2

0 1 0 1 1 1 0 0 1 0

Mask

34

圖 5.2 交換運算模組【資料來源:戴邦豪(2010)】

圖 5.3 插入運算模組【資料來源:戴邦豪(2010)】

描述完三個重要的運算模組之後,本研究將介紹 GA_Sold的流程。如之前所 描述,一個舊染色體表達法(Sold)包含了 k+1 個區段;而為了產生一個子代染色體,

這 k+1 個區段是各自應用這三個模組來產生新的子代區段。然後再將這 k+1 個新 的子代區段組合起來成為一個完整的子代染色體。而整個 GA_Sold的流程如下:

Procedure GA_Sold

Step 1: Initial Setting

 Input parameters T , f P , size 0 pc1, 0 pm1.

 Set t = 0; (t denotes the age of population Pt)

 Form a population P0 by randomly generating 𝑃𝑠𝑖𝑧𝑒 chromosomes.

Step 2: Record the Best Solution in Pt

 Find 𝜔𝑏𝑒𝑠𝑡(𝑡) (i.e., the best solution in Pt)

J1 J2 J3 J4 J5 J6 J7 J8 J9 J10

Parent

Offspring J1 J2 J3 J7 J5 J6 J4 J8 J9 J10

Swap

J1 J2 J3 J4 J5 J6 J7 J8 J9 J10

Parent

Offspring J1 J2 J3 J7 J4 J5 J6 J8 J9 J10

Insertion

35

 Denote 𝐿𝑏𝑒𝑠𝑡(𝑡) as the makespan of 𝜔𝑏𝑒𝑠𝑡(𝑡).

Step 3: Apply Crossover Operation to Update Pt

 Skip Check: Generate a random number r , if rpc then skip the crossover operation and go to Step 4;

 Select Parents: Carry out the binary tournament section method twice to pick two chromosomes from Pt as a pair of parents, which are respectively called X and p1 Xp2 (Xp2 denotes the inferior one in terms of fitness values). Each segment i (1ik1) in X and p1 Xp2 is respectively called Si, p1 and Si, p2.

 Create New Chromosome

 Create offspring for each segment i

For segment i = 1, …, k+1

Apply the position-based crossover operator on Si, p1 and Si, p2 to create one new segment S . i

Endfor

 Combine S (i 1ik1) to form a new chromosome Xoffspring

 Update Population Pt:

 If Xp2 is inferior to Xoffspring, then Xp2 is removed from Pt and

offspring

X is placed into Pt; else go to Step 4

36

Step 4: Apply Mutation Operation to Update Pt

 Skip Check: Generate a random number r , if rpm then skip the mutation operation and go to Step 5;

 Select Parent: Use the binary tournament selection method to pick one parent, denoted by Xparent and each of its segment is denoted by Si,p.

 Select Operator: Of the swap and insertion operators, randomly determine which one to use—each one is with the same probability (0.5).

 Create New Chromosome

 Create offspring for each segment i

For segment i = 1, …, k+1

Apply the swap/insertion operator on Si,p to create one new segment S . i

Endfor

 Combine S (i 1ik1) to form a new chromosome Xoffspring

 Update Population Pt: If Xparent is inferior to Xoffspring, then Xparent is

removed from Pt andXoffspringis placed into Pt; else go to Step 4. .

Step 5: Termination Check

 If 𝐿𝑏𝑒𝑠𝑡(𝑡) = 𝐿𝑏𝑒𝑠𝑡(𝑡 + 1) = ⋯ = 𝐿𝑏𝑒𝑠𝑡(𝑡 + 𝑇𝑓), Then STOP;

Else, go to Step 2.

37

5.1.2 GA_Snew的進化流程

而 GA_Snew的進化流程其實是 GA_Sold進化流程的一個特例。因為在 GA_Snew

中染色體表達法為一個區段的表達的方式,而表達法在 GA_Sold中為 k+1 個區段;

因此只要將流程中的多個區段改為單一區段就是 GA_Snew的流程了。