Thứ Ba, 8 tháng 3, 2016

Báo cáo đồ án trí tuệ nhân tạo : xây dựng chương trình cho phép tìm kiếm đường đi tốt nhất theo giải thuật tìm kiếm Greedy best first search cho Không gian trạng thái bài toán người đưa thư

Thuật toán Tìm Kiếm Greedy best first search (GBFS) diem[i] = new Point(dt.Nha[i].Location.X + dt.Nha[i].Height / 2, dt.Nha[i].Location.Y + dt.Nha[i].Width / 2); } tb = new TextBox[dt.Sonha, dt.Sonha]; for (int i = 0; i < dt.Sonha; i++) { for (int j = 0; j < dt.Sonha; j++) { tb[i, j] = new TextBox(); tb[i, j].Text = "0"; } } for (int i = 0; i < dt.Sonha; i++) { for (int j = i + 1; j < dt.Sonha; j++) { tb[i, j].Size = new Size(23, 18); tb[i, j].Text = dt.Mangcost[i, j].ToString(); tb[i, j].Location = new Point((diem[i].X + diem[j].X) / 2, (diem[i].Y + diem[j].Y) / 2); this.Controls.Add(tb[i, j]); } } } // Hàm xóa hiển thị private void xoahienthi() Trần Thị Hồng Diệp Tin học 5A Thuật toán Tìm Kiếm Greedy best first search (GBFS) { foreach (TextBox tbs in this.tb) { this.Controls.Remove(tbs); } foreach (nha n in dt.Nha) { this.Controls.Remove(n); } } // Hàm lưu nhà private void luunha(int x, int y) { StreamReader sr = new StreamReader("dt1.txt"); string sonutcu = sr.ReadLine(); int sonutmoi = Convert.ToInt32(sonutcu) + 1; string temp = sr.ReadToEnd(); sr.Close(); StreamWriter sw = new StreamWriter("dt1.txt"); sw.WriteLine(sonutmoi); sw.WriteLine(temp); string toado = x.ToString() + "," + y.ToString(); sw.Write(toado); sw.Close(); } //Hàm xóa dữ liệu Trần Thị Hồng Diệp Tin học 5A Thuật toán Tìm Kiếm Greedy best first search (GBFS) private void xoadulieu() { StreamWriter sw1 = new StreamWriter("dt1.txt"); sw1.Write(""); sw1.Close(); StreamWriter sw2 = new StreamWriter("dt2.txt"); sw2.Write(""); sw2.Close(); } // Hàm lưu giá private void luugia() { for (int i = 0; i < dt.Sonha; i++) { for (int j = i+1; j < dt.Sonha; j++) { tb[j, i].Text = tb[i, j].Text; } } StreamWriter sw = new StreamWriter("dt2.txt"); string temp = null; for (int i = 0; i < dt.Sonha; i++) { for (int j = 0; j < dt.Sonha; j++) { Trần Thị Hồng Diệp Tin học 5A Thuật toán Tìm Kiếm Greedy best first search (GBFS) temp = temp + tb[i, j].Text + " | "; } temp = temp + "\r\n"; } sw.WriteLine(temp); sw.Close(); } // Hàm lưu giá sau khi thêm nhà private void luugiasauthemnha() { string temp = null; if (dt.Sonha == 0) { StreamWriter sw = new StreamWriter("dt2.txt"); temp = "00 |"; sw.WriteLine(temp); sw.Close(); } else { StreamReader sr = new StreamReader("dt2.txt"); string[] dauvao = new string[dt.Sonha - 1]; for (int i = 0; i < dt.Sonha - 1; i++) { dauvao[i] = sr.ReadLine(); } sr.Close(); Trần Thị Hồng Diệp Tin học 5A Thuật toán Tìm Kiếm Greedy best first search (GBFS) StreamWriter sw = new StreamWriter("dt2.txt"); for (int i = 0; i < dt.Sonha - 1; i++) { temp = temp + dauvao[i] + " | 00 |"; temp = temp + "\r\n"; } for (int i = 0; i < dt.Sonha; i++) { temp = temp + "00 | "; } sw.WriteLine(temp); sw.Close(); } } private void themtb() { tb = new TextBox[dt.Sonha, dt.Sonha]; for (int i = 0; i < dt.Sonha; i++) { for (int j = 0; j < dt.Sonha; j++) { tb[i, j] = new TextBox(); tb[i, j].Text = "0"; } } Trần Thị Hồng Diệp Tin học 5A Thuật toán Tìm Kiếm Greedy best first search (GBFS) for (int i = 0; i < dt.Sonha; i++) { for (int j = i + 1; j < dt.Sonha; j++) { tb[i, j].Size = new Size(23, 18); tb[i, j].Text = dt.Mangcost[i, j].ToString(); tb[i, j].Location = new Point((diem[i].X + diem[j].X) / 2, (diem[i].Y + diem[j].Y) / 2); this.Controls.Add(tb[i, j]); } } } private void Form1_Load(object sender, EventArgs e) { hienthi(); } private void Form1_Paint(object sender, PaintEventArgs e) { Graphics dohoa = this.CreateGraphics(); Pen to = new Pen(Color.Red, 2); for (int i = 0; i < dt.Sonha; i++) { for (int j = i + 1; j < dt.Sonha; j++) { dohoa.DrawLine(to,diem[i],diem[j]); } } Trần Thị Hồng Diệp Tin học 5A

Không có nhận xét nào :

Đăng nhận xét