?? - PowerPoint PPT Presentation

1 / 120
About This Presentation
Title:

??

Description:

Title: - No 1 Author: abc Last modified by: Svetla Created Date: 9/27/2002 8:43:21 AM – PowerPoint PPT presentation

Number of Views:32
Avg rating:3.0/5.0
Slides: 121
Provided by: abc106
Category:

less

Transcript and Presenter's Notes

Title: ??


1
???????????? ?? ??????
  • ???. ?????? ???????
  • ???????? ?? ?????????? ? ???????????
  • ?? ??. ??????? ????????

2
?????????? ?? ????? ??????
  • ???? 13

3
  • ????, ??????
  • ???????
  • ?????
  • ???????
  • ???????????? ??????

4
????
pop
push
5
??????? ????????
  • push - ????????? ?? ???????
  • push(X,Stack,XStack).
  • pop - ??????? ?? ???????
  • pop(Stack,_,_)-
  • empty_stack(Stack),
  • write('Empty stack'),nl.
  • pop(XStack,X,Stack).
  • empty_stack - ???????? ???? ????? ???? ? ??????
  • empty_stack( ).

6
??????
pop
push
7
??????? ????????
  • push - ????????? ?? ???????
  • push(X,Queue,NewQueue)-
  • append(Queue,X, NewQueue).
  • pop - ??????? ?? ???????
  • pop(Queue,_,_)-
  • empty_queue (Queue),
  • write('Empty queue'),nl.
  • pop(XQueue,X, Queue).
  • empty_queue - ???????? ???? ?????? ?????? ?
    ??????
  • empty_queue( ).

8
??????
  • ???????? ???? ????? ??????? ?????????? ?? ?????
    ????/??????
  • in_stack(X,Stack)
  • in_queue(X,Queue)

9
  • in_stack(X,Stack)-
  • \ empty_stack(Stack),!,
  • pop(Stack,Y,RestStack),
  • ( XY, !
  • in_stack(X,RestStack)
  • ).

10
Graph - ??????? ???? arc(a,b). arc(b,c). arc(c,d
). arc(d,e). arc(b,d). arc(c,e). arc(a,d). arc(c,a
).
11
Graph - ????????? ???? my_arc(a,b). my_arc(b,c).
my_ arc(c,d). my_ arc(d,e). my_ arc(b,d). my_
arc(c,e). my_ arc(a,d). my_ arc(c,a). arc(X,Y)-m
y_ arc(X,Y). arc(X,Y)-my_ arc(Y,X).
12
Graph g( a,e,c, b,d,a, c, ,
d,a,e,c). arc(X,Y)- g(Graph),
member(X,Nodes,Graph),
member(Y,Nodes).
13
??????
  • ????? ? ????? X, ?? ?? ??????? ?????? ?????, ??
    ????? ??? ????, ????? ?? ??????? ? X.
  • succ(X,S)-
  • findall(Y,arc(X,Y),S).

14
??????
  • ????? ? ????? X, ?? ?? ??????? ?????? ??????????
    ????? ?? X, ?.?. ?? ????? ??? ???, ????? ??
    ??????? ? X.
  • ????? ? ????? X, ?? ?? ??????? ?????? ?????
    ?????????? ?? X, ?.?. ?? ????? ??? ???, ????? ??
    X.

15
  • successor(X,S)-
  • findall(Y,arc(X,Y),S).
  • offspring(X,S)-
  • successor(X,DS),
  • del_all(X,DS,DS1),
  • succ_list(DS1,S2),
  • append(DS1,S2,Temp),
  • compress(Temp,S).

16
  • compress(,).
  • compress(XRest,XResult)-
  • del_all(X,Rest,New),
  • compress(New,Result).
  • del_all(_,,).
  • del_all(X,XL,L1) - del_all(X,L,L1).
  • del_all(X,YL1,YL2)-
  • X\Y, del_all(X,L1,L2).

17
  • diff(,_,).
  • diff(A,,A).
  • diff(XA,B,XC)-
  • \ member(X,B),
  • diff(A,B,C).
  • diff(_A,B,C)-diff(A,B,C).

18
  • succ_list(,).
  • succ_list(A1Rest, S)-
  • offspring(A1,S1),
  • diff(Rest,S1,R1),
  • succ_list(R1,S2),
  • append(S1,S2,S3),
  • compress(S3,S).

19
?????? ????? ? ????? nodes(N)-
setof(X,Yarc(X,Y),S1), setof(Y,Xarc(X,Y),S2),
append(S1,S2,S), setof(X,member(X,S),N).
20
??????
  • ?????? ?? ??? ????? X ? Y. ?? ?? ?????? ????????
    way, ????? ?? ?????? ??? ?? X ?? Y ? ????? ????

21
  • way(X,Y,Path)-
  • way1(X,Y, ,Path).
  • way1(X,X, CurrentPath, FinalPath)-
  • reverse(XCurrentPath, FinalPath).
  • way1(X,Y, CurrentPath, FinalPath)-
  • arc(X,Z),
  • \ member(Z,CurrentPath),
  • way1(Z,Y,XCurrentPath,FinalPath).

