HỌC VIỆN KỸ THUẬT QUÂN SỰ
KHOA CÔNG NGHỆ THÔNG TIN
BÁO CÁO MÔN HỌC
TRÍ TUỆ NHÂN TẠO
BÁO CÁO BÀI TẬP LN
Đ! T"i !"#$"%&'"()*+*",+!))$ /01
2"#3(40,"+*""5("6"5*72778)*+
.5#)5""59
:;"(+*"
<$='>"?@6"'*+$="AB'"5"#0,)C
;D6"='>""#8)&*'>""#C9
E='>""$"#8)&+$=",B'"59
;D6"F%&8"@%!)B9
<$'@B'6"'!"5'!."#C9
GH6" IJKL
"#C JMLNI
O9)& LMIIKI
@)&"@%!="A'!)*%2C9
P,7%H6"%A="#C)Q"R
277(40,"Q%ST("6"5*72778
#)5""59
9P/01
<;U=!
;U=!C7/V<!#05:)*WA"XQ"
Y%B"S"6""5?ZXWA'U=!*0*+[3=
%2(
O#'U=!C7/-'8\'?]"A)*D+"?^_9
E"AVE#'?'5:`
E"AVE#'?'5:<
;U=!C7/%!#!SW(ab!\'?]"A'>"?@)&c
5%dC9
E'U=!*0"eW"1S+*"*"F"(
?!?!W"1f7g7"#??5#!#'"!"
hi"5.?"-i5.?""5 !7?!W
E#'?'5
55#!"5#!'77)!"jn#'?'5?
!:
+:
:
<./01*'"k
l1!8W,"4("@%)*BW,"4('*"!B"3'Q"9
!: <55j"iN-m5"iI
+:<55j"i-m5"iN9
:<55j"i-m5"iM9
O!872+-n
<./0172778?1W,"&7
E\'?]"A%&8"o4B"A)*!)!g7V#??5#:9
p72778+.5#)5""5
E!%&84!%>"kb!
\'?]"A"@"2-S27(%&8
O["&'>"roulette wheel2"Q"(qO"#4B"A%&%_"
)9
k"b!%$"##)5"5r55)"2Y"#Cb!*'"k
9
;>"s+%&)a"##)5""5r55)*qO2=o)$%&)1!
89
qO"#C"k)?t%&8S29
<I?!W8%&"A"@")!g7-"1f"!"E#??5#*
'"!")*!7g7"2+(b!"6""5u'"$'>"4B"A
'="#C"@"2*%$"%&W,"4('*"!"3'W,'9
O#2"#3*0-"!?ZX7277?)5v7"#??5#-"rv7"
*`#"'5"v#??5#%A)!g7"A!9
III)Xây d1ng chương tr7nh
!f
P/01'(%A)"#C-W@)&6"9
public int[,] knapsack = new int[7, 2] { { 5, 7 }, { 8, 8 }, { 3, 4 }, { 2, 10
}, { 7, 4 }, { 9, 6 }, { 4,4} };
private string[] str_dt = new string[30];
private string[] str_p = new string[30];
private string[] str_f = new string[30];
W["$"#C4B"A+!%B
;U)f"1"
private void button1_Click(object sender, EventArgs e)
{
//int dem = 0;
lb.Items.Clear();
for (int i = 0; i < 30; i++)
{
gen_str: string str_ = Random_ks();
if (i==0)
str_dt[i] = str_;
else
for (int j = 0; j < i; j++)
{
if (str_dt[j] == str_)
goto gen_str;
else
str_dt[i] = str_;
}
}
EwD"#&*7"!"$'>"x"T0y"#C*W@)&
6"%U]Y"#2"#39
"#C*W@)&"A"2Y
<""z!)5{)**'"k-)1!8"|!"@")!g7"$4B
"A9
P/01*'h)"?'
private string Elitism(string[] str_)
{
int max = 0,sum1=0;
int index = 0,sum2=0;
for (int i = 0; i < 30; i++)
{
string tmp = str_[i];
for (int j = 0; j < 7; j++)
{
if (Convert.ToInt16(tmp[j]) == 49)
{
sum1 += knapsack[j, 0];
sum2 += knapsack[j, 1];
}
}
if (sum2 <= 22 && sum1 > max)
{
max = sum1;
index = i;
}
sum1 = sum2 = 0;
}
return str_[index];
"$4B"A'+u#??5#_'"!"-="A)*''Q""A
"@"Q"9
277Elitism7g770"A"@"V_'>"*"A
"@":?!4B"A'9
O*7Bs)$b!4B"A%&"$"oW9
277Elitism="A"a"@+*"-3=aW)*''Q"
"A"@"9
P/01*';"!""$%>"+,"#'>""A%A",7"X)!g79
private void Mutation(string[] str)
{
Random rnd = new Random();
int index_str = rnd.Next(0,30);
string tmp = str[index_str];
int num = rnd.Next(1, 3);
for (int i = 0; i < num; i++)
{
int index = rnd.Next(0,6);
if (tmp[index].Equals("0"))
{
tmp.Remove(index, 1);
tmp.Insert(index, "1");
}
else
{
tmp.Remove(index, 1);
tmp.Insert(index, "0");
}
}
str_p[index_str] = tmp;
}
P/01*'8+.5#)5""59
private int roulette(string[] str_p_)
{
int sum1 =0,sum2=0;
string tmp = "";
for (int i=0;i<30;i++)
{
tmp = str_p_[i];
for (int j = 0; j < 7; j++)
{
if (Convert.ToInt16(tmp[j]) == 49)
{
sum1 += knapsack[j, 1];
}
}
sum2 += sum1;
sum1 = 0;
}
Random rnd = new Random();
int r = rnd.Next(0,sum2);
int sum3 = 0, sum4 = 0,ret=0;
for (int i = 0; i < 30; i++)
{
tmp = str_p_[i];
for (int j = 0; j < 7; j++)
{
if (Convert.ToInt16(tmp[j]) == 49)
{
sum3 += knapsack[j, 1];
}
}
sum4 += sum3;
sum3 = 0;
if (sum4 > r)
{
ret = i;
goto end;
}
}
end: return ret;
}
O,*)!g7*W,"4(4B"A"%&?!)!g7
,"4("!?t"3'%)e("@"Wd)*"@Q"b!+*"3
72778!"1?1"@""#\+,"1",9
p:E"*)f"!'W(
!9 q)5+*('`b!"B0
+9O#!r5+)59'9*"#!W
Em cảm ơn thầy vì đã dạy em môn Trí tuệ nhân tạo.