第七章 結論與建議
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;
}
}
}
} }