.


:




:

































 

 

 

 





, , . , , , , (. 11.7).

. 11.7. : a , f j .

, , , , : , . , d. . f. , la, , f ], , , [a,b,e,j]

. , , , . , . , . . , breadth first (Faths, Solution)

, Paths . Solution.

238 II. Prolog


: , . , , , . , , :

[ (StartHode] ]

.

:

,
;


,
,

,

, . 11.7, , .

1. : ])

2. []:

[ [,], [,*] ]

( , .)

3. , [,],
:

[ [d,b,a], te,b,a])

: [ [, a] r (d,b,a), [e,b,a] ]

4. [,)
, :

[ [d,b,a], [e,b,a], [f,c,a], [g,c,a] ]

[d,b,a] [,,]

[ [f,c,s], [g,c,a], [h,d,b,aj, Ji,e,b,a], [j,e,b,a) i

[f,c,a], , f, .

, , 11.3. . . , , , bagof bresdthfirst. member cone, , .


11.



 


 

11.3.

 

% solve(Start, Solution):

Solution ( ) Start

solve(Start, Solution):-

breadthfirst([ [Start] ], Solution).

* breadthfirstt [ Pathl, Path2,...], Solution):

Solution

breadthfirstt [ [Node | Path] _], [Node l Path]):-goal(Mode).

breadthfirstI [Path j Paths], Solution):-extend; Path, KewPaths), concl Paths, NewPaths, Pathsl), breadthfirst! Pathsl, Solution).

extend! [Node I Path], NewPaths):-bagoft [NewNode, Node [ Path],

(s< Node, NewNode), not member NewNode, [Node I Path} }),

NewPathsi,

% , bagof, % , Node extend (Path, [] >.

. (. 8). , Paths Z, . Paths -

, 11.3, , 11.4. .

11.4. 11.3; . extand 11.3

* soivef Start, Solution):

Solution (

% .) Start

solve{ Start, Solution):-

breadthfirst! [ [Start] I Z] - Z, Solution).

breadthfirstt ((Node I Path] I _] - _, [Node I Path]):-goal (Node >.

breadthfirst: [Path Paths] - Z, Solution) extend! Path, NewPaths;,

cone NewPaths, SI, Z), % NewPaths

Paths \ Zl, I -

breadthfirstt Paths - Zi, Solution).

240 II. Prolog


11.6. , , . , = 2 d = 3, , ( ). K(b,d> , . , N(b, d] N[ b, a - 1).

11.7. , 11.3, , , , 11.4. , , 11.4:

Paths s~ z:

, , ; , . 11.7. : , .

11.8. , , , ?

11.9. , , , ( , )? : s. ?

 

11.10. ; .. . , . ( s) , , , .

11.11. , final, find2 find3, , . .

findK Mode, [Mode]):-

goal(Node).

findN Mode, [Node | Path]):-

find2< Node, Path):-

conc( Path, ,_ \, conc/3 find:: Node, Pa~th).

find3(Node,- Path):-goal! Goal), find3: Node, [Goal], Path).

finds (Node, [Mode | Path], [Node I Path]).

finds(Node, [Node2 |?athZ], Path):-s(Nodel, Node2), find3(Node, [Nodel, Kode2 [ Path2], Path}.


11.



11.12.
:

% search* Start, Pathl - Fath2): - S Solution - Pathl Path2 search S, PI - 2) ■-

similar length[ PI, P2>, %

goal G),

path2 (G, 2, ),

pathl [ S, PI, 8).

pathl (N, [H], N).

pathl (First, [First [ Rest], Last):-s (First, Second), pathl; Second, Rest, Last). path2(, [N], N).

path2(First, [First I Rest], Last):-s(Second, First), path2 (Second, Rest, Last).

similar_length{ Listl, List2}:- %
equalJLength! List2, List), i

{ Listl = List; Listl = [_ I List]!.

equal_length([],[]).

equal_length[ [xl | Li), [X2 | L2]):-equal_length'[Ll, L2 i.

11.13. .

11.14. , , , . . , , . , 11.3 11.4, ,


 






:


: 2015-10-01; !; : 613 |


:

:

. .
==> ...

1738 - | 1664 -


© 2015-2024 lektsii.org - -

: 0.027 .