22
??????
  • ????? ? ????. ?? ?? ??????? ?????? ?????? ??
    ????? ???? X ?? ???? ????? ???? Y, ?????? ?? ??
    ????? ? ??????? ?????? ?????????? ????? ?.

23
  • k_size_ways(X,Y,K,Paths)-
  • findall( P, ( way(X,Y,P),
  • length(P,K) ),
  • Paths).

24
  • hamilton(HPaths)-
  • nodes(Nodes),
  • length(Nodes,N),
  • findall( HP, ( member(X,Nodes),
  • member(Y,Nodes),
  • X \ Y,

  • k_size_ways(X,Y,N,KP),
  • member(HP,KP) ),
  • HPaths).

25
  • is_hamilton(HPath)-
  • nodes(Nodes),
  • length(Nodes,N),
  • length(HPath,N),
  • equal(Nodes,HPath).
  • equal( , ).
  • equal(XA,B)-
  • member(X,B),
  • del(X,B,B1),
  • equal(A,B1).

26
Graph arc(a,b). arc(b,c). arc(c,d). arc(d,e). ar
c(b,d). arc(c,e). arc(a,d). hamilton(HPaths)-
nodes(N), length(N,K),
findall(P1, (member(X,N),member(Y,N),
X \ Y,
way(X,Y,,P1),length(P1,K) ),
HPaths).
27
  • way(X,Y,Path)-
  • way1(X,Y, ,Path).
  • way2(X,X, CurrentPath, FinalPath)-
  • reverse(CurrentPath, FinalPath).
  • X-Z, Z-T1, ..., Tn-Y
  • way2(X,Y, CurrentPath, FinalPath)-
  • arc(X,Z),
  • \ member(X-Z,CurrentPath),
  • way2(Z,Y,X-ZCurrentPath,FinalPath).

28
arc(a,b). arc(b,c). arc(c,d). arc(d,e). arc(b,d).
arc(c,e). arc(a,d). all_arcs(A)-
findall(X-Y,arc(X,Y),A).
29
  • euler(EPaths)-
  • all_arcs(Arcs),
  • length(Arcs,N),
  • nodes(Nodes),
  • findall( HP, ( member(X,Nodes),
  • member(Y,Nodes),
  • X \ Y,
  • way2(X,Y,
    ,HP),
  • length(HP,N) ),
  • EPaths).

30
(No Transcript)
31
??????? ?? ?????? ?????????
  • ??????
  • Q ?????? ????????? ?? ?????????
  • S?Q ???????? ????????? ?? ??????? ?????????
  • G?Q ???????? ????????? ?? ??????(??????)
    ?????????
  • succs Q -gtp(Q) ???????, ????? ?? ????????
    ????????? s ????? ?????? ????????? succs(s),
    ????? ????? ?? ?? ????????? ?? s ?? ???? ??????
  • cost Q,Q -gt Positive Number ???????, ????? ??
    ???????? ??? ????????? S ? S ????? ???????? ???
    ????????????? ?? ???? ?????? ?? S ?? S.
    ????????? ? ?????????? ???? ??? ??????????? S ?
    S ?? ??????? (?.?. ?????????? ?????? ?? ??????
    ????????? ? ??????? ?? ???? ??????)
  • ????? ??
  • ??? (???????????????? ?? ??????? ?????????) ??
    ?????? ??????? ????????? ?? ?????? ??????
    ????????? ? Q

32
??????? ?? ?????? ????????? (??????? ?? ??? ?
????)
  • ?????? (graph) ?? ?????? ?? ????????? N ?? ?????
    / ??????? / ????????? (nodes) ? ????????? A ??
    ???????? ?????? ?? ???????, ???????? ???? (arcs)
    .
  • ?????? n2 ? ????? (neighbor) ?? n1, ???
    ?????????? ???? ????? n1 ? n2, ?.?. ltn1,n2gt ? A.
  • ??? (path) ? ???????????????? ?? ??????? n0, n1,
    ... nk ?????? ?? ltni-1,nigt ? A, i1..k .

33
??????? ?? ?????? ????????? (??????? ?? ??? ?
????)
  • ?????? ?? ??????? ???????/????????? (start
    nodes) ? ??????/ ?????? ????????? (goal nodes) ,
    ??????? (solution) ? ??? ?? ??????? ?????????
    ?? ?????? ?????????.

34
?????? ????
35
?????? ?????
g
s
36
??? ?????????
  • ??? ????????? ?? ???????
  • ????? ? ????
  • ??????? ?????????
  • ?????? ?????????
  • ?????????????? ?? ?? ????????? ???????? ??
    ????????? ?????????

37
??? ?????????
  • ???????? ?? ?????/??????? (frontier) ?? ????????,
    ????? ?? ???? ??????????
  • ?? ????? ?? ??????? ?? ??????? ?????? ??
    ????????? ? ?????? ??? ?????????????? ?????,
    ?????? ?? ???????? ?? ?????? ?????

