第五章 分類元微觀動態車流系統架構
5.1 系統運作流程
微觀車流所發生的各種變化其最主要的變因來自於駕駛人的駕駛行為不同所致,故 要架構出符合實際車流情況的系統可依循駕駛者的駕駛思考流程與行為來建構系統,以 冀望能得到接近實際情況之模式。本研究初步擬定採用之駕駛者思考流程假設如下:
1. 決定本車期望速率(依不同駕駛者習慣、目的、行駛路段限速、路型等因素有 關)。
2. 本車所在車道狀況。
甲、前車狀況(相對車速、車距、車種等因素)。
乙、後車狀況(相對車速、車距、車種等因素)。
丙、決定採取等速、加速、減速或變換車道等行為。
3. 若決定採取變換車道。
甲、若兩側皆有車道,則以左車道優先觀察,再觀察右車道。
乙、若只有左側車道(右側車道)則觀察左側車道(右側車道) 。 4. 所觀察車道之行車狀況。
甲、觀察左車道行車狀況是否比現車道佳(若否,則直接觀察另一車道) 。 乙、前後車間距離變化。
丙、觀察前車與本車距離變化。
丁、觀察後車與本車距離變化(先觀察前車還是後車僅作假設) 。 戊、決定是否變換車道。
己、若不變換則觀察另一車道(僅有左(右)車道能變換者無此步驟) 。 庚、若兩旁車道皆不能變換則維持原車道。
根據所擬定之思考流程可得出系統概念流程圖如圖 5-1。
圖 5-1 系統運作流程圖 5.2 系統運作範例
考量到國內尚未有運用分類元法於車流方面的相關研究,本研究先根據前節所提架 構擬定一簡單系統模式運作流程範例,以了解分類元法運用在高速公路微觀車流模式之 可能性。而考量到現場攝影所能蒐集到的資訊完整性,各階段所執行步驟將隨研究發展
環境資訊的提供
前後車距離,前後車相對速度,左右 車道狀況(前後車距、相對速度),車
種,路況、天氣狀況等
駕駛資訊的提供
風險愛好程度、對車輛的認知程度 (是否為自用車)、駕駛年資、車輛廠
牌(性能因素)等
跟車行為決策
變換車道行為決策 前車相對速度、距離
後車相對速度、距離 本車速度、道路速限、
駕駛個性、車況
決定加、減速行為(或是 決定變換車道)
左車道之狀況(前後車 距、相對速度)
右車道之狀況(前後車 距、相對速度)
決定所要變換的車道 本車速度、道路速限、
駕駛個性、車況
決定所採取的變換車道 策略(角度、速度、加減
速)
循環
依決策結果作出反應,
並和實際結果進行比對
後進行獎懲
進行調整。
1.分類元初始值設定
步驟一:決定 Rule 群 1 的格式。
格式:本車車速|期望車速/是否採取變換車道流程
步驟二:系統隨機產生期望速率之母體群 100 組(介於 60~110 之間) ,每組給予 同樣之 ST。假設初始 ST=10。
步驟三:每次出價比例(佔總持有產財率) :0.5 生命稅:1(每次競價後收取)
獎勵值:5+該次出價值 懲罰值:5
2.第一階段(變化車道動機)
步驟一:第一次假設有四組 Rule 符合環境條件規則,且因為 Rule 強度均相同,
故四個 Rule 出價皆相同(5),此時隨機取出一個 Rule 作得標者。
步驟二:進行所有 Rule 之 ST 調整。
步驟三:所有參與出價者收取叫價稅 5。
步驟四:所有 Rule 收取生命稅 1。
步驟五:針對得標者反應行為輸出與實際環境狀況作比較,並依其結果優劣作相 對應之獎懲。
步驟六:進行下一環境目標之比對。
本階段 Rule 假設判斷邏輯如圖 5-2,各 Rule 之力量值(ST)變化狀況範例如 下表 5-1~表 5-3。
1011010|1100100/0 (90|100/不變換車道)
1010101|1101001/1 (90|105/變換車道) 1100100|1010000/1
(90|80/變換車道)
1101001|1011010/1 (90|90/不變換車道)
依常理,假設此兩者為錯誤的 Rule
1. 其經由 effector 驗證後發現不符合實際情況 給予懲罰 5,故其最終 ST 為-1 而力量變弱。
2. 經由 GA 產生一個新的 Rule 補充,其 ST 設 為初始值。 (也可設定不足 90 組時再補充)
依常理,假設此兩者為正確的 Rule
1. 經由 effector 驗證後發現符合實際情況(雖 然預期車速為虛擬值,但假設其符合邏 輯),故給予獎勵。
2. 其 ST 變為加上所出價格再加 5=14
圖 5-2 系統範例 – 系統分類元運作概念流程圖 1
表 5-1 第一階段各參數初始值
Rule 編號(A 群) Rule 內容 ST SP Iteration 1 90|100/不變換車道 10 14 0
2 90|80/變換車道 10 14 0
3 90|105/變換車道 10 14 0
4 90|90/不變換車道 10 14 0
5~100 XXXXXXXXXX 10 14 0
表 5-2 第一階段完成後之獎勵(以”90|105/變換車道”得標為例) Rule 編號(A 群) Rule 內容 ST SP Iteration 1 90|100/不變換車道 4 14 1
2 90|80/變換車道 4 14 1
3 90|105/變換車道 14 14 1
4 90|90/不變換車道 4 14 1
5~100 XXXXXXXXXX 9 14 1
表 5-3 第一階段完成後之懲罰(以”90|80/變換車道”得標為例) Rule 編號(A 群) Rule 內容 ST SP Iteration 1 90|100/不變換車道 4 14 1 2 90|80/變換車道 -1 14 1
3 90|105/變換車道 4 14 1
4 90|90/不變換車道 4 14 1
5~100 XXXXXXXXXX 9 14 1
3.第二階段(決定變換之目標車道)
假設上列情況中,由(85|105/變換車道)此一情況延續下來,下一步驟是進行
鄰近車道狀況評估。
步驟一:決定 Rule 2 格式。
85|0|100|5/是 85|0|100/50/是 85|0|90|5/否 85|0|80|50/否
Rule 編號(B 群) Rule 內容 ST SP Iteration
1 85|0|100|5/是 10 x 0
2 85|0|100/50/是 10 x 0
3 85|0|90|5/否 10 x 0
4 85|0|80|50/否 10 x 0
9~100 XXXXXXXXXX 10 x 0
表 5-5 第二階段完成後(以 85|0|100/50/是變換車道得標為例)
Rule 編號(B 群) Rule 內容 ST SP Iteration
1 85|0|100|5/是 4 x 1
2 85|0|100/50/是 14 x 1
7 85|0|90|5/否 4 x 1
8 85|0|80|50/否 4 x 1
9~100 XXXXXXXXXX 9 x 1
表 5-6 第二階段完成後 Rule 1 參數變化
Rule 編號(A 群) Rule 內容 ST SP Iteration
1 85|100/不變換車道 4 14 1
2 85|80/變換車道 4 14 1
3 85|105/變換車道 15(原為 14) 14 1
4 85|90/不變換車道 4 14 1
5~100 XXXXXXXXXX 9 14 1
5.第三階段
此階段可依據變換車道後的情況來進行前兩階段的 Rule 之連鎖獎懲。在此
假設於第二階段完成變換車道後並未再進行下一階段的變換車道行為,且前車速
度假設保持 100km/h 不變,代表實際上駕駛所能接受的速度為 100km/h 左右,但
無法準確的得知其變換車道前的預期速度(亦即原本可能希望要變到 105km/h,但
在實際上不論怎麼變都無法達到-環境因素),故可對其連鎖獎勵方式採用如
「ST’=ST+5/|(實際車速-期望速率)|」的方式,依第一階段所產生的期望速率與最
Rule1 格式:本車道代碼|本車車種|本車車速|前車車種|前車車速|前車車距|
後車車種|後車車速|後車車距 Action1:加速、減速、等速
可能解空間:3*2*16*2*16*16*2*16*16*3 = 75,497,472
2.模式二:同模式一,考量本車、前車及後車環境條件,但於前車車速及後車車速部份 改採用相對車速的概念,冀望藉此減少可能解的空間,縮短尋解的時間。其 中「本車車速-前車車速」及「本車車速-後車車速」分成大於 0(本車車速大於 前後車)、小於 0(本車車速小於前後車)及等於 0(本車與前後車車速相等)三種 情況。
Rule1 格式:本車道代碼|本車車種|本車車速|前車車種|本車車速-前車車速|前 車車距|後車車種|本車車速-後車車速|後車車距
Action1:加速、減速、等速
可能解空間:3*2*16*2*3*16*2*3*16*3 = 2,654,208
3.模式三:考量到駕駛者本身如果是受到前後車的影響而進行被動的加、減速影響,則 本車的條件對於決策反應的影響不大,故本模式省略本車環境條件。其中「本 車車速-前車車速」及「本車車速-後車車速」分成大於 0(本車車速大於前後 車)、小於 0(本車車速小於前後車)及等於 0(本車與前後車車速相等)三種情況。
Rule1 格式:前車車種|本車車速-前車車速|前車車距|後車車種|本車車速-後車車 速|後車車距
Action1:加速、減速、等速
可能解空間:2*3*16*2*3*16*3 = 27,648
4.模式四:同模式三的考量,大多數情況下,駕駛本身於跟車行為中受到前車的影響最 為直接,故將本車、後車環境條件同時省略而建構出本模式以同模式三作比 較。其中「本車車速-前車車速」分成大於 0(本車車速大於前車)、小於 0(本 車車速小於前車)及等於 0(本車與前車車速相等)三種情況。
Rule1 格式:前車車種|本車車速-前車車速|前車車距
Action1:加速、減速、等速 可能解空間:2*3*16*3 = 288
上述各模式一、二、三及四間雖有不同的 Rule 規則,然而其在演算法方面皆採取 相同的訓練、驗證與預測流程,相關流程步驟主要如下圖 5-5~圖 5-8,其主要步驟為:
1.應用基因演算法產生初始的 Rule 群共 x 群,每一群 Rule 可指定其擁有 y 個 Rules。
2.目標車輛與前後車輛相關參數輸入及參數編碼。
3.將編碼後車流樣本參數依序取出。
4.針對所取出的車流資料,從相對應的 Rule 群中依序取出 Rule 中的條件部份和其作比 對是否符合。
5.將所有合格的 Rule 放入競標群中,並依其 ST 進行出價,同時從 ST 中扣除其出價金 額。
6.對所有 Rule 索取生命稅。
7.由合格 Rule 群中取出標價最高的一個,若有數個同樣標價者,隨機取出一個最得標 者。並將得標者其 Rule 中所指示的”動作”部份和實際結果作比較是否符合以進行適當的 獎勵與懲罰。
8.重覆執行到滿足收歛條件後結束此次訓練過程。
圖 5-5 用於驗證之訓練流程 應用基因演算法產生
初始的 Rule 群共 x 群,
每一群 Rule 可指定其 擁有 y 個 Rules。
目標車與前後車輛相關參數輸入 相關參數編碼
將編碼後參數取出第 n 筆資料,從 n=1 開始。
針對第 n 筆資料,從相對應的 Rule 群中,由第 1 個 Rule 開始 取出,並和第 n 筆資料作比對其 條件部份是否符合?
符合 不符合
將此 Rule 放入競標群中,並依其 ST 進 行出價,同時從 ST 中扣除其出價金額。
對此 Rule 索取生命稅。
本次取出之 Rule 是否為 Rule 群中的最後一個?
是
否,取出下一 個 Rule 取出標價最高的一個,若有數個同樣標價者,隨機
取出一個最得標者。並將得標者其 Rule 中所指示 的”動作”部份和實際結果作比較是否符合?
是
將本 Rule 之 ST 予以適 當的獎勵
否
將本 Rule 之 ST 予以適 當的懲罰
否,取出下一個環 境條件
本環境條件不是最後一個?
結束此次訓練過程 是
本 Rule 群中 ST>0 的 Rules 數目是否不足?
是,運用基因演算 否
法產生新 Rules
補足。
圖 5-6 驗證流程 讀取各 Rule 群中完成
訓練後 ST>0 的 Rules。
目標車與前後車輛相關參數輸入 相關參數編碼
將編碼後參數取出第 n 筆資料,從 n=1 開始。
針對第 n 筆資料,從相對應的 Rule 群中,由第 1 個 Rule 開始 取出,並和第 n 筆資料作比對其 條件部份是否符合?
符合 不符合
將此 Rule 放入競標群中,並依其 ST 進 行出價。
本次取出之 Rule 是否為 Rule 群中的最後一個?
是
否,取出下一 個 Rule 取出標價最高的一個,若有數個同樣標價者,隨機
取出一個最得標者。並將得標者其 Rule 中所指示 的”動作”部份和實際結果作比較是否符合?
是 準確率+1。
否
否,取出下一個環 境條件
本環境條件不是最後一個?
結束此次驗證過程 是
否
準確率維持不變。
圖 5-7 用於預測之訓練流程 應用基因演算法產生
初始的 Rule 群共 x 群,
每一群 Rule 可指定其 擁有 y 個 Rules。
目標車與前後車輛相關參數輸入
相關參數編碼
將編碼後參數取出第 n 筆資料,從 n=1 開 始,但跳過其中準備作為預測用的部份。
針對第 n 筆資料,從相對應的 Rule 群中,由第 1 個 Rule 開始 取出,並和第 n 筆資料作比對其 條件部份是否符合?
符合 不符合
將此 Rule 放入競標群中,並依其 ST 進 行出價,同時從 ST 中扣除其出價金額。
對此 Rule 索取生命稅。
本次取出之 Rule 是否為 Rule 群中的最後一個?
是
否,取出下一 個 Rule 取出標價最高的一個,若有數個同樣標價者,隨機
取出一個最得標者。並將得標者其 Rule 中所指示 的”動作”部份和實際結果作比較是否符合?
是
將本 Rule 之 ST 予以適 當的獎勵
否
將本 Rule 之 ST 予以適 當的懲罰
否,取出下一個環 境條件
本環境條件不是最後一個?
結束此次訓練過程 是
本 Rule 群中 ST>0 的 Rules 數目是否不足?
是,運用基因演算 否
法產生新 Rules
補足。
圖 5-8 預測流程 讀取各 Rule 群中完成
訓練後 ST>0 的 Rules。
目標車與前後車輛相關參數輸入 相關參數編碼
針對第 n 筆資料,從相對應的 Rule 群中,由第 1 個 Rule 開始 取出,並和第 n 筆資料作比對其 條件部份是否符合?
符合 不符合
將此 Rule 放入競標群中,並依其 ST 進 行出價。
本次取出之 Rule 是否為 Rule 群中的最後一個?
是
否,取出下一 個 Rule 取出標價最高的一個,若有數個同樣標價者,隨機
取出一個最得標者。並將得標者其 Rule 中所指示 的”動作”部份和實際結果作比較是否符合?
是 準確率+1。
否
否,取出下一個環 境條件
本環境條件不是最後一個?
結束此次驗證過程 是
否
準確率維持不變。
將編碼後的參數依續取出未用於訓練過程
中的資料,從 n 最小者開始。
第六章 程式實作與驗證
6.1 系統實作
本研究於模式系統實作為程式時,所採取之編碼方式、運作流程、車流資料分群,
基因演算法中的複製、交配、突變及親代選擇,分類元法中的獎罰規則、Rule 作用方式、
起始解的引用等不同,皆會影響所得解的品質或尋求解的時間等,故於本節將相關細節 詳述之。
1.資料輸入兼編碼部份
考量到原始調查資料在最初的標準座標轉換上即有約±0.8 公尺的誤差,故在 有無加減速的判斷上,當其加速度絕對值大於 5(公里/小時平方)者才判斷其有發 生加、減速的行為。
於編碼部份,車速範圍 51~130(km/h),每 5km/h 為一區隔,故有 16 個區段,
可用 5 個位元代表。距離範圍 11~90(m),每 5 公尺作一區隔,共 16 個間隔,可 用 7 個位元代表。車種代碼:0 為小客車(含休旅車)、1 為其它車輛。車道代碼:
3 車道,以 2 個位元代表,0 為內車道(最左側),2 為最外側車道(最右側)。反應 動作代碼:0 為維持等速、1 為加速、2 為減速、3 為採取變換車道。
2.獎勵與懲罰方式
分類元在作出反應並經由 Effectors 驗證後如果證明其反應是正確的,那麼
給予獎勵是很合常理的。然而若是作出了錯誤的反應就給予懲罰這點則有進一步
考量的空間。舉例來說就類似工廠付錢喊價得標後買了原料回來,然而其製成品
並不為市場所接受,無人購買時,又要再給予懲罰收稅,這樣似乎又有點太過嚴
苛。這種作法在實作上來說是可以迅速的對每一個分類元作出評價,提升系統收
斂的速度,然而卻也有可能會使得分類元間的差異性降低,因為分類元只要不小
心出個錯,其強度就會大幅下降,使得最終留下來的只剩下完全不會出錯且一直
符合環境條件的分類元(也可稱其是具有通用性的分類元,因為不具通用性者在
收取生命稅後強度也會逐漸下降)。本研究考量所欲得到的微觀車流系統為一能
快速反應現實情況的系統,故需要在短時間內得到有用的結果,決定在系統中應 用懲罰的概念以加速求解的過程。
3.取代線觀念[19]:
取代線的概念主要在保護特定的分類元不會在系統尋解時因為其出現的頻 率不夠而發生被淘汰的現象。取代線在分類元數目少時好處較明顯,但在分類元 數目多時,取代線就不一定有好處。本研究由於在攝影車流資料上,是採取連續 擷取車流相關資訊的方式,故其中的變換車道出現頻率相較於一般加減速出現頻 率小,所以有必要採取取代線的關念來確保變換車道的相關 Rule 不致於因為出 現頻率小而被淘汰。
4.Rule 數的決定方面
分類元法運用於本研究上時,當分類元的數目少時,表示每一個分類元所要 涵蓋的目標集合範圍也相對變大,故不容易預測正確。而當分類元的數目過多 時,雖然每一個分類元所負責處理的目標範圍變小了,但也代表每一個分類元所 能預測出的範圍變小,因此若是多層結構的分類元系統,眾多分類元間的連鎖規 沒抓到則其準確率反而會下降。本研究因為採用單一階段為主,故 Rule 間沒有 連鎖的問題,所以分類元的數目越多其預測能力會越佳。然而假使隨著系統樣本 的增加,所需的分類元數也隨之增加,固然可以維持一定的準確率,但就失去了 分類元法的效益,因此本研究的模式設計上將以損失部份準確率的前提下,大幅 度的少所需要的分類元數為主。
5.訓練、驗證與預測
本研究中將訓練定義為利用攝影調查法所得到的各項車流資料,依其時間先
後順序對所建立微觀車流模式中的分類元參數進行調整。驗證則是利用和訓練時
相同的樣本及樣本數作測試,將所得到的車流資料同樣依時間先後順序輸入微觀
車流系統後,將系統所作加、減、等速及變換車道等反應與實際資料作比對,藉
以了解系統的準確率。預測與驗證基本上採用相同的流程,其不同之處在於,用
於預測時的系統訓練只用車流資料中的前 75%,而用另外的 25%則作為模式預測
的準確率評估。訓練與測試的準確率相近時,代表系統學習到的是好的規則,而 不是記憶資料。
6.親代的選擇
在執行交配、複製、突變等動作之前,要先從親代群中選取兩個親代,而選 取的方式通常有輪盤式選擇與競爭式選擇。在分類元系統中,力量值代表了該 Rule 的競力大小,若採用競爭式選擇法,在應用基因演算法在產生新的 Rules 時 會發生陷入同一個區域而無法擴大搜尋解的範圍(因為所採用的都是同樣的親 代,使子代間的差異性變小),將可能使所有的 Rule 趨近於最早出現的可行解上 (因為其力量值會越來越大),使 Rule 間的差異性變小,影響解的品質,故本研究 在親代的選取上採用輪盤式選擇法,依各 Rule 間力量值的比例作為其獲選的機 率,因此只要是力量值高於條件者皆有機會被選取。
7.交配、複製與突變
交配方面考慮到程式運作效能,本研究採用單點交配法,又為了避免限入重 覆解的困境中(如下例),在交配時採交叉交配法,且一次可產生兩個新的子代。
例:兩個同樣的親代「110|0、110|0」採對稱交配,將會產生兩個同樣的子代 1100,
而這兩個同樣的子代,又將會因為其和親代相同而具有較高的適應力,故系統執 行時間一久,將使此一型態的 Rule 過多,造成系統尋解能力的低落。而「110|0、
1|100」採用交叉交配法則可以避免這個問題,其結果為 1101 和 0100(如下圖)。
因此不論其兩個親代是否型態相同,皆有機會產生和親代不一樣的兩個子代,藉 以增加搜尋解的範圍。
圖 6-1 交配範例圖
複製時直接延用被選到的親代作為新的子代。突變的部份,採用遮罩法,遮 1100
1100
交配 1100
1100 1100
交配
0100 1101
對稱交配 夜叉交配
罩隨機產生,例如 1100 的親代,配合 1010 的遮罩,其子代為 0110。
8.起始解
經由實測結果所得,起始解的好壞對本研究演算法收歛的時間有很大的影 響,但其最終所得到的系統於準確率上差異不大。本研究初期於起始解的部份採 用兩種方式,分別為完全採用基演算法產生及直接從車流資料樣本中取出。經初 步實測比對後證實兩者間僅在系統收歛時間上有很大差異外,於最終準確率上差 異不大,加以考量本研究所架構之模式主要目的並非在尋找未知的可行解,而在 於尋找樣本空間中的行為特性,故於後期的模式訓練上為節省時間皆採第二種方 式。
9.程式碼
本研究所架構系統詳細完整程式碼如附錄三,然而考慮到篇幅問題,僅放上 所有模式中評比最佳者作為代表。
10.系統運作流程概念
本研究所架構之系統運作流程概念及分類元法獎懲範例示意如圖 6-2~6-4。
圖 6-2 系統運作流程示意圖
車道別條件 車種條件 車速條件 車距條件
分類元系統
維持等速 採取加速 採取減速 預測反應行為
(Rule 中的動作部份)
實際反應結果
維持等速 採取加速 採取減速 環境條件部份(Rule 中的條件部份)
比較結果以對分類元系統進行獎懲
環境條件部份輸入 環境條件部份輸入
圖 6-3 分類元運作範例圖
圖 6-4 分類元運作範例圖(續)
驗證預測準確率時所用樣本為後 25%(後 100 筆)。
1.模式一(考量本車、前車及後車影響)驗證與預測結果 表 6-1 分類元數與驗證準確率相關表
分類元數 40 80 120 160 200 240 280 320 360 400 佔樣本比(%) 10 20 30 40 50 60 70 80 90 100 準確率(%) 90.98 92.73 94.24 95.24 95.74 96.24 97.24 97.24 97.24 97.24
表 6-2 分類元數與預測準確率相關表
分類元數 40 80 120 160 200 240 280 320 360 400 佔樣本比(%) 10 20 30 40 50 60 70 80 90 100 準確率(%) 91.14 93.67 94.94 94.94 94.94 94.94 94.94 94.94 94.94 94.94
86 88 90 92 94 96 98
佔樣
本比(%) 10 20 30 40 50 60 70 80 90
驗證準確率(%) 預測準確率(%)
圖 6-2 模式一驗證及預測準確率與分類元規則數量關系圖 2.模式二(同模式一,但前後車束改採用相對車速)驗證與預測
表 6-3 分類元數與驗證準確率相關表
分類元數 40 80 120 160 200 240 280 320 360 400
準確率(%) 91.23 92.98 93.98 94.74 95.99 96.24 97.24 97.24 97.24 97.24
表 6-4 分類元數與預測準確率相關表
分類元數 40 80 120 160 200 240 280 320 360 400 準確率(%) 91.14 92.4 93.67 93.67 93.67 93.67 93.67 93.67 93.67 93.67
88 90 92 94 96 98
佔樣本
比(%) 10 20 30 40 50 60 70 80 90
驗證準確率(%) 預測準確率(%)
圖 6-3 模式二驗證及預測準確率與分類元規則數量關系圖 3.模式三(僅考量前車及後車影響)驗證與預測
表 6-5 分類元數與驗證準確率相關表
分類元數 40 80 120 160 200 240 280 320 360 400 準確率(%) 73.93 78.95 86.72 94.24 95.24 95.24 95.24 95.24 95.24 95.24
表 6-6 分類元數與預測準確率相關表
分類元數 40 80 120 160 200 240 280 320 360 400
準確率(%) 59.49 63.3 64.55 69.62 74.68 74.68 74.68 74.68 74.68 74.68
50 60 70 80 90 100
佔樣本
比(%) 10 20 30 40 50 60 70 80 90
驗證準確率(%) 預測準確率(%)
圖 6-4 模式三驗證及預測準確率與分類元規則數量關系圖 4.模式四(僅考量前車影響)驗證與預測
表 6-5 分類元數與驗證準確率相關表
分類元數 40 80 120 160 200 240 280 320 360 400 準確率(%) 89.47 90.73 91.48 91.48 91.48 91.48 91.48 91.48 91.48 91.48
表 6-6 分類元數與預測準確率相關表
分類元數 40 80 120 160 200 240 280 320 360 400 準確率(%) 88.6 92.4 92.4 92.4 92.4 92.4 92.4 92.4 92.4 92.4
86 88 90 92 94 96
佔樣本比
(%) 10 20 30 40 50 60 70 80 90
驗證準確率(%) 預測準確率(%)
圖 6-5 模式四驗證及預測準確率與分類元規則數量關系圖
本研究也嘗試將分群條件放寬,於車輛有無加減速行為的判斷方面將誤差假設值依 序縮小成 4、3、2、1 及 0(原本在加速度正負 5km/h^2 以下皆視為等速),發現此時模式 四的預測效果變得相當低,而模式一、二及三的準確率同樣有下降的區勢,但下降的程 度為模式一<模式二<模式三。
當誤差假設值縮小為 0 時,則模式一最高驗證準確率可達 93.45%,然而其相對所 需的分類元規則數為 285(佔樣本的 71.43%),故可看出此時車流資料樣本中的離散程度 較大,故需要較多的分類元規則才能達到相同的準確率。下表為此條件下訓練後力量值 最大的前八個規則,其力量值皆比其它的規則有大幅度的領先,故可知為適用性較高的 規則,也可當作是車流資料樣本中最常發生的駕駛行為。由表中的各分類元規則可歸納 出,不論本車所在車道、車種、車速為何,當前後無車時,所採取的行動為維持等速,
相當符合一般正常駕駛行為,故可說明其力量值為何會大幅領先其他分類元規則。
表 6-7 訓練後所得之 Rule 範例(依力量值由大至小取七個)
本車車道代碼c 本車車
種代碼c 前車車種c 後車車種c 本車車速c 前車車距c 前車車速c 後車車距c 後車車速c 採取行動c ST
0 0 0 0 7 0 0 0 0 0 1316778
1 0 0 0 7 0 0 0 0 0 914867.6
1 0 0 0 9 0 0 0 0 0 713907.9
2 1 0 0 7 0 0 0 0 0 512958.2
0 0 0 0 5 0 0 0 0 0 412476.9
2 1 0 0 5 0 0 0 0 0 312000
1 1 0 0 6 0 0 0 0 0 311999
模式二、三與四各有其相對優缺點與適用性,所應用的車流資料樣本特性不同時,
最合適的模式也隨之不同,越是不規則離散而不具有集中行為特性的資料,需要越多的 環境條件資訊與分類元規則數來提高準確率,而當樣本資料具有明顯的行為趨勢時就可 用較少的環境條件資訊與分類元規則數來提高準確率,故各模式間無絕對的優劣之分,
需看所要求的應用目的為何來作取捨應用。
第七章 結論與建議
7.1 結論
於本研究中證實分類元法在尋求可行解及分配各可行解的比重上具有相當不錯的 能力,且適用性高,唯與其他演算法間的優劣比較(如尋解時間、所得解的品質等)礙於 所需資料的取得不易,無法輕易下定論(可能因樣本性質不同、程式寫法不同、執行電 腦不同等而得到不同的結果)。分類元法中各 Rule 群格式的定義、Rule 間的互動關系、
初始狀態、獎懲規則及目標解的樣本空間大小等因數,彼此間的關聯密切,且對解的品 質影響相當大,需依應用目標對象的不同特性而研析設計,無一種固定的組合方式保證 適用於所有的問題。關於系統分類元數與準確率關系方面,於各模式組合的分析中發 現,當要求分類元數目少時,其最大的驗證準確率就會降低,當要求最大驗證準確率高 時,所需要的分類元數就無法降低,然而視研究需要可採取一折衷點,犧牲部份準確率 以大幅降低所需分類元數。
較佳模式為應用分類元法的規則力量分配原理,配合車流資料樣本特性與考量實務 上所需將分類元法間的運算規則予以調整,以使模式可以依樣本特性的不同、所應用目 的不同(需高準確率、低分類元規則數或一平衡點)進行調整。綜合以上所述,由本研究 應用分類元法所得到的結果可證實,分類元法應用在構建高速公路微觀車流模式上確實 具有可行性。
7.2 建議
本研究由於為國內首度應用分類元方法於微觀車流方面之研究,故在許多細節部份 未能完全發揮分類元的特性,尚有待後進之士予以改善本研究不足之處。
本研究已知不足之處如後:
1.編碼方式
本研究採用單純的十進位轉二進位方式進行編碼,其應用於基因演算法時可
能會產生親代與子代在編碼前的巨大差異。例如 120/1111000 及 127/1111111
於交配後可能產生 15/0001111,與實際編碼前的親代相差甚遠。
2.Rule 間的權重(力量值 ST)分配規則
本研究於 Rule 間的權重分配採用最簡單的固定值獎罰分配法,且因為 Rule 僅有一層,未能定立出 Rule 群間的關聯性,故未應用到桶隊接力法進行功勞分 配。
3.基因演算法中的演算規則
基因演算法的規則影響目標解尋解及收歛的速度,在交配方式上本研究僅採 用單點交配法,或許可再考量加入其他交配法之應用。
4.程式執行邏輯上的最佳化
本研究所有的理論方法不論是基因演算法或是分類元法,在將其實際編寫為 程式語言時皆有許多不同的方式可達成相同的結果,然而其所需的時間確可能因 所採用的程式語言、邏輯運作上的不同而不一樣,故會影響程式在尋找相同品質 的解時所需要的執行時間。
5.模式組合
本研究參考暨有文獻中對駕駛人行為、車流特性等研究將參數分成不同的組 合關聯,擬定出五個模式,雖然已有一定的成效,但相信仍然尚有改善的空間。
6.車流資料的蒐集
本研究中由於變換車道部份礙於樣本數不足將導致該 Rule 競爭力不足,被 分類元系統認為是不好的 Rule 而淘汰,故有賴更進一步的車流資料蒐集來完善 變換車道部份研究。
分類元法專長於解決複雜問題,如單一駕駛人從上高速公路至離開期間所有
狀況下反應行為的模擬。然而經由單一攝影機所取得之攝影資訊其涵蓋範圍過於
狹短,故無法針對單一駕駛進行完整的追縱調查與研究。
參考文獻
1. Gazis, D. C., R. Herman, and R. B. Potts, “Car-Following Theory of Steady-State Traffic Flow”, Operations Research, Vol. 7, pp.499-505, 1959.
2. Herman, R., E. W. Montroll, R. B. Potts, and R. W. Rothery, “Traffic Dynamics: Analysis of Stability in Car Following”, Operations Research, Vol. 7, pp.499-505, 1959.
3. Chakroborty, P., S. Kikuchi, “Evaluation of the General Motors Based Car-following Models and A Proposed Fuzzy Inference Model”, Transportation Research Part C 7, pp.209-235, 1999
4. Lewis, R.M., H.L. Michael, “Simulation of Traffic Flow to Obtain Volume Warrants for Intersection Control”, HRR 15, pp.1-43, 1963
5. Leutzbach, W., “Introduction to the Theory of Traffic Flow”, Springer-Verlag, 1988.
6. Prigogine, I., and F. C. Andrews, “A Boltzmann-Like Approach for Traffic Flows”, Operations Research, Vol. 8, pp.789-797, 1960.
7. May, A. D., Traffic Flow Fundamentals, New Jersey, Prentice-Hall Inc., 1990.
8. Paveri-Fontana, S.L., “On Boltzmann-like Treatments for Traffic Flow: A Critical Review of the Basic Model and An Alternative Proposal for Dilute Traffic Analysis”, Transportation Research Vol.9, pp.225-235, 1975.
9. Reuschel, A., “Vehicle Moves in a Platoon”, Oesterreichisches Ingenieur-Archir 4, pp.193-215, 1950.
10. Pipes, L. A. ,”An Operational Analysis of Traffic Dynamics”, Journal of Applied Physics 24(3), pp.274-287,1953.
11. Gazis, D. C. , R. Herman, and R. B. Potts, “Car-Following Theory Of Steady-State Traffic Flow”, Operations Research 7,pp499-505,1959.
12. Greenshield, B. ,”A Study of Traffic Capacity”, Highway Research Board Proceedings
14,pp468-477,1933.
13. J. H. Holland, Adaptation in Natural and Artificial Systems, University of Michigan Press, 1975.
14. 羅仕京, 「車流氣體動力模式之構建與模擬-以波茲曼輸運方程為基礎」 ,國立交通 大學運輸科技與管理學系博士論文,民國九十一年。
15. 林貴億, 「平行模擬車流波茲曼方程式之研究」 ,國立交通大學運輸科技與管理學系 碩士論文,民國九十一年。
16. 黃國平, 「混合車流二維座標模擬模式之建立及驗證」 ,國立台灣大學土木工程學研 究所碩士論文,民國七十二年。
17. 陳世泉, 「混合車流中機車駕駛行為之分析」 ,國立台灣大學土木工程學研究所碩士 論文,民國八十二年。
18. 林育瑞, 「利用類神經網路構建機車車流模式之研究」 ,國立成功大學交通管理科學 研究所碩士論文,民國九十一年。
19. 黃榮助, 「模糊分類元系統及其應用」 ,國立交通大學資訊科學研究所碩士論文,民 國八十六年。
20. 陳兆芳, 「一個以分類元系統建構之動態適應式網路路徑決定方法」 ,國立交通大學 資訊科學研究所碩士論文,民國八十九年。
21. 黃崇源, 「分類元系統構成中之長期記憶形成與類推式認知學習研究」 ,國立交通大 學資訊科學研究所碩士論文,民國八十九年。
22. 李志哲, 「應用模糊分類元系統於股票技術分析」 ,國立交通大學資訊管理學程碩士
論文,民國九十二年。
附錄一 車流原始資料
75 1 1 23 t00044.png 0.00 0.00 97.39 0.00 34.08 0.00 0 0
154 1 1 49 t00116.png 76.75 0.00 0.00 0.00 0.00 -2.90 0 0
233 1 0 77 t00152.png 83.93 0.00 0.00 58.90 0.00 0.00 0 0
312 1 0 102 t00198.png 0.00 0.00 0.00 0.00 0.00 0.00 0 0
391 2 1 125 t00262.png 61.14 0.00 0.00 0.00 0.00 -2.76 0 0
470 1 0 150 t00294.png 102.42 0.00 0.00 0.00 0.00 0.17 0 0
549 0 0 173 t00335.png 85.28 0.00 0.00 0.00 0.00 -0.96 0 0
628 1 0 197 t00381.png 92.90 0.00 0.00 0.00 0.00 -0.90 0 0
707 1 0 218 t00424.png 89.94 88.08 0.00 21.19 0.00 4.42 1 0
786 0 1 235 t00468.png 0.00 0.00 0.00 0.00 0.00 0.00 0 0
865 1 0 254 t00503.png 100.12 0.00 0.00 0.00 0.00 -4.80 0 0
944 1 0 273 t00532.png 96.67 99.84 0.00 54.93 0.00 0.00 0 0
1023 0 0 289 t00587.png 91.72 0.00 82.98 0.00 20.52 -3.29 0 0
1102 0 1 306 t00621.png 87.41 0.00 0.00 0.00 0.00 -3.41 0 0
1181 0 0 325 t00659.png 93.72 0.00 0.00 0.00 0.00 1.40 0 0
1260 1 0 343 t00693.png 89.67 0.00 0.00 0.00 0.00 2.51 0 0
1339 0 0 360 t00737.png 0.00 0.00 0.00 0.00 0.00 0.00 0 0
1418 0 0 377 t00777.png 91.96 0.00 0.00 35.26 0.00 -5.52 0 0
1497 0 0 395 t00819.png 92.75 0.00 0.00 0.00 0.00 2.69 0 0
1498 1 0 396 t00819.png 97.67 0.00 0.00 0.00 0.00 -3.24 0 0
1499 0 0 395 t00820.png 87.35 0.00 0.00 0.00 0.00 -5.40 0 0
1500 1 0 396 t00820.png 96.51 0.00 0.00 0.00 0.00 -1.17 0 0
1501 0 0 395 t00821.png 0.00 0.00 0.00 0.00 0.00 0.00 0 0
1502 1 0 396 t00821.png 0.00 0.00 0.00 0.00 0.00 0.00 0 0
1503 1 0 397 t00822.png 106.11 0.00 76.61 0.00 21.61 0.00 0 0
1504 1 0 398 t00822.png 76.61 106.11 0.00 21.61 0.00 0.00 0 0
1505 1 0 397 t00823.png 108.20 0.00 0.00 0.00 0.00 2.09 0 0
1506 0 0 398 t00823.png 125.76 0.00 0.00 0.00 0.00 49.16 0 0
1507 1 0 397 t00824.png 104.57 0.00 0.00 0.00 0.00 -3.64 0 0
1508 0 0 398 t00824.png 121.03 0.00 88.39 0.00 23.64 -4.73 0 1
1509 2 0 399 t00824.png 91.17 0.00 0.00 0.00 0.00 0.00 0 0
1510 0 1 400 t00824.png 88.39 121.03 0.00 23.64 0.00 0.00 0 0
1511 1 0 397 t00825.png 101.58 0.00 0.00 0.00 0.00 -2.99 0 0
1512 0 0 398 t00825.png 118.85 0.00 92.51 0.00 32.50 -2.18 0 1
1513 2 0 399 t00825.png 88.47 0.00 0.00 0.00 0.00 -2.70 0 0
1514 0 1 400 t00825.png 92.51 118.85 0.00 32.50 0.00 4.12 0 0
1515 1 0 397 t00826.png 0.00 0.00 0.00 0.00 0.00 0.00 0 0
1516 0 0 398 t00826.png 0.00 0.00 0.00 0.00 39.74 0.00 0 1
1517 0 1 400 t00826.png 0.00 0.00 0.00 39.74 0.00 0.00 0 0
1518 2 0 399 t00826.png 90.53 0.00 0.00 0.00 0.00 2.06 0 0
1519 0 1 400 t00827.png 0.00 0.00 0.00 0.00 0.00 0.00 0 0
1520 2 0 399 t00827.png 0.00 0.00 0.00 0.00 0.00 0.00 0 0
附錄二 車流平均資料
75 0 0 75 94.11 0.00 83.93 53.94 58.90 -2.28 0 0
154 0 0 154 90.94 0.00 0.00 55.63 0.00 -1.36 0 0
233 2 1 233 82.77 0.00 0.00 0.00 0.00 -0.98 0 0
312 1 0 312 111.80 93.42 90.21 32.40 21.47 -15.47 0 0
391 1 0 391 91.53 0.00 92.34 0.00 98.05 -1.03 1 0
392 2 1 392 93.23 0.00 0.00 98.05 0.00 -0.11 0 0
393 1 0 393 78.96 0.00 0.00 0.00 0.00 1.36 0 0
394 0 0 394 98.10 0.00 100.92 0.00 84.91 -2.66 0 0
395 1 0 395 90.05 0.00 0.00 0.00 0.00 -1.35 0 0
396 1 0 396 98.37 0.00 0.00 84.91 0.00 -2.20 0 0
397 0 0 397 105.12 0.00 76.61 0.00 21.61 -1.51 0 1
398 2 0 398 110.56 106.11 90.45 21.61 31.96 14.08 0 0
399 0 1 399 90.06 0.00 0.00 0.00 0.00 -0.32 0 0
附錄三 原始碼範例
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
namespace Classifier_System {
public class Form1 : System.Windows.Forms.Form {
private int length1 = 4, length2 = 2, length3 = 1, sample, sample1, tempx, tempx1, tempx2, tempx3, tempx4;//sample 記錄樣 本數
private Random random1 = new Random(unchecked((int)DateTime.Now.Ticks)), random2;
private Random[] randomArray = new Random[z1];
private System.Data.OleDb.OleDbConnection oleDbConnection1;
private System.Data.OleDb.OleDbCommand oleDbSelect1;
private System.Windows.Forms.Label label2;
private System.Windows.Forms.Label label1;
private System.Data.OleDb.OleDbDataReader oleReader;
private System.Windows.Forms.TextBox textBox2;
private System.Windows.Forms.TextBox textBox1;
private System.Windows.Forms.TextBox textBox3;
private System.Windows.Forms.Label label3;
private System.Windows.Forms.Label label4;
private System.Windows.Forms.TextBox textBox4;
private System.Windows.Forms.Button button1;
private System.Windows.Forms.TextBox textBox5;
private System.Windows.Forms.Label label5;
private System.Windows.Forms.Label label6;
private System.Windows.Forms.TextBox textBox6;
private System.Windows.Forms.Label label7;
private System.Windows.Forms.TextBox textBox7;
private System.Windows.Forms.Label label8;
private System.Windows.Forms.TextBox textBox8;
private System.Windows.Forms.Label label9;
private System.Windows.Forms.TextBox textBox9;
private System.Windows.Forms.TextBox textBox10;
private System.Windows.Forms.Label label10;
private System.Windows.Forms.Label label11;
private System.Windows.Forms.TextBox textBox11;
private System.Data.OleDb.OleDbCommand oleDbInsert1;
private System.Data.OleDb.OleDbCommand oleDbDelete1;
private System.Data.OleDb.OleDbConnection oleDbConnection2;
private System.Data.OleDb.OleDbCommand oleDbSelect2;
private System.Windows.Forms.Button button2;
private System.Windows.Forms.Button button3;
private System.Windows.Forms.TextBox textBox12;
private System.Windows.Forms.Label label12;
private System.Windows.Forms.Label label13;
private System.Windows.Forms.TextBox textBox13;
private System.ComponentModel.Container components = null;
public Form1()
{
InitializeComponent();
RunFirst();
}
protected override void Dispose( bool disposing )
{
base.Dispose( disposing );
}
private void InitializeComponent()
{
this.button1 = new System.Windows.Forms.Button();
this.oleDbConnection1 = new System.Data.OleDb.OleDbConnection();
this.oleDbSelect1 = new System.Data.OleDb.OleDbCommand();
this.textBox1 = new System.Windows.Forms.TextBox();
this.label2 = new System.Windows.Forms.Label();
this.label1 = new System.Windows.Forms.Label();
this.textBox2 = new System.Windows.Forms.TextBox();
this.textBox3 = new System.Windows.Forms.TextBox();
this.label3 = new System.Windows.Forms.Label();
this.label4 = new System.Windows.Forms.Label();
this.textBox4 = new System.Windows.Forms.TextBox();
this.textBox5 = new System.Windows.Forms.TextBox();
this.label5 = new System.Windows.Forms.Label();
this.label6 = new System.Windows.Forms.Label();
this.textBox6 = new System.Windows.Forms.TextBox();
this.label7 = new System.Windows.Forms.Label();
this.textBox7 = new System.Windows.Forms.TextBox();
this.label8 = new System.Windows.Forms.Label();
this.textBox8 = new System.Windows.Forms.TextBox();
this.label9 = new System.Windows.Forms.Label();
this.textBox9 = new System.Windows.Forms.TextBox();
this.textBox10 = new System.Windows.Forms.TextBox();
this.label10 = new System.Windows.Forms.Label();
this.label11 = new System.Windows.Forms.Label();
this.textBox11 = new System.Windows.Forms.TextBox();
this.oleDbInsert1 = new System.Data.OleDb.OleDbCommand();
this.oleDbDelete1 = new System.Data.OleDb.OleDbCommand();
this.oleDbConnection2 = new System.Data.OleDb.OleDbConnection();
this.oleDbSelect2 = new System.Data.OleDb.OleDbCommand();
this.button2 = new System.Windows.Forms.Button();
this.button3 = new System.Windows.Forms.Button();
this.textBox12 = new System.Windows.Forms.TextBox();
this.label12 = new System.Windows.Forms.Label();
this.label13 = new System.Windows.Forms.Label();
this.textBox13 = new System.Windows.Forms.TextBox();
this.SuspendLayout();
//
// button1
//
this.button1.Location = new System.Drawing.Point(224, 228);
this.button1.Name = "button1";
this.button1.Size = new System.Drawing.Size(75, 24);
this.button1.TabIndex = 0;
this.button1.Text = "訓練";
this.button1.Click += new System.EventHandler(this.button1_Click);
//
// oleDbConnection1
//
this.oleDbConnection1.ConnectionString = @"Jet OLEDB:Global Partial Bulk Ops=2;Jet OLEDB:Registry Path=;Jet OLEDB:Database Locking Mode=1;Data Source=""F:\OLD Backup\【作業區】\【_我的論文資料__應用分類元方法於微觀車流系統之 模擬-以高快速公路多車道為例】\接下來以這個為主繼續,但不要忘了其他的版本中有的在這被刪了。\【應用程式】\車流資 料.mdb"";Mode=Share Deny None;Jet OLEDB:Engine Type=5;Provider=""Microsoft.Jet.OLEDB.4.0"";Jet OLEDB:System database=;Jet OLEDB:SFP=False;persist security info=False;Extended Properties=;Jet OLEDB:Compact Without Replica Repair=False;Jet
OLEDB:Encrypt Database=False;Jet OLEDB:Create System Database=False;Jet OLEDB:Don't Copy Locale on Compact=False;User ID=Admin;Jet OLEDB:Global Bulk Transactions=1";
//
// textBox1
//
this.textBox1.Location = new System.Drawing.Point(138, 14);
this.textBox1.Name = "textBox1";
this.textBox1.Size = new System.Drawing.Size(42, 22);
this.textBox1.TabIndex = 5;
this.textBox1.Text = "300";
//
// label2
//
this.label2.Location = new System.Drawing.Point(50, 43);
this.label2.Name = "label2";
this.label2.Size = new System.Drawing.Size(94, 14);
this.label2.TabIndex = 4;
this.label2.Text = "分類元維持數:";
//
// label1
//
this.label1.Font = new System.Drawing.Font("新細明體", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(136)));
this.label1.Location = new System.Drawing.Point(50, 18);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(80, 14);
this.label1.TabIndex = 3;
this.label1.Text = "分類元數目:";
//
// textBox2 //
this.textBox2.Location = new System.Drawing.Point(150, 38);
this.textBox2.Name = "textBox2";
this.textBox2.Size = new System.Drawing.Size(42, 22);
this.textBox2.TabIndex = 5;
this.textBox2.Text = "100";
//
// textBox3
//
this.textBox3.Location = new System.Drawing.Point(150, 66);
this.textBox3.Name = "textBox3";
this.textBox3.Size = new System.Drawing.Size(42, 22);
this.textBox3.TabIndex = 5;
this.textBox3.Text = "10";
//
// label3
//
this.label3.Location = new System.Drawing.Point(48, 68);
this.label3.Name = "label3";
this.label3.Size = new System.Drawing.Size(80, 14);
this.label3.TabIndex = 4;
this.label3.Text = "初始力量值:";
//
// label4
//
this.label4.Location = new System.Drawing.Point(48, 93);
this.label4.Name = "label4";
this.label4.Size = new System.Drawing.Size(80, 14);
this.label4.TabIndex = 4;
this.label4.Text = "訓練次數:";
//
// textBox4
//
this.textBox4.Location = new System.Drawing.Point(152, 94);
this.textBox4.Name = "textBox4";
this.textBox4.Size = new System.Drawing.Size(42, 22);
this.textBox4.TabIndex = 5;
this.textBox4.Text = "1000000";
//
// textBox5
//
this.textBox5.Location = new System.Drawing.Point(144, 126);
this.textBox5.Name = "textBox5";
this.textBox5.Size = new System.Drawing.Size(42, 22);
this.textBox5.TabIndex = 5;
this.textBox5.Text = "1";
//
// label5
//
this.label5.Location = new System.Drawing.Point(42, 128);
this.label5.Name = "label5";
this.label5.Size = new System.Drawing.Size(94, 14);
this.label5.TabIndex = 4;
this.label5.Text = "生命稅(定值):";
//
// label6
//
this.label6.Location = new System.Drawing.Point(50, 162);
this.label6.Name = "label6";
this.label6.Size = new System.Drawing.Size(94, 14);
this.label6.TabIndex = 4;
this.label6.Text = "出價比例:";
//
// textBox6
//
this.textBox6.Location = new System.Drawing.Point(154, 162);
this.textBox6.Name = "textBox6";
this.textBox6.Size = new System.Drawing.Size(42, 22);
this.textBox6.TabIndex = 5;
this.textBox6.Text = "0.1";
//
// label7
//
this.label7.Location = new System.Drawing.Point(48, 198);
this.label7.Name = "label7";
this.label7.Size = new System.Drawing.Size(94, 14);
this.label7.TabIndex = 4;
this.label7.Text = "獎勵值(定值):";
//
// textBox7
//
this.textBox7.Location = new System.Drawing.Point(154, 200);
this.textBox7.Name = "textBox7";
this.textBox7.Size = new System.Drawing.Size(42, 22);
this.textBox7.TabIndex = 5;
this.textBox7.Text = "10";
//
// label8
//
this.label8.Location = new System.Drawing.Point(50, 234);
this.label8.Name = "label8";
this.label8.Size = new System.Drawing.Size(94, 14);
this.label8.TabIndex = 4;
this.label8.Text = "懲罰值(定值):";
//
// textBox8
//
this.textBox8.Location = new System.Drawing.Point(158, 238);
this.textBox8.Name = "textBox8";
this.textBox8.Size = new System.Drawing.Size(42, 22);
this.textBox8.TabIndex = 5;
this.textBox8.Text = "10";
//
// label9
//
this.label9.Location = new System.Drawing.Point(248, 26);
this.label9.Name = "label9";
this.label9.Size = new System.Drawing.Size(94, 14);
this.label9.TabIndex = 4;
this.label9.Text = "交配比例:";
//
// textBox9
//
this.textBox9.Location = new System.Drawing.Point(356, 24);
this.textBox9.Name = "textBox9";
this.textBox9.Size = new System.Drawing.Size(42, 22);
this.textBox9.TabIndex = 5;
this.textBox9.Text = "70";
//
// textBox10
//
this.textBox10.Location = new System.Drawing.Point(360, 62);
this.textBox10.Name = "textBox10";
this.textBox10.Size = new System.Drawing.Size(42, 22);
this.textBox10.TabIndex = 5;
this.textBox10.Text = "19";
//
// label10
//
this.label10.Location = new System.Drawing.Point(250, 62);
this.label10.Name = "label10";
this.label10.Size = new System.Drawing.Size(94, 14);
this.label10.TabIndex = 4;
this.label10.Text = "複製比例:";
//
// label11
//
this.label11.Location = new System.Drawing.Point(252, 94);
this.label11.Name = "label11";
this.label11.Size = new System.Drawing.Size(94, 14);
this.label11.TabIndex = 4;
this.label11.Text = "突變比例:";
//
// textBox11
//
this.textBox11.Location = new System.Drawing.Point(364, 96);
this.textBox11.Name = "textBox11";
this.textBox11.Size = new System.Drawing.Size(42, 22);
this.textBox11.TabIndex = 5;
this.textBox11.Text = "11";
//
// oleDbConnection2
//
this.oleDbConnection2.ConnectionString = @"Jet OLEDB:Global Partial Bulk Ops=2;Jet OLEDB:Registry Path=;Jet OLEDB:Database Locking Mode=1;Data Source=""F:\OLD Backup\【作業區】\【_我的論文資料__應用分類元方法於微觀車流系統之 模擬-以高快速公路多車道為例】\接下來以這個為主繼續,但不要忘了其他的版本中有的在這被刪了。\【應用程式】\車流資 料.mdb"";Mode=Share Deny None;Jet OLEDB:Engine Type=5;Provider=""Microsoft.Jet.OLEDB.4.0"";Jet OLEDB:System database=;Jet OLEDB:SFP=False;persist security info=False;Extended Properties=;Jet OLEDB:Compact Without Replica Repair=False;Jet
OLEDB:Encrypt Database=False;Jet OLEDB:Create System Database=False;Jet OLEDB:Don't Copy Locale on Compact=False;User ID=Admin;Jet OLEDB:Global Bulk Transactions=1";
//
// button2
//
this.button2.Location = new System.Drawing.Point(312, 228);
this.button2.Name = "button2";
this.button2.Size = new System.Drawing.Size(75, 24);
this.button2.TabIndex = 0;
this.button2.Text = "驗證";
this.button2.Click += new System.EventHandler(this.button2_Click);
//
// button3
//
this.button3.Location = new System.Drawing.Point(396, 228);
this.button3.Name = "button3";
this.button3.Size = new System.Drawing.Size(75, 24);
this.button3.TabIndex = 0;
this.button3.Text = "預測";
//
// textBox12
//
this.textBox12.Location = new System.Drawing.Point(362, 134);
this.textBox12.Name = "textBox12";
this.textBox12.Size = new System.Drawing.Size(42, 22);
this.textBox12.TabIndex = 5;
this.textBox12.Text = "0";
//
// label12
//
this.label12.Location = new System.Drawing.Point(252, 132);
this.label12.Name = "label12";
this.label12.Size = new System.Drawing.Size(94, 14);
this.label12.TabIndex = 4;
this.label12.Text = "訓練樣本數:";
//
// label13
//
this.label13.Location = new System.Drawing.Point(252, 168);
this.label13.Name = "label13";
this.label13.Size = new System.Drawing.Size(94, 14);
this.label13.TabIndex = 4;
this.label13.Text = "驗證樣本數:";
//
// textBox13
//
this.textBox13.Location = new System.Drawing.Point(362, 166);
this.textBox13.Name = "textBox13";
this.textBox13.Size = new System.Drawing.Size(42, 22);
this.textBox13.TabIndex = 5;
this.textBox13.Text = "0";
//
// Form1
//
this.AutoScaleBaseSize = new System.Drawing.Size(5, 15);
this.ClientSize = new System.Drawing.Size(482, 273);
this.Controls.Add(this.textBox1);
this.Controls.Add(this.label2);
this.Controls.Add(this.label1);
this.Controls.Add(this.button1);
this.Controls.Add(this.textBox2);
this.Controls.Add(this.textBox3);
this.Controls.Add(this.label3);
this.Controls.Add(this.label4);
this.Controls.Add(this.textBox4);
this.Controls.Add(this.textBox5);
this.Controls.Add(this.label5);
this.Controls.Add(this.label6);
this.Controls.Add(this.textBox6);
this.Controls.Add(this.label7);
this.Controls.Add(this.textBox7);
this.Controls.Add(this.label8);
this.Controls.Add(this.textBox8);
this.Controls.Add(this.label9);
this.Controls.Add(this.textBox9);
this.Controls.Add(this.textBox10);
this.Controls.Add(this.label10);
this.Controls.Add(this.label11);
this.Controls.Add(this.textBox11);
this.Controls.Add(this.button2);
this.Controls.Add(this.button3);
this.Controls.Add(this.textBox12);
this.Controls.Add(this.label12);
this.Controls.Add(this.label13);
this.Controls.Add(this.textBox13);
this.Name = "Form1";
this.Text = "Form1";
this.ResumeLayout(false);
}
[STAThread]
static void Main()
{
Application.Run(new Form1());
}
private void button1_Click(object sender, System.EventArgs e)
{
this.RunFirst();
//陣列初始化
/*一般起始解比較
int seed = unchecked((int)DateTime.Now.Ticks);
random2 = new Random(seed);
for (int i=0; i<z1; i++)
{
this.randomArray[i] = new Random(random2.Next(20));
}
本車車速c[i] = this.randomArray[4].Next(16);
前車車距c[i] = this.randomArray[5].Next(16);
前車車速c[i] = this.randomArray[6].Next(16);
後車車距c[i] = this.randomArray[7].Next(16);
後車車速c[i] = this.randomArray[8].Next(16);
採取行動c[i] = this.randomArray[9].Next(3);
this.oleDbConnection1.Open();
this.oleReader = this.oleDbSelect1.ExecuteReader();
int j = 0, l = 0;
while (this.oleReader.Read())
{
this.本車車道代碼c[j] = this.oleReader.GetInt32(0);
this.本車車種代碼c[j] = this.oleReader.GetInt32(1);
this.本車車速c[j] = ((int)this.oleReader.GetFloat(2)-51)/z15;
this.前車車速c[j] = ((int)this.oleReader.GetFloat(3)-51)/z15;
this.後車車速c[j] = ((int)this.oleReader.GetFloat(4)-51)/z15;
this.前車車距c[j] = ((int)this.oleReader.GetFloat(5)-11)/z15;
this.後車車距c[j] = ((int)this.oleReader.GetFloat(6)-11)/z15;
if (this.本車車速c[j] < 0){this.本車車速c[j] = 0;}
else if((this.前車車速c[j]-this.本車車速c[j])>0)
{
//維持等速【本車加速度r=0】、加速【本車加速度r=1】、減速【本車加速度r=2】、變換車道【本
車加速度r=3】、5為誤差值
if (System.Math.Abs(this.oleReader.GetFloat(7)) < z14)
{
this.前車車種c[j] = this.oleReader.GetInt32(8);
this.後車車種c[j] = this.oleReader.GetInt32(9);
this.ST[j] = z3 + sample;
this.SP[j] = z5;
}
j = j+1;
}
this.oleDbConnection1.Close();
// */
for (int i=0; i<z4; i++)
{
this.oleDbSelect1.CommandText = "SELECT 車道代碼, 車種代碼, 本車車速, 前車車速, 後車車速, 前 車車距, 後車車距, 本車加速度, 前車車種, 後車車種, 車輛代碼 FROM averageFlowData ORDER BY 車輛代碼";
this.oleDbConnection1.Open();
this.oleReader = this.oleDbSelect1.ExecuteReader();
l=0;
while (this.oleReader.Read())
{
this.本車車道代碼r = this.oleReader.GetInt32(0);
this.本車車種代碼r = this.oleReader.GetInt32(1);
this.本車車速r = ((int)this.oleReader.GetFloat(2)-51)/z15;
this.前車車速r = ((int)this.oleReader.GetFloat(3)-51)/z15;
this.後車車速r = ((int)this.oleReader.GetFloat(4)-51)/z15;
this.前車車距r = ((int)this.oleReader.GetFloat(5)-11)/z15;
this.後車車距r = ((int)this.oleReader.GetFloat(6)-11)/z15;
if (this.本車車速r < 0){this.本車車速r = 0;}
}
//維持等速【本車加速度r=0】、加速【本車加速度r=1】、減速【本車加速度r=2】、變換車道【本
車加速度r=3】、5為誤差值
if (System.Math.Abs(this.oleReader.GetFloat(7)) < z14)
{
this.前車車種r = this.oleReader.GetInt32(8);
this.後車車種r = this.oleReader.GetInt32(9);
this.ClassiFier1();
}
this.oleDbConnection1.Close();
if (i%100 == 0 && i != 0)
{
if(MessageBox.Show("第" + i.ToString() + "循環中,合格的RULE有" + correctNB,"請選擇
",MessageBoxButtons.OKCancel) == DialogResult.Cancel )
{
break;
}
this.oleDbConnection2.Open();
this.oleDbDelete1.CommandText = string.Format("DELETE * FROM RulesSaved");
this.oleDbDelete1.ExecuteNonQuery();
for (int k=0; k<z; k++)
{
if (ST[k]>z3)
{
this.oleDbSelect2.CommandText = string.Format("SELECT Count(0) FROM RulesSaved WHERE 本車車道代碼c={0} AND 本車車種代碼c={1} AND 前車車種c={2} AND 後車車種c={3} AND 本車車速c={4}
this.oleDbInsert1.CommandText = string.Format("INSERT INTO RulesSaved(本車車道代碼c, 本車車種代碼c, 前車車種c, 後車車種c, 本車車速c, 前車車距c, 前車車速c, 後車車距c, 後車車速c, 採取行動c, ST) VALUES ({0}, {1}, {2}, {3}, '{4}', {5}, {6}, {7}, {8}, {9}, {10})", 本車車道代碼c[k], 本車車種代碼c[k], 前車車種 c[k], 後車車種c[k], 本車車速c[k], 前車車距c[k], 前車車速c[k], 後車車距c[k], 後車車速c[k], 採取行動c[k], ST[k]);
this.oleDbInsert1.ExecuteNonQuery();
}
}
}
this.oleDbConnection2.Close();
}
correctNB = 0;
}
MessageBox.Show("訓練完成!");
}
private void RunFirst()
{
z = Convert.ToInt32(this.textBox1.Text);
z2 = Convert.ToInt32(this.textBox2.Text);
z3 = Convert.ToInt32(this.textBox3.Text);
z4 = Convert.ToInt32(this.textBox4.Text);
z7 = Convert.ToInt32(this.textBox5.Text);
z8 = Convert.ToSingle(this.textBox6.Text);
z9 = Convert.ToInt32(this.textBox7.Text);
z10 = Convert.ToInt32(this.textBox8.Text);
z12 = Convert.ToInt32(this.textBox12.Text);
z13 = Convert.ToInt32(this.textBox13.Text);
z14 = 2;
z15 = 1;
z16 = 1;
this.rCrossOver = Convert.ToInt32(this.textBox9.Text);
this.rCopy = Convert.ToInt32(this.textBox10.Text);
this.rMutation = Convert.ToInt32(this.textBox11.Text);
this.oleDbSelect1.Connection = this.oleDbConnection1;
this.oleDbSelect2.Connection = this.oleDbConnection2;
this.oleDbInsert1.Connection = this.oleDbConnection2;
this.oleDbDelete1.Connection = this.oleDbConnection2;
this.oleDbConnection1.Open();
this.oleDbSelect1.CommandText = "SELECT Count(0) FROM averageFlowData";
this.sample1 = Convert.ToInt32(this.oleDbSelect1.ExecuteScalar());
this.oleDbConnection1.Close();
sample = sample1;
if (z12 > 0 )
{
sample = z12;
}
int seed = unchecked((int)DateTime.Now.Ticks);
int [] r1 = new int[j];
r = random1.Next(rCrossOver+rCopy+rMutation);
if(r<rCrossOver)
{
//CrossOver, 採一點交配法
CrossOver(ref 本車車速c[i], length1, 本車車速c[parent[r1[j]]], 本車車速c[parent[r1[j+1]]], ref 本車車速c[i+1], i);
CrossOver(ref 前車車距c[i], length1, 前車車距c[parent[r1[j]]], 前車車距c[parent[r1[j+1]]], ref 前車車距c[i+1], i);
CrossOver(ref 前車車速c[i], length1, 前車車速c[parent[r1[j]]], 前車車速c[parent[r1[j+1]]], ref 前車車速c[i+1], i);
CrossOver(ref 後車車距c[i], length1, 後車車距c[parent[r1[j]]], 後車車距c[parent[r1[j+1]]], ref 後車車距c[i+1], i);
CrossOver(ref 後車車速c[i], length1, 後車車速c[parent[r1[j]]], 後車車速c[parent[r1[j+1]]], ref 後車車速c[i+1], i);
CrossOver(ref 採取行動c[i], length2, 採取行動c[parent[r1[j]]], 採取行動c[parent[r1[j+1]]], ref 採取行動c[i+1], i);
CrossOver(ref 本車車道代碼c[i], length2, 本車車道代碼c[parent[r1[j]]], 本車車道代碼 c[parent[r1[j+1]]], ref 本車車道代碼c[i+1], i);
CrossOver(ref 本車車種代碼c[i], length3, 本車車種代碼c[parent[r1[j]]], 本車車種代碼 c[parent[r1[j+1]]], ref 本車車種代碼c[i+1], i);
CrossOver(ref 前車車種c[i], length3, 前車車種c[parent[r1[j]]], 前車車種c[parent[r1[j+1]]], ref 前車車種c[i+1], i);
CrossOver(ref 後車車種c[i], length3, 後車車種c[parent[r1[j]]], 後車車種c[parent[r1[j+1]]], ref 後車車種c[i+1], i);
else if(rCrossOver<=r && r<(rCopy+rCrossOver))
{
Mutation(ref 前車車速c[i], length1, 前車車速c[parent[r1[j]]]);
private void CrossOver(ref int var0, int length, int var1, int var2, ref int var3, int i)
{
int r, temp1, temp2;
r = random1.Next(length-1)+1;
//交配法二
temp1 = var1 | (int)(Math.Pow(2, r)-1);
temp2 = (var2>>(length-r)) | ((int)(Math.Pow(2, length-r)-1)<<r);
var0 = temp1 & temp2;
if (ST[i+1] <= 0)
{
temp1 = ((var1 & (int)(Math.Pow(2, r)-1)) << (length-r)) | (int)(Math.Pow(2, length-r)-1);
temp2 = var2 | ((int)(Math.Pow(2, r)-1)<<(length-r));
var3 = temp1 & temp2;
}
}
private void Mutation(ref int var0, int length, int var1)
{
int r;
r = random1.Next((int)(Math.Pow(2, length)-1)+1);
var0 = var1 ^ r;
Array.Sort(BidPrice);
for (int i=0; BidWin[i,1]>0; i++)
ST[BidWin[i,0]] = ST[BidWin[i,0]]/(1-z8)+z7+z9*10+sample;
correctNB = correctNB+1;
if (ST[i]>0 && 本車車道代碼c[i]==本車車道代碼r && 本車車種代碼c[i]==本車車種代碼r &&
Array.Sort(BidPrice);
for (int i=0; BidWin[i,1]>0; i++)
Array.Sort(BidPrice);
for (int i=0; BidWin[i,1]>0; i++)
BidWin[j,0] = i;
Array.Sort(BidPrice);
for (int i=0; BidWin[i,1]>0; i++)
Array.Sort(BidPrice);
for (int i=0; BidWin[i,1]>0; i++)
ST[i] = ST[i]-z7;
// }
}
//取出得標者, 並進行功勞分配
Array.Sort(BidPrice);
for (int i=0; BidWin[i,1]>0; i++)
Array.Sort(BidPrice);
for (int i=0; BidWin[i,1]>0; i++)
Array.Sort(BidPrice);
for (int i=0; BidWin[i,1]>0; i++)
{
if (BidWin[i,1]==BidPrice[z-1])
{
Array.Sort(BidPrice);
for (int i=0; BidWin[i,1]>0; i++)
r[i] =random2.Next(unchecked((int)totalST));
}
while (k < 2*(z-j) && tempTotalST <= r[k] && r[k] < (tempTotalST+ST[i]))
{
parent[k] = i;
k = k+1;
}
Mutation(ref 本車車速c[i], length1, 本車車速c[random1.Next(z)]);
Mutation(ref 前車車距c[i], length1, 前車車距c[random1.Next(z)]);
Mutation(ref 前車車速c[i], length1, 前車車速c[random1.Next(z)]);
Mutation(ref 後車車距c[i], length1, 後車車距c[random1.Next(z)]);
Mutation(ref 後車車速c[i], length1, 後車車速c[random1.Next(z)]);
Mutation(ref 採取行動c[i], length2, 採取行動c[random1.Next(z)]);
Mutation(ref 本車車道代碼c[i], length2, 本車車道代碼c[random1.Next(z)]);
Mutation(ref 本車車種代碼c[i], length3, 本車車種代碼c[random1.Next(z)]);
Mutation(ref 前車車種c[i], length3, 前車車種c[random1.Next(z)]);
Mutation(ref 後車車種c[i], length3, 後車車種c[random1.Next(z)]);
}
}
Gene(parent, j);
}
}
private void button2_Click(object sender, System.EventArgs e)
{
this.oleDbConnection1.Open();
this.oleReader = this.oleDbSelect1.ExecuteReader();
int j = 0;
while (this.oleReader.Read())
{
if (j<z)
{
//車速 51~130(km/h)每5km/h為一區隔,故有16個區段
//距離11~90(m)每5公尺作一區隔,共16個間隔
this.本車車道代碼c[j] = this.oleReader.GetInt32(0);
this.本車車種代碼c[j] = this.oleReader.GetInt32(1);
this.前車車種c[j] = this.oleReader.GetInt32(2);
this.後車車種c[j] = this.oleReader.GetInt32(3);
this.本車車速c[j] = this.oleReader.GetInt32(4);
this.前車車距c[j] = this.oleReader.GetInt32(5);
this.前車車速c[j] = this.oleReader.GetInt32(6);
this.後車車距c[j] = this.oleReader.GetInt32(7);
this.後車車速c[j] = this.oleReader.GetInt32(8);
this.採取行動c[j] = this.oleReader.GetInt32(9);
this.ST[j] = this.oleReader.GetFloat(10);
this.SP[j] = z5;
j = j+1;
}
}
this.oleDbConnection1.Close();
//開始驗證
int l=0;
correctNB = 0;
this.oleDbSelect1.CommandText = "SELECT 車道代碼, 車種代碼, 本車車速, 前車車速, 後車車速, 前車車距, 後車車距, 本車加速度, 前車車種, 後車車種, 車輛代碼 FROM averageFlowData ORDER BY 車輛代碼";
this.oleDbConnection1.Open();
this.oleReader = this.oleDbSelect1.ExecuteReader();
while (this.oleReader.Read())
{
//車速 51~130(km/h)每5km/h為一區隔,故有16個區段
//距離11~90(m)每5公尺作一區隔,共16個間隔
this.本車車道代碼r = this.oleReader.GetInt32(0);
this.本車車種代碼r = this.oleReader.GetInt32(1);
this.本車車速r = ((int)this.oleReader.GetFloat(2)-51)/z15;
this.前車車速r = ((int)this.oleReader.GetFloat(3)-51)/z15;
this.後車車速r = ((int)this.oleReader.GetFloat(4)-51)/z15;
this.前車車距r = ((int)this.oleReader.GetFloat(5)-11)/z15;
this.後車車距r = ((int)this.oleReader.GetFloat(6)-11)/z15;
if (this.本車車速r < 0){this.本車車速r = 0;}
{
if (System.Math.Abs(this.oleReader.GetFloat(7)) < z14)
{
this.前車車種r = this.oleReader.GetInt32(8);
this.後車車種r = this.oleReader.GetInt32(9);
if (z12 == 0 && z13 == 0)
this.oleDbConnection1.Close();
MessageBox.Show("驗證完成!準確率為" + (correctNB/sample));
tempx=0;
速c[i]==本車車速r && 前車車種c[i]==前車車種r && 前車車距c[i]==前車車距r && 前車車速c[i]==前車車速r && 後車車種c[i]==
Array.Sort(BidPrice);
for (int i=0; BidWin[i,1]>0; i++)
Array.Sort(BidPrice);
for (int i=0; BidWin[i,1]>0; i++)
Array.Sort(BidPrice);
for (int i=0; BidWin[i,1]>0; i++)
correctNB = correctNB+1;
Array.Sort(BidPrice);
for (int i=0; BidWin[i,1]>0; i++)
Array.Sort(BidPrice);
for (int i=0; BidWin[i,1]>0; i++)
Array.Sort(BidPrice);
for (int i=0; BidWin[i,1]>0; i++)
Array.Sort(BidPrice);
for (int i=0; BidWin[i,1]>0; i++)
Array.Sort(BidPrice);
for (int i=0; BidWin[i,1]>0; i++)
}
}
//取出得標者, 並進行功勞分配
Array.Sort(BidPrice);
for (int i=0; BidWin[i,1]>0; i++)
{
if (BidWin[i,1]==BidPrice[z-1])
{
if (採取行動c[BidWin[i,0]]==採取行動r)
{
correctNB = correctNB+1;
break;
}
}
}
}
//完全不合的
if (BidWin[0,1]==0)
{
if (this.random1.Next(3) == 採取行動r)
{
correctNB = correctNB+1;
tempx4=tempx4+1;
}
}
}
} }