trình bày về ứng dụng của mạng suy diễn tính toán
Trang 1CHU<1NG 5
cAC UNG D{)NG
Trong chuang n~y trlnh bay mQt s6 ling dl,lllg cua mi;lng suy di~n tinh roan, mahlnh tri thlic cac C-Object va ma hlnh m~lllgcac C-Objeet duQc trlnh bay trongcac chuang 2, 3 va 4 Cac ling dl;lngn~y bao g6m:
- Chuang trlnh giiii roan mQtC-Object
- Chuang trlnh giiii cac bai roan Hinh hQcph~ng
- Chuang trlnh giiii cae bai roan Hinh hQc ghli rich 3 chi€u
- Chuang trlnh giiii mQts6 bai roan v~ cac phan ling h6a hQe
" Ngoai fa, lu~n van con th1!c hit%nvit%cdi d~t mQt package v€ mi;lng suy di~n
tinh roan t6ng quat voi d~y du cac thu tl;lcgiai quye't cac va'n d€ cd ban duQc trlnn bay trang chudng 2 Ph~n chinh eua cai d~t package n~y duQc d€ trang
ph~n phl;lll;lC.
5.1 CmJONG TRINH GIAI TOAN C-OBJECT:
Trang ph~n n~y chung ta trlnh bay s1;1'cai d~t trang MAPLE mQt package
"CobjeccSolver" giai roan Object t6ng quat trong mQt ca sa tri thlic cac Object Nhu the' voi package n~y chung ta c6 th€ giai tl! dQng cae bai roan trencac lo~i tam giac cling nhu tren cac lo~i tli giae khac nhau VIcac tam giac va cac
C-tu giac cling vOi nhii'ng kie'n thlic v€ suy di~n va tinh roan lien quail eo th€ duQcbi€u di~n duoi di;lng cae d6i tuQng tinh roan (C-Object) MAPLE la ffiQtph~nffi~mdi;lis6 tinh roan (Computer Algebra) kha mi;lnhvoi s1!h6 trQ l?p trlnh trennhii'ng ea'u truc dii' lit%utrU'u tuQng ra't phue t~p thich hQp eho vit%edi d~t thii'nghit%mcac ma hlnh va phudng phap giai roan
Trang 25.1.1 Sd d6 ho~t dQng giai toan cua chtidng tr'inh
HO'.lt dQng giai toan mQt C-Objeet eila chuang trlnh dlfa tren mQt co sa tri thue cae C-Objeet ducJe t6 ehue theo mo hlnh tri thue cae C-Objeet T6 ehue co sa tri
thue cae C-Objeet nhu dil trlnh bay trong chuang 3, baa g6m cae t?P tin (file) vanban e6 eftu true ehua dl,l'ngcae kien thue ma chuang trlnh egn sii' d\lllg trong vit$e
suy 1u?n va unh toan Nhae l'.lirang t6 ehue cae t?P tin ehinh trong co sa tri thue
cae C-Objeet 1a:
[1] T?p tin "Objeets.txt" 1u'u tnl cae dinh danh (hay ten gQi) cho cac khainit$m v~ cac lo'.li d6i tucJng C-Object
[2] T?p tin "RELA TIONS.txt" 1u'u trll thong tin v~ cac lo'.li quail ht$ khacnhau tren cae lo'.li C-Objeet
[3] T?p tin "Hierarehy.txt" lu'u l'.li cac bi§u d6 Hasse v~ quail ht$ phan eiptren cae khai nit$m
[4] Cac t?P tin vOi ten t?P tin e6 d'.lng "<ten khai nit$m C-Objeet>.txt" d§ lu'utrfi' eiu true cila lo'.li d6i tucJng<ten khai nit$m C-Object> Vi d\l: t?P tin
"TAM_GIAC.txt" 1u'utrll eftu true eila lo'.li d6i tucJng tam giae
[5] T?p tin "Operators.txt" lu'u trll cae thong tin v~ cae toan tii' tren cae d6itu'cJng
[6] T?p tin "FACTS.txt" 1u'utrll thong tin v~ cae lo'.lisl,l'kit$nkhae nhau
[7] T?p tin "RULES.txt" lu'u trll ht$ lu?t eila co sa tri thUG.
So d6 ho'.lt dQng t6ng quat eila chuang trlnh duQe th§ hit$n trong hlnh 5.1 bell
duaL Qua trlnh hO'.lt dQng giai mQt bai toan e6 th§ ducJe di~n giai nhu san: Khie6 yell cgu giai mQt bai toan, chuang trlnh se dQc d~ bai va phan uch d~ baitoan Vit$c phan uch d~ se xae l?p mo hlnh bai toan g6m: cae d6i tucJng,cacthuQc tinh ducJequail tam, cae tham bien, cae s1,I'kit$n (g6m eae~lf kit$nth§ hit$n
Trang 3quail h~ tinh roan, cac sv ki~n th€ hi~n quail h~ khac, cac sv ki~n phan lo';li d6itu'Qng, .) va m1,lctieu cua bai roan Sau do bQph~n giai d~ se thvc hi~n vi~c
Hm kie'm Wi giai dva tren co sa tri thuc dii co, va th€ hi~n Wi giai tlm du'Qc
0
GIAI f)~
Tri th1fc
" Hinh 5.1 So d6 tang quat cua ho';lt dQng giai mQt d€ bai roan
5.1.2 Qui tiDe v~ d~ bili
f)~ bai co th€ du'Qc cho du'oi d';lng mQt t~p tin van ban co ca'u truc kha tvnhien va don gian d1;tatren mQt vai tu khoa nhu'"begin_hypothesis ",
"begin_goal ","end_goal" cling voi mQt so' qui tioc khai baa cac thalli bie'n,cac d6i tu'Qng, cac s1;tki~n va yeu cgu cua bai roan Day cling Ifl qui u'oc chungeho vi~e khai baa mQt bai roan tang quat rhea ma hlnh m';lng cac C-Object trongmQt COKB Ca'u truc cua d€ bai roan co d';lng nhu sail:
Trang 4Ta co the gQi cac chilcnang giai roan C-Object v~ cho bitt t~p tin d~ b~i.
cling ca'p tnle ti€p nhil'ng thong tin cda d~ b~i roan baa g6m: <kiSu d6i tu'<;1ng>,
<t~p h<;1pg6m cac sl;(ki~n gia thi€t> v~ < t~p h<;1pg6m cac sl;(ki~n mQc ti6u>
Vi du 5.1: Trang mQt tam giac gia sa cho tru'oc c';lnh a, v~ bitt b =5 Ngo~i ragia thi€t r~ng ta co cac sl;(ki~n saD day: GocA =2 GocB, a2=b2 + C2 Hay
xacdinh g6c B v~ goc C cda tam giac
Bai toart n~y QU<;1Ckhai baa rhea ca'u truc qui u'oc tr6n nhu' saD:
begin_hypothesis
objects:
Obj : TAM_GIACifacts:
Obj.a, Obj.b = 5Obj.GocA = 2*Obj GocB
end_hypothesis
begin_goal
Obj.GocB, Obj.GocCend aoal '
Trang 5
Ne'u ta mu6n yeti eiu giai bai roan tren b~ng each gQitn!e tie'p cae thu Wegiai
va cling ca'p cho thu t1Jccae thong tin v~ d~ bai thl ta eo th€ vie't dong 1t$nhgQi
Solvablels("TAM_GIAC", {a,b =5, GocA =2*GoeB, aA2=bA2 + cA2},
{GoeB, GocC})khi mu6n xet tint giai duQc cua bai roan, hay 1a vie't dong 1t$nhgQi
ComputeVars("TAM_GIAC", {a,b =5, GocA =2*GoeB, aA2 =bA2 +cA2}, {GocB, GocC})
khi mu6n tint GocB va Gocc
Vi du 5.2: Xet mQt tli' giac (16i) ABCD Gia sa bie't cac c<;tnha, b, e, d va goc A.Hay tint dit$n tich cua tli' giac
Bai roan niy duQckhai baa rhea ca'u truc qui uoe tren nhu sau:
begin_hypothesis
,,> objects:
Obj : TV_GIACifacts:
Obj.a, Obj.b, Obj.c, Obj.dObj.GocA
end_hypothesis
begin_goal
Obj.Send_goal
Ne'u ta mu6n yeti ciu giai bai roan tren b~ng each gQi tn!e tie'p cae thu t1JCgiai
va cling ca'p eho thu We cae thong tin v~ d~ bai thl ta eo th€ vie't dong 1t$nhgQi
Solvab1els("TU_GIAC", {a, b, e, d, GocA},{ S})
khi mu6n xet tinh giai duQc cua bai roan, hay 1a vie't dong 1t$nhgQi
ComputeVars("TU_GIAC", {a, b, e, d, GocA},{ S})
Trang 65.1.3 M(}t s6 thu tQ.c chinh
Du'oi day la trich d.1n cua 3 thu tvc chinh du'cjc cai d~t trang MAPLE 6.0 voichilc Dang chinh cua thu tvc nhu'sau:
- Thutl,lcSolvable1s( <ki€u d6i tu'cjng>,<GT>, <KL»
Trong do GT la t~p hcjp g6m cac s1,1'ki~n gia thie't, KL la t~p hcjp g6m cac s1,1'ki~n mvc hell Thu tvc n~y co nhi~m vv xac dinh xem bai toaD co giai du'cjchay kh6ng, va trong tru'ong hcjp giai du'cjcthl no cho ta mQt Wi gai (bao g6mffiQtdanh sach cac bu'oc giai)
- Thu t\lc ComputeVars«ki€u d6i tu'cjng>,<GT>, <KL»
Trang do GT la t~p hcjp g6m cac s1,1'ki~n gia thie't, KL la t~p hcjp g6m cacbie'n c~n tinh toaD Thu tl,lc n~y co nhi~m V\l th1,1'chi~n tinh toaD va cho ta gia
tq cac bie'n dn tinh hay mQt bi€u thilc tinh toaD theo cac bie'n va cac s1,1'ki~nita:bie\ trong tru'ong hcjp bai toaD la giai du'QC
- 1hu tvc IsDetermine( <ki€u d6i tu'cjng>, <Facts»
Trong do Facts la t~p hcjp g6m cac st.1'ki~n da: bie't cua d6i tu'cjng Thu tt.Icn~y
se khao sat va xem d6i tu'cjng co xac dinh hay kh6ng dt.1'avao t~p cac s,! ki~n
da: bie't No cho ta ke't qua true khi d6i tu'cjng la xac dinh va cho ke't qua false
trong tru'ong hQp ngu'cjc 1~i
CONet_Solver[Solvablels] := proc(nameO, facts, vars::set)
local factlist, sol, sol_found, goalvars, varset, setl, set2, Aset, news,
factlist := ClassifyFacts(nameO, facts);
Aset := convert( ObjStruct(nameO)[2], set);
Trang 7set! := factlist[l]; set2:= map(s->op(SetVars(lhs(s))), factlist[2]);
ilist := [];
sol := []; sol_found:= false;
varset := vars;
for fact in facts do
varset := varset union 'intersecf(SetVars(fact), Aset);
end do;
goalvars := vars minus setI;
end: # init vars
add-properties2 := procO
local fact, newfs, vars;
newfs := {}; vars:= {};
for fact in ObjStruct(nameO)[5] do
if KindFact(nameO, fact)=2 then
newfs:= 'union'(newfs, {fact}); vars:= 'union'(vars, SetVars(lhs(fact)));fi;
goalvars := goalvars minus setl;
if goalvars = {} then RETURN (true);
else RETURN (false);
local fact, fact!, kl;
for fact in factlist[3] do
factI := Deduce_from32s(nameO, factlist[2], fact, goalvars);
Trang 8if ki =2 and not Unify_in(nameO, factI, factIist[2]) then
factIist[2] := 'union'(factlist[2], {factI});
sol:= [op(sol), ["Deduce_from32s", {factI}]];
set2 := 'union'(set2, SetVars(lhs(factI)));
RETUR1~({factI});
elif ki = 3 and not Unify_in(nameO, factI, factlist[3]) then
factlist[3] := 'union '(factlist[3], {factI});
sol:= [op(sol), ["Deduce_from32s", {factI}]];
local fact, set_I;
for fact in faetlist[3] do
set_I := Deduce_from3Is(nameO, factlist[I], fact);
if set_l <> {} then
factlist[l] := 'union'(factlist[I], set_I);
sol := [op(sol), ["Deduce_from3Is", set_I]];
setI := 'union'(setI, set_I);
Trang 9# su kien moi loai 2, hoac loai 3 nhung tinh thee duoc nhung bien thuoc set! va set2.end: # deduce h2
# thu ap dung qui tac mac nhien Deduce_ITom31s
news := deduce_31 sO;
if news <> {} then sol_found:= test_goalO; next;
Trang 10if news <> {}then sol_found:= test_goalO; next;
end do; # while
RETURN ([sol_found, sol]);
end: # CONet_Solver[Solvablels]
CONet_Solver[ComputeVars] := proc(nameO::string, facts::set, goalvars::set)
# Tinh cae bien trong <goalvars> thee cae su kien trong <facts>
#RETRUN tap cae su kien loai 2 hay 3 the hien bieu thuc tinh cae bien,
# hoac RETURN ( {}) neu khong tinh duoc
local Aset, result, n, i, vars, vars- thay, exprs, fact;
result := Solvable1s(nameO, facts, goalvars);
Aset := convert( ObjStruct(nameO)[2], set);
if result [1]=false then RETURN ({});
if member(lhs(fact), vars) then
exprs := subs (fact, exprs);
exprs := {op(exprs), fact}; vars:= vars minus {lhs(fact)};
vars_thay:= vars_thay union 'intersecf(SetVars(rhs(fact)), Aset);elif member(1hs(fact),vars_thay) then
exprs := subs (fact, exprs);
vars_thay:= (vars_thay minus {lhs(fact)})union
'intersect' (SetVars(rhs(fact)), Aset);
fi;
fi;
Trang 11end do; # for i
. RETURN(simplify(exprs));
end: # CONet_Solver[ComputeVars]
CONet_Solver[IsDetermine] := proc(nameO::string, facts::set)
# Xet xem doi tuong co duoc xac dinh tu tap su kien da cho hay khong
# su dung Solvable1s va cac luat (rule) xac dinh doi tuong
local factlist, Aset, nvars, vars, rules, i, j, n;
factlist := ClassifyFacts(nameO, facts);
Aset := convert( ObjStruct(nameO)[2], set);
rules := ObjStruct(nameO)[7]; n:= nops(rules); # so luat trong Object
nvars := nops(Aset);
for i from 1 to n do
if rules[i] [2] = {"Object"} then
vars := 'minus'(rules[i] [1], factlist[1]); nvars:= nops(vars);
break;
£1;
end do;
for j from (i+1) to n do
if rules[j] [2] = {"Object"} and nops('minus'(rules[j] [1], factlist[1])) < nvars thenvars := 'minus'(rules[j] [1], factlist[1]); nvars := nops(vars); i := j;
£1;
end do;
# truong hop khong co luat xac dinh doi tuong
if nvars = nops(Aset) then vars := Aset;
£1;
# Xet tinh giai duoc cua: facts => vars
RETURN ( Solvable1s(nameO, facts, vars) [1] );
end: # CONet- Solver[IsDetermine]
5.1.4 LO'ighH
Chudng trlnh co th€ cho Wi giai ligan gQn ho~c chi tie't tuy thee yell c~u, Wigiai co th€ duQc th€ hi~n tn!c tie'p tren man hlnh ho~c la ghi thanh t~p tin trenilia duoi d<:lngvan ban co ca"utruc E>6ivoi bai toan trong vi d\l 5.1 d tren Wi giaitim duQc se g6m cac buoc giai nhu sau:
1
1 Suy fa {GacB =2"GacA} tU {GacA=2 GacB}
2 Suy fa {GacA = ~ 1t} tu {a2 = b2+ c2} boi mQt lu~t suy di@n
Trang 12
4 Suy ra {GocB} ill' {GocB=1- 7t} bdi "Deduce_from3"
5 Suy ra {GocC = 1-7t} tit {GocA = ~ 7t, GocB=1- 7t} bdi ap dl)ng quail h<$tinhtoan:
["relation 0", 1, {GocB, GocA, GocC}, 1, { }, GocA + GocB + GocC = Pi, 2]
6 Suy ra {GocC} tu {GocC=4" 7t}
D6i voi b~d toan trong vi dl) 5.2 d tren, gia sa tu giac la ABCD, Wi giai tlm duQc
se g6m cac buoc giai nhusau:
Tinh TAM_GIAC[A,B,D].b, (c~nh AD)
Tinh TAlvCGIAC[A,B,D].c, (c~nh AB)
Tinh TAlvCGIAC[A,B,D].GocA, (g6c A)
Tinh TAJvCGIAC[C,B,D].b, (c~nh CD)
">
.:; Tinh TAi\I_GIAC[C,B,D].c, (c~nh CB)
Tinh TAt\CGIAC[A,B,D].a, TAM_GIAC[A,B,D].S,
(qnh BD,di~n tich tam giac ABD)Tinh TU_GIAC[A,B,C,D].BD, (duong cheo BD cua tu giac)
Tinh TAt\1_GIAC[C,B,D].a, (c~nh BD cua tam giac CBD)
Tinh TAt\rCGIAC[C,B,D].S, (di<$ntich tam giac CBD)
Tinh TU_GIAC[A,B,C,D].S, (di<$ntich tU giac ABCD)
5.2CHUdNG TRINH GIAI TOAN HINH HQC PHANG:
Trong phftn fifty chung ta se trlnh bay v€ ffiQtling dlfng cua ma hint COKB
va m~ng cac C-Object: package giai cac bai toan hint hQc ph&ng d1,1'atren mahint tri thlic cac C-Object S6 d6 ho~t dQng giai toan cua bai toan theo ma hlnh .m~ng cac C-Object cling gi6ng nhu s6 d6 duQc trinh bay trong phftn tren d6i voivi<$cgiai mQt C-Object (xem hint 5.1) Ky thu?t thie't ke' cac th:u?t giai dff duQc
Trang 13i trinhbay trong chuang 3 va chuang 4 Phffn eai d<litev th€ tuang tv' nhu phffn did?t m<;lngsuy di~n tinh roan va phffn eai d<litmodule giai roan C-Objeet d daychung ta se neu leD phffn ngon ngfi' d<lietaeho bai roan va trlnh bay mQt s6 vi dVmint hQa.
5.2.1 Ngon figii' d~c ta bili tmin
- Cae tu kh6a khai bao ea'u true d€ bai roan: "begin_hypothesis",
"end_hypothesis", "parameters", "obj ects", "facts",
"determine" Bai roan duQe khai bao theo ea'u true sau day:
"TAM_GIAC", "TAM_GIAC_CAN", "TU_GIAC", "HINH_BINH_HANH",
Khai bao cae d6i tu'Qnge6 th€ vi€t theo eu phap sau:
<day cae ten d6i tuQng> : <ki€u d6i tuQng>; ,
Trang 14Ki€u d6i tuQng co th€ duQe ghi duoi d~ng mQt ten ki€u don Ki€u d6i tuQngcon co th€ duQe ghi duoi d~ng mQt ten ea'"utrue thie't l~p tren mQt danh saehn~n cae d6i tuQng co ban Ch~ng h~n voi A, B, C la 3 di€m (cae d6i tuQngki€u "DIEM") ta co th€ khai baa mQt d6i tu'Qng Obj thuQe ki€u
"TAM_GIAC" va la tam giae ABC nhu sail:
Obj : TAM_GIAC[A,B,C];
Hdn n[!a (rang pha'n khai baa cac sif ki?ll va mlJc lieu ta co thtf sd' dl!ng mQl
ten ki€u diu true thi~t l~p eho mQt Q.oituQng ma khong e~n khai baG tru\1ed6i tuQng n~y Ch~ng hq.n, voi A, B, C, D la cae di~m (d6i tuQng ki~u
"DIEM") thl cae d6i tu'Qngla do~n th~ng AB, do~n th~ng AC, da~n thing
Be .la kh6ng e~n thie't phai khai baa truoe nhung ta co th€ khai baa sll ki~nlien quail de'n cae d6i tuQng nth trong ph~n 511ki~n Vi dl;!nhu cae sll ki~n:,.,,>
;,( ["VUONG", DOAN[A,B], DOAN[C,D]]
DOAN[A,C] =DOAN[A,B] + DOAN[B,C]
Cae tit khoa trong ea'"utrue khai baa cae slJ ki~n th€ hi~n mQt quail h~ rheaki€u quail h~ duQe ghi trong t~p tin "Relations.txt" Ch~ng h~n nhu cae lo~iquail h~ sail day:
["VUONG", "DOAN", "DOAN"]
["SSONG", "DOAN", "DOAN"]
["=", "TAM_GIAC", "TAM_GIAC"]
["DONGDANG", "TAM_GIAC", "Tfu\l_GIAC"]
["THUOC", "DIEM", "DOAN"]
Cae ky hi~u roan tii' (phep roan sO'hQe va phep roan so sanh) va cae ham,roan tii' "." B€ truy e~p thanh ph~n eua ea'"ut.rtie d6i tuQng
Cae ten d~i di~n eho cae h~ng hay cae d6i tUQng h~ng Vi dl;!: so' Pi, g6c tQa
dQ 0 trong hlnh hQc giai rich 2 ehi~u hay 3 chi~u
.,
Trang 155.2.2 Cae vi dt;l
Vi du 5.3: Xet bai tmln: Cho tam giac din ABC, din t(,liA, va cho bi€t tntoe goe
dlnh A bang a, e(,lnh day a bang m Ben ngoai tam giae co hai hlnh vuong
ABDE va ACFG Tinh dQ dai EG
Trang 16Bu'oc 2: determine 01.DOAN[A,B].
II trang d6i tuQng 01
Bu'oc 3: determine 03.DOAN[A, B]
Bu'oc 4: determine 04.DOAN[A, C] "
Bu'oc 5: determine 02.DOAN[A, E]
Bu'oc 6: determine 02.DOAN[A, G]
Bu'oc 7: determine 02 DOAN[E, G]
// trang d6i tu'<Jng02
Ghi ch6: Ne'u ta khai baa 2 tham so' alpha, m va cac slf ki~n