38
??? ?????????
  • ????????????, ?? ???? ???? ?????????? ?? ???????
    ?????? ???? ???, ???? ?? ?? ???? ???????? ??
    ????? ??? ??????? ? ?????? ???????? ?????? ??
    ????????
  • ???????, ?? ????? ?????? ?? ????????? ? ????
    ????? ??? ???????? ?? ?????? ?? ?????? ????????
    ??????????? ?? ??????? (search strategy).

39
frontier
start node
unexplored nodes
explored nodes
40
??????? ?????????
  • ????????????? (?????) ???????
  • ??????????? (??????????) ???????

41
??????? ?????????
  • ????????????? (?????) ???????
  • ??????? ? ????????? (Depth-first search)
  • ??????? ? ?????? (Breadth-first search)
  • ??????? ? ?????????? ????????? (Depth-bound
    search)
  • ?????????? ??????? ?? ????(Iterative-deepening
    search)

42
??????? ? ?????????
  • ??? ????????? ? ????????? ??????? ?? ?????????
    ???? ????
  • ??? ?????? ? p1,p2, . . .
  • ?????? ?? p1
  • ???????? p1', p1'',, p1(k), ????? ?????????? p1
    ?? ??????? ? ???????? ?? ????? (????? p2), ?.?.
    p1', p1'',, p1(k), p2, . . .
  • p2 ?? ????????? ???? ???? ???? ?????? ??????,
    ????? ?? ??????????? ?? p1 ?? ???? ??????????

43
??????????? ?? ?????
  • arc(Node1,Node2).
  • arc(Node1,Node2,Cost).
  • arc(a,b). arc(d,e).
  • arc(a,d). arc(e,c).
  • arc(b,a). arc(e,d).
  • arc(b,c).
  • arc(c,e).
  • arc(d,a).
  • arc(d,b).
  • arc(d,c).

b
a
c
e
d
44
??????????? ?? ???????
Start
a
  • arc(a,b).
  • arc(a,d).
  • arc(b,a).
  • arc(b,c).
  • arc(c,e).
  • arc(d,a).
  • arc(d,b).
  • arc(d,c).
  • arc(d,e).
  • arc(e,c).
  • arc(e,d).

Start
a
b
b
d
Goal
c
b
c
e
e
c
e
c
c
Goal
e
d
Goal
d
e
Goal
45
??????????? ?? ?????? ?????????? ? ?????????
  • a
  • b a d a
  • c b a d a
  • e c b a d a
  • I-?? ???????
  • e c b a gt a b c e
  • ??????????????????
  • d a
  • b d a c d a e d a
  • c b d a c d a e d a
  • e c b d a c d a e d a
  • II-?? ???????
  • e c b d a gt a d b c e
  • ??????????????????
  • c d a e d a
  • e c d a e d a
  • III-?? ???????
  • e c d a gt a d c e
  • ??????????????????

??????? ?????????
a
b
?????? ?????????
d
c
b
c
e
e
c
c
e
d
e
46
??????? ? ?????????
Start
1
Goal
2
13
3
Goal
12
4
14
16
15
7
5
Goal
10
8
6
Goal
11
9
47
??????? ? ????????? (Depth-first)
  • depth_first(PathStack,Goal,FinalPath) -
  • extend(Path,NewPaths),
  • append(NewPaths, Stack, NewStack),
  • depth_first(NewStack,Goal,FinalPath).

48
??????? ? ????????? (Depth-first)
  • depth_first(GoalPath_,Goal,FinalPath)-
  • reverse(GoalPath,FinalPath).

49
??????????? ?? ??????
  • extend(NodePath,NewPaths) -
  • findall(NewNode,NodePath,
  • (arc(Node,NewNode),
  • \ member(NewNode,NodePath)),
  • NewPaths).

50
??????? ? ????????? (Depth-first)
  • depth_first(GoalPath_,Goal,FinalPath)-
  • reverse(GoalPath,FinalPath).
  • depth_first(PathStack,Goal,FinalPath) -
  • extend(Path,NewPaths),
  • append(NewPaths,Stack,NewStack),
  • depth_first(NewStack,Goal,FinalPath).
  • extend(NodePath,NewPaths) -
  • findall(NewNode,NodePath,
  • (arc(Node,NewNode),
  • \ member(NewNode,NodePath)),
  • NewPaths).

51
??????
  • arc('Mehadia','Dobreta',75).
  • arc('Neamt','Iasi',87).
  • arc('Oradea','Zerind',71).
  • arc('Oradea','Sibiu',151).
  • arc('Pitesti','Rimnicu',97).
  • arc('Pitesti','Craiova',138).
  • arc('Pitesti','Bucharest',101).
  • arc('Rimnicu','Sibiu',80).
  • arc('Rimnicu','Pitesti',97).
  • arc('Rimnicu','Craiova',146).
  • arc('Sibiu','Arad',140).
  • arc('Sibiu','Oradea',151).
  • arc('Sibiu','Fagaras',99).
  • arc('Sibiu','Rimnicu',80).
  • arc('Timisoara','Arad',118).
  • arc('Timisoara','Lugoj',111).
  • arc('Urziceni','Bucharest',85).
  • arc('Urziceni','Hirsova',98).
  • arc('Urziceni','Vaslui',142).
  • arc('Arad','Zerind',75).
  • arc('Arad','Sibiu',140).
  • arc('Arad','Timisoara',118).
  • arc('Bucharest','Fagaras',211).
  • arc('Bucharest','Pitesti',101).
  • arc('Bucharest','Giurgiu',90).
  • arc('Bucharest','Urziceni',85).
  • arc('Craiova','Dobreta',120).
  • arc('Craiova','Rimnicu',146).
  • arc('Craiova','Pitesti',138).
  • arc('Dobreta','Mehadia',75).
  • arc('Dobreta','Craiova',120).
  • arc('Eforie','Hirsova',86).
  • arc('Fagaras','Sibiu',99).
  • arc('Fagaras','Bucharest',211).
  • arc('Giurgiu','Bucharest',90).
  • arc('Hirsova','Urziceni',98).
  • arc('Hirsova','Eforie',86).
  • arc('Iasi','Neamt',87).

52
??????
  • ?- depth_first('Arad','Craiova',Path).
  • Path 'Arad','Zerind','Oradea','Sibiu', 'Fagar
    as','Bucharest','Pitesti', 'Rimnicu','Craiova'?
  • Path 'Arad','Zerind','Oradea','Sibiu',
    'Fagaras','Bucharest', 'Pitesti','Craiova'

53
Start
Goal
54
Start
Goal
55
??????? ? ??????
  • ??? ????????? ? ?????? ??????? ?? ????????? ????
    ??????
  • ??? ?????? ? p1,p2, . . .pn
  • ?????? ?? p1
  • ???????? p1', p1'',, p1(k) , ????? ??????????
    p1 ?? ??????? ? ???? ?? ???????? (???? pn), ?.?.
    p2, ,pn, p1', p1'',,p1(k) ? ?? ??????????
    ???? ???? ???? ?????? ?????? p2, , pn, ??
    ?????????
  • ?????? ???-??????? ???

56
??????? ? ??????
Start
1
3
2
7
6
5
4
13
12
14
9
8
11
10
22
20
21
18
19
17
16
15
Goal
25
24
23
Goal
57
??????? ? ????????? (Depth-first)
  • depth_first(PathStack,Goal,FinalPath) -
  • extend(Path,NewPaths),
  • append(NewPaths, Stack, NewStack),
  • depth_first(NewStack,Goal,FinalPath).

58
??????? ? ?????? (Breadth-first)
  • breadth_first(PathStack,Goal,FinalPath)-
  • extend(Path,NewPaths),
  • append(NewPaths, Stack, NewStack),
  • breadth_first(NewStack,Goal,FinalPath).

59
??????? ? ?????? (Breadth-first)
  • breadth_first(PathQueue,Goal,FinalPath)-
  • extend(Path,NewPaths),
  • append(NewPaths, Queue, NewQueue),
  • breadth_first(NewQueue,Goal,FinalPath).

60
??????? ? ?????? (Breadth-first)
  • breadth_first(PathQueue,Goal,FinalPath)-
  • extend(Path,NewPaths),
  • append(Queue, NewPaths, NewQueue),
  • breadth_first(NewQueue,Goal,FinalPath).

61
??????? ? ?????? (Breadth-first)
  • breadth_first(GoalPath_,Goal, FinalPath)-
  • reverse(GoalPath,FinalPath).
  • breadth_first(PathQueue,Goal,FinalPath) -
  • extend(Path,NewPaths),
  • append(Queue,NewPaths,NewQueue),
  • breadth_first(NewQueue,Goal,FinalPath).
  • extend(NodePath,NewPaths) -
  • findall(NewNode,NodePath,
  • (arc(Node,NewNode,_),
  • \ member(NewNode,NodePath)),
  • NewPaths).

62
??????
  • ?- breadth_first('Arad','Craiova',Path).
  • Path 'Arad','Sibiu','Rimnicu','Craiova'

63
Start
Goal
64
Start
Goal
65
??????? ? ?????????? ?????????
  • ?????? ?? ?????????? ????????? Depth, ?? ?????
    ?? ?????? ???????
  • ?????? ???, ????? ?????? ???? ?? ?????? ?? Depth
    ?? ???? ????? ?? ?????

66
??????? ? ?????????? ?????????
1
Depth4
9
2
13
10
6
3
12
11
14
5
4
8
7
67
??????? ? ????????? (Depth-first)
  • depth_first(PathStack,Goal,FinalPath) -
  • extend(Path,NewPaths),
  • append(NewPaths, Stack, NewStack),
  • depth_first(NewStack,Goal,FinalPath).

68
??????? ? ?????????? ????????? (Depth-bound)
  • depth_bound(Depth,PathStack,Goal,FinalPath)-
  • extend(Path,NewPaths),
  • append(NewPaths, Stack, NewStack),
  • depth_bound(Depth,NewStack,Goal,FinalPath).

69
??????? ? ?????????? ????????? (Depth-bound)
  • depth_bound(Depth,PathStack,Goal,FinalPath)-
  • extend_bound(Depth,Path,NewPaths),
  • append(NewPaths, Stack, NewStack),
  • depth_bound(Depth,NewStack,Goal,FinalPath).

70
??????? ? ?????????? ????????? (Depth-bound)
  • extend_bound(Depth,Path,NewPaths) -
  • length(Path,Len),
  • Len lt Depth, !,
  • extend(Path,NewPaths).
  • extend_bound(_,_,).
  • extend(NodePath,NewPaths) -
  • findall(NewNode,NodePath,
  • (arc(Node,NewNode,_),
  • \ member(NewNode, NodePath)),
  • NewPaths).

71
??????? ? ?????????? ????????? (Depth-bound)
  • depth_bound(Depth,GoalPath_,Goal,FinalPath)
    -
  • reverse(GoalPath,FinalPath).
  • depth_bound(Depth,PathStack,Goal,FinalPath)-
  • extend_bound(Depth,Path,NewPaths),
  • append(NewPaths,Stack,NewStack),
  • depth_bound(Depth,NewStack,Goal,FinalPath).
  • extend_bound(Depth,Path,NewPaths) -
  • length(Path,Len),
  • Len lt Depth, !,
  • extend(Path,NewPaths).
  • extend_bound(_,_,).

72
??????
  • ?- depth_bound(5,'Arad','Craiova',Path).
  • Path'Arad','Sibiu','Rimnicu', 'Pitesti','Craiov
    a' ?
  • Path'Arad','Sibiu','Rimnicu','Craiova' ?
  • no

73
Start
Goal
74
Start
Goal
75
?????????? ??????? ?? ????
  • ????? ?????????????? ?? ????????? ? ????? ??????
    ? ?? ???????? ????? ??????? (????? ? ?????), ??
    ?? ???? ????????? ??????? ?????, ????? ?????
    ??????? ?? ??????? ????? ????? ? ??????.
  • ????????? ???? ? ?? ?? ????????????? ??????????
    ?? ??????, ?????? ?? ?? ?????
  • ????? ?? ??????? ? ?????????? ????????? ???
    Depth1, 2,
  • ??? ???????? ??? ?? ?? ?????? ?? ????????? d ??
    ????? ?? ????????? d1.
  • ?????? ???-??????? ???

76
?????????? ??????? ?? ????
  • ??? ?? ?????????? ??? ?? ????????? ?? ????????
    ????????? ? ??????? ???? ? ???? ? ????????? ?
    ?????????? ?????? ???????????? ?? ???????????,
    ?????? ????? ?????????? ?? ??????????? Depth ??
    ???? ?? ??????????? ?? ???? ? ???? ???????????? ?
    ????????????? ?? ???????????.
  • ?? ?? ?? ????????? ?????????? ?? ???????, ??? ??
    ??????????, ???? ???????????? ?? ???????????
    Depth ?? ?????????? ?? ????????????? ????????
    ?????????? ???????? Max, ?.?. Depth Max.

77
?????????? ??????? ?? ????
Depth4
1
Depth1
1
1
Depth2
9
2
3
2
3
6
13
10
1
Depth3
2
5
4
8
12
11
14
7
15
5
4
3
7
6
78
?????????? ??????? ?? ???? (Iterative deepening)
  • ??? ???? ????? ?????? ?? ???????????? ????????? ?
    ????????? ???? ?? ?????? ? ?????.
  • ????????? ??????? ??? Depth1
  • iterative_deepening(Stack,Goal,FinalPath) -
  • findall(arc(X,Y,Z),arc(X,Y,Z),Graph),
  • length(Graph,Max),iterative_deepening1(1,Stack,G
    oal,FinalPath,Max).

79
?????????? ??????? ?? ???? (Iterative deepening)
  • iterative_deepening1(Depth,Stack,Goal,Path,Max)-
  • nl,write(depthDepth),
  • depth_bound(Depth,Stack,Goal,Path).
  • iterative_deepening1(Depth,Stack,Goal,Path,Max)-
  • Depth1 is Depth1,
  • Depth1 lt Max,!, iterative_deepening1(Depth1,St
    ack,Goal,Path,Max).

80
?????????? ??????? ?? ???? (Iterative deepening)
  • iterative_deepening(Stack,Goal,Path) -
  • findall(arc(X,Y,Z),arc(X,Y,Z),Graph),
    length(Graph,N), iterative_deepening1(1,Stack,Go
    al,Path,N).
  • iterative_deepening1(Depth,Stack,Goal,Path,Max)
    -
  • nl,write(depthDepth),
  • depth_bound(Depth, Stack,Goal,Path).
  • iterative_deepening1(Depth,Stack,Goal,Path,Max)
    -
  • Depth1 is Depth1, Depth1 lt
    Max,!,iterative_deepening1(Depth1,Stack,Goal,Path
    ,Max).

81
??????
  • ?- iterative_deepening('Arad','Craiova',Path)
    .
  • depth1
  • depth2
  • depth3
  • depth4
  • Path 'Arad','Sibiu','Rimnicu','Craiova' ?

82
Start
Goal
83
??????? ?????????
  • ????????????? (?????) ???????
  • ??????????? (??????????) ???????

84
??? ?????????
  • ???????? ?? ?????/??????? (frontier) ?? ????????,
    ????? ?? ???? ??????????
  • ?? ????? ?? ??????? ?? ??????? ?????? ??
    ????????? ? ?????? ??? ?????????????? ?????,
    ?????? ?? ???????? ?? ?????? ?????
  • ??? ????????????? ?? ?????? ?? ??????????
    ???????????? ?????? ?? ????????
  • ??????? ?? ??????? ? ????????? ??? ??
    ???????????? ?????? ?? ????????

85
??????? ?????????
  • ??????????? (??????????) ???????
  • ????? ?? ???-??????? ????????(Best-first search)
  • ??????? ? ??? (Beam search)
  • ????? ?? ??????????? (Hill Climbing)
  • ?

86
h
frontier
start node
unexplored nodes
explored nodes
87
?????????? ??????
  • ?????????? ??????
  • ??????? ???? ?????? ?? ?????? ????????? ?? ?????
    ??? ???? ?????????? ?? ???? ?? ?????
  • ?????? ?? ? 0 ? ???????? ?????????
  • ?????? ?? ?? ????????? ?????, ?.?. ?? ?? ???????
    ????????? ????? ??????? (????? ? ?????)
  • h(Path,Goal,H)
  • h(NodePath,Goal,H) - stright_line_distance(Nod
    e,Goal,H).

88
????? ?? ???-??????? ???????? (Best-first search)
  • ??????? ?? ????????? ???? ???????? ?????? ?
    ????????? ??? ?? ???????? ?????????? ?????? ??
    ????????
  • ??? ??????? ? p1,p2, . . .,pn
  • ?????? ?? p1
  • ???????? p1', p1'',, p1(k) , ????? ??????????
    p1 ?? ??????? ??? ?????? ? ??? ?? ??????? ?
    ????????? ??? ?? ???????? ?? ????????q1,q2,...,qn
    k
  • ?? ?????????? ?????? ?? ????????? ????? ???? ?
    ???-????? ?????? ??????, ?.?. q1

89
????? ?? ???-??????? ???????? (Best-first search)
  • best_first(GoalPath_,Goal,FinalPath)-
  • reverse(GoalPath,FinalPath).
  • best_first(PathList,Goal,FinalPath)-
  • extend(Path,NewPaths),
  • append(List,NewPaths,NewList),
  • sort(NewList,Goal,SortedList),
  • best_first(SortedList,Goal,FinalPath).

90
????? ?? ???-??????? ???????? (Best-first search)
  • extend(NodePath,NewPaths) -
  • findall(NewNode,NodePath,
  • (arc(Node,NewNode,_),
  • not member(NewNode,NodePath)),
  • NewPaths).
  • reverse(,).
  • reverse(XRest,List)-
  • reverse(Rest,NewRest),
  • append(NewRest,X,List).

91
????? ?? ???-??????? ???????? (Best-first search)
  • sort(,Goal,).
  • sort(List,Goal,MinPathSortedList)-
  • min(List,Goal,MinPath,NewList),
  • sort(NewList,Goal, SortedList).
  • min(Path1List,Goal,Path2,Path1NewList)-
  • min(List,Goal,Path2,NewList),
  • h(Path1,Goal,H1),
  • h(Path2,Goal,H2),
  • H2ltH1,!.
  • min(PathList,Goal,Path,List).

92
??????
  • arc('Mehadia','Dobreta',75).
  • arc('Neamt','Iasi',87).
  • arc('Oradea','Zerind',71).
  • arc('Oradea','Sibiu',151).
  • arc('Pitesti','Rimnicu',97).
  • arc('Pitesti','Craiova',138).
  • arc('Pitesti','Bucharest',101).
  • arc('Rimnicu','Sibiu',80).
  • arc('Rimnicu','Pitesti',97).
  • arc('Rimnicu','Craiova',146).
  • arc('Sibiu','Arad',140).
  • arc('Sibiu','Oradea',151).
  • arc('Sibiu','Fagaras',99).
  • arc('Sibiu','Rimnicu',80).
  • arc('Timisoara','Arad',118).
  • arc('Timisoara','Lugoj',111).
  • arc('Urziceni','Bucharest',85).
  • arc('Urziceni','Hirsova',98).
  • arc('Urziceni','Vaslui',142).
  • arc('Arad','Zerind',75).
  • arc('Arad','Sibiu',140).
  • arc('Arad','Timisoara',118).
  • arc('Bucharest','Fagaras',211).
  • arc('Bucharest','Pitesti',101).
  • arc('Bucharest','Giurgiu',90).
  • arc('Bucharest','Urziceni',85).
  • arc('Craiova','Dobreta',120).
  • arc('Craiova','Rimnicu',146).
  • arc('Craiova','Pitesti',138).
  • arc('Dobreta','Mehadia',75).
  • arc('Dobreta','Craiova',120).
  • arc('Eforie','Hirsova',86).
  • arc('Fagaras','Sibiu',99).
  • arc('Fagaras','Bucharest',211).
  • arc('Giurgiu','Bucharest',90).
  • arc('Hirsova','Urziceni',98).
  • arc('Hirsova','Eforie',86).
  • arc('Iasi','Neamt',87).

93
??????
  • ?- best_first('Arad','Bucharest',Path).
  • Path 'Arad','Sibiu','Fagaras','Bucharest'

94
Start
Goal
95
Start
Goal
96
??????????? (???-????????) ??? ????? ????? ?????
(Arad ? Bucharest) ?????? ???? Sibiu, Rimnicu ?
Pitesti.
Neamt
Oradea
71
Zerind
87
Iasi
75
151
92
Arad
??????????? ??? ? (1408097101) 418 miles
140
140
118
Vaslui
99
Faragas
Sibiu
Sibiu
Timisoara
142
80
80
211
111
Rimnicu
Lugoj
98
Rimnicu
Urziceni
Hirsova
86
70
97
97
Pitesti
Pitesti
Mehadia
146
101
101
Bucharest
86
75
138
Dobreta
90
Craiova
120
Eforie
Giurgui
97
??????? ? ??? (Beam search)
  • ??????? ? ?????? ?? ???? - B
  • ??????? ?? ????????? ???? ???????? ?????? ?
    ????????? ??? ?? ???????? ?????????? ?????? ??
    ????????
  • ??? ??????? ? p1,p2, . . .,pB
  • ?????? ?? p1
  • ???????? p1', p1'',, p1(k) , ????? ??????????
    p1 ?? ??????? ??? ?????? ? ??? ?? ??????? ?
    ????????? ??? ?? ???????? ?? ????????q1,q2,...,qB
    k
  • ??????? ?? ??????? B (??????? ?? ????) ?? ????
    ???? ? ???-????? ??????, ?.?. q1,q2,...,qB
  • ?? ?????????? ?????? ?? ????????? ????? ???? ?
    ???-????? ?????? ??????, ?.?. q1

98
??????? ? ??? (Beam search)
  • beam_search(Beam,GoalPath_,Goal,FinalPath)-
  • reverse(GoalPath,FinalPath).
  • beam_search(Beam,PathList,Goal,FinalPath)-
  • extend(Path,NewPaths),
  • append(List,NewPaths,NewList),
  • sort(NewList,Goal,SortedList),
  • trim(Beam,SortedList,TrimedList),
  • beam_search(Beam,TrimedList,Goal,FinalPath).

99
??????? ? ??? (Beam search)
  • trim(N,XRest,XTrim)-
  • Ngt0,
  • M is N-1,
  • trim(M, Rest, Trim).
  • trim(_,_,).

100
??????? ? ??? (Beam search)
  • extend(NodePath,NewPaths) -
  • findall(NewNode,NodePath,
  • (arc(Node,NewNode,_),
  • not member(NewNode,NodePath)),
  • NewPaths).
  • reverse(,).
  • reverse(XRest,List)-
  • reverse(Rest,NewRest),
  • append(NewRest,X,List).

101
??????? ? ??? (Beam search)
  • sort(,Goal,).
  • sort(List,Goal,MinPathSortedList)-
  • min(List,Goal,MinPath,NewList),
  • sort(NewList,Goal, SortedList).
  • min(Path1List,Goal,Path2,Path1NewList)-
  • min(List,Goal,Path2,NewList),
  • h(Path1,Goal,H1),
  • h(Path2,Goal,H2),
  • H2ltH1,!.
  • min(PathList,Goal,Path,List).

102
????? ?? ??????????? (Hill Climbing)
  • ??????????? ?? ??????? ? ??? ? ?????? B1
  • ??????? ??????? ???? ???-?????? ????? ???
  • ??? ??????? ? p1
  • ???????? p1', p1'',, p1(k) , ????? ??????????
    p1 ?? ??????? ??? ?????? ? ??? ?? ??????? ?
    ????????? ??? ?? ???????? ?? ????????q1,q2,...,qk
  • ??? ?????? ?? ?????? ???? ???-?????? ??? q1
  • ?? ?????????? ?????? ?? ????????? ???? ?
    ???-????? ?????? ??????, ?.?. q1

103
????? ?? ??????????? (Hill Climbing) - 1
  • hill_climbing(List,Goal,FinalPath)-
  • beam_search(1,List,Goal,FinalPath).

104
????? ?? ??????????? (Hill Climbing) - 2
  • hill_climbing(GoalPath,Goal,FinalPath)-
  • reverse(GoalPath,FinalPath).
  • hill_climbing(Path,Goal,FinalPath)-
  • extend(Path,NewPaths),
  • best_path(NewPaths,Goal,BestPath),
  • hill_climbing(BestPath,Goal,FinalPath).

105
????? ?? ??????????? (Hill Climbing) - 2
  • extend(NodePath,NewPaths) -
  • findall(NewNode,NodePath,
  • (arc(Node,NewNode,_),
  • not member(NewNode,NodePath)),
  • NewPaths).
  • reverse(,).
  • reverse(XRest,List)-
  • reverse(Rest,NewRest),
  • append(NewRest,X,List).

106
????? ?? ??????????? (Hill Climbing) - 2
  • best_path(Path1List,Goal,Path2)-
  • best_path(List,Goal,Path2),
  • h(Path1,Goal,H1),
  • h(Path2,Goal,H2),
  • H2ltH1,!.
  • best_path(PathList,Goal,Path).

107
A
  • ??????? ?? ????????? ???? ???????? ?????? ?
    ????????? ??? ?? ???????? ?????????? ?????? ??
    ????????
  • ??? ??????? ? p1,p2, . . .,pn
  • ?????? ?? p1
  • ???????? p1', p1'',, p1(k) , ????? ??????????
    p1 ?? ??????? ??? ?????? ? ??? ?? ??????? ?
    ????????? ??? ?? ???????? ?? ????????q1,q2,...,qn
    k
  • ?? ?????????? ?????? ?? ????????? ????? ???? ?
    ???-????? ?????? ??????, ?.?. q1

108
h
frontier
g
start node
unexplored nodes
explored nodes
f gh
109
A
  • a_star(GoalPath_,Goal,FinalPath)-
  • reverse(GoalPath, FinalPath).
  • a_star(PathList,Goal,FinalPath) -
  • extend(Path,NewPaths),
  • append(List,NewPaths,NewList),
  • sort(NewList,Goal,SortedList),
  • a_star(SortedList,Goal,FinalPath).

110
A
  • sort(,Goal,).
  • sort(List,Goal,MinPathSortedList)-
  • min(List,Goal,MinPath,NewList),
  • sort(NewList,Goal, SortedList).
  • min(Path1List,Goal,Path2,Path1NewList)-
  • min(List,Goal,Path2,NewList),
  • f(Path1,Goal,F1),
  • f(Path2,Goal,F2),
  • F2ltF1,!.
  • min(PathList,Goal,Path,List).

111
A
  • h(NodePath,Goal, H) -
  • stright_line_distance(Node,Goal,H).
  • f(Path,Goal,F) -
  • reverse_path_cost(Path,G),
  • h(Path,Goal,H),
  • F is GH.
  • reverse_path_cost(A,B,Cost) -
  • arc(B,A,Cost).
  • reverse_path_cost(A,BPath,Cost) -
  • arc(B,A,Cost1),
  • reverse_path_cost(BPath,Cost2),
  • Cost is Cost1Cost2.

112
A
  • extend(NodePath,NewPaths) -
  • findall(NewNode,NodePath,
  • (arc(Node,NewNode,_),
  • not member(NewNode,NodePath)),
  • NewPaths).
  • reverse(,).
  • reverse(XRest,List)-
  • reverse(Rest,NewRest),
  • append(NewRest,X,List).

113
??????????? (???-????????) ??? ????? ????? ?????
(Arad ? Bucharest) ?????? ???? Sibiu, Rimnicu ?
Pitesti.
Neamt
Oradea
71
Zerind
87
Iasi
75
151
92
Arad
??????????? ??? ? (1408097101) 418 miles
140
140
118
Vaslui
99
Faragas
Sibiu
Sibiu
Timisoara
142
80
80
211
111
Rimnicu
Lugoj
98
Rimnicu
Urziceni
Hirsova
86
70
97
97
Pitesti
Pitesti
Mehadia
146
101
101
Bucharest
86
75
138
Dobreta
90
Craiova
120
Eforie
Giurgui
114
????? ?? ???????, ????????? ????????? ?? f
380, f 400 ? f 420 ??? ??????? ?????????
Arad. ????????? ??????????? ????? ? ??????
?????? ???? ?????? f ??-????? ????????? ??
?????????? ?? ???? ??????.
Zerind
Oradea
420
400
380
Arad
Fagaras
Sibiu
Rimnicu
Timisoara
Bucharest
Pitesti
Craiova
115
????????? ????????? ? Arad. ?????? ?? ?????????
?? Arad ?? Arad (?????????? ?? g) ? 0 miles.
???????????? ?? ????? ????? ?? Arad ?? Bucharest
(?????????? ?? h ) ? 366 miles. ?????? ?????? ?
( f g h ) 366 miles.
Zerind
Oradea
F 75 374 F 449
F 291 380 F 671
F 0 366 F 366
Arad
Fagaras
Sibiu
F 239 178 F 417
F 140 253 F 393
Bucharest(2)
F 220 193 F 413
F 118 329 F 447
F 450 0 F 450
Rimnicu
Timisoara
Bucharest
Bucharest
Bucharest
Bucharest
F 418 0 F 418
Pitesti
F 317 98 F 415
Craiova
F 366 160 F 526
116
8-puzzle
Y
1
2
3
Value / X / Y
3
4
5
6
1/1/3, 2/2/3, 3/3/3, 4/1/2, 5/2/2, 6/3/2,
7/1/1, 8/2/1, nil/3/1
2
7
8
nil
1
3
2
1
X
117
8-puzzle
Y
Manhattan Distance D Xi-Xj Yi-Yj
1
2
3
3
4
5
6
2
7
8
nil
1
3
2
1
X
118
Start
Goal
119
(No Transcript)
120
(No Transcript)
Write a Comment
User Comments (0)
About PowerShow